CycleGAN README

The project's README from github.com/junyanz/CycleGAN. As one markdown file: README.md.




CycleGAN

PyTorch | project page | paper

Torch implementation for learning an image-to-image translation (i.e. pix2pix) without input-output pairs, for example:

New: Please check out contrastive-unpaired-translation (CUT), our new unpaired image-to-image translation model that enables fast and memory-efficient training.

Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks
Jun-Yan Zhu*, Taesung Park*, Phillip Isola, Alexei A. Efros
Berkeley AI Research Lab, UC Berkeley
In ICCV 2017. (* equal contributions)

This package includes CycleGAN, pix2pix, as well as other methods like BiGAN/ALI and Apple's paper S+U learning.
The code was written by Jun-Yan Zhu and Taesung Park.
Update: Please check out PyTorch implementation for CycleGAN and pix2pix. The PyTorch version is under active development and can produce results comparable or better than this Torch version.

Other implementations:

[Tensorflow] (by Harry Yang), [Tensorflow] (by Archit Rathore), [Tensorflow] (by Van Huy), [Tensorflow] (by Xiaowei Hu), [Tensorflow-simple] (by Zhenliang He), [TensorLayer] (by luoxier), [Chainer] (by Yanghua Jin), [Minimal PyTorch] (by yunjey), [Mxnet] (by Ldpe2G), [lasagne/Keras] (by tjwei), [Keras] (by Simon Karlsson)

Applications

Monet Paintings to Photos

Collection Style Transfer

Object Transfiguration

Season Transfer

Photo Enhancement: Narrow depth of field

Prerequisites

Getting Started

Installation

luarocks install nngraph
luarocks install class
luarocks install https://raw.githubusercontent.com/szym/display/master/display-scm-0.rockspec
git clone https://github.com/junyanz/CycleGAN
cd CycleGAN

Apply a Pre-trained Model

bash ./datasets/download_dataset.sh ae_photos
bash ./pretrained_models/download_model.sh style_cezanne
DATA_ROOT=./datasets/ae_photos name=style_cezanne_pretrained model=one_direction_test phase=test loadSize=256 fineSize=256 resize_or_crop="scale_width" th test.lua

The test results will be saved to ./results/style_cezanne_pretrained/latest_test/index.html.
Please refer to Model Zoo for more pre-trained models. ./examples/test_vangogh_style_on_ae_photos.sh is an example script that downloads the pretrained Van Gogh style network and runs it on Efros's photos.

Train

bash ./datasets/download_dataset.sh horse2zebra
DATA_ROOT=./datasets/horse2zebra name=horse2zebra_model th train.lua
DATA_ROOT=./datasets/horse2zebra name=horse2zebra_model gpu=0 cudnn=0 th train.lua
th -ldisplay.start 8000 0.0.0.0

Test

DATA_ROOT=./datasets/horse2zebra name=horse2zebra_model phase=test th test.lua

The test results will be saved to an HTML file here: ./results/horse2zebra_model/latest_test/index.html.

Model Zoo

Download the pre-trained models with the following script. The model will be saved to ./checkpoints/model_name/latest_net_G.t7.

bash ./pretrained_models/download_model.sh model_name

CPU models can be downloaded using:

bash pretrained_models/download_model.sh <name>_cpu

, where <name> can be horse2zebra, style_monet, etc. You just need to append _cpu to the target model.

Training and Test Details

To train a model,

DATA_ROOT=/path/to/data/ name=expt_name th train.lua

Models are saved to ./checkpoints/expt_name (can be changed by passing checkpoint_dir=your_dir in train.lua).
See opt_train in options.lua for additional training options.

To test the model,

DATA_ROOT=/path/to/data/ name=expt_name phase=test th test.lua

This will run the model named expt_name in both directions on all images in /path/to/data/testA and /path/to/data/testB.
A webpage with result images will be saved to ./results/expt_name (can be changed by passing results_dir=your_dir in test.lua).
See opt_test in options.lua for additional test options. Please use model=one_direction_test if you only would like to generate outputs of the trained network in only one direction, and specify which_direction=AtoB or which_direction=BtoA to set the direction.

There are other options that can be used. For example, you can specify resize_or_crop=crop option to avoid resizing the image to squares. This is indeed how we trained GTA2Cityscapes model in the projet webpage and Cycada model. We prepared the images at 1024px resolution, and used resize_or_crop=crop fineSize=360 to work with the cropped images of size 360x360. We also used lambda_identity=1.0.

Datasets

Download the datasets using the following script. Many of the datasets were collected by other researchers. Please cite their papers if you use the data.

bash ./datasets/download_dataset.sh dataset_name

Display UI

Optionally, for displaying images during training and test, use the display package.

By default, the server listens on localhost. Pass 0.0.0.0 to allow external connections on any interface:

th -ldisplay.start 8000 0.0.0.0

Then open http://(hostname):(port)/ in your browser to load the remote desktop.

Setup Training and Test data

To train CycleGAN model on your own datasets, you need to create a data folder with two subdirectories trainA and trainB that contain images from domain A and B. You can test your model on your training set by setting phase='train' in test.lua. You can also create subdirectories testA and testB if you have test data.

You should not expect our method to work on just any random combination of input and output datasets (e.g. cats<->keyboards). From our experiments, we find it works better if two datasets share similar visual content. For example, landscape painting<->landscape photographs works much better than portrait painting <-> landscape photographs. zebras<->horses achieves compelling results while cats<->dogs completely fails. See the following section for more discussion.

Failure cases

Our model does not work well when the test image is rather different from the images on which the model is trained, as is the case in the figure to the left (we trained on horses and zebras without riders, but test here one a horse with a rider). See additional typical failure cases here. On translation tasks that involve color and texture changes, like many of those reported above, the method often succeeds. We have also explored tasks that require geometric changes, with little success. For example, on the task of dog<->cat transfiguration, the learned translation degenerates into making minimal changes to the input. We also observe a lingering gap between the results achievable with paired training data and those achieved by our unpaired method. In some cases, this gap may be very hard -- or even impossible,-- to close: for example, our method sometimes permutes the labels for tree and building in the output of the cityscapes photos->labels task.

Citation

If you use this code for your research, please cite our paper:

@inproceedings{CycleGAN2017,
  title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networkss},
  author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},
  booktitle={Computer Vision (ICCV), 2017 IEEE International Conference on},
  year={2017}
}

contrastive-unpaired-translation (CUT)
pix2pix-Torch | pix2pixHD | BicycleGAN | vid2vid | SPADE/GauGAN
iGAN | GAN Dissection | GAN Paint

Cat Paper Collection

If you love cats, and love reading cool graphics, vision, and ML papers, please check out the Cat Paper Collection.

Acknowledgments

Code borrows from pix2pix and DCGAN. The data loader is modified from DCGAN and Context-Encoder. The generative network is adopted from neural-style with Instance Normalization.

CycleGAN (junyanz/CycleGAN)

Searching Database…

12.9K ·GitHub
这是什么?CycleGAN 是 'Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks' 的原始 Torch 实现,可以把马变成斑马,把莫奈、梵高等画风应用到照片上,也能完成类似的图像转换,而无需成对的前后对比训练图片。
这是可以直接使用的应用,还是需要通过命令行运行的研究代码?这是研究代码:一个 Torch(Lua)实现,通过命令行脚本运行,用于训练和测试图像到图像转换模型,并不是打包好的应用程序。
如何让预训练模型跑起来?安装 Torch 及其依赖(nngraph、class、display),克隆仓库,然后下载预训练模型(如 'stylecezanne')和测试照片,再运行提供的测试脚本,将风格化图像生成到 ./results 目录中。
我随意选两类图像,它都能处理吗?不能,效果很大程度上取决于两个领域在视觉上的相似程度:只涉及颜色和纹理变化的任务(马变斑马、照片变画作)能成功,但像狗变猫这样的几何变换基本失败,只会产生很小的变化。
能在 Windows 上运行吗?不能,README 只记录了 Linux 和 OSX;Mac 用户还需要通过 Homebrew 安装 GNU 命令 gfind 和 gwc。
有没有维护更积极的版本?有,作者维护着一个单独的 CycleGAN 和 pix2pix PyTorch 实现,该版本仍在积极开发中,效果可以与这个 Torch 版本相当,甚至更好。
模型库里有哪些预训练模型?可直接下载的模型包括 horse2zebra、apple2orange、莫奈/梵高/浮世绘/塞尚等画风、Cityscapes 标签图到照片的转换、地图到卫星照片的转换,以及 iPhone 到单反相机的花卉照片转换。
训练自己的模型需要成对的前后对比图片吗?不需要,只要把各自领域中互不相关的图片分别放入 trainA 和 trainB 文件夹即可;CycleGAN 无需配对图片就能学会转换,不过当两个领域的视觉内容比较接近时效果最好。
训练时如何实时查看进展?安装 Lua 的 'display' 包,用 'th -ldisplay.start' 启动它,然后在浏览器中打开给出的网址,即可在训练过程中实时查看结果。
Creator
junyanz
Size
12.5 MB
Stars
12.9K
Updated
CommitSep 12
Age
9y
Commits · 90 Days