Conditional GAN is an extension of DCGAN. DCGAN is able to generate good quality images but the problem with them is that they generate random plausible examples of a given dataset. It is difficult to control the type of images generated by the network.
Conditional GAN avoids this problem. Conditional GAN is a type of GAN that involves the conditional generation of images by a generator model. It utilises the labels of the data and generates images of a particular label.
The above figure shows how a CGAN differs from normal GAN.
The model is trained on CIFAR-10 dataset. To run the code, Open Terminal and navigate to this directory and run
python test.py
Parameters | Values |
---|---|
Learning Rate | 2e-4 |
Epochs | 50 |
Optimizer | Adam |
Leaky ReLU slope | 0.2 |
Loss function | BCELoss |
Conditional GAN generated images
Below are original images from the dataset and cGAN generated images.
Discriminative loss plot
Generative Loss plot
To calculate FID score, first you need to install FID library
pip install pytorch-fid
After installing, open FID.py file and edit the location .This location is required to store the original and generated images seperately (check the code for more information). After running FID.py file, make sure that the images are stored in their respective paths.
After storing the images, open your terminal and run
python -m pytorch_fid path/to/dataset1 path/to/dataset2
(Order doesn't matter. Your dataset1 can either be real images or generated images.)
The model achieved an FID score is 70.63