Skip to content

A (clean) PyTorch implementation of CycleGAN on Horse2zebra dataset

Notifications You must be signed in to change notification settings

byrkbrk/cycle-gan

Repository files navigation

Cycle GAN

Introduction

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.

Setting up the environment

  1. Install Conda, if not already installed.
  2. Clone the repository
    git clone https://github.com/byrkbrk/cycle-gan.git
    
  3. In the directory cycle-gan, for macos, execute:
    conda env create -f cycle-gan-env_macos.yaml
    
    For linux or windows run:
    conda env create -f cycle-gan-env_linux_or_windows.yaml
    
  4. Activate the environment:
    conda activate cycle-gan-env
    

Training and Inference

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.

Results

Horse (A) $\longrightarrow$ Zebra (B)

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).

AB-jpeg AB-jpeg
AB-jpeg AB-jpeg
AB-jpeg

Zebra (B) $\longrightarrow$ Horse (A)

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.

BA-jpeg BA-jpeg
BA-jpeg BA-jpeg

Releases

No releases published

Packages

No packages published

Languages