Intuition behind GANs — Generative Adversarial Networks (Beginner Friendly)

Yajat Malhotra
4 min readNov 29, 2020

GANs or Generative Adversarial Networks are a type of machine learning framework. It has two neural networks which compete against each other in a game. One is a generator, and the other is a discriminator. In this article, we will see how they work.

GAN generating faces of people who do not exist (Image by Author)
A GAN generating faces of people who do not exist (Image by Author)

How do GANs work?

GANs are made of two neural networks, i.e. a generator and a discriminator. To make it simple, let’s think of the generator as a counterfeit currency maker and the discriminator as an inspector. The role of the counterfeit currency maker is to generate a realistic currency note, and that of the inspector is to flag the fake currency notes from the real ones. Here the inspector is not all that bad though; he also helps the counterfeit currency maker in improving his results by giving him feedback.

At first, the generator knows nothing and the discriminator is an untrained classifier model which classifies the images given to it as real or fake.

The generator’s task is to fool the discriminator. To do that, it tries its best and produces a random image from some input noise which is then fed into the discriminator with a bunch of real currency note images.

Random image produced by a generator (Image by Author)
Random image produced by a generator (Image by Author)

The discriminator is seeing these images for the first time, so it doesn’t know what is what. So, to teach it, we will give it the answers for the first batch so that it can learn from it.

Updating the discriminator in GANs (Image by Author)
Updating the discriminator in GANs (Image by Author)

Then the same process is repeated, but this time, instead of the discriminator, the generator will use the discriminator’s output as feedback to tune itself.

Updating the generator in GANs (Image by Author)
Updating the generator in GANs (Image by Author)

These two steps are alternately performed till the generator starts producing realistic currency notes and is able to fool the discriminator.

While training these two models, we have to be very careful. We don’t want to make either of them too good at their job because if that happens, it will hinder the other model’s progress and you will not get a good result. To avoid that, we have to make sure that they both are equally good at their jobs throughout the training process.

Uses of GANs

  1. Art: GANs can be used to generate art.
    NVIDIA GauGAN: You can draw a rough sketch of a landscape, and the GAN will produce a photo-realistic image of that sketch.
    Art Breeder: You can mix two images and create funky looking images. You can add different art styles to your photos.
  2. Science:
    • GANs can be used to create more data for models for which data is scarce or hard to collect.
    • They can also be used to improve astronomical images, images with noise, etc.
  3. Video Games:
    • GANs are used to upscale textures from a very low resolution to up to 4K.
  4. Other:
    ThisPersonDoesNotExist: The faces on this site are all artificially generated using GANs.

Basic Projects for Beginners

  1. Generating handwritten numbers using GANs
Generating handwritten numbers using GANs
Source code

2. Generating images of different fashion items

Generating images of different fashion items
Source code

Other Resources

  1. Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, and Yoshua Bengio. Generative Adversarial Networks. In NIPS, 2014.
  2. Tero Karras, Timo Aila, Samuli Laine and Jaakko Lehtinen (NVIDIA). Progressive Growing of GANs for Improved Quality, Stability, and Variation. In ICLR, 2018.

About Me

Hello fellow enthusiast! I am Yajat Malhotra. I am a fresher pursuing a bachelor’s degree in Computer Science and Engineering. This is my first article. I hope you enjoyed reading it and that you learnt something new from it.

You can find me on various platforms: LinkedIn, Twitter, Kaggle and GitHub

If you have any questions, feel free to ask.
If you have any feedback, do share it with me.



Yajat Malhotra

An AI Enthusiast who wants to provide digital solutions for real-life human and business problems utilising my knowledge in AI and Machine Learning.