We implement a simple form of Cycle GAN described in the article Unpaired Image-to-Image Translation, in PyTorch. While preparing, we inspired by the repositories pytorch-CycleGAN-and-pix2pix and PyTorch-CycleGAN,
and the course Apply GANs. We trained the model on dataset Horse2zebra, which is availabe in the directory datasets
.
- Install Conda, if not already installed.
- Clone the repository
git clone https://github.com/byrkbrk/cycle-gan.git
- In the directory
cycle-gan
, for macos, execute:For linux or windows run:conda env create -f cycle-gan-env_macos.yaml
conda env create -f cycle-gan-env_linux_or_windows.yaml
- Activate the environment:
conda activate cycle-gan-env
To train the model from scratch:
python3 train.py --dataset-name horse2zebra --n-epochs 200 --batch-size 1
To train the model from a checkpoint,
python3 train.py --checkpoint-name <your-checkpoint>
where replace the input <your-checkpoint>
with your checkpoint name; horse2zebra_checkpoint_10.pth
as an example.
For inference, suffices to execute
python3 generate.py <your-checkpoint>
where replace the input <your-checkpoint>
with your checkpoint.
To generate images from our pretrained model, run
python3 generate.py pretrained_horse2zebra_checkpoint_219.pth --allow-checkpoint-download True --dataset-name horse2zebra
It downloads the pretrained checkpoint, generates the images using horse2zebra test dataset, and saves into directory generated-images
.
From our pretrained model, we present the images that are also shared in the CycleGAN article. The results below are foundable in the directory generated-images/horse2zebra-AB
(with the indices 10, 12, 18, 33, 88).
The results below are from the pretrained model, and foundable in the directory generated-images/horse2zebra-BA
(with the indices 39, 72, 95, 113). The test images below are also presented in the CycleGAN article.