Home

Awesome

UniversalStyleTransfer

Torch implementation of our NIPS17 paper on universal style transfer.

TensorFlow implementation by Evan Davis.

PyTorch implementation I by Xueting Li and implementation II by Pietro Battilana.

MatConvNet implementation by Ryan Webster.

Universal style transfer aims to transfer arbitrary visual styles to content images. As long as you can find your desired style images on web, you can edit your content image with different transferring effects.

<img src='figs/p3.jpg' width=800>

Prerequisites

Style transfer

th test_wct.lua -content YourContentPath -style YourStylePath -alpha 0.6
th test_wct.lua -contentDir YourContentDir -styleDir YourStyleDir -alpha 0.6

By default, we perform WCT (whitening and coloring transform) on conv1-5 features. The "-alpha" serves as the style weight to control the transfer effect. Some transfer results and comparisons with existing methods are shown here.

For comparison, we replace WCT with AdaIN (adaptive instance normalization), another way of transform proposed in [Huang et al., ICCV17].

th test_adain.lua -content YourContentPath -style YourStylePath

Texture synthesis

By setting the content image as a random noise image, our stylization framework can be easily applied to texture synthesis. Different input noise leads to diverse synthesis results. Moreover, we can adjust the parameter "-styleSize" as a kind of scale control to obtain different effects.

th test_wct.lua -style YourTexturePath -synthesis 1 -styleSize 512
<img src='figs/p4.jpg' width=800>

Interpolation

Our method also supports the transferring or synthesis of multiple styles thourgh interpolation. Below is an example of handling two styles. The "-beta" serves as the intepolation weight.

th test_wct_interpolation2.lua -content YourContentPath -style YourStylePath1,YourStylePath2 -beta 0.5
<img src='figs/p6.jpg' width=800>
th test_wct_interpolation2.lua -style YourTexturePath1,YourTexturePath2 -beta 0.5 -synthesis 1
<img src='figs/p5.jpg' width=800>

Below we show an example of texture synthesis path from t1 (left) to t2, then t3, ..., to t8 and back to t1. We also try the Neural 3D Mesh Renderer to apply the synthesized texture on a 3D Mesh.

<p> <img src='figs/t.jpg' height=100 width=100 /> <img src='figs/t0.jpg' height=100 width=100 /> <img src='figs/t3.jpg' height=100 width=100 /> <img src='figs/t4.jpg' height=100 width=100 /> <img src='figs/t5.jpg' height=100 width=100 /> <img src='figs/t6.jpg' height=100 width=100 /> <img src='figs/t7.jpg' height=100 width=100 /> <img src='figs/t8.jpg' height=100 width=100 /> </p> <p> <img src='figs/white.jpg' height=100 width=100 /> <img src='figs/white.jpg' height=100 width=100 /> <img src='figs/texture_interpolation.gif' width=200 /> <img src='figs/3D_render.gif' width=200 /> </p>

Spatial control

Often times, the one-click global transfer still does not meet requirements from professinal users (e.g., artists). Users prefer to transfer different styles to different regions in the content image, i.e., spatial control. We provide an example of transferring two styles to the foreground and background respectively, i.e., Style I for foreground (mask=1), Style II for background (mask=0), provided a binary mask.

th test_wct_mask.lua -content YourConentPath -style YourStylePath1,YourStylePath2 -mask YourBinaryMaskPath
<img src='figs/p2.jpg' width=800>

Swap on conv5

We also include the Style-swap function in our algorithm. For each whitened content feature patch, we swap it with nearest whitened style feature patch. Please refer to the Style-swap paper for more details.

We provide a parameter "-swap5" to perform swap operation on conv5 features. As the swap operation is computationally expensive (searching nearest patches), we do not carry out the swapping on early layers with large feature maps (e.g., conv1-4).

th test_wct.lua -content YourContentPath -style YourStylePath -swap5 1

Below is an exemplary comparison between w/o and w/ swap operation on conv5. With the swapping, the eyeball in the content is replaced with the ball in the style (bottom) as they are cloeset neighbours in whitened feature space.

<img src='figs/p1.jpg' width=840>

Note

Citation

@inproceedings{WCT-NIPS-2017,
    author = {Li, Yijun and Fang, Chen and Yang, Jimei and Wang, Zhaowen and Lu, Xin and Yang, Ming-Hsuan},
    title = {Universal Style Transfer via Feature Transforms},
    booktitle = {Advances in Neural Information Processing Systems},
    year = {2017}
}

User study

A common issue in style transfer is the evaluation. To understand the user preference, we conduct a user study to evaluate 5 methods shown in Figure 6 of our paper. We appreciate your help if you can spend 3~4 minutes on this study. Check the updated feedback here from extensive users. Please be polite and serious on results and comments.

Acknowledgement