Defining the loss functions

As shown in the previous section, the Discriminator's output is linear because the loss function we are going to use applies the nonlinearity for us. To implement the adversarial training process by following the original formulation, the loss function to use is binary cross-entropy:

(tf2)

bce = tf.keras.losses.BinaryCrossentropy(from_logits=True)

The bce object is used to compute the binary cross-entropy between two distributions:

  • The learned distribution, which is represented by the Discriminator's output, is squashed into the [0,1] range (by applying it the sigmoid function, since the from_logits parameter is ...

Get Hands-On Neural Networks with TensorFlow 2.0 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.