Neural networks can do a lot. They can interpret images, understand our voices and translate conversations But did you know that they can also paint?
A recent research paper (entitled «Artistic Style Neural Algorithm») has sparked a wave of online discussions with several striking illustrative examples. In essence, the article discusses a technique for training a deep neural network to separate the art style from the structure of an image and combine the style of one image with the structure of another. The result of all this is that you can train a huge neural network to turn photographs into «neural paintings» that look like they were painted by famous artists — so-called «digital fakes».
Here are some examples from the article. The first image is the original. The later images are generated results and the drawing from which the sample was taken is shown in thumbnail.
The original researchers did not release their code, unfortunately. However, some intrepid programmers have been copying their results from the last few days and their code is available open source on the Internet. All you need to get started is a Linux machine and a little patience.
Today I will tell you how to do it and show you some of my own results. You can think of it as a loose extension of our DeepDream tutorial. It’s a little tricky, but anyone with a Linux machine can follow along — no programming experience required.
Software setup
First, if you’re not in a hurry or don’t have a Linux computer, you can still play around with DeepStyle with DeepForger bot on Twitter (send him the image and style and he will eventually respond with the results you want). If you want to process more images quickly (and with more control over the results), read on for a tutorial.
First of all, make sure you have the latest version ubuntu (14.04 is what I used). You should have at least a few extra gigabytes of hard drive space. For more information, see our tutorial on dual booting Ubuntu alongside Windows. You will also need superuser rights, so make sure you do this before you continue.
Basic tools
From the very beginning, this is an open source project, so we want to install git . Git is the gold standard for version control software . Pretty much every open source project worth knowing about is hosted on Github.
To download and install Git, just open a terminal and type » sudo apt-get install git
» and agree to the requirements of the installer.
Next: we’re going install some basic tools, necessary for the operation of the software.
Install Lua first. This is the language in which the tool is written. It’s pretty simple. Just type » sudo apt-get install lua5.2
” and follow the installation process.
Second, we’re going to get Luarox. It’s a tool that makes it easy to install other tools (don’t you love Linux?). To do this, enter » sudo apt-get install luarocks
» and follow sudo apt-get install luarocks
by installation.
Third, we are going to install Luajit. This is a timely compiler for Lua that will make our lives a little easier. Just type » sudo apt-get install luajit
«.
So far, so good.
Frameworks
Next, we’re going to install Torch, a scientific computing and machine learning framework that forms the backbone of the application. Unfortunately, it cannot be installed using apt-get (the standard Ubuntu package manager).
Luckily, they have a one-line installer that uses command line magic. Go back to your terminal and type » curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-all | bash
curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-all | bash
«.
When you’re done, type » luajit -ltorch
«. This will bring up the cutter interface and check that everything is installed correctly.
Way out of this.
Now we are going to install loadcaffe — package for the neural network. Install its only dependency by typing » sudo apt-get install libprotobuf-dev protobuf-compiler
«. You can then install the package itself using » sudo luarocks install loadcaffe"
.
Double checking dependencies
Finally, we’re going to pre-update some things, just to make sure everything runs smoothly.
Enter » sudo luarocks install image
to make sure your image pack is up to date. Then type » luarocks install nn
«, which will do the same for your «nn» package.
Setting the Deep Style
Good! At this point, we are ready to actually install the software itself. For the sake of cleanliness, create a new folder in your home directory (‘mkdir DeepStyle’). Then enter it using » cd Deepstyle
«. Now type » sudo git clone https://github.com/jcjohnson/neural-style.git".
Next, we need to download the model. Make a cup of coffee or something, it will take some time. Go back to the terminal and type » sudo sh models/download_models.sh
«. This will start a long, complicated download process. If it fails due to permission errors, try giving yourself read and write permissions to the appropriate folders using chmod.