Jun 01, 2021 Article blog
This article was reproduced to Know ID: Charles (Bai Lu) knows his personal column
Download the W3Cschool Mobile App, 0 Foundation Anytime, Anywhere Learning Programming >> Poke this to learnLead
Build a simple GAN network with Python to generate MNIST datasets. W HERE GAN IS GENERATED AGAINST THE NETWORK.
Full name:
Generative Adversarial Networks
Stealing introduced a wave of mind-bombled GAN, came to send a wave of text.
After all, it has been a hot and interesting direction in deep learning since it was proposed by Ian Goodfellow in 2014.
Let's Go~~~
Baidu web download link:
https://pan.baidu.com/s/1h6haOWnQojZU67igrNveeA
Password: 51pr
Related modules:
tensorflow-gpu module;
numpy module;
matplotlib module;
and some Python's own modules.
The TensorFlow-GPU version is:
1.7.0
Install Python and add it to the environment variable, and pip installs the relevant modules that are required.
Among them, TensorFlow-GPU environment construction please refer to the relevant network tutorials, pay attention to the version and drive strict correspondence can be.
The basic idea of generating an adversarial network (GAN) derives from the two-person zero-sum game in game theory, consisting of a generator and a judge, which is trained through adversarial learning.
Specifically:
GAN generators are mainly used to learn the characteristic distribution of real images so as to make their own generated images more realistic, in order to deceive the judge. The judge needs to make a true and false judgment on the image you enter.
The whole process is strung together, the generator tries to make the resulting image more realistic, so that the judge thinks that the resulting image is the real image, and the judge tries to identify the true and false images, so that the generator can not deceive themselves.
As the training progresses, the generator and the judge continue to fight, and the end result is, of course:
The image generated by the generator is close to the real image, and the probability that the judge is correct for the image generated by the generator is close to 0.5.
The process can also be summed up in the following image:
In terms of the GAN network-specific model that generates MNIST:
The generator structure is:
The structure of the judge is:
For specific implementation details, see the source code in the relevant file.
The comments in the code are more detailed T_T
How to train:
Run the GanMnist.py file in the cmd window.
Los trend during training:
Image evolution generated by the generator (show.py file):
How to test:
Run the Test.py file in the cmd window.
Generate MNIST dataset results from trained models:
T_T Well, this example may not reflect how interesting GAN is.
So set up a Flag, next time you have time to use the GAN network to do some interesting things, very, very interesting things