Using Deep Convolutional Generative Adversarial Network to Generate Fake Images of Celebrities

Ravi Ranjan
5 min readJun 29, 2020

--

Source : Forbes

Generative Adversarial Network: A framework for teaching Deep Learning model so that the model captures the training data’s distribution in order to generate new data from the same distribution. These are made of two distinct models:

  1. Generative Model or Generator : The job of this model is to generate fake images or distribution of the training data which looks like exactly the same as training data.
  2. Discriminative model or Discriminator: The job of this model is to look at an image and verify whether the image is real or fake.

While training the generator tries its best to generate better fakes of original training data and the discriminator tries its best to correctly identify whether the image or data comes from training set or from generator.

Deep Convolutional Generative Adversarial Network

It is just an advancement of Generative Adversarial Network where convolutional and convolutional transpose layers are used explicitly in generator and discriminator.

The discriminator is made of :

  1. convolution layers
  2. batch norm layers and
  3. LeakyReLU activation

The input to the discriminator is a 3x64x64 input image and the output is a scalar probability that the input is from the real data distribution.

The generator is comprised of

  1. convolutional-transpose layers,
  2. batch norm layers, and
  3. ReLU activations.

The input to generator is a latent vector, z, drawn from a standard normal distribution and the output of the generator is a 3x64x64 RGB image. The strided conv-transpose layers allow the latent vector to be transformed into a volume with the same shape as an image.

The discriminator and generator looks like the following:

Source: Deep Learning: The Straight Dope

Modelling Objective

The objective of this experiment is to generate fake images of the celebrities. So the dataset that I am going to use is image dataset of celebrities taken from kaggle. The dataset contains celebrity images of 128 x 128 size.

Model Architecture

Discriminator : The discriminator is a binary classification network whose job is to take an image as input and output a scalar probability whether the input image is fake or real. The discriminator takes 3 x 64 x 64 size input image processes it through Conv2d, BatchNorm2d and LeakyReLU layers and outputs the final probability after passing through sigmoid activation function.

Generator: The design of the generator is made in such a way that it maps the latent space vector to data-space. As the input in our experiment is image so converting latent space to data-space is creating RGB images of size same as the size of the input image. The aforesaid conversion from latent space to data-space is accomplished through a series of strided 2-dimensional convolutional transpose layer, each paired with a 2-D batch norm layer and relu activation. The output of the generator has to pass through the tanh function so that the output ranges in the input data range of [-1, 1][-1, 1].The visual representation of the architecture is shown below:

Source: Original Paper on DCGAN

Training the Discriminator and Generator

Generator:

  1. First we generate a batch of images using the generator and then pass the image into the discriminator.
  2. The loss is calculated by setting the target labels to 1 i.e. real the generator’s objective is to “fool” the discriminator.
  3. The loss is used to perform gradient descent so that it becomes better at generating better and real looking fakes.

The implementation is as follows:

Discriminator:

  1. The output of discriminator is 1 if the image was from the real training set, and 0 if it was from the generator.
  2. A batch of real images is passed to the generator, and the loss is computed by setting the target labels to 1.
  3. Then batch of fake images from the generator is passed into the discriminator and the loss is computed by setting the target labels to 0.
  4. Finally we add the two losses and use the overall loss to perform gradient descent to adjust the weights of the discriminator.

The implementation is as follows:

Full Cycle Training

Source: Research Gate

The implementation is as follows:

Results

Loss and Scores after 25 epochs:

Losses and Scores after 25 epochs (Training time 1:30 hr)

Result After 25 epochs:

Loss and Scores after 100 epochs:

Losses and Scores after 100 epochs (Time to train 4 hrs)

Result After 100 epochs:

Metrics Logged

Conclusion

A Generative Adversarial Network is a powerful Deep Neural Network Model for image processing. In GANs a dependent learning exists as the generator learns to generate more near to the real images from the feedback of the discriminator and discriminator learns to classify images precisely from the feedback of the generator. But to perfectly train the generator and discriminator so that the generator generates exactly real fakes and discriminator classify those images perfectly we either need to train the model longer or need a workaround to increase the scores and reduce the loss.

Future problems or work that needs the use of GANs are:

  1. Info-graphics from text
  2. Website design
  3. Generate designs for house interior or building models, etc.

One but funny future work of GANs would be or may be the model would be able to generate real image from any given source and use it to track people around the world as was presented in FAST & FURIOUS 7.

References

  1. Original Paper on Generative Adversarial Networks

Ian J. Goodfellow , Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair , Aaron Courville, Yoshua Bengio

Departement d’informatique et de recherche op ´ erationnelle ´ Universite de Montr ´ eal

2. Original Paper on Deep Convolutional GAN

Alec Radford & Luke Metz indico Research Boston, MA

Soumith Chintala Facebook AI Research New York, NY

3. Lecture by Aakash NS

4. PyTorch Tutorial on DCGAN

5. Notebook on DCGAN MNIST, Anime Faces by Aakash NS

6. A note on best practices for Generative Adversarial Network in ganhacks

  • Soumith Chintala
  • Emily Denton
  • Martin Arjovsky
  • Michael Mathieu

--

--

Ravi Ranjan
Ravi Ranjan

Written by Ravi Ranjan

Full Stack Developer | Node | Nest | React | MongoDB | PostgresSQL | Express

No responses yet