Training the generator network

To train the generator network, we have to train the adversarial model. When we train the adversarial model, it trains the generator network only but freezes the discriminator network. We won't train the discriminator network, as we have already trained it. Perform the following steps to train the adversarial model:

  1. Start by creating a batch of noise vectors again. Sample these noise vectors from a Gaussian/Normal distribution:
z_noise = np.random.normal(0, 1, size=(batch_size, z_shape))
  1. Next, train the adversarial model on this batch of noise vectors, as follows:
g_loss = adversarial_model.train_on_batch(z_noise, [1] * batch_size)

We train the adversarial model on the batch of noise vectors and real labels. Here, real labels is a vector with all values equal to 1. We are also training the generator to fool the discriminator network. To do this, we provide it with a vector that has all the values equal to 1. In this step, the generator will receive feedback from the generator network and improve itself accordingly.

  1. Finally, print the generator loss to the console to keep track of the losses:
print("g_loss:", g_loss)

There is a passive method to evaluate the training process. After every 10 epochs, generate fake images and manually check the quality of the images:

    if epoch % 10 == 0:
z_noise = np.random.normal(0, 1, size=(batch_size, z_shape))
gen_images1 = gen_model.predict_on_batch(z_noise)

for img in gen_images1[:2]:
save_rgb_img(img, "results/one_{}.png".format(epoch))

These images will help you to decide whether to continue the training or to stop it early. Stop the training if quality of the generated high-resolution images is good. Or continue the training until your model becomes good.

We have successfully trained a DCGAN network on the ANIME character dataset. Now we can use the model to generate images of anime characters. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.44.229