Source: Deep Learning on Medium
In my previous blog i had given description about the generative models, taxonomy of GAN and basic understanding of GAN. In this section we shall be focusing more on the Internal Working of GAN.
From our previous blog we got an understanding that GAN consists of two components of CNN network termed as Generative neural network (G-Network) and Discriminator neural network (D-Network). In the below section we understand how these network work together to produce an generated image from an data distribution.
There are three basic steps on how GAN trains and works to produce new image / data .
Stage 1- Training the D-network : In the very beginning of the training , G-network takes an random input as noise (eg. Gaussian Noise) and generate an random image as shown below in the Fig 1. The D-network basically acts a classifier trained from input as real data and distinguishes between real and fake objects based on the predicted probability value which lies between 0–1(eg: dogs and non-dogs). We obtain the error value by finding the difference between the predicted value and comparing it with 0 for fake and 1 for real ,by back propagation process the weights of the D-network shall be updated in the process so as to it can classify much better.
Stage 2-Training the G-network :As the iteration process continues we simultaneously train the G- network by using the input random noise and generating new images these generated images are validated using D-network and it classifies the images as real or fake (eg: dogs and non-dogs). Similarly we obtain the errors from the predicted probability and update the weights of the G-network as shown in Fig 2. We always train both the G and D network separately and simultaneously so that one does not over train itself and converges sooner compared to other.
It is similar to Step 1 but now the D- network gets new batch of real data (eg.dog) as input for its training and can classify better between real and fake images as the output predicted probability is higher compared to previous value. The error value calculated are back propagated and the weight are updated again Fig 3 .During this step 2 D- network gives a feed back to the G-network for the reason behind its classification as real or fake , it gives feature level analysis to the G-network saying which features did it find to be more inappropriate so that G-network can correct it in the next iteration and generate better images.
As for G -network it generates better images of real samples /objects (eg. dogs) instead of randomly generating some images , since it has learnt from the back propagation process from step 1 , the same process is followed but due to additional feedback of the D-network its able to generate better images which has better features of the real image added to its new generated image . The same procedure of calculation of error and update of weights due to back propagation continues Fig 4.
Same as before G-network will add the new feature of real data while generation of new image (eg. eye,ears features for dog image) and it will be passed to the D-network to classify it as real or fake , the D-network trains with new batch of real images but it finds very difficult to discriminate between real and fake images of the generated data , the output predicted probability is now closer for real and fake images (eg: dogs and non dogs) Fig 5. The weights get updated by back propagation for both G and D- networks. Slowly the values of both the G and D- network start to converge.
Conclusion :The above mentioned steps are just one cycle so when we train a GAN for an epoch , iterations all these steps are continuously happening and both networks learn to generate new images as they converge. From the above working the G-network can we considered a De-convolutional network and D- network can we considered as Convolutional network.
In the next series we shall understand more on GAN applications . For better explanation all the images are taken from open source videos.Since I might not be an expert on the topic, if you find any mistakes in the article, or have any suggestions for improvement, please mention in comments.