Home

Awesome

Style Transfer (Neural Style)

A tensorflow implementation of style transfer (neural style) described in the papers:

The implementation is coincided with the paper both in variable-names and algorithms so that a reader of the paper can understand the code without too much effort.

Usage

Prerequisites

  1. Tensorflow
  2. Python packages : numpy, scipy, PIL(or Pillow), matplotlib
  3. Pretrained VGG19 file : imagenet-vgg-verydeep-19.mat

      * Please download the file from link above.
      * Save the file under pre_trained_model

Running

python run_main.py --content <content file> --style <style file> --output <output file>

Example: python run_main.py --content images/tubingen.jpg --style images/starry-night.jpg --output result.jpg

Arguments

Required :

Optional :

Sample results

The Neckarfront in Tübingen, Germany

Results were obtained from default setting.
An image was rendered approximately after 4 mins on GTX 980 ti.

<p align="center"> <img src="images/tubingen.jpg" height="192px"> <img src="samples/tubingen_shipwreck.jpg" height="192px"> <img src="samples/tubingen_starry-night.jpg" height="192px"> <img src="samples/tubingen_seated-nude.jpg" height="192px"> <img src="samples/tubingen_the_scream.jpg" height="192px"> <img src="samples/tubingen_kandinsky.jpg" height="192px"> </p>

The Gyeongbokgung Palace in Seoul, South Korea

Results were obtained from default setting except --max_size 1200.
An image was rendered approximately after 19.5 mins on GTX 980 ti.

<p align="center"> <img src="images/gyeongbokgung.jpg" height="172px"> <img src="samples/gyeongbokgung_shipwreck.jpg" height="172px"> <img src="samples/gyeongbokgung_starry-night.jpg" height="172px"> <img src="samples/gyeongbokgung_seated-nude.jpg" height="172px"> <img src="samples/gyeongbokgung_the_scream.jpg" height="172px"> <img src="samples/gyeongbokgung_kandinsky.jpg" height="172px"> </p>

References

The implementation is based on the projects:

https://github.com/Hvass-Labs/TensorFlow-Tutorials/blob/master/15_Style_Transfer.ipynb

https://github.com/anishathalye/neural-style

https://github.com/cysmith/neural-style-tf

I went through these implementations and found some differences from each other.

  1. Style image shape : there are some variations how to resize a style image.
           In this implementation, a style image is resized to the shape of a content image.

  2. Optimizer : gradient descent, Adam, L-BFGS.
           In this implementation, only L-BFGS is provided.

  3. Scale factor of loss : scale factors for content-loss and style-loss are different.
           In this implementation, style loss is implemented as in the paper.
           About content loss, there are 3 choices.
           * Choice 1 : as in A Neural Algorithm of Artistic Style
           * Choice 2 : as in Artistic style transfer for videos
           * Choice 3 : as in https://github.com/cysmith/neural-style-tf

  4. Total variance denoising : implementation details for total variance denoising are slightly different.
           In this implementation, total variance denoising is not provided since the paper does not use it.

Acknowledgements

This implementation has been tested with Tensorflow r0.12 on Windows 10 and Ubuntu 14.04.