A TensorFlow implementation of neural style transfer with VGG19 (a working version of VGG19 is also included). This implementation is inspired by a deep learning course developed by deeplearning.ai. The default hyper parameters used in the model file have been fine tuned with the help of this great paper so the model should be able produce satisfactory results with most style-content combinations.
Download the following files and place them in the same directory to run the model
- imagenet-vgg-verydeep-19.mat - pretrained weights for VGG19
- synset.txt - (Optional) download only if you want to make predictions with the included VGG19 model.
To use the model for art style transferring, simply run the following code
model = NSTModel(content_path='content_img_path', style_path='style_img_path')
model.run()
The default image size is 224*224. Feel free to try out other sizes, make sure that the content image and the style image are the same size.
A (kind of inefficent) image loading and preprocessing function (load_image) is provided in utilities.py. Use this function to
-
Resize the input image by padding or cropping, pass in a new size shape=[height, width]. (Black bars as a result of padding will affect the output image.)
-
Convert the input image to BGR format by passing in bgr=True - this conversion is required by some VGG models. Does not seem to make a difference with the weights used in the projects.
-
Show the output image in a new window by passing in show_img=True - Cannot be used with image preprocessing as negative-valued pixels will not be displayed properly.
-
Preprocess the input image by passing in preprocess=True - subtract the vgg-means from the RGB channels of the input image.
The model only trains on CPUs since I only own a Mac. In most cases 50 (30 min) iterations can output suprisingly good results for the time given it is given. The model will improve very slowly from this point on.
Iter = 10 (Left) and iter = 20 (Right).
Iter = 30 (Left) and iter = 40 (Right).
Iter = 50 (Left) and iter = 200 (Right).
Iter = 460 (Left) and iter = 1110 (Right).
- Better Documentation when I have time
- Possible GPU version