We will use Adam as the training method for both the generator and discriminator networks. If you are interested in the details of gradient descent methods, please refer to Chapter 3, Best Practices for Model Design and Training, to learn more about the common training methods.
Let's first define the loss function for the discriminator network and optimizers for both of the networks:
criterion = nn.BCELoss()
optimizerD = optim.Adam(netD.parameters(), lr=lr, betas=(0.5, 0.999))
optimizerG = optim.Adam(netG.parameters(), lr=lr, betas=(0.5, 0.999))
Here, nn.BCELoss() represents the Binary Cross-Entropy loss function, which we previously used in Chapter 1, Generative Adversarial Networks Fundamentals.
Next, let's load the MNIST dataset to the GPU memory:
dataset = dset.MNIST(root=DATA_PATH, download=True,
transform=transforms...