Skip to content

TensorFlow implementations of art style transfer, such as Neural Style.

License

Notifications You must be signed in to change notification settings

conan7882/neural-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Style

  • TensorFlow implementation of A Neural Algorithm of Artistic Style (2015).
  • This paper combines the content and style of two different images by matching features extracted from a pre-trained CNN (for image classification task).
  • The style transfer process proposed in this paper is an optimization process, which minimizes the difference of content and style features between the output image and input context and style images.

Requirements

Implementation Details

  • VGG19 features are used as mentioned in the original paper. Content Layer is conv4_2 and style layers are conv1_1, conv2_1, conv3_1, conv4_1 and conv5_1.
  • Inspired by this implementationn, both content and style features are normalized based on the size of content and style images, respectively. I found this is useful especially when two input images have large difference in size.
  • The output image is initialized by the content image, which helps to obtain a good output image faster.
  • The weights for content and style costs used in this implementation are 5e-4 and 0.2, respectively. If the output image initialized from a random noise, maybe higher content cost is needed.
  • Total variation regularization is used to reduce noise in the output image. The weight 0.01 is used for total variation regularization.
  • L-BFGS is used for optimization. The maximum iteration is set to be 500, though the result does not change after 200 iterations.

Result

Preparation

  1. Setup directories in file main.py.

    • STYLE_PATH - path of style image
    • CONTENT_PATH - path of content image
    • VGG_PATH - path of pre-trained VGG19 parameters
    • SAVE_DIR - path of saving result images
  2. Download the pre-trained VGG parameters

    • Download pre-trained VGG19 model here and put it in VGG_PATH.

Run Script:

Put style and content images in STYLE_PATH and CONTENT_PATH, then run:

python main.py --save --style STYLE_IM_FILE --content CONTENT_IM_FILE
  • Result will be saved in SAVE_DIR every 20 iteraton.

Argument

  • --style: Name of style image.
  • --content: Name of content image.
  • --cscale: Rescale content image with larger side to be cscale if cscale > 0. Default: 0.
  • --rescale: Whether rescale the style image to the size comparable to the content image or not if the style image is larger than the content image in width or height. Default: False.
  • --wstyle: Weight of style cost for optimization. Default: 0.2.
  • --wcontent: Weight of content cost for optimization. Default: 5e-4.
  • --wvariation: Weight of total variation for optimization. Default: 0.1.
  • --maxiter: Maximum number of iterations. Default: 500.
  • --save: Whether save the result or not. Default: False.

Releases

No releases published

Packages

No packages published

Languages