A library for style transfer
Project description
Gatys' Algorithm
- Start with a content image C, a style image S and a random image G
- Use a pretrained CNN model (authors used VGG) graph in Tensorflow and mark first 4 conv nodes
- Define your content cost as the L2 norm between conv4_2 node outputs of C and G
- Pass S and G to the graph and define style cost as the weighted sum of L2 norms of gram matrices at those 4 conv nodes between S and G
- Define the cost function as weighted sum of the content and style costs and the optimizer using Adam.
- Update the generated image by minimizing the cost.
- Repeat step 5 for some finite number (1000) of times after which hopefully we have a stylized image.
Johnson's Algorithm (only works for fixed style image S)
- We initialize a image transformation network N that produces the same shape output as input like a FCN
Training (Use MiniBatch SGD with Adam)
- Pass C through N to get a G.
- Pass C, S and G through VGG (We are going to use VGG as a loss network only)
- Define Feature reconstruction loss as L2 norm between features of layers of C and G. This works as content cost
- Define Style reconstruction loss as L2 norm between gram matrices of features of layers of S and G. This works as style cost. (The authors call these losses as perceptual loss functions)
- Resize each image in training dataset (80k from MS-COCO) to 256x256 and train N with batch size of 4 (thus making 20k batches) for 40 k iterations (thus 2 epochs for the entire dataset). Dont pass any batch through the network more than twice (We dont want N to tune to specific C images).
Inference
- Any new image C can be stylized just by passing it through N. This makes it fast and deployable on devices like Android.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
style_transfer-0.0.2.tar.gz
(7.5 kB
view hashes)