style-transfer-of-arbitrary-region

This is the code for the paper: Local Perceptual Loss Function for Arbitrary Region Style Transfer (ICPR2018 under reviewing)

About

This is a tensorflow implementation of a conditional style transfer network which is trained to realize style transfer of arbitrary region. The conditional transfer network has two inputs, one is content image, the other one is a mask image. For example, if we want to change the left half part pf the content image, we only need to feed the content image and the correspodding mask to the model. The result is shown as image

Usage

You can download all trained models from here Baidu Yun

python stylize_image.py --content <content image> --mask <mask image> --model-path <model-path> --output-path <output image path>

For example:

python stylize_image.py --content content/dog.jpg  --mask mask/mask1.jpg  --model-path logfile_night/night.ckpt --output-path stylized_image.jpg

Train

The content image can be downloaded from coco. The pre-trained vgg19 modelfile can be downloaded from VGG19. Then you can train a new model as

python train_network.py --style <style_image> --train-path <the content image folder> --save-path <the save path> --vgg-path <the pretrained vgg19 model>

for example

python train_network.py --style style/style1.jpg --train-path train2014 --save-path logfile --vgg-path imagenet-vgg-verydeep-19.mat

Sample results

image

When look at the above results,we will find that there are some defect at the edge of the stylized picture.Therefore we can combine the origin content image with the stylized picture to generate more beautiful one. You can run

python final_generate.py --content <content image> --mask <mask image> --stylized <generate image> --output-path <output image save path>

for example :

python final_generate.py --content car.jpg --mask mask_car.jpg --stylized stylize_car.jpg --output-path final_car.jpg

The finnal results are as follow: image