GAN confrontation generation network study notes (1) Brief description of GAN

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


foreword

This article mainly records the study notes for learning GAN. If there are any mistakes, please let me know!


Tip: The following is the content of the main text of this article, and the following cases are
for reference

1. Overview of GAN network

The full name of the GAN network is generative adversarial network, translated as a generative confrontation network, which is a machine learning method. Proposed by Ian J. Goodfello et al. in Generative Adversarial Nets paper in 2014. Among them, in the GAN network, there are two models - the generative model (generative model G) and the discriminative model (discriminative model D).

Let's take generating pictures as an example. The ultimate goal of this tutorial is to use the GAN network to generate anime avatars.
1.G is a network that generates pictures. It accepts a random noise z, and then generates pictures through this noise. The generated data is recorded as G(z).
2.D is a discriminative network that judges whether a picture is "real" (whether it is fabricated). Its input parameter is x, x represents a picture, and the output D(x) represents the probability that x is a real picture. If it is 1, it means that it is definitely a real picture, and if the output is 0, it means that it cannot be real. picture of.

During the training process, the goal of the generation network G is to generate fake pictures to deceive the discriminant network D, and the goal of the discriminant network D is to be able to distinguish whether a certain picture is generated by G. This becomes a game process. At the same time, the abilities of G and D are gradually improving during the training process. In the most ideal case, it is D(G(z))=0.5. (That is to say, the discriminator cannot judge the authenticity of the image, but can only guess, so it is 0.5)

A more figurative statement: a generator ("artist") learns to create images that look real, while a discriminator ("art critic") learns to distinguish between real and fake images. During training, the generator gets better at generating realistic images, while the discriminator gets better at distinguishing those images. The training process reaches an equilibrium when the discriminator is no longer able to distinguish real images from fake ones.

insert image description here
Therefore, during the training process, we will learn the discriminator and the generator.

2. Learning of the discriminator

First, we initialize the generator G, and then input a set of random vectors (Randomly sample a vactor), the generator will generate some pictures according to the input vectors, and we mark these pictures as 0 (false pictures). At the same time, mark the real pictures in the existing training set as 1 (true pictures). Both are thrown into the discriminator D at the same time to train the discriminator D. So that when the input is a real picture, the discriminator gives a high score (the score is close to 1), and when the input is a fake picture, the discriminator gives a low score (close to 0).

insert image description here
We have real pictures marked as 1 and fake pictures marked as 0. At this time, we can easily train D (with x and y).

3. Generator learning

For D we have data labeled 1 and 0 so we can train it. So for the generator, there is x (that is, random noise z), so where is y?

For the generator, our purpose is to enable it to generate real pictures, in other words, we hope that the generated pictures can fool D. So how to generate the so-called y through the discriminator? ? We can do this:

We generate a set of fake pictures through the generation network through random vectors (noise data), we mark these fake pictures as 1 (that is, artificially treat the fake pictures as real), and then input these fake pictures into In the discriminator, when the discriminator discriminates these pictures, it will find that these pictures are fake pictures, and then give a low score, which will cause an error (because the mark is 1, but the discriminator gives a low score) .

Therefore, when training the generator, this network is concatenated. When training the generator, a very important operation is to keep the parameters of the discriminator network unchanged, but to propagate the error in the same direction, and then update the parameters of the generation network after passing it to the generation network, thus completing the generation network. of training.
insert image description here
After completing the training of the generator, we can generate new fake pictures to train the discriminator. We refer to this process as individual alternation training. At the same time, it is necessary to define a number of iterations, and stop after alternating iterations to a certain number of times.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43869415/article/details/121077465