What is Generative Adversarial Network? All You Need to Know

Generative Adversarial Network

Do you wanna know What is Generative Adversarial Network?. How Generative Adversarial Network works?. and all the other details. Then Give your few minutes to this blog, to understand What is Generative Adversarial Network? completely in a super-easy way.

Hello, & Welcome!

In this blog, I am gonna tell you-

So without wasting your time, let’s get started-

What is Generative Adversarial Network?

Generative Adversarial Network (GAN) is a powerful algorithm of Deep Learning. It is unsupervised learning. GAN was first developed by Ian J. Goodfellow in 2014.

The whole concept of Generative Adversarial Network is based on two models- Generator and Discriminator. They both compete with each other. And their competition makes GAN more powerful and accurate.

Generative Adversarial Network is used in Image Generation, Video Generation, and Audio Generation.

GAN is able to create an image, videos, audio in the same way as human creates. In short, GAN is a Robot Artist, who can create any kind of art perfectly. This functionality of GAN makes it powerful.

Generative Adversarial Network is a generative model. Because, in GAN, the model has no labeled dataset. I will discuss this in detail in the next section.

NOTE- So, in order to understand, What is Descriptive modeling and Generative modeling. First, you should have a basic idea of supervised and unsupervised learning.

let’s start with supervised and unsupervised learning.

Supervised and Unsupervised learning.

Supervised learning is Predictive learning, where the model predicts the output based on the training dataset.

In Supervised Learning we have a training dataset, that is used to train the model.

In supervised learning, the training dataset contains input values and output values. And we train our model by providing both input and output variables. Model learn on these input and output values. And after training, when we pass any new input value to the model, the model predicts its output based on the output values of training data. This predicted output is then matched with the output of the training dataset. If there is a huge difference between the two, then the model performs the correction.

Classification and Regression is an example of Supervised learning.

In unsupervised learning, we pass only input values to the model. And the model doesn’t have output values.

So, in unsupervised learning, the model tries to extract the pattern from the input values and divide it into different clusters. In unsupervised learning, we don’t have output values. Therefore the model doesn’t perform the correction. Because correction is based on the output value.

Clustering and generative Modeling are examples of unsupervised learning.

Generative Vs Discriminative Algorithms.

As I have discussed that in supervised learning, the model predicts a class label based on the input values.

That’s why you can call supervised learning is Discriminative modeling. Because in supervised learning, the model discriminates the input values into different classes.

The discriminative algorithm map features into labels and then classify it.

But, a generative model does its opposite work. The generative model predicts the features based on the labels.

A Generative model is a type of unsupervised learning. Because in a Generative model, we have only input values. The generative model used these input values and generate new values.

In the generative model, we don’t have any output values. This model generates output only with the help of input data.

Generative models are able to generate new examples from previous samples. And these samples are not only similar to the examples but also indistinguishable as well.

How Generative Adversarial Network works?

GAN has two sub-models- The Generator and The Discriminator. So, a generator model takes a sample and generates a sample of data. A Discriminator model decides whether the data is generated or taken from the real sample. In simple words, it detects whether the data is real or fake.

The discriminator model uses a binary classification problem. That gives results in the form of 0 and 1.

To understand how GAN works, just have a look in this image-

Generative Adversarial Network

Let’s understand with the help of an example.

Take an example of image generation. So for that following steps are performed-

Step 1- At Generator Network

In the first step, the generator network or model takes a random input and generate a sample. This random input may be the pixel values of the image. And with the help of these pixel values, a generator model can create an image.

Step 2- At Discriminator Network

The discriminator network learns from the real images and becomes able to detect real or fake.

Step 3-

The generator passes the image to the discriminator. And discriminator detects whether it’s real or fake.

The main objective of the generator is to fool the discriminator. Whereas Discriminator’s objective is not to fool by a generator.

Step 4-

If the Discriminator fails to detect the image, then it is penalized. That means if the generator passes the fake image to the discriminator, but discriminator detects it as real. So in that case, the discriminator is penalized. Whereas the Generator is rewarded.

Similarly if, a discriminator successfully identifies that image is fake. So in that case, the discriminator is rewarded and the generator is penalized.

So, by doing this approach the network learns by correcting its faults. This functionality increases the accuracy of the GAN.

How to Train GAN?

The training of the GAN happens in two phases. In the first phase, we train the Discriminator. In second, we train the generator.

Let’s see in the step by step approach.

Phase 1- Training of Discriminator-

When we train the discriminator, we freeze or pause the generator. That means the generator will not able to learn from the training set. And the Generator network will only do the forward pass. It can’t backpropagate.

The discriminator is trained with real data. And it checks that is it predicting correctly or not. And the same process repeats with fake data. In order to check whether it is detecting the fake data or not.

Phase 2- Training of Generator-

While training the generator, we freeze the discriminator. In this phase, we get the output or result from the previous phase. And we can use these results to make a generator better who can fool the discriminator.

Let’s see how you can perform training in steps.

  1. Define The Problem- First, you need to define the problem and collect the data. This is the very first step for training the GAN.
  2. Select the Architecture of GAN- Based on your problem, choose the architecture of GAN. Architecture means how your GAN look.
  3. Train Discriminator on Real-World Data- Then after, you have to train the discriminator model with real data. In the case of image generation, you have to use real images for training the discriminator.
  4. Generate Fake input from Generator– In this step, you have to generate fake input or images with the help of the generator.
  5. Train Discriminator on Fake Data- So, whatever fake data you generated on a generator, use this data to train the discriminator. So that discriminator can detect it as fake data.
  6. Train Generator with the Output of Discriminator- After getting the output of discriminator, train the generator. The generator’s objective is to fool the discriminator.

GAN Vs CNN

Generative Adversarial Network or GAN is the opposite of the Convolutional Neural Network (CNN). Because in the CNN, Image is converted into features. But GAN use features to create an image.

let’s understand the difference between two with the help of this image-

CNN-

Generative Adversarial Network

GAN-

Generative Adversarial Network

I hope now you understand.

Application of Generative Adversarial Network

GAN has various applications. Here I will discuss the most popular applications of GAN.

1. Prediction of Next Frame in Video-

GAN can predict the next frame of video with the help of a few video frames. Before the GAN, it was impossible. But the invention of GAN make it possible. This is known as DVD GAN or Dual video discriminative GAN.

This feature of GAN plays an important role in security. It can be used for surveillance purposes.

2. Artwork-

GAN can create art in the same way as human creates. Some Researchers devised a GAN, dubbed SkeGAN, that can create a stroke-based vector sketch of cats, yoga-poses, and mosquitoes.

3. Robotics-

GAN makes robots more robust and powerful. With the help of GAN, robots can react more humanly.

4. Other Applications-

There are some other applications of GAN, such as-

  1. Music.
  2. Deepfake detection.
  3. Text to Image Generation.
  4. Medicine.
  5. Image to Image Translation.
  6. Enhance the resolution of an Image.
  7. Interactive Image Generation.

Types of Generative Adversarial Network

There are following types of GAN-

1. Vanilla GAN-

The vanilla GAN is the simplest type of GAN. They only try to optimize the mathematical equation. In vanilla GAN, the generator and discriminator have a simple multi-layer perceptron.

2. Conditional GAN-

Here, conditional parameters are used. It is also known as CGAN. In CGAN, there is another parameter ‘y’. It is added to the generator for generating the data.

CGAN is the extension of normal GAN. In CGAN, both the generator and discriminator are conditioned on some extra information.

CGAN is used for an image to image translation, video generation, and many more.

3. Deep Convolution GAN (DCGAN)-

DCGAN is the most powerful and successful type of GAN. It has a convolutional network instead of a multi-layer perception. Here, max-pooling is not performed in the Convolution network.

In DCGAN, the layers are not fully connected. DCGAN replace all max-pooling with convolution stride. It uses ReLU in the generator. And use LeakyReLU in discriminator.

So that’s all about Generative Adversarial Network.

I hope now you understand What is Generative Adversarial Network? and its detail. If you have any questions, feel free to ask me in the comment section.

Enjoy Learning!

All the Best!

Read Stochastic Gradient Descent from here- Stochastic Gradient Descent- A Super Easy Complete Guide!

Thank YOU!

Though of the Day…

It’s what you learn after you know it all that counts.’

John Wooden

Read Deep Learning Basics here

Leave a Comment

Your email address will not be published. Required fields are marked *