The Best Introduction to What GANs Are - Removed

Deep Learning has found numerous applications in the industries. Neural networks are being widely used in almost every business sector, such as healthcare, finance, and e-commerce. These neural networks help solve business problems. In this article, we’ll learn about What GANs are.

In this article, we learn the following topics: 

  • What are Generative Adversarial Networks?
  • What is a Generator?
  • What is a Discriminator?
  • How do GANs work?
  • Types of GANs
  • Applications of GANs

What are Generative Adversarial Networks?

Generative Adversarial Networks (GANs) were introduced in 2014 by Ian J. Goodfellow and co-authors. GANs perform unsupervised learning tasks in machine learning. It consists of 2 models that automatically discover and learn the patterns in input data. 

The two models are known as Generator and Discriminator.

They compete with each other to scrutinize, capture, and replicate the variations within a dataset. GANs can be used to generate new examples that plausibly could have been drawn from the original dataset.

Machine Learning FREE Course

Take the 1st Step to Machine Learning SuccessEnroll Now
Machine Learning FREE Course

Shown below is an example of a GAN. There is a database that has real 100 rupee notes. The generator neural network generates fake 100 rupee notes. The discriminator network will help identify the real and fake notes.

GAN

What is a Generator?

A Generator in GANs is a neural network that creates fake data to be trained on the discriminator. It learns to generate plausible data. The generated examples/instances become negative training examples for the discriminator. It takes a fixed-length random vector carrying noise as input and generates a sample. 

GeneratorNetwork.

The main aim of the Generator is to make the discriminator classify its output as real. The part of the GAN that trains the Generator includes:

  • noisy input vector
  • generator network, which transforms the random input into a data instance
  • discriminator network, which classifies the generated data 
  • generator loss, which penalizes the Generator for failing to dolt the discriminator

The backpropagation method is used to adjust each weight in the right direction by calculating the weight's impact on the output. It is also used to obtain gradients and these gradients can help change the generator weights.

GeneratorTraining

Let’s see the next topic in this article on what GANs are, i.e., a Discriminator.

What is a Discriminator?

The Discriminator is a neural network that identifies real data from the fake data created by the Generator. The discriminator's training data comes from different two sources:

  • The real data instances, such as real pictures of birds, humans, currency notes, etc., are used by the Discriminator as positive samples during training.
  • The fake data instances created by the Generator are used as negative examples during the training process.

DiscriminatorNetwork

While training the discriminator, it connects to two loss functions. During discriminator training, the discriminator ignores the generator loss and just uses the discriminator loss.

In the process of training the discriminator, the discriminator classifies both real data and fake data from the generator. The discriminator loss penalizes the discriminator for misclassifying a real data instance as fake or a fake data instance as real.

The discriminator updates its weights through backpropagation from the discriminator loss through the discriminator network.

/DiscriminatorTraining

Now, let’s learn how GANs work in this article on ‘What are GANs’.

How Do GANs Work?

GANs consists of two neural networks. There is a Generator G(x) and a Discriminator D(x). Both of them play an adversarial game. The generator's aim is to fool the discriminator by producing data that are similar to those in the training set. The discriminator will try not to be fooled by identifying fake data from real data. Both of them work simultaneously to learn and train complex data like audio, video, or image files.

The Generator network takes a sample and generates a fake sample of data. The Generator is trained to increase the Discriminator network's probability of making mistakes.

FakeImages

Below is an example of a GAN trying to identify if the 100 rupee notes are real or fake. So, first, a noise vector or the input vector is fed to the Generator network. The generator creates fake 100 rupee notes. The real images of 100 rupee notes stored in a database are passed to the discriminator along with the fake notes. The Discriminator then identifies the notes as classifying them as real or fake.

We train the model, calculate the loss function at the end of the discriminator network, and backpropagate the loss into both discriminator and generator models.

GANExample

Mathematical Equation

The mathematical equation for training a GAN can be represented as:

Here, 

G = Generator

D = Discriminator

Pdata(x) = distribution of real data

p(z) = distribution of generator

x = sample from Pdata(x)

z = sample from P(z)
D(x) = Discriminator network
G(z) = Generator network

With this understanding, let’s learn the next topic on what are GANs, i.e. training a GAN.

Post Graduate Program in AI and Machine Learning

In Partnership with Purdue UniversityExplore Course
Post Graduate Program in AI and Machine Learning

Steps for Training GAN

  • Define the problem
  • Choose the architecture of GAN 
  • Train discriminator on real data 
  • Generate fake inputs for the generator 
  • Train discriminator on fake data
  • Train generator with the output of the discriminator

Let us now look at the different types of GANs.

Vanilla GANs: Vanilla GANs have a min-max optimization formulation where the Discriminator is a binary classifier and uses sigmoid cross-entropy loss during optimization. The Generator and the Discriminator in Vanilla GANs are multi-layer perceptrons. The algorithm tries to optimize the mathematical equation using stochastic gradient descent.

Deep Convolutional GANs (DCGANs): DCGANs support convolution neural networks instead of vanilla neural networks at both Discriminator and Generator. They are more stable and generate better quality images. The Generator is a set of convolution layers with fractional-strided convolutions or transpose convolutions, so it up-samples the input image at every convolutional layer. The discriminator is a set of convolution layers with strided convolutions, so it down-samples the input image at every convolution layer.

Conditional GANs: Vanilla GANs can be extended into Conditional models by using extra-label information to generate better results. In CGAN, an additional parameter ‘y’ is added to the Generator for generating the corresponding data. Labels are fed as input to the Discriminator to help distinguish the real data from the fake generated data.

Super Resolution GANs: SRGANs use deep neural networks along with an adversarial network to produce higher resolution images. SRGANs generate a photorealistic high-resolution image when given a low-resolution image.

Now that we have understood what are GANs, let’s look at some of the important applications of GANs.

Deep Learning Course (with TensorFlow & Keras)

Master the Deep Learning Concepts and ModelsView Course
Deep Learning Course (with TensorFlow & Keras)

Application of GANs

  • With the help of DCGANs, you can train images of cartoon characters for generating faces of anime characters as well as Pokemon characters.

CartoonCharacters.

  • GANs can be trained on the images of humans to generate realistic faces. The faces that you see below have been generated using GANs and do not exist in reality.

RealisticFaces

  • GANs can build realistic images from textual descriptions of objects like birds, humans, and other animals. We input a sentence and generate multiple images fitting the description. 

Below is an example of a text to image translation using GANs for a bird with a black head, yellow body, and a short break.

Conclusion

After reading this article, you would have learned the basics of GANs and how it works. You understood about generators and discriminators. You saw how GANs can help identify real and fake images. You looked at the training process of the Generative Adversarial Network and the applications of GANs.

Do you have questions related to this article on What are GANs? If you have, then please put them in the comments section of this article. Our team will help you solve your queries. 

About the Author

Avijeet BiswalAvijeet Biswal

Avijeet is a Senior Research Analyst at Simplilearn. Passionate about Data Analytics, Machine Learning, and Deep Learning, Avijeet is also interested in politics, cricket, and football.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.