A convolutional neural network performing style transfer between two images. Implemented with tensorflow
Uses a VGG-19 network pretrained on ImageNet Dataset. Middle layers activations of content image and style image are utilized to define a composite cost. Then the generated image is run through the network and the defined cost is optimized with Adam optimization algorithm with respect to the generated image input. That way the generated image changes from random pixels to a composition of the content and style images.
content image (C) + style image (S) = generated image (G)
The total cost is computed as follows
where
- Jcontent(C,G) : The L2 norm squared of the diffence of activations of content image(C) and generated image (G) in a particular layer of the network.
- Jcontent(S,G) : The Frobenius norm of the diffence of the Gramian matrices of activations for style image(S) and generated image (G), computed and averaged across five layers of the network.
- α,β : the relative weighing of the two costs to the total cost.
Execute style_transfer python script. By configuring content_image and style_image paths you can transfer style between your images. The input images must be 400x300 pixels (width/height). You can change the learning_rate, and the layers used for defining the cost J(C) and J(S), also you can tweak their relative weighing on the total cost.
The code will:
- Train the defined model for configurable number of iterations
- Every 100 iterations will store the generated image to the /output path.
Based on code and lectures from the Deeplearning.ai specialization.
Deeplearning.ai CNN course on Coursera.[1]
Leon A. Gatys, Alexander S. Ecker, Matthias Bethge, (2015). A Neural Algorithm of Artistic Style.[2]
Karen Simonyan and Andrew Zisserman (2015). Very deep convolutional networks for large-scale image recognition.[3]
MatConvNet. Pretrained VGG-19 network on imageNet.[4]