{"id":13394521,"url":"https://github.com/junyanz/CycleGAN","last_synced_at":"2025-03-13T20:31:37.759Z","repository":{"id":38428479,"uuid":"86721514","full_name":"junyanz/CycleGAN","owner":"junyanz","description":"Software that can generate photos from paintings,  turn horses into zebras,  perform style transfer, and more.","archived":false,"fork":false,"pushed_at":"2023-09-12T19:48:53.000Z","size":12841,"stargazers_count":12370,"open_issues_count":57,"forks_count":1944,"subscribers_count":389,"default_branch":"master","last_synced_at":"2024-10-29T15:04:29.399Z","etag":null,"topics":["computer-graphics","computer-vision","cyclegan","deep-learning","gan","gans","generative-adversarial-network","image-generation","image-manipulation","pix2pix","torch"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junyanz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-03-30T15:56:21.000Z","updated_at":"2024-10-28T20:43:46.000Z","dependencies_parsed_at":"2022-07-16T13:30:30.556Z","dependency_job_id":"83f466f1-2622-4051-9b01-7bb5dd8f0fb0","html_url":"https://github.com/junyanz/CycleGAN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junyanz%2FCycleGAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junyanz%2FCycleGAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junyanz%2FCycleGAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junyanz%2FCycleGAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junyanz","download_url":"https://codeload.github.com/junyanz/CycleGAN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243159180,"owners_count":20245674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-graphics","computer-vision","cyclegan","deep-learning","gan","gans","generative-adversarial-network","image-generation","image-manipulation","pix2pix","torch"],"created_at":"2024-07-30T17:01:22.486Z","updated_at":"2025-03-13T20:31:33.737Z","avatar_url":"https://github.com/junyanz.png","language":"Lua","readme":"\u003cimg src='imgs/horse2zebra.gif' align=\"right\" width=384\u003e\n\n\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e\n\n# CycleGAN\n### [PyTorch](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix) | [project page](https://junyanz.github.io/CycleGAN/) |   [paper](https://arxiv.org/pdf/1703.10593.pdf)\n\nTorch implementation for learning an image-to-image translation (i.e. [pix2pix](https://github.com/phillipi/pix2pix)) **without** input-output pairs, for example:\n\n**New**:  Please check out [contrastive-unpaired-translation](https://github.com/taesungp/contrastive-unpaired-translation) (CUT), our new unpaired image-to-image translation model that enables fast and memory-efficient training.\n\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/teaser_high_res.jpg\" width=\"1000px\"/\u003e\n\n[Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks](https://junyanz.github.io/CycleGAN/)  \n [Jun-Yan Zhu](https://people.eecs.berkeley.edu/~junyanz/)\\*,  [Taesung Park](https://taesung.me/)\\*, [Phillip Isola](http://web.mit.edu/phillipi/), [Alexei A. Efros](https://people.eecs.berkeley.edu/~efros/)  \n Berkeley AI Research Lab, UC Berkeley  \n In ICCV 2017. (* equal contributions)  \n\nThis package includes CycleGAN, [pix2pix](https://github.com/phillipi/pix2pix), as well as other methods like [BiGAN](https://arxiv.org/abs/1605.09782)/[ALI](https://ishmaelbelghazi.github.io/ALI/) and Apple's paper [S+U learning](https://arxiv.org/pdf/1612.07828.pdf).  \nThe code was written by [Jun-Yan Zhu](https://github.com/junyanz) and [Taesung Park](https://github.com/taesung).  \n**Update**: Please check out [PyTorch](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix) implementation for CycleGAN and pix2pix.\nThe PyTorch version is under active development and can produce results comparable or better than this Torch version.\n\n## Other implementations:\n\u003cp\u003e\u003ca href=\"https://github.com/leehomyc/cyclegan-1\"\u003e [Tensorflow]\u003c/a\u003e (by Harry Yang),\n\u003ca href=\"https://github.com/architrathore/CycleGAN/\"\u003e[Tensorflow]\u003c/a\u003e (by Archit Rathore),\n\u003ca href=\"https://github.com/vanhuyz/CycleGAN-TensorFlow\"\u003e[Tensorflow]\u003c/a\u003e (by Van Huy),\n\u003ca href=\"https://github.com/XHUJOY/CycleGAN-tensorflow\"\u003e[Tensorflow]\u003c/a\u003e (by Xiaowei Hu),\n\u003ca href=\"https://github.com/LynnHo/CycleGAN-Tensorflow-Simple\"\u003e [Tensorflow-simple]\u003c/a\u003e (by Zhenliang He),\n\u003ca href=\"https://github.com/luoxier/CycleGAN_Tensorlayer\"\u003e [TensorLayer]\u003c/a\u003e (by luoxier),\n\u003ca href=\"https://github.com/Aixile/chainer-cyclegan\"\u003e[Chainer]\u003c/a\u003e (by Yanghua Jin),\n\u003ca href=\"https://github.com/yunjey/mnist-svhn-transfer\"\u003e[Minimal PyTorch]\u003c/a\u003e (by yunjey),\n\u003ca href=\"https://github.com/Ldpe2G/DeepLearningForFun/tree/master/Mxnet-Scala/CycleGAN\"\u003e[Mxnet]\u003c/a\u003e (by Ldpe2G),\n\u003ca href=\"https://github.com/tjwei/GANotebooks\"\u003e[lasagne/Keras]\u003c/a\u003e (by tjwei),\n\u003ca href=\"https://github.com/simontomaskarlsson/CycleGAN-Keras\"\u003e[Keras]\u003c/a\u003e (by Simon Karlsson)\u003c/p\u003e\n\u003c/ul\u003e\n\n## Applications\n### Monet Paintings to Photos\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/painting2photo.jpg\" width=\"1000px\"/\u003e\n\n### Collection Style Transfer\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/photo2painting.jpg\" width=\"1000px\"/\u003e\n\n### Object Transfiguration\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/objects.jpg\" width=\"1000px\"/\u003e\n\n### Season Transfer\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/season.jpg\" width=\"1000px\"/\u003e\n\n### Photo Enhancement: Narrow depth of field\n\u003cimg src=\"https://junyanz.github.io/CycleGAN/images/photo_enhancement.jpg\" width=\"1000px\"/\u003e\n\n\n\n## Prerequisites\n- Linux or OSX\n- NVIDIA GPU + CUDA CuDNN (CPU mode and CUDA without CuDNN may work with minimal modification, but untested)\n- For MAC users, you need the Linux/GNU commands `gfind` and `gwc`, which can be installed with `brew install findutils coreutils`.\n\n## Getting Started\n### Installation\n- Install torch and dependencies from https://github.com/torch/distro\n- Install torch packages `nngraph`, `class`, `display`\n```bash\nluarocks install nngraph\nluarocks install class\nluarocks install https://raw.githubusercontent.com/szym/display/master/display-scm-0.rockspec\n```\n- Clone this repo:\n```bash\ngit clone https://github.com/junyanz/CycleGAN\ncd CycleGAN\n```\n\n### Apply a Pre-trained Model\n- Download the test photos (taken by [Alexei Efros](https://www.flickr.com/photos/aaefros)):\n```\nbash ./datasets/download_dataset.sh ae_photos\n```\n- Download the pre-trained model `style_cezanne` (For CPU model, use `style_cezanne_cpu`):\n```\nbash ./pretrained_models/download_model.sh style_cezanne\n```\n- Now, let's generate Paul Cézanne style images:\n```\nDATA_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\n```\nThe test results will be saved to `./results/style_cezanne_pretrained/latest_test/index.html`.  \nPlease refer to [Model Zoo](#model-zoo) for more pre-trained models.\n`./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.\n\n### Train\n- Download a dataset (e.g. zebra and horse images from ImageNet):\n```bash\nbash ./datasets/download_dataset.sh horse2zebra\n```\n- Train a model:\n```bash\nDATA_ROOT=./datasets/horse2zebra name=horse2zebra_model th train.lua\n```\n- (CPU only) The same training command without using a GPU or CUDNN. Setting the environment variables ```gpu=0 cudnn=0``` forces CPU only\n```bash\nDATA_ROOT=./datasets/horse2zebra name=horse2zebra_model gpu=0 cudnn=0 th train.lua\n```\n- (Optionally) start the display server to view results as the model trains. (See [Display UI](#display-ui) for more details):\n```bash\nth -ldisplay.start 8000 0.0.0.0\n```\n\n### Test\n- Finally, test the model:\n```bash\nDATA_ROOT=./datasets/horse2zebra name=horse2zebra_model phase=test th test.lua\n```\nThe test results will be saved to an HTML file here: `./results/horse2zebra_model/latest_test/index.html`.\n\n\n## Model Zoo\nDownload the pre-trained models with the following script. The model will be saved to `./checkpoints/model_name/latest_net_G.t7`.\n```bash\nbash ./pretrained_models/download_model.sh model_name\n```\n- `orange2apple` (orange -\u003e apple) and `apple2orange`: trained on ImageNet categories `apple` and `orange`.\n- `horse2zebra` (horse -\u003e zebra) and `zebra2horse` (zebra -\u003e horse): trained on ImageNet categories `horse` and `zebra`.\n- `style_monet` (landscape photo -\u003e Monet painting style),  `style_vangogh` (landscape photo  -\u003e Van Gogh painting style), `style_ukiyoe` (landscape photo  -\u003e Ukiyo-e painting style), `style_cezanne` (landscape photo  -\u003e Cezanne painting style): trained on paintings and Flickr landscape photos.\n- `monet2photo` (Monet paintings -\u003e real landscape): trained on paintings and Flickr landscape photographs.\n- `cityscapes_photo2label` (street scene -\u003e label) and `cityscapes_label2photo` (label -\u003e street scene): trained on the Cityscapes dataset.\n- `map2sat` (map -\u003e aerial photo) and `sat2map` (aerial photo -\u003e map): trained on Google maps.\n- `iphone2dslr_flower` (iPhone photos of flowers -\u003e DSLR photos of flowers): trained on Flickr photos.\n\nCPU models can be downloaded using:\n```bash\nbash pretrained_models/download_model.sh \u003cname\u003e_cpu\n```\n, where `\u003cname\u003e` can be `horse2zebra`, `style_monet`, etc. You just need to append `_cpu` to the target model.\n\n## Training and Test Details\nTo train a model,  \n```bash\nDATA_ROOT=/path/to/data/ name=expt_name th train.lua\n```\nModels are saved to `./checkpoints/expt_name` (can be changed by passing `checkpoint_dir=your_dir` in train.lua).  \nSee `opt_train` in `options.lua` for additional training options.\n\nTo test the model,\n```bash\nDATA_ROOT=/path/to/data/ name=expt_name phase=test th test.lua\n```\nThis will run the model named `expt_name` in both directions on all images in `/path/to/data/testA` and `/path/to/data/testB`.  \nA webpage with result images will be saved to `./results/expt_name` (can be changed by passing `results_dir=your_dir` in test.lua).  \nSee `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.\n\nThere 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](https://junyanz.github.io/CycleGAN/) and [Cycada](https://arxiv.org/pdf/1711.03213.pdf) 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`.\n\n## Datasets\nDownload the datasets using the following script. Many of the datasets were collected by other researchers. Please cite their papers if you use the data.\n```bash\nbash ./datasets/download_dataset.sh dataset_name\n```\n- `facades`: 400 images from the [CMP Facades dataset](http://cmp.felk.cvut.cz/~tylecr1/facade/). [[Citation](datasets/bibtex/facades.tex)]\n- `cityscapes`: 2975 images from the [Cityscapes training set](https://www.cityscapes-dataset.com/). [[Citation](datasets/bibtex/cityscapes.tex)]. Note: Due to license issue, we do not host the dataset on our repo. Please download the dataset directly from the Cityscapes webpage. Please refer to `./datasets/prepare_cityscapes_dataset.py` for more detail.\n- `maps`: 1096 training images scraped from Google Maps.\n- `horse2zebra`: 939 horse images and 1177 zebra images downloaded from [ImageNet](http://www.image-net.org/) using the keywords `wild horse` and `zebra`\n- `apple2orange`: 996 apple images and 1020 orange images downloaded from [ImageNet](http://www.image-net.org/) using the keywords `apple` and `navel orange`.\n- `summer2winter_yosemite`: 1273 summer Yosemite images and 854 winter Yosemite images were downloaded using Flickr API. See more details in our paper.\n- `monet2photo`, `vangogh2photo`, `ukiyoe2photo`, `cezanne2photo`: The art images were downloaded from [Wikiart](https://www.wikiart.org/). The real photos are downloaded from Flickr using the combination of the tags *landscape* and *landscapephotography*. The training set size of each class is Monet:1074, Cezanne:584, Van Gogh:401, Ukiyo-e:1433, Photographs:6853.\n- `iphone2dslr_flower`: both classes of images were downloaded from Flickr. The training set size of each class is iPhone:1813, DSLR:3316. See more details in our paper.\n\n\n## Display UI\nOptionally, for displaying images during training and test, use the [display package](https://github.com/szym/display).\n\n- Install it with: `luarocks install https://raw.githubusercontent.com/szym/display/master/display-scm-0.rockspec`\n- Then start the server with: `th -ldisplay.start`\n- Open this URL in your browser: [http://localhost:8000](http://localhost:8000)\n\nBy default, the server listens on localhost. Pass `0.0.0.0` to allow external connections on any interface:\n```bash\nth -ldisplay.start 8000 0.0.0.0\n```\nThen open `http://(hostname):(port)/` in your browser to load the remote desktop.\n\n## Setup Training and Test data\nTo 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.\n\nYou should **not** expect our method to work on just any random combination of input and output datasets (e.g. `cats\u003c-\u003ekeyboards`). From our experiments, we find it works better if two datasets share similar visual content. For example, `landscape painting\u003c-\u003elandscape photographs` works much better than `portrait painting \u003c-\u003e landscape photographs`. `zebras\u003c-\u003ehorses` achieves compelling results while `cats\u003c-\u003edogs` completely fails.  See the following section for more discussion.\n\n\n## Failure cases\n\u003cimg align=\"left\" style=\"padding:10px\" src=\"https://junyanz.github.io/CycleGAN/images/failure_putin.jpg\" width=320\u003e\n\nOur 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](https://junyanz.github.io/CycleGAN/images/failures.jpg). 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\u003c-\u003ecat` 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-\u003elabels task.\n\n\n\n## Citation\nIf you use this code for your research, please cite our [paper](https://junyanz.github.io/CycleGAN/):\n\n```\n@inproceedings{CycleGAN2017,\n  title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networkss},\n  author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},\n  booktitle={Computer Vision (ICCV), 2017 IEEE International Conference on},\n  year={2017}\n}\n\n```\n\n\n## Related Projects:\n**[contrastive-unpaired-translation](https://github.com/taesungp/contrastive-unpaired-translation) (CUT)**\u003cbr\u003e\n**[pix2pix-Torch](https://github.com/phillipi/pix2pix) | [pix2pixHD](https://github.com/NVIDIA/pix2pixHD) |\n[BicycleGAN](https://github.com/junyanz/BicycleGAN) | [vid2vid](https://tcwang0509.github.io/vid2vid/) | [SPADE/GauGAN](https://github.com/NVlabs/SPADE)**\u003cbr\u003e\n**[iGAN](https://github.com/junyanz/iGAN) | [GAN Dissection](https://github.com/CSAILVision/GANDissect) | [GAN Paint](http://ganpaint.io/)**\n\n## Cat Paper Collection\nIf you love cats, and love reading cool graphics, vision, and ML papers, please check out the Cat Paper [Collection](https://github.com/junyanz/CatPapers).  \n\n\n## Acknowledgments\nCode borrows from [pix2pix](https://github.com/phillipi/pix2pix) and [DCGAN](https://github.com/soumith/dcgan.torch). The data loader is modified from [DCGAN](https://github.com/soumith/dcgan.torch) and  [Context-Encoder](https://github.com/pathak22/context-encoder). The generative network is adopted from [neural-style](https://github.com/jcjohnson/neural-style) with [Instance Normalization](https://github.com/DmitryUlyanov/texture_nets/blob/master/InstanceNormalization.lua).\n","funding_links":[],"categories":["Lua","图像风格","Code 💻","实战项目","Machine Learning","人工智能 \u003ca name=\"AI\"\u003e\u003c/a\u003e","Codes"],"sub_categories":["网络服务_其他","毕业设计实战项目","Computer Vision"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunyanz%2FCycleGAN","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunyanz%2FCycleGAN","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunyanz%2FCycleGAN/lists"}