December 2018
Beginner to intermediate
684 pages
21h 9m
English
Adversarial training iterates over the epochs, generates random image and noise input, and trains both the discriminator and the generator (as part of the combined model):
valid = np.ones((batch_size, 1))fake = np.zeros((batch_size, 1))for epoch in range(epochs): # Select a random half of images idx = np.random.randint(0, X_train.shape[0], batch_size) imgs = X_train[idx] # Sample noise and generate a batch of new images noise = np.random.normal(0, 1, (batch_size, latent_dim)) gen_imgs = generator.predict(noise) # Train the discriminator (real classified as ones and generated as zeros) d_loss_real = discriminator.train_on_batch(imgs, valid) d_loss_fake = discriminator.train_on_batch(gen_imgs, fake) d_loss = 0.5 * np.add(d_loss_real, ...