GAN implemented with mxnet
This is a mxnet implementation of GAN for the purpose of generating MNIST dataset pictures.
Two sort of network structures are supported: Lenet-5 and deep convolution.
The deep convolution network based model has the discriminator structure as follows:
generators
As for the generators, they always have the structures opposite to their discriminator counterpart.
input and output layers
For the ease of computation and generalizing to other datasets with different data shapes, the input data will be first resized to 64x64 before fed to the model. In terms of the output layers, those of the two discriminators are both sigmoid cross entropy layers.
If deep convolution network models are to be used, one will need to carry out the otherwise comment behavior.
* Draw the generated pictures
By assigning the variable 'if_drawing' in the file core/config.py to be 'True', one could see the generated pictures plotted every several iterations. The period of plotting can be assigned by the variable 'draw_iter_num'.
* Save models periodically
By default, the models will be saved to the directory of model_export each 5 epoches. One could switch off the saving function by assigning the variable if_save_params to be False in the file core/config.py.
There are also other behaviors supported, one may swich on/off them in the file core/config.py.
2. Train the network
Start training by running the python script train.py in the project directory:
```sh
$ cd GAN-mxnet
$ python3 train.py
In general, the Lenet-5 based models will train faster than the deep convolution based models.
After the process of training, the losses of the generator and discriminator will be plotted which may indicate the state of training.
A conditional GAN(CGAN) is also provided to generate MNIST pictures. One obvious advantage of CGANs is that they allow the user to manipulate the behavior of the model. In this project, by assigning the condition to be the number classes to which the pictures belong to, we could control which numbers the generator generates in the pictures.
Simply go the root directory of the CGAN, and run the training script:
$ cd GAN-mxnet/CGAN
$ python3 train.py
After training for less than an hour on gpus, the models should converge. The trained models will be exported to the directory of GAN-mxnet/CGAN/model-export
.
In the same directory, run the test.py
script:
$ python3 test.py
One will see that the model generates the picutures as assigned instead of randomly.
Here are the tricks I used to make the generated pictures look better:
I might have the wrong skills of training a GAN. If there are errors in these tips, please let me know and I will changes them as well as my comprehensions.