Pytorch framework implements DCGAN (relatively easy to understand)

Table of contents

1. Understand DCGAN

2. The structure of the DCGAN network model in this paper

(1) Generate model structure

(2) Discriminant model structure

(3) DCGAN model structure

3. Dataset download 

4. GAN code implementation

5. The mainWindow window displays the pictures generated by the generator

expand


GAN principle and Pytorch framework to realize GAN (relatively easy to understand)

1. Understand DCGAN

  • The original GAN ​​network is mainly based on the fully connected layer to realize the generator G and the discriminator D (the above connection gives the basic principle and implementation of GAN). Due to the relatively high dimension of the picture and the huge amount of network parameters, the training effect is not very good. excellent.
  • DCGAN proposes a generative network implemented using a transposed convolution (Transpose Convolution) layer, and a discriminative network implemented by an ordinary convolution layer, which greatly reduces the amount of network parameters, and at the same time, the image generation effect is also greatly improved, showing the GAN model. The image generation effect far exceeds the potential of the VAE model.
  • DCGAN proposes a series of empirical GAN ​​network training techniques, which were proved to be beneficial to the stable training of the network before GAN was proposed.

2. The structure of the DCGAN network model in this paper

(1) Generate model structure

 The deep convolutional neural network is used as the generation model, in which random noise is used as the input of the generation model, and the input vector is mapped to a two-dimensional output image (RGB) through five deconvolutions.

gen = Generator()
summary(gen, input_size=(1,100,1,1))

(2) Discriminant model structure

Similarly, with a deep convolutional neural network as a generative model, the structure of the discriminative model is opposite to that of the generative model.

dis = Discriminator()
summary(dis,input_size=(1,3,64,64))

(3) DCGAN model structure

3. Dataset download 

Link: https://pan.baidu.com/s/1i_VU3aQpLkCx4Z5fhDVKHA 
Extraction code: 79y3

4. GAN code implementation

Tip: The code is placed on Github, and readers can download it by themselves: https://github.com/KeepTryingTo/Pytorch-GAN

5. The mainWindow window displays the pictures generated by the generator

Tip: Here is a program (mainWindow.py) to display the pictures displayed by the generator, load the generator model saved after the previous training, and then use the model to randomly generate pictures, as follows:

(1) Run mainWindow.py The initial interface is as follows

(2) Click to generate a picture

expand

The role of detach in pytorch

Reference article:

"TensorFlow Deep Learning"

"Machine Learning Principles, Algorithms and Applications"

Guess you like

Origin blog.csdn.net/Keep_Trying_Go/article/details/130402245