"Deep Learning" ------ Generative Adversarial Network (GAN) study notes

1. Principles of Generative Adversarial Networks (GAN)

The idea of ​​​​GAN : a two-player game idea (two-player game), the sum of the interests of both sides of the game is a constant.
Like the movie "Cat and Mouse", Generative Network G can be seen as fake check makers who try to make fake checks and use them without detection, while Discrimination Network is similar to police, they try to detect fake checks . The competition in this game prompted both teams to refine their methods until the counterfeit and the real were indistinguishable.
insert image description here

The generative adversarial network (GAN) is divided into two parts: the generation network G (Generator) and the discriminant network D (Disciminator)
(1) the generation network G: the generator, which is responsible for generating fake data
(2) the discrimination network D: the discriminator, Responsible for the authenticity of the entered data

Network framework:
insert image description here
A more detailed schematic:
insert image description here
In the most ideal state: The
generation network generates fake samples that are "real". G(z) The
adversarial network is difficult to judge whether the samples generated by G(z) are real, so D (G(z)) = 0.5. The resulting generative model G is used to generate fake samples.

2. GAN training ideas

The training of GAN needs to train a network at the same time. The training method is: alternate iterative training alone , that is, when training the generative network, fix the adversarial network, and then train the generative network; when training the adversarial network, fix the generation network. network, and then train the adversarial network . The purpose of this is to prevent one network from being too much stronger than the other, because if one network is too strong, the other will be too weak and the performance of both networks will be weakened. These two are like the contradictions in philosophy, although they seem to be opposites, but the result of the combined effect of the two is to cause things to move forward.
Therefore, the two networks are not a struggle in the full sense, but an enemy and a friend , and they have to work together to achieve a common goal. Throughout the training process, the discriminator has to teach the generator how to adjust on the generated data, while also learning how to be a better teacher. They keep getting stronger in adversarial learning, and ideally reach an equilibrium----D(G(z)) = 0.5 (Nash equilibrium)

2.1 Training of the discriminator

Ideally: feed it a sample from the training set and the sample generated by the generator, if the input is a fake sample generated, the discriminator will output 0, if it is a real sample, it will output 1 .
step1: Build the network model for training the discriminator and compile the model.
Step2: Label the real sample and the fake sample obtained by the generator with different labels. The label is used by the discriminator to distinguish whether the sample is a real sample or a fake sample. valid is a matrix of (Bach_Size, 1) with all 0s; fake is a matrix of (Bach_Size, 1) with all 1s.
step3: The input discriminator of the real sample, compare its output with fake to get the loss value
step4: The fake sample generated by the generator is input to the discriminator, compare its output with the vaild to get the loss value, and finally add the two to get the discriminator's value total loss value. The total loss is reduced by continuous training.

2.2 Generator training

Ideally: the generator must try to make the discriminator think it generates fake samples, i.e. the discriminator inputs 1 after getting the fake samples.
When training the generator, fix the parameters of the discriminator, first build the network model for training the generator and compile the model combined. When training the generated network G, the parameters of the identification network D do not change, that is, just pass the loss back all the time, and then update the parameters of the generated network after passing it to the generation network G.

In order to train the generator, the discriminator needs to tell the generator how to adjust so that the samples it generates are closer to the real ones.
The discriminator adjusts the generated samples by back-propagating the gradient of the discriminator output, telling the generator how much each feature should be adjusted to make the whole sample more realistic. Meanwhile, further back-propagating these sample gradients becomes the weights that make up the generator.

2.3 Objective function

Objective function in the original paper:
min ⁡ G max ⁡ DV ( D , G ) = E x ∼ P data ( x ) [ log ⁡ ( D ( x ) ) ] + E z ∼ P z ( z ) [ log ⁡ ( 1 − D ( G ( z ) ) ) ] \min_G \max_D V(D,G) = E_{x \sim Pdata(x)}[\log(D(x))]+E_{z \sim P_z( z)}[\log(1-D(G(z)))]GminDmaxV(D,G)=ExPdata(x)[log(D(x))]+EzPwith( with )[log(1D ( G ( z ) ) ) ]
This formula includes the training process of two networks,that is, the identification network D is optimized first, and then the generation network G is optimized.
Want to distinguish the performance of the network as large as possible, ielog ⁡ ( D ( x ) ) \log(D(x))log ( D ( x ) ) is the largest. When the input to the discrimination network is a real sample, the ideal situation is log ⁡ ( D ( x ) ) = 0 \log(D(x)) = 0log(D(x))=0 , log ⁡ ( 1 − D ( G ( z ) ) ) = 0 \log(1-D(G(z)))=0 log(1D(G(z)))=0
At the same time, make the performance of the generated network as large as possible, so that the generated samples and the real samples cannot be distinguished throughout the network, that is,log ⁡ ( 1 − D ( G ( z ) ) ) \log(1-D(G(z ) )))log(1D ( G ( z ) ) ) is minimal, ideallylog ⁡ ( 1 − D ( G ( z ) ) ) ≈ − ∞ \log(1-D(G(z))) \approx -\inftylog(1D(G(z)))
in the objective function, when the discriminatorDDD and generatorGGWhen G can no longer progress, a balance is reached, the Nash balance.
Want to know about Nash's recommended movie"A Beautiful Mind"

The algorithm of GAN network training in the paper:
insert image description here

参考:
1.https://blog.csdn.net/qq_40784418/article/details/105777608

2.https://blog.csdn.net/on2way/article/details/72773771?utm_source=app&app_version=5.0.0&code=app_1562916241&uLinkId=usr1mkqgl919blen

3.https://blog.csdn.net/u014038273/article/details/78783419

4. Interpretation of the initial paper of GAN

Guess you like

Origin blog.csdn.net/Naruto_8/article/details/122616528