Training the model

Let's go through this process step by step.

  1. Start by adding TensorBoard to store losses:
tensorboard = TensorBoard(log_dir="logs/".format(time.time()))tensorboard.set_model(stage2_gen)tensorboard.set_model(stage2_dis)
  1. Then, create two tensors with the labels real and fake. These will be required during the training of the generator and the discriminator. Use label smoothing, which is covered in Chapter 1, Introduction to Generative Adversarial Networks:
real_labels = np.ones((batch_size, 1), dtype=float) * 0.9fake_labels = np.zeros((batch_size, 1), dtype=float) * 0.1
  1. Next, create a for loop, which should run for the number of times specified by the number of epochs, as follows:
for epoch in range(epochs):    print(

Get Generative Adversarial Networks Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.