How to create neural style art on your local machine

21 June 2022

This article explains every step needed to create "deep style" neural art in the style of deep dream generator.com on your own machine.

Deepdreamgenerator.com charges money to create high resolution art, but you can do it at home for free.

Here's an example of their "neural style" - where you combine an input image with a guide (or texture) image:

"Deep dream" versus "neural style"

There are two types of image merging to differentiate. Originally, Google developed "deep dream", a surreal style that mostly looks like a painting made of shiny dogs.

Later, the "neural style" was created (called "deep style" on deepdreamgenerator.com). This avoids the dogs and looks more like the image above. It's also called "style transfer".

Why Docker isn't a great option

At first, you might want to download a virtual machine or Docker image that has all the software you need already configured. There are lots of images available on hub.docker.com if you search for the terms in the last section.

However, the image merge process is highly GPU intensive. If you try to use only your CPU it will take far too long. And trying to install the NVIDIA CUDA framework inside a Docker image inside the WSL was more work than just installing everything on my main machine.

If you want to try get your GPU to work in Docker look at this article.

How to install

These are instructions for Windows. If you're using Apple or Linux things should be similar with only a few changes.

Here we go:

winget install python3 # you may have to do this twice to get it to run
python # to test it's installed
exit()
cd c:\dd
pip install -r requirements.txt
cls && python .\neural_style.py --content c:\dd\input.jpg --styles c:\dd\texture.jpg --output c:\dd\output.jpg --iterations 500 --overwrite

Problems

Here's an example of my input, texture, and output files (with and without color preservation):

We can see that choice of images makes a huge different to the appeal of the output. As do the merge settings.

Finally, I had trouble with images above 1920px resolution running out of memory. I need to investigate if there's a way to do this slower, but with less RAM. Otherwise there's no way to do resolutions detailed enough for large prints.

Anish Athalye recommends looking at https://github.com/lengstrom/fast-style-transfer for faster processing with less memory.