The steps given in this section show how to train the discriminator network. This is a continuation of the last series of steps:
- Generate fake high-resolution images using the generator network:
generated_high_resolution_images =
generator.predict(low_resolution_images)
- Create a batch of real labels and fake labels:
real_labels = np.ones((batch_size, 16, 16, 1))
fake_labels = np.zeros((batch_size, 16, 16, 1))
- Train the discriminator network on real images and real labels:
d_loss_real = discriminator.train_on_batch(high_resolution_images,
real_labels)
- Train the discriminator on generated images and fake labels:
d_loss_fake = discriminator.train_on_batch(generated_high_resolution_images, fake_labels)
- Finally, calculate the total discriminator loss:
d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
We have now added the code to train the discriminator network. Next, add the code to train the adversarial model, which trains the generator network.