Neurally Stylin

I’ve been playing with neural-style, a deep-learning algorithm that lets you apply the texture/style information from one image to the content of another image.

If you’d like to play with this on your own, and you’re comfortable with AWS, you can use the following script.

First, start an ami-ffba7b94 instance as g2.2xlarge. This is a Torch machine learning AMI. Currently, that costs $0.65/hour. If you do it as a spot instance, it’s way cheaper - more like $0.08 an hour. If you bid $0.10 or so, you’re very unlikely to get killed. This installs neural-style and creates a little shortcut doit script that takes input image, style, and size (pixels) as arguments. Don’t set size bigger than about 600 or it’ll run out of memory.

There are a ton more options you can set, read the neural-style docs.

# start a ami-ffba7b94 instance (Torch machine learning AMI)
# https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:ami=ami-ffba7b94
# on a g2.2xlarge instance. if you do it as a spot instance
# it is WAY cheaper and generally if you bid $0.10 or so you won't get killed.
# then run this script on your new instance and source .bashrc
# and you will have a nice little 'doit' script.
# make sure you source .bashrc or relogin after running this.

luarocks install image
luarocks install loadcaffe
luarocks install torch
echo "export LD_LIBRARY_PATH=/home/ubuntu/torch-distro/install/lib:/home/ubuntu/torch-distro/install/lib:/home/ubuntu/cudnn-6.5-linux-x64-v2-rc2" >> ~/.bashrc

git clone https://github.com/jcjohnson/neural-style
cd neural-style
sh models/download_models.sh

echo '#!/bin/bash

OUT=$(basename ${IMAGE%.jpg})_$(basename ${STYLE%.jpg}).png

th neural_style.lua -num_iterations 2000 -style_image $STYLE  -content_image $IMAGE -image_size $SIZE -backend cudnn -output_image $OUT
' > doit
chmod +x doit

The above link has some good examples; here’s some of my own output:

Ada-mew, applied to an abstract-ish image I got off etsy, The Starry Night, and a Louis Wain cat.

Celeste, applied to a Mandelbrot set, The Starry Night, and a Dr. Seuss image.

Celeste and Ariel, applied to Gustav Klimt.