Skip to content
This is the Pytorch implementation of "Learning Linear Transformations for Fast Arbitrary Style Transfer".
Python
Branch: master
Clone or download
Pull request Compare This branch is 3 commits behind sunshineatnoon:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
data
doc
libs
.DS_Store
LICENSE
README.md
TestArtistic.py
TestPhotoReal.py
TestVideo.py
Train.py
real-time-demo.py

README.md

Learning Linear Transformations for Fast Arbitrary Style Transfer

[Paper]

Prerequisites

All code tested on Ubuntu 16.04, pytorch 0.4.1, and opencv 3.4.2

Style Transfer

  • Clone from github: git clone https://github.com/sunshineatnoon/LinearStyleTransfer
  • Download pre-trained models from google drive.
  • Uncompress to root folder :
cd LinearStyleTransfer
unzip models.zip
rm models.zip

Artistic style transfer

python TestArtistic.py --vgg_dir models/vgg_r41.pth --decoder_dir models/dec_r41.pth --matrixPath models/r41.pth --layer r41

or conduct style transfer on relu_31 features

python TestArtistic.py --vgg_dir models/vgg_r31.pth --decoder_dir models/dec_r31.pth --matrixPath models/r31.pth --layer r31

Photo-realistic style transfer

python TestPhotoReal.py --vgg_dir models/vgg_r31.pth --decoder_dir models/dec_r31.pth --matrixPath models/r31.pth --layer r31

Note: images with _filtered.png as postfix are images filtered by bilateral filter after style transfer.

Video style transfer

python TestVideo.py --vgg_dir models/vgg_r31.pth --decoder_dir models/dec_r31.pth --matrix_dir models/r31.pth --layer r31

Real-time video demo

python real-time-demo.py --vgg_dir models/vgg_r31.pth --decoder_dir models/dec_r31.pth --matrixPath models/r31.pth --layer r31

Model Training

Data Preparation

  • MSCOCO
wget http://msvocds.blob.core.windows.net/coco2014/train2014.zip
  • WikiArt
    • Either manually download from kaggle.
    • Or install kaggle-cli and download by running:
    kg download -u <username> -p <password> -c painter-by-numbers -f train.zip
    

Training

To train a model that transfers relu4_1 features, run:

python Train.py --vgg_dir models/vgg_r41.pth --decoder_dir models/dec_r41.pth --layer r41 --contentPath PATH_TO_MSCOCO --stylePath PATH_TO_WikiArt --outf OUTPUT_DIR

or train a model that transfers relu3_1 features:

python Train.py --vgg_dir models/vgg_r31.pth --decoder_dir models/dec_r31.pth --layer r31 --contentPath PATH_TO_MSCOCO --stylePath PATH_TO_WikiArt --outf OUTPUT_DIR

Key hyper-parameters:

  • style_layers: which features to compute style loss.
  • style_weight: larger style weight leads to heavier style in transferred images.

Intermediate results and weight will be stored in OUTPUT_DIR

Citation

@article{li2018learning,
  title={Learning Linear Transformations for Fast Arbitrary Style Transfer},
  author={Xueting Li and Sifei Liu and Jan Kautz and Ming-Hsuan Yang},
  journal={arXiv preprint arXiv:1808.04537},
  year={2018}
}
You can’t perform that action at this time.