Deepstyle

How to create your own deepstyle neural art with Ubuntu.

Want to buy my Deepstyle prints? Check out Redbubble.

Don’t know what “Deepstyle Neural Art” is?

This is based on the research paper by Leon A. Gatys, Alexander S. Ecker and Matthias Bethge, you can read about their findings here.

In short, you can apply styles from famous painters like Vincent van Gogh, Rembrandt, Edvard Munch or whomever you choose to your photos for a interesting effect.

As a photographer i find this interesting, since i have a large supply of my own material to apply this to 🙂

To get this to work you need a computer with Ubuntu 14.04 LTS installed, or you could rent a box in the cloud from Digitalocean.

Other useful software that you might want to have handy on your computer to transfer the output files from the Ubuntu box would be PuTTY (for issueing commands in SSH) and WinSCP (for file transfer).

I hope you find this tutorial useful!

 

Assuming you have Ubuntu installed, lets get to it!

Dependencies needed
(copy/paste commands below to your terminal):
  1. Make sure everything is up to date
    sudo apt-get update && sudo apt-get upgrade
  2. Install GIT
    sudo apt-get install git
  3. Install LUA
    sudo apt-get install lua5.2
  4. Install LuaRocks
    sudo apt-get install luarocks
  5. Install LuaJIT
    sudo apt-get install luajit.
  6. Install Torch
    sudo curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-all | bash
  7. Install LoadCaffe
    sudo apt-get install libprotobuf-dev protobuf-compiler
    sudo luarocks install loadcaffe
  8. Update LuaRocks needed for this
    sudo luarocks install paths
    sudo luarocks install sys
    sudo luarocks install image
    sudo luarocks install nn
    sudo luarocks install optim
Installing Neural Style:

We will be using Neural Style from Justin Johnson on Github.

  1. Make sure you are in home directory
    cd or cd ~
  2. Make directory
    mkdir DeepStyle
  3. Go into directory
    cd Deepstyle
  4. Clone Neural Style repo
    sudo git clone https://github.com/jcjohnson/neural-style.git
  5. Go into directory
    cd neural-style
  6. Download models (around 655MB download)
    sudo sh models/download_models.sh

After this you should be all setup for churning out neural art.

To get started:

  1. Make sure you are in correct directory
    cd ~/DeepStyle/neural-style
  2. Command for running Neural Style (without GPU)
    sudo th neural_style.lua -style_image NAMEOFPAINTING.jpg -content_image YOURPHOTO.jpg -gpu -1 -output_image NAMEOFOUTPUT.png
    This will output a image 512px wide, which is the default setting.
    Check Neural Style on Github for more information on parameters.

    You can change this by doing:
    sudo th neural_style.lua -style_image NAMEOFPAINTING.jpg -content_image YOURPHOTO.jpg -gpu -1 -image_size SIZEINPIXELS -output_image NAMEOFOUTPUT.png
    Be advised that the pixel size will affect how much RAM is used, for a 512px image you should have a minimum of 4GB RAM.
    Using a box in the cloud can help you with this, like Digitalocean.
Some of my results:
hallgrimskirkja_deepstyle

Hallgrimskirkja in Reykjavik, Iceland with the style of Charles Demuth (Style: right)

skogafoss_munch

Skogafoss in Iceland – “The Scream” Edvard Munch Style (Style: right)

hardanger_deepstyle

Styled from “Heart of the Andes” by Fredric Edwin Church (Style: middle)

bryggen_deepstyle

Bryggen in Bergen, Norway with the style of Charles Demuth (Style: right)

kvernufoss_giger

Kvernufoss in Iceland with style of H.R Giger (Style: right)

THE ART OF PATIENCE:

Generating these images can take time, depending on your hardware, with the use of GPU it will be a lot faster, or by using a cloud service like Digitalocean (non GPU, but quite affordable) or Amazon EC2 (for GPU cloud)

If you’re going with the Amazon EC2 (g2.2xlarge or g2.8xlarge) alternative there is a good tutorial on Reddit for this.

If you decide to use the GPU on your Ubuntu box here’s how to do it:
(requires a CUDA capable card from Nvidia)

  1. Go to home directory
    cd or cd ~
  2. Download repo from Nvidia
    sudo wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb
  3. Install repo
    sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
  4. Update packagelist
    sudo apt-get update
  5. Install CUDA
    sudo apt-get install cuda
  6. Reboot to load driver
    sudo reboot
  7. Check if card is being recognized
    nvidia-smi
  8. Install CUDA backend for torch
    sudo luarocks install cutorch
    sudo luarocks install cunn
  9. Check if backend is working
    cd ~/DeepStyle/neural-style
    sudo th -e "require 'cutorch'; require 'cunn'; print(cutorch)"
    This should produce a output.
  10. Test with neural style
    sudo th neural_style.lua -gpu 0 -print_iter 2
USES:

There are many possibilites with Neural style, here are some examples:


RESOURCES:

Justin Johnson @ Github – Neural Style

Deepdream @ Reddit

OpenCL support for Torch