Let us build a simple Generative Adversarial Network (GAN) from scratch | GAN theory and intuition

preview_player
Показать описание
Imagine you have Neural Network (NN1) whose job is to initially output a random noise 32x32 matrix (a noise image).

Now imagine there is a second neural network (NN2). The output of NN1 is given as the input to NN2.

NN2 is trained to predict a probability (p) for the input 32x32 image to be the very specific image of a ‘cat’.

Since the initial input image is a noise, the probability ‘p’ will be a low number. Say p = 0.001.

Now we can define loss functions for NN1 and NN2.

If the predicted output ‘p’ is close to zero, the loss of NN1 is very low. The higher the value of ‘p’, the higher the loss.

If the predicted output ‘p’ is close to 1, the loss of NN2 is very low. Do you understand what this means? This means that the image output by NN1 looks very much like the cat image that NN2 is referring to.

Basically if ‘p’ is close to 1, then NN1 generated a ‘fake’ image of a cat that looks exactly like the original cat.

So how do we try to bring the output ‘p’ as close to 1 as possible? We make NN1 fight against NN2.

NN1 has a singular mission. To take ‘p’ close to 1.
NN2 has a singular mission. To take ‘p’ close to 0.

If we train the weights and biases of NN1 and NN2 according to their corresponding losses, we get a very good ‘generator’ who can create an incredibly good-looking ‘fake’ cat image.

This simple task is the basic principle of GAN: Generative Adversarial Network.

NN1 is called the Generator.
NN2 is called the Discriminator.

They are adversaries.

Heard of deepfake? You might have seen videos/GIFs of Trump speaking exactly like Obama. GAN enables that.

GAN is very much different from the diffusion models used in current Generative AI image models. But GAN is much simpler and better for very well-defined tasks.

It is such an amazing concept yet so simple that you think how could you not come up with this? I guess that is the beauty of anything so good.

In this lecture we will build a simple GAN from scratch.
Have fun implementing GAN. Feel free to reach out for any questions.
Рекомендации по теме
Комментарии
Автор

Really interesting. Generator descrimator System. Competing each other like trial and error method .

padmanabhannamboothiri
Автор

Sir can u make a series on computer vision using pytorch, explaining object detection, segmentation etc, with hands on practicals, Thank you

xAn_
Автор

sir, how I get to notify about you are going to live.

rahulkumar-rcrj