• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A dockerized version of neural style transfer algorithms

neural-style-docker

Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker Stylized Docker

A dockerized version of neural style transfer algorithms. nvidia-docker is used to make use of GPU hardware.

Install

Prerequisites

Installation

You can either pull the Docker image from Docker Hub with

docker pull albarji/neural-style

or build the image locally with

make

Usage

This docker container operates by receiving images through a volume to be mounted at the /images directory. For instance, to apply a style image somestyle.png onto a content image somecontent.png located at the current directory, run:

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content somecontent.png --style somestyle.png

All paths referenced in the arguments are regarded as relative to the /images folder within the container. So in case of having a local structure such as

contents/
    docker.png
    whatever.jpg
styles/
    picasso.png
    vangogh.png
results/
    something.md

applying the vangogh.png style to the docker.png image amounts to

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png --style styles/vangogh.png

You can provide several content and style images, in which case all cross-combinations will be generated.

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png contents/whatever.jpg --style styles/vangogh.png styles/picasso.png

By default all generated images are saved into the container /images. When running the commands above the results will get saved into the host local folder (through the mounted volume). If you want to locate the generated images at a different folder you can use the --output parameters. Note that, similarly to the --content and --style arguments, the path provided in --output will be regarded as relative to the /images folder. For instance, using the local structure from the example above, saving the generated images in the "results" folder will require the following:

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png --style styles/vangogh.png --output results

Fine tuning the results

Better results can be attained by modifying some of the transfer parameters.

Algorithm

The --alg parameter allows changing the neural style transfer algorithm to use.

  • gatys: highly detailed transfer, slow processing times (default)
  • gatys-multiresolution: multipass version of Gatys method, provides even better quality, but is also much slower
  • chen-schmidt: fast patch-based style transfer
  • chen-schmidt-inverse: even faster aproximation to chen-schmidt through the use of an inverse network

The following example illustrates kind of results to be expected by these different algorithms

Content image Algorithm Style image
Content Gatys Gatys Style
Content Gatys Multiresolution Gatys-Multiresolution Style
Content Chen-Schmidt Chen-Schmidt Style
Content Chen-Schmidt Inverse Chen-Schmidt Inverse Style

Output image size

By default the output image will have the same size as the input content image, but a different target size can be specified through the --size parameter. For example, to produce a 512 image

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png --style styles/vangogh.png --size 512

Note the proportions of the image are maintained, therefore the value of the size parameter is understood as the width of the target image, the height being scaled accordingly to keep proportion.

If the image to be generated is large, a tiling strategy will be used, applying the neural style transfer method to small tiles of the image and stitching them together. Tiles overlap to provide some guarantees on overall consistency, though results might vary depending on the algorithm used.

Tiling

The size of these tiles is defined through the configuration file gpuconfig.json inside the container. This file contains dictionary keys for different GPU models and each neural style algorithm. Your GPU will be automatically checked against the registered configurations and the appropriate tile size will be selected. These values have been chosen to maximize the use of the available GPU memory, asumming the whole GPU is available for the style transfer task.

If your GPU is not included in the configuration file, the default values will we used instead, though to obtain better performance you might want to edit this file and rebuild the docker images.

Note also that since the full style image is applied to each tile separately, as a result the style features will appear as smaller in the rendered image.

Style weight

Gatys and Gatys Multiresolution algorithms allow to adjust the amount of style imposed over the content image, by means of the --sw parameter. By default a value of 5 is used, meaning the importance of the style is 5 times the importance of the content. Smaller weight values result in the transfer of colors, while higher values transfer textures and even objects of the style.

If several weight values are provided, all combinations will be generated. For instance, to generate the same style transfer with three different weights, use

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png --style styles/vangogh.png --sw 5 10 20

Note also that they Gatys Multiresolution algorithm tends to produce a stronger style imprint, and this you might want to use weight values smaller than the default (e.g. 3).

Style scale

If the transferred style results in too large or too small features, the scaling can be modified through the --ss parameter. A value of 1 keeps the style at its original scale. Smaller values reduce the scale of the style, resulting in smaller style features in the output image. Conversely, larger values produce larger features. Similarly to the style weight, several values can be provided

nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content contents/docker.png --style styles/vangogh.png --ss 0.75 1 1.25

Warning: using a value larger than 1 will increasy the memory consumption.

Transparency

Transparency values (alpha channels) are preserved by the neural style transfer. Note for instance how in the Wikipedia logo example above the transparent background is not transformed.

References

More Repositories

1

mixture-of-diffusers

Mixture of Diffusers for scene composition and high resolution image generation
Python
342
star
2

proxTV

Matlab and Python toolbox for fast Total Variation proximity operators
C++
206
star
3

neurowriter

Framework to imitate writing styles using deep learning
Python
91
star
4

deeprl-snes

Deep Reinforcement Learning methods to learn plays SNES games
Python
17
star
5

curso-analisis-textos

Curso de análisis de textos con técnicas de aprendizaje automático
Jupyter Notebook
15
star
6

big-things-2019

Source code and data for my talk at Big Things 2019
Jupyter Notebook
9
star
7

spainAI_hackathon_2020_pln

Solution awarded with #2 prize at the PLN task of the SpainAI Hackathon 2020
Jupyter Notebook
5
star
8

teaching-environments

Some conda environments I use for my lectures on machine learning
Python
5
star
9

caffe-demos

Data files and scripts to run Caffe deep learning demos
Python
5
star
10

toy-diffusion

A toy implementation of a diffusion model for low-dimensional data
Jupyter Notebook
4
star
11

texata2015-finals

Submission for Texata final round
Python
3
star
12

svm-playground

A playground to experiment with Support Vector Machine models in a visual way
Jupyter Notebook
3
star
13

texata2015-round1

Notebook for the ideal solution of the first round in the Texata 2015 competition
2
star
14

quantum-experiments

Some experiments with quantum computing
Jupyter Notebook
2
star
15

teachingbox

A Vagrant box I use for my machine learning lectures
2
star
16

guertena

Guertena is an easy to use, quality oriented python library for neural style transfer.
Python
2
star
17

style-swap-docker

A dockerized version of the Style Swap algorithm by rtqichen
Shell
1
star
18

teaching-environments-deeplearning

Environments for Deep Learning lectures
Python
1
star
19

deeprl-pong

Learning to play Pong through Deep Reinforcement Learning methods
Python
1
star
20

keras-gradcam-demo

Notebook demo on how to use Keras to classify images with Xception net, and obtain visual explanations with Grad-CAM
Jupyter Notebook
1
star
21

babellibrary

Some simple scripts to generate a book from the Library of Babel
Python
1
star