Javatpoint Logo
Javatpoint Logo

What is a Generative Adversarial Network (GAN)


In this tutorial, we are discussing the Generative Adversarial Network or GAN. GAN is an architecture of Deep Learning. The Generative Adversarial Network consists of two neural networks. These networks are competing with each other in a zero-sum game framework. The Generative Adversarial Networks (GANs) can be described as extremely powerful kinds of neural networks that are employed to aid in Unsupervised Learning. They were created and first introduced in 2014 by Ian J. Goodfellow 2014. GANs are comprised of two neural networks that are in competition with one another and can analyse the changes within a set of data. The Generative Adversarial Network is generated the new data which assembles a few known as data distributions.

GANs are a method for generative modelling that uses deep learning methods like CNN (Convolutional Neural Network). Generative modelling is an unsupervised learning method that automatically discovers and learns patterns in input data so that the model can be used for new examples from the original dataset.

GANs are a method of training generative modelling by framing the problem as a supervised learning problem and using two sub-models. GANs have two components:

  1. Generator: The generator is mainly a convolution neutral network. Generator This is a program that generates new data from real-world images. The main aim of the generator is to generate the output which is mistaken for the real data.
  2. Discriminator: The Discriminator is mainly a deconvolution neutral network. Discriminator This compares the images with real-world examples to classify fake and real images. The main aim of the discriminator is to identify the artificial output which is received in the network.

When the generator generates false data, the discriminator is distinguish between the artificial data and the original data.


The Generator generates random images (e.g., The Generator generates some random images (e.g., tables), and then the Discriminator compares these images with real-world table images. Finally, the Generator sends the feedback directly to Generator. See the GAN structure in the following figure.

What is a Generative Adversarial Network (GAN)

What is the Reason GANs were Invented in the First Place?

The Generative Adversarial Network or GAN was invented in the first place. The reason behind that is discussed here. It is well-known that most of the neural networks used in mainstream research are easily misled into misclassifying items by introducing a tiny amount of noise to the data. Surprisingly, the model modified after adding noise has a higher probability of making a mistake than when it has made a good prediction. The reason for this is that machines learn from the smallest amount of data. This is a main drawback as it can be overfitted. The relationship between input and output is almost linear. While the lines of separation between different classes could be linear, they are comprised of linearities, and even minor changes in one point of the feature space could cause data to be classified incorrectly.

How does GAN work?

Generative Adversarial Networks (GANs) can be broken down into three parts, which are discussed in below -

  • Generative: To learn more about a dynamic model that explains how data are generated using a probabilistic model.
  • Adversarial: The process of training models, is conducted in an adversarial environment.
  • Networks: Make use of deep neural networks to create Artificial Intelligence (AI) algorithms to train for purposes.

Previously we told you that GAN has two neutral networks. One is Generator and another is Discriminator. The generator is used to generate false or artificial data. And on the other hand, the discriminator is used to identify the artificial data. The artificial data is like images, audio, video, etc, which is generated by the generator. These two neutral networks are competing in the training phase. The steps of the generator and discriminator are repeated many numbers of times. And from time to time the result was better than the previous results. In the below diagram, we can visualize this process.

What is a Generative Adversarial Network (GAN)

The generative model can capture the data distribution. It is tried to maximise the probability of making mistake in the discriminator. So, the discriminator cannot find which is real data and which is artificial data. On the other side, the discriminator is tried to understand which data is received from the training data and which is received from the generator. The Generative Adversarial Network is used to minimax the game. Here the work of the discriminator is to minimize the rewards V(D, G). Another side the generator works to minimize the discriminator rewards and also maximize the loss. The mathematical formula of GAN is given below -

V (D,G)=Ex~pdata (x) [log?D(x)]+ Ez~pz(z) [log?(1-D(G(z))]

The uses terms in the above equation are given below -

D = Discriminator

G = Generator

pdata(x) = real data distribution

x = pdata(x) sample

D(x) = Network for Discriminator

p(z) = Generator distribution

z = p(z) sample

G(z) = Network for Generator

What is meant by the Generator Model?

In this case, when the discriminator is idle then the generator is trained. After that, the Generator is generated the data and by this data, the discriminator is also trained. We can also predict the data and we also use this result for generator training. From time to time the result is better. The generator gets successful to fool the discriminator and then the discriminator does not identify which data is false.

What is meant by the Discriminator Model?

In this case, when the generator is idle then the Discriminator is trained. In the Discriminator, the network does not backpropagate. The network in Discriminator is mainly done the forward propagation. The Discriminator is mainly trained to find the real data for n epochs. Then it also verified whether it correctly predict the data that is real data or not. The Discriminator is also trained with the generated data from the generator. Then it also verified whether it correctly predicted the data that is artificial data or not.


Now we give an example of that how can we generating images of Dogs in the Generative Adversarial Network.

Step 1: Training of Discriminator

The 1st step is training the Discriminator by using the idle Generator. We discuss the steps below -

  1. First, a random noise signal is sent through a generator. This generates useless images that contain noise.
  2. (See fig. 2)
  3. Discriminator has two inputs. The first is the Generator sample output images, and the second is real-world dog image samples.
  4. After comparing the images in fig., The Discriminator then populates certain values (probability). 2. It calculates 0.8 to 0.3 and 0.0.5 for generator output images and 0.1, 9.9, and 0.2 for real-world images.
  5. An error can be calculated by comparing the probabilities of generated images with 0 (Zero) and the probabilities of real-word images with 1. (Ex. (Ex.
  6. After it has calculated individual errors, it will calculate cumulative loss(loss), which is backpropagated. The weights of the Discriminator can then be adjusted. This is how a Discriminator gets trained.
What is a Generative Adversarial Network (GAN)

Step 2: Training the Generator

The 2nd step is training the Generator by using the idle Discriminator. We discuss the steps below -

  1. The loss is propagated back to the Discriminator in step 1. This will allow it to adjust its weights. We must also backpropagate an error, so it can adjust its weights and train itself to produce better images.
  2. The Generator generates images that are used to input the Generator.
  3. The Discriminator will now use the newly generated images as input. It calculates probabilities such as 0.5, 0.01, and 0.2. (See fig. 2)
  4. An error can be calculated by comparing the probabilities of images generated with 1 (One).
  5. After it has calculated individual errors, it will calculate cumulative loss(loss), which is backpropagated. The weights of the Generator then are adjusted. This is how Generator gets trained.
What is a Generative Adversarial Network (GAN)

After a few more iterations, the Generator will start generating images similar to real-world images.

What are the types of Generative Adversarial Network or GAN model?

There are various types of GAN models or Generative Adversarial Network models. These are given in below -

1. Condition GAN:

It is one type of GAN. The Condition GAN also represent a CGAN. This GAN has mainly described the deep learning method. In the CGAN, we put some conditional parameters. In the generator, when we add data "X" then it generates its corresponding data. In the CGAN, the labels are put in the input to help the discriminator identify the fake data and the real data.

2. Vanilla GAN:

It is one of the simplest types of GAN. The Vanilla GAN also represent a VGAN. In the vanilla GAN, the Generator and the Discriminator are very simple and have multilayer perceptron's. The algorithm of the VGAN is also very easy. The VGAN is used to optimization of a mathematical equation which is used in the stochastic gradient descent.

3. Laplacian Pyramid GAN:

It is another type of GAN. The Laplacian Pyramid GAN also represent a LAPGAN. The LAPGAN represents the linearly invertible image. This consists of a set of bandpass images which is also residual of low frequency. The images are also spaced an octave apart. In the Laplacian Pyramid GAN, we use multiple numbers of generators and Discriminators. Here we also used the Laplacian pyramid of different levels. High-quality images produced by the LAPGAN. In the first step, the image is always down-sampled in Laplacian Pyramid GAN. After that, the images are upscaled in each layer of the pyramid and then pass the images which have some noise from the CGAN. The images belong in CGAN until it gets the original size.

4. Super Resolution GAN:

It is another type of Generative Adversarial Network. The Super Resolution GAN also represent an SRGAN. The SRGAN is produce a high-resolution image. In this GAN, the deep neural network is used with the adversarial network. The SRGAN is very much useful for upscaling low-resolution images into high-resolution images. And it is also used to errors minimizing in the images.

5. Deep Convolutional GAN:

The last type of Generative Adversarial Network or GAN is Deep convolutional GAN. The Deep convolutional GAN also represent a DCGAN. This GAN is most powerful GAN than others. The DCGAN is very popular. Deep convolution GAN is ConvNets in place of multi-layer perceptron's. This is easily implemented without max pooling. The layers of DCGAN are not fully connected.

Advantages of Generative Adversarial Network:

There are various advantages of Generative Adversarial Network. The advantages are given below -

1. Produce high-quality results:

GAN produce photorealistic as well as high-quality results for various types of tasks like video synthesis, image synthesis, music synthesis and so on.

2. Not supervised learning:

GAN has produced unsupervised learning. GAN can be training the data without any condition like it need not any labelled data. GAN can easily make the data for learning unsupervised tasks. In unsupervised learning, there is difficult to obtain the labelled data. So, it used data without labelling.

3. Data Generation which is Synthetic:

GAN is also generating some new data which is synthetic. It is used to assemble the distribution of known data. This feature helps with various creative applications, augmentation of data and many more.

4. Versatile:

The Generative Adversarial Network is versatile. It is used for various kinds of tasks like image-to-text synthesis, text-to-image synthesis, image-to-image synthesis, image synthesis, augmentation of data, detected anomalies and many more.

Disadvantages of Generative Adversarial Network:

There are various disadvantages of Generative Adversarial Networks. The disadvantages are given below -

1. Cost for computation:

GAN needs to very high computational cost. It requires more computational resources. Due to a large number of computations, the GAN is trained slowly for the large dataset and the high-resolution images.

2. Fairness and bias:

The Generative Adversarial Network can reflect the unfairness and biases which is present in the training data. It is also leading to biased synthetic data or the leading to discrimination.

3. Difficult to trained:

The Generative Adversarial Network or GAN is very difficult to train with various kinds of risk like mode of collapse, instability and converge failure.

4. Overfitting:

The Generative Adversarial Network have the problem of overfitting. The training data and producing synthetic data can be overfitted here. This is similar to the lacking diversity and training data.

Interpretability and Accountability:

The Generative Adversarial Network is very challenging to ensure accountability and transparency in their application. GAN is opaque and difficult to explain.

Applications to GAN:

There are various applications of Generative Adversarial Networks. The applications are given below -

1. Generating images:

The GAN is used to generating the images and picture synthesis. It can create fresh and life like images. The Generative Adversarial Network can make the highly resolute image.

2. Super Resolution:

The GAN is used to super-resolution images. It is one of the important applications of Generative Adversarial Networks.

3. Image Modification:

The Generative Adversarial Network is used to modify the image. Resize the images and do another type of modification.

4. Photos of real people:

The Generative Adversarial Network is used to photos of real people. It is used in practical fields.

5. Face Ageing:

The Generative Adversarial Network is used to face ageing. It can easily increase or decrease the face ageing of the images.

6. Text to image synthesis:

The GAN is used to text to image synthesis. This is used to make the image realistic visualisation which comes from the text.

7. Image-to-image synthesis:

The GAN is used for image-to-image synthesis. It can be used to change the theme of images, change the day to night of the image, can convert real images to drawing images and vice versa, and also can change the style of creativity in the image.

Next Topic#

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA