May 2019
Intermediate to advanced
272 pages
7h 19m
English
We need to implement several functions to accommodate the Wasserstein GAN with Gradient Penalty loss. Our implementation is an adaptation of the implementation written by the Keras team; it can be found at https://github.com/keras-team/keras-contrib/blob/master/examples/improved_wgan.py
We start with the necessary imports:
import keras.backend as Kfrom keras.layers.merge import _Merge
We first define the Wasserstein loss, which is just the average of the Discriminator's output multiplied by the respective sign:
def loss_wasserstein(y_true, y_pred): return K.mean(y_true * y_pred)
Next, we define the Gradient Penalty loss:
def loss_gradient_penalty(y_true, y_pred, averaged_samples, gradient_penalty_weight): # get ...
Read now
Unlock full access