This is a TensorFlow implementation for performing style transfer using neural networks. The code uses key ideas from the Perceptual Losses for Real-Time Style Transfer and Super-Resolution and A Neural Algorithm of Artistic Style papers.
The code is written in Python 3.5+ and uses TensorFlow. The requirements
can be found in top-requirements.txt and installed using
pip install -r top-requirements.txt.
For training a model from scratch, we need to specify a folder containing the
content images and the path to the style image. For example, assuming we've
downloaded the MS COCO 2014 dataset and put
the training images to data/train. We can train a model to apply the style of
images/style/wave.jpg with the command
python3 train.py --style=images/style/wave.jpg --train_path=data/train --weights_path=weights/wave.hdf5This will produce a weights file that we can use to generate new images from unseen content images 🎉.
--stylePath to style image. Required.--trainPath to training (content) images. Required.--weightsPath where to save the model's weights. Required.
We can style new content images from a path or from a webcam 📷.
For example, for styling images/content/viaducto.jpg with weights located
in weights/wave.hdf5 run
python3 style.py --content=images/content/viaducto.jpg --weights=weights/wave.hdf5For styling from a webcam feed, run
python3 style.py --weights=weights/wave.hdf5 --webcam--contentPath to content image. Required if--webcamisn't used.--genPath where to save the generated image. If it isn't provided the image will be shown on screen.--weightsPath to model's weights. Required.--webcamGenerate images from the webcam. Can't be used if a content image is specified.
Weights for models trained on the style images found in images/style/ can be
found under releases.
These are the loss weights used during training for some style images
(which can be found in images/style/)
wave:- Content weight: 1
- Style weight: 100
- Total variation weight: 1e-5
mosaic:- Content weight: 3
- Style weight: 100
- Total variation weight: 1e-5


