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.
As a photographer i find this interesting, since i have a large supply of my own material to apply this to 🙂
I hope you find this tutorial useful!
Assuming you have Ubuntu installed, lets get to it!
(copy/paste commands below to your terminal):
- Make sure everything is up to date
sudo apt-get update && sudo apt-get upgrade
- Install GIT
sudo apt-get install git
- Install LUA
sudo apt-get install lua5.2
- Install LuaRocks
sudo apt-get install luarocks
- Install LuaJIT
sudo apt-get install luajit.
- Install Torch
sudo curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-all | bash
- Install LoadCaffe
sudo apt-get install libprotobuf-dev protobuf-compiler
sudo luarocks install loadcaffe
- 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.
- Make sure you are in home directory
- Make directory
- Go into directory
- Clone Neural Style repo
sudo git clone https://github.com/jcjohnson/neural-style.git
- Go into directory
- 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:
- Make sure you are in correct directory
- 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:
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 decide to use the GPU on your Ubuntu box here’s how to do it:
(requires a CUDA capable card from Nvidia)
- Go to home directory
- 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
- Install repo
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
- Update packagelist
sudo apt-get update
- Install CUDA
sudo apt-get install cuda
- Reboot to load driver
- Check if card is being recognized
- Install CUDA backend for torch
sudo luarocks install cutorch
sudo luarocks install cunn
- Check if backend is working
sudo th -e "require 'cutorch'; require 'cunn'; print(cutorch)"
This should produce a output.
- Test with neural style
sudo th neural_style.lua -gpu 0 -print_iter 2
There are many possibilites with Neural style, here are some examples: