This repository contains the code (in TensorFlow) for the paper:
Avatar-Net: Multi-scale Zero-shot Style Transfer by Feature Decoration
Lu Sheng, Ziyi Lin, Jing Shao, Xiaogang Wang
CVPR 2018
In this repository, we propose an efficient and effective Avatar-Net that enables visually plausible multi-scale transfer for arbitrary style in real-time. The key ingredient is a style decorator that makes up the content features by semantically aligned style features, which does not only holistically match their feature distributions but also preserve detailed style patterns in the decorated features. By embedding this module into an image reconstruction network that fuses multi-scale style abstractions, the Avatar-Net renders multi-scale stylization for any style image in one feed-forward pass.
Method | Gatys et. al. | AdaIN | WCT | Style-Swap | Avatar-Net |
---|---|---|---|---|---|
256x256 (sec) | 12.18 | 0.053 | 0.62 | 0.064 | 0.071 |
512x512 (sec) | 43.25 | 0.11 | 0.93 | 0.23 | 0.28 |
Simply use the bash file ./scripts/evaluate_style_transfer.sh
to apply Avatar-Net to all content images in CONTENT_DIR
from any style image in STYLE_DIR
. For example,
bash ./scripts/evaluate_style_transfer.sh gpu_id CONTENT_DIR STYLE_DIR EVAL_DIR
gpu_id
: the mounted GPU ID for the TensorFlow session.CONTENT_DIR
: the directory of the content images. It can be ./data/contents/images
for multiple exemplar content images, or ./data/contents/sequences
for an exemplar content video.STYLE_DIR
: the directory of the style images. It can be ./data/styles
for multiple exemplar style images.EVAL_DIR
: the output directory. It contains multiple subdirectories named after the names of the style images.More detailed evaluation options can be found in evaluate_style_transfer.py
, such as
python evaluate_style_transfer.py
The detailed configuration of Avatar-Net is listed in configs/AvatarNet.yml
, including the training specifications and network hyper-parameters. The style decorator has three options:
patch_size
: the patch size for the normalized cross-correlation, in default is 5
.style_coding
: the projection and reconstruction method, either ZCA
or AdaIN
.style_interp
: interpolation option between the transferred features and the content features, either normalized
or biased
.The style transfer is actually performed in AvatarNet.transfer_styles(self, inputs, styles, inter_weight, intra_weights)
, in which
inputs
: the content images.styles
: a list of style images (len(styles)
> 2 for multiple style interpolation).inter_weight
: the weight balancing the style and content images.intra_weights
: a list of weights balancing the effects from different styles.Users may modify the evaluation script for multiple style interpolation or content-style trade-off.
tfexamples
, according to the python script ./datasets/convert_mscoco_to_tfexamples.py
.bash ./scripts/train_image_reconstruction.sh gpu_id DATASET_DIR MODEL_DIR
to start training with default hyper-parameters. gpu_id
is the mounted GPU for the applied Tensorflow session. Replace DATASET_DIR
with the path to MSCOCO training images and MODEL_DIR
to Avatar-Net model directory.If you find this code useful for your research, please cite the paper:
Lu Sheng, Ziyi Lin, Jing Shao and Xiaogang Wang, "Avatar-Net: Multi-scale Zero-shot Style Transfer by Feature Decoration", in IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2018. [Arxiv]
@inproceedings{sheng2018avatar,
Title = {Avatar-Net: Multi-scale Zero-shot Style Transfer by Feature Decoration},
author = {Sheng, Lu and Lin, Ziyi and Shao, Jing and Wang, Xiaogang},
Booktitle = {Computer Vision and Pattern Recognition (CVPR), 2018 IEEE Conference on},
pages={1--9},
year={2018}
}
This project is inspired by many style-agnostic style transfer methods, including AdaIN, WCT and Style-Swap, both from their papers and codes.
If you have any questions or suggestions about this paper, feel free to contact me (lsheng@ee.cuhk.edu.hk)