Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

neural-style simple docker container

Notifications You must be signed in to change notification settings

octavflorescu/neural-style

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUDA 10.1 implementation of

neural-style docker

This is a docker implementation of jcjohnson neural-style solution.

This docker container allows you to easily run complicated neural networks with any of your images. Just install this docker container, run one command and get result. No configuration required. Only if you run with CUDA...

Latest version available on github https://github.com/ffedoroff/neural-style and docker-hub https://hub.docker.com/r/ffedoroff/neural-style/

original description (by jcjohnson)

This is a torch implementation of the paper A Neural Algorithm of Artistic Style by Leon A. Gatys, Alexander S. Ecker, and Matthias Bethge.

The paper presents an algorithm for combining the content of one image with the style of another image using convolutional neural networks. Here's an example that maps the artistic style of The Starry Night onto a night-time photograph of the Stanford campus:

Applying the style of different images to the same content image gives interesting results. Here we reproduce Figure 2 from the paper, which renders a photograph of the Tubingen in Germany in a variety of styles:

Here are the results of applying the style of various pieces of artwork to this photograph of the golden gate bridge:

Setup

0. Preparations for CUDA running on Ubuntu docker

0.1. Install Ubuntu OS

Make sure you have enough space for docker images
20GB for Ubuntu OS + ~10GB for docker images + something extra

0.2. Install nvidia driver, cuda, cudnn on your main OS

I have followed this: https://medium.com/repro-repo/install-cuda-10-1-and-cudnn-7-5-0-for-pytorch-on-ubuntu-18-04-lts-9b6124c44cc
When this gets outdated, before building/running the docker, do not forget to also update its starting (source) nvidia docker cuda image.

1. Install docker

Install docker using that instructions

1.1. Install nvidia-docker for CUDA usage

2. Install this container

docker pull ffedoroff/neural-style

2.1. Or build it yourself for CUDA

cd ~/neural-style
(sudo) docker build -t neural_transfer .

Run

You should create folder on local computer for your source and style images. For example:

mkdir ~/prism/01/

You should put images into that folder. For example style.jpg and source.jpg.

Then you should run docker container connected to your local folder with lua script, and after 4-7 hours of processing magic happened.

docker run -v ~/prism/01:/out -i -t ffedoroff/neural-style th neural_style.lua -gpu -1 \
-style_image style.jpg -content_image source.jpg

You can check results in your local ~/prism/01/ folder

If you close console windows, the process will terminate. So if you want to run it in background, add -d parameter. You can also run as much instances as you want. But point it into different local folders.

docker run -v ~/prism/01:/out -i -d -t ffedoroff/neural-style th neural_style.lua -gpu -1 \
-style_image style.jpg -content_image source.jpg

docker run -v ~/prism/02:/out -i -d -t ffedoroff/neural-style th neural_style.lua -gpu -1 \
-style_image style.jpg -content_image source.jpg

docker run -v ~/prism/03:/out -i -d -t ffedoroff/neural-style th neural_style.lua -gpu -1 \
-style_image style.jpg -content_image source.jpg

CUDA:

nvidia-docker run -v ~/prism/03:/out -i -d -t neural_transfer th neural_style.lua \
              -gpu 0 -backend cudnn -cudnn_autotune \
              -style_image style.jpg -content_image source.jpg

options

To use multiple style images, pass a comma-separated list like this:

-style_image starry_night.jpg,the_scream.jpg.

Note that paths to images should not contain the ~ character to represent your home directory; you should instead use a relative path or a full absolute path.

Options:

  • -image_size: Maximum side length (in pixels) of of the generated image. Default is 512.
  • -style_blend_weights: The weight for blending the style of multiple style images, as a comma-separated list, such as -style_blend_weights 3,7. By default all style images are equally weighted.
  • -gpu: Zero-indexed ID of the GPU to use; for CPU mode set -gpu to -1.

Optimization options:

  • -content_weight: How much to weight the content reconstruction term. Default is 5e0.
  • -style_weight: How much to weight the style reconstruction term. Default is 1e2.
  • -tv_weight: Weight of total-variation (TV) regularization; this helps to smooth the image. Default is 1e-3. Set to 0 to disable TV regularization.
  • -num_iterations: Default is 1000.
  • -init: Method for generating the generated image; one of random or image. Default is random which uses a noise initialization as in the paper; image initializes with the content image.
  • -optimizer: The optimization algorithm to use; either lbfgs or adam; default is lbfgs. L-BFGS tends to give better results, but uses more memory. Switching to ADAM will reduce memory usage; when using ADAM you will probably need to play with other parameters to get good results, especially the style weight, content weight, and learning rate; you may also want to normalize gradients when using ADAM.
  • -learning_rate: Learning rate to use with the ADAM optimizer. Default is 1e1.
  • -normalize_gradients: If this flag is present, style and content gradients from each layer will be L1 normalized. Idea from andersbll/neural_artistic_style.

Output options:

  • -output_image: Name of the output image. Default is out.png.
  • -print_iter: Print progress every print_iter iterations. Set to 0 to disable printing.
  • -save_iter: Save the image every save_iter iterations. Set to 0 to disable saving intermediate results.

Layer options:

  • -content_layers: Comma-separated list of layer names to use for content reconstruction. Default is relu4_2.
  • -style_layers: Comma-separated list of layer names to use for style reconstruction. Default is relu1_1,relu2_1,relu3_1,relu4_1,relu5_1.

Other options:

  • -style_scale: Scale at which to extract features from the style image. Default is 1.0.
  • -original_colors: If you set this to 1, then the output image will keep the colors of the content image.
  • -proto_file: Path to the deploy.txt file for the VGG Caffe model.
  • -model_file: Path to the .caffemodel file for the VGG Caffe model. Default is the original VGG-19 model; you can also try the normalized VGG-19 model used in the paper.
  • -pooling: The type of pooling layers to use; one of max or avg. Default is max. The VGG-19 models uses max pooling layers, but the paper mentions that replacing these layers with average pooling layers can improve the results. I haven't been able to get good results using average pooling, but the option is here.
  • -backend: nn, cudnn, or clnn. Default is nn. cudnn requires cudnn.torch and may reduce memory usage. clnn requires cltorch and clnn
  • -cudnn_autotune: When using the cuDNN backend, pass this flag to use the built-in cuDNN autotuner to select the best convolution algorithms for your architecture. This will make the first iteration a bit slower and can take a bit more memory, but may significantly speed up the cuDNN backend.

About

neural-style simple docker container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 40.9%
  • Dockerfile 35.2%
  • Shell 23.9%