PyTorch Style Transfer

Multi-style Generative Network for Real-time Transfer [arXiv] [project]
Hang Zhang, Kristin Dana
	title={Multi-style Generative Network for Real-time Transfer},
	author={Zhang, Hang and Dana, Kristin},
	journal={arXiv preprint arXiv:1703.06953},

We provide PyTorh Implementation of MSG-Net (ours) and Neural Style (Gatys et al. CVPR 2016) in this GitHub repo. Please install PyTorch before running the program. We also provide Torch and MXNet implementations.

Tabe of content


Stylize Images Using Pre-trained Model

  • Clone the repo and download the pre-trained model
git clone
cd PyTorch-Style-Transfer/experiments
bash models/
  • Camera Demo
python demo --model models/9styles.model

  • Test the model
python eval --content-image images/content/venice-boat.jpg --style-image images/9styles/candy.jpg --model models/9styles.model --content-size 1024

If you don’t have a GPU, simply set --cuda=0. For a different style, set --style-image path/to/style. If you would to stylize your own photo, change the --content-image path/to/your/photo. More options:

  1. --content-image: path to content image you want to stylize.
  2. --style-image: path to style image (typically covered during the training).
  3. --model: path to the pre-trained model to be used for stylizing the image.
  4. --output-image: path for saving the output image.
  5. --content-size: the content image size to test on.
  6. --cuda: set it to 1 for running on GPU, 0 for CPU.

Train Your Own MSG-Net Model

  • Download the dataset
bash dataset/
  • Train the model
python train --epochs 4

If you would like to customize styles, set --style-folder path/to/your/styles. More options:

  1. --style-folder: path to the folder style images.
  2. --vgg-model-dir: path to folder where the vgg model will be downloaded. 0. --save-model-dir: path to folder where trained model will be saved. 0. --cuda: set it to 1 for running on GPU, 0 for CPU.

Neural Styles

Image Style Transfer Using Convolutional Neural Networks by Leon A. Gatys, Alexander S. Ecker, and Matthias Bethge.

python optim --content-image images/content/venice-boat.jpg --style-image images/9styles/candy.jpg
  • --content-image: path to content image.
  • --style-image: path to style image.
  • --output-image: path for saving the output image.
  • --content-size: the content image size to test on.
  • --style-size: the style image size to test on.
  • --cuda: set it to 1 for running on GPU, 0 for CPU.


The code benefits from outstanding prior work and their implementations including:

Written by Hang Zhang on April 25, 2017

HTML Counter unique visitors since May 2014