This is our PyTorch implementation for both unpaired and paired MR-to-CT image-to-image translation.
The original code was written by Jun-Yan Zhu and Taesung Park, and supported by Tongzhou Wang.
This PyTorch implementation produces results comparable to or better than our original Torch software. If you would like to reproduce the exact same results as in the papers, check out the original CycleGAN Torch and pix2pix Torch code
- Linux or macOS
- Python 2 or 3
- CPU or NVIDIA GPU + CUDA CuDNN
- Install PyTorch 0.4, torchvision, and other dependencies from http://pytorch.org
- Install python libraries visdom and dominate.
pip install visdom dominate
- Alternatively, all dependencies can be installed by
pip install -r requirements.txt
- Clone this repo:
git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix
cd pytorch-CycleGAN-and-pix2pix
- For Conda users, we include a script
./scripts/conda_deps.sh
to install PyTorch and other libraries.
- Download a CycleGAN dataset (e.g. maps):
bash ./datasets/download_cyclegan_dataset.sh maps
- Train a model:
#!./scripts/train_cyclegan.sh
python train.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan
- To view training results and loss plots, run
python -m visdom.server
and click the URL http://localhost:8097. To see more intermediate results, check out./checkpoints/maps_cyclegan/web/index.html
- Test the model:
#!./scripts/test_cyclegan.sh
python test.py --dataroot ./datasets/maps --name maps_cyclegan --model cycle_gan
The test results will be saved to a html file here: ./results/maps_cyclegan/latest_test/index.html
.
- Download a pix2pix dataset (e.g.facades):
bash ./datasets/download_pix2pix_dataset.sh facades
- Train a model:
#!./scripts/train_pix2pix.sh
python train.py --dataroot ./datasets/facades --name facades_pix2pix --model pix2pix --which_direction BtoA
- To view training results and loss plots, run
python -m visdom.server
and click the URL http://localhost:8097. To see more intermediate results, check out./checkpoints/facades_pix2pix/web/index.html
- Test the model (
bash ./scripts/test_pix2pix.sh
):
#!./scripts/test_pix2pix.sh
python test.py --dataroot ./datasets/facades --name facades_pix2pix --model pix2pix --which_direction BtoA
The test results will be saved to a html file here: ./results/facades_pix2pix/test_latest/index.html
.
More example scripts can be found at scripts
directory.
CycleGAN-Torch | pix2pix-Torch | pix2pixHD | iGAN | BicycleGAN
Code is inspired by pytorch-DCGAN.