- 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.
- Python 3.3+
- Tensorflow 1.3
- TensorCV
- 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.
-
Setup directories in file
main.py
.STYLE_PATH
- path of style imageCONTENT_PATH
- path of content imageVGG_PATH
- path of pre-trained VGG19 parametersSAVE_DIR
- path of saving result images
-
Download the pre-trained VGG parameters
- Download pre-trained VGG19 model here and put it in
VGG_PATH
.
- Download pre-trained VGG19 model here and put it in
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.
--style
: Name of style image.--content
: Name of content image.--cscale
: Rescale content image with larger side to becscale
ifcscale
> 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
.