Skip to content
Gary Boodhoo edited this page Apr 22, 2018 · 92 revisions

Welcome to Visual Strategies for Neural Artistic Style Transfer

Requirements:

  • Laptop running Windows or MacOS
  • A camera (phone or laptop camera ok)
  • A way to transfer image files from your camera to your laptop
  • Image editing software (any suitable application you are comfortable with, mobile apps are also fine)
  • 5-6 personal images to get started with

Background

Neural artistic style transfer is a method for repainting images in the style of other images using a neural network. The algorithm is computationally intensive because it must be run about a thousand times to produce a decent picture. The bigger the picture, the longer this takes. In order to create rapidly, we'll run these computations on a remote server.

The neural-style code was written by Justin Johnson, a PhD student in the Stanford Vision Lab. His work implements ideas described in the foundational paper, A Neural Algorithm of Artistic Style (Gatys, Ecker, Bethge, 1993). The "AI" for this workshop runs on an Amazon EC2 P3 server. This configuration is specific to this workshop and will only work for the time you're here. Ask me how to replicate this process at home if you're interested.

Getting Started

The server needs three inputs before it can synthesize an output:

The content image

This is the image to be styled

The style image

The neural net takes its stylistic cues from this image

The render script

This is a batch file which runs the neural-style algorithm upon the specified style and content images using specified parameters

#!/bin/bash
# Welcome to Visual Strategies for Neural Artistic Style Transfer!
# This script automates setup and rendering of neural style transfer imagery
# using Justin Johnson's neural-style repository
# https://github.com/jcjohnson/neural-style


# Replace this with the filename of your content image
# example:
# CONTENT_IMAGE=yourimagename.jpg (or .png)

CONTENT_IMAGE=content-4.jpg

# Replace this with the filename of your style image
# example:
# STYLE_IMAGE=yourimagename.jpg (or .png)

STYLE_IMAGE=style-basket.jpg

# Various parameters

STYLE_WEIGHT=8e3    # default = 5e2 | range 1e0 (1) - 10e5 (10000) 
CONTENT_WEIGHT=2e3  # default = 5e0 | range 1e0 (1) - 10e5 (10000) 
STYLE_SCALE=0.7     # default = 1.0 | range 0.1 - 2.0


#### SYSTEM ####
# some housekeeping

SCRIPT_NAME=`basename "$0"`
IMAGE_PATH=./pictures/
OUTPUT_IMAGE=./temp/${SCRIPT_NAME%.*}.png
NEURALSTYLE=../../neural-style/

# run neural style plz

th ${NEURALSTYLE}neural_style.lua \
  -content_image $IMAGE_PATH$CONTENT_IMAGE \
  -style_image $IMAGE_PATH$STYLE_IMAGE \
  -output_image $OUTPUT_IMAGE \
  -proto_file ${NEURALSTYLE}models/VGG_ILSVRC_19_layers_deploy.prototxt \
  -model_file ${NEURALSTYLE}models/VGG_ILSVRC_19_layers.caffemodel \
  -init image \
  -style_scale $STYLE_SCALE \
  -print_iter 100 \
  -content_weight $CONTENT_WEIGHT \
  -style_weight $STYLE_WEIGHT \
  -image_size 512 \
  -tv_weight 0 \
  -normalize_gradients \
  -backend cudnn -cudnn_autotune \
  -gpu 0 \

Let's configure a workspace on our laptops to connect with the server. We'll need a way to transfer files, and we also need a way to run scripts. By the way, no programming experience is required. I've already written the render scripts, but you will need to edit them to use filenames of your own pictures.

Setup

Setup for macOS
Setup for Windows