August 2018
Intermediate to advanced
272 pages
7h 2m
English
In TensorFlow, we can implement the whole GAN loss, as shown in the following code. As input, we take the output of the discriminator for a batch of fake images from the generator and a batch of real images from our dataset:
def gan_loss(logits_real, logits_fake): # Target label vectors for generator and discriminator losses. true_labels = tf.ones_like(logits_real) fake_labels = tf.zeros_like(logits_fake) # DISCRIMINATOR loss has 2 parts: how well it classifies real images and how well it # classifies fake images. real_image_loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits_real, labels=true_labels) fake_image_loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits_fake, labels=fake_labels) # Combine ...
Read now
Unlock full access