The objective is to implement and compare types of Generative Adversarial Networks (GANs). The exploration involves 4 GAN architectures: GAN, DCGAN(Deep Convolutional GAN), CGAN(Conditional GAN), and BiGAN(Bidirectional GAN). The primary focus is on conducting a comparative study to assess their efficacy in generating chest X-ray images illustrating both normal and pneumonia affected conditions
- GAN (Generative Adversarial Network): Traditional GAN. https://dl.acm.org/doi/abs/10.1145/3422622
- DCGAN (Deep Convolutional GAN): Uses CNNs in generator and discriminator to capture spatial features. https://arxiv.org/abs/1511.06434v2
- CGAN (Conditional GAN): Incorporates additional information, called conditioning information, such as target labels of images, during training process. https://arxiv.org/abs/1411.1784
- BiGAN (Bidirectional GAN): It not only maps latent samples to generated data, but also has an inverse mapping from data to latent representation, this is achieved by making use of encoder network alongside the generator and discriminator. https://arxiv.org/abs/1605.09782
The dataset utilized for this project is available via following link: Chest X-ray classification dataset. For the models implemented, only training data from this dataset has been used.
- Install dataset
pip install datasets
- Load dataset
from datasets import load_dataset
df = load_dataset("keremberke/chest-xray-classification", name="full")
train_df = df['train']
generated_images_{ganName}/
: contains images generated by each respective GAN architecture (bigan
,cgan
,dcgan
,gan
).models/
: includes individual python scripts for each architecture.data_loader.py
: python script used to load the dataset for training models
- Clone the repository
git clone https://github.com/varad0207/GANs.git
- Setting up Dependencies - ensure you have python installed on your system. Use pip to install project dependencies listed in requirements.txt file
pip install -r requirements.txt
- Load the dataset
mkdir data
python data_loader.py
- Navigate to model directory
cd models
- Run GAN model scripts - for example to run traditional GAN
python gan.py
You can change number of epochs and batch_size as per your wish, i have used 50 epochs and batch_size of 32.
- Generating images - the scripts will execute and train respective models. The generated images will be saved in their respective generated images directory
Below are the comparative plots illustrating the generator and discriminator losses and discriminator accuracy for each GAN architecture after 50 epochs
The images below showcase a comparison of images generated by each GAN after 50 epochs with a batch size of 32
Based on the observed trends in the performance of different GAN architectures:
- BiGAN shows a balanced performance with a gradual decrease in generator loss, stable discriminator loss, and accuracy settling around 50%. This indicates its ability to generate realistic images while maintaining equilibrium between the generator and discriminator.
- CGAN maintains a relatively stable discriminator loss with high accuracy around 90%. This suggests its ability to distinguish between real and generated images consistently.
- GAN demonstrates moderate stability in both generator and discriminator losses, with the discriminator accuracy stabilizing around 90%. It shows potential in generating images with decent quality.
- DCGAN, while having a consistently low discriminator loss, faces challenges in the generator's performance, leading to fluctuating generator losses. The discriminator's near 100% accuracy indicates overfitting or an excessively confident discriminator.
- BiGAN stands out for its ability to strike a balance between generating realistic images and maintaining equilibrium in the adversarial process.
- CGAN and GAN display decent performance with consistent discriminator behavior, although their generator losses show different trends.
- DCGAN showcases an issue with discriminator overconfidence despite having low discriminator loss, suggesting potential issues with the generator's performance.
These conclusions are based on the observed trends and aim to provide insights into the strengths and weaknesses of each GAN architecture in generating chest X-ray images depicting normal and pneumonia-affected conditions.
The model architectures implemented in this project were adapted and inspired by https://github.com/eriklindernoren/Keras-GAN