Arbitrary Style Transfer in TensorFlow js
This is an implementation of Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization on Tensorflow 2 and Tensorflow js. Demo website : https://cryu854.github.io/ArbitraryStyle-tfjs/
The model runs purely on your browser, so your data will not be leaked.
REFLECT_PADDING=True
to use reflection padding in both encoder and decoder to avoid border artifacts, but the model will not be able to be deployed on the browser.Use main.py
to stylize a content image to arbitrary style.
Stylization takes 29ms per frame(256x256) on a GTX 1080ti.
Example usage:
python main.py inference --content ./path/to/content.jpg \
--style ./path/to/style.jpg \
--alpha 1.0 \
--model ./path/to/pre-trainind_model
Use --alpha
to adjust the stylization intensity. The value should between 0 and 1 (default).
Use main.py
to train a new style transfer network.
Training takes 2.5~3 hours on a GTX 1080ti.
Before you run this, you should download MSCOCO and WikiArt dataset.
Example usage:
python main.py train --content ./path/to/MSCOCO_dataset \
--style ./path/to/WikiArt_dataset \
--batch 8 \
--debug True \
--validate_content ./path/to/validate/content.jpg \
--validate_style ./path/to/validate/style.jpg
Use tensorflow-js converter to generate a web friendly json model.
If you use reflection padding in encoder or decoder, the converter will not work properly because the current version of tensorflow-js does not support the mirrorpad operator.
Example usage:
tensorflowjs_converter --input_format=tf_saved_model --saved_model_tags=serve models/model models/web_model