PyTorch Implementation of DCGAN trained on the CelebA dataset.
PyTorch implementation of DCGAN introduced in the paper: Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks, Alec Radford, Luke Metz, Soumith Chintala.
Generative Adversarial Networks (GANs) are one of the most popular (and coolest) Machine Learning algorithms developed in recent times. They belong to a set of algorithms called generative models, which are widely used for unupervised learning tasks which aim to learn the uderlying structure of the given data. As the name suggests GANs allow you to generate new unseen data that mimic the actual given real data. However, GANs pose problems in training and require carefullly tuned hyperparameters.This paper aims to solve this problem.
DCGAN is one of the most popular and succesful network design for GAN. It mainly composes of convolution layers without max pooling or fully connected layers. It uses strided convolutions and transposed convolutions for the downsampling and the upsampling respectively.
Generator architecture of DCGAN
Network Design of DCGAN:
Hyperparameters are chosen as given in the paper.
This implementation uses the CelebA dataset. However, any other dataset can
also be used. Download the data and update the directory location inside the root
variable in utils.py
.
CelebA Dataset
To train the model, run train.py
. To set the training parametrs, update the values in the params
dictionary in train.py
.
Checkpoints would be saved by default in model directory every 2 epochs.
By default, GPU is used for training if available.
Training will take a long time. It took me around 3 hours on a NVIDIA GeForce GTX 1060 GPU. Using a CPU is not recommended.
Loss Curves
D: Discriminator, G: Generator
To generate new unseen images, run generate.py
.
python3 generate.py --load_path /path/to/pth/checkpoint --num_output n
Generated Images
After Epoch 1: After Epoch 10: