Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Python uses GAN to generate MNIST datasets


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 learn
Lead

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~~~


Related documents

Baidu web download link: https://pan.baidu.com/s/1h6haOWnQojZU67igrNveeA

Password: 51pr


Develop tools

Related modules:

tensorflow-gpu module;

numpy module;

matplotlib module;

and some Python's own modules.

The TensorFlow-GPU version is:

1.7.0


Environment construction

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.


Introduction to the principle

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:

 Python uses GAN to generate MNIST datasets1

In terms of the GAN network-specific model that generates MNIST:

The generator structure is:

 Python uses GAN to generate MNIST datasets2

The structure of the judge is:

 Python uses GAN to generate MNIST datasets3

For specific implementation details, see the source code in the relevant file.

The comments in the code are more detailed T_T


The results are shown

How to train:

Run the GanMnist.py file in the cmd window.

Los trend during training:

 Python uses GAN to generate MNIST datasets4

Image evolution generated by the generator (show.py file):

 Python uses GAN to generate MNIST datasets5

How to test:

Run the Test.py file in the cmd window.

Generate MNIST dataset results from trained models:

 Python uses GAN to generate MNIST datasets6

more

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