To generate images of handwritten digits, we will leverage the same network as we learned about in the previous section. The strategy we will adopt is as follows:
- Import MNIST data.
- Initialize random noise.
- Define the generator model.
- Define the discriminator model.
- Train the two models alternately.
- Let the model train until the generator and discriminator losses are largely the same.
Let's execute each of the preceding steps in the following code:
The following code is available as Handwritten_digit_generation_using_GAN.ipynb in the Chapter12 folder in this book's GitHub repository - https://tinyurl.com/mcvp-packt The code is moderately lengthy. We strongly recommend you to execute the notebook in GitHub to reproduce results while you understand the steps to perform and explanation of various code components from text.
- Import the relevant packages and define the device:
!pip install -q torch_snippets
from torch_snippets import *
device...