Skip to content

Quick to run code to generate images with Neural Style Transfer in PyTorch.

Notifications You must be signed in to change notification settings

mkacki98/nst-wedding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Style Transfer

Easy to run Neural Style Transfer for a given content and style images.

I used it create a wedding gift!

Background on the method

Neural Style Transfer Gatys, 2015 is a ML technique in which a network is trained to generate an output image g from a content image c (e.g. a photograph) which resembles a style image s (e.g. Picasso painting).

Two prerequsities for a high-level understanding.

Firstly, VGG (Simonyan, 2015)[https://arxiv.org/abs/1409.1556] is a very large convolutional architecture trained on a benchmark image recognition task. As a result, the architecture learns how to pick up features of objects and can be used for transfer learning.

Secondly, last layers of convolutional architectures pick up high-level objects (like faces, buildings etc., the actual important bits in the picture).

In Gatys, 2015, both c and s are passed through VGG to create internal representations of the images. The loss function of the architecture then combines two parts - content and style loss.

Content loss measures how similar last layers of g and c are. The loss is 0 if they are exactly the same.

On the other hand, style loss measures how similar all activations of s and g are once passed through VGG.

You see these two losses are kind of pulling the way g will like in different directions (more like content or more like style). Since the final loss is a weighted combination of the two losses, by manipulating the weights you can shape the way the final image g will look like.

Setup

conda env create -f environment.yml

By default it runs using content-image.jpg and picasso.jpg, change --style parameter to a new of a style jpg file to change the style, play around with weights to manipulate changes to the input image.

python main.py --style lempicka --num_steps 10 --style_weight 10000000

Credits

Credits to Alexis Jackq.

About

Quick to run code to generate images with Neural Style Transfer in PyTorch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages