(discriminator, x, x_fake, y, is_training)
Returns the WGAN gradient penalty.

  Args:
    discriminator: Instance of `AbstractDiscriminator`.
    x: samples from the true distribution, shape [bs, h, w, channels].
    x_fake: samples from the fake distribution, shape [bs, h, w, channels].
    y: Encoded class embedding for the samples. None for unsupervised models.
    is_training: boolean, are we in train or eval model.

  Returns:
    A tensor with the computed penalty.
Returns the WGAN gradient penalty.
Returns the WGAN gradient penalty .
def wgangp_penalty(discriminator, x, x_fake, y, is_training):
  """Returns the WGAN gradient penalty.

  Args:
    discriminator: Instance of `AbstractDiscriminator`.
    x: samples from the true distribution, shape [bs, h, w, channels].
    x_fake: samples from the fake distribution, shape [bs, h, w, channels].
    y: Encoded class embedding for the samples. None for unsupervised models.
    is_training: boolean, are we in train or eval model.

  Returns:
    A tensor with the computed penalty.
  """
  with tf.name_scope("wgangp_penalty"):
    alpha = ops.random_uniform(shape=[x.shape[0].value, 1, 1, 1], name="alpha")
    interpolates = x + alpha * (x_fake - x)
    logits = discriminator(
        interpolates, y=y, is_training=is_training, reuse=True)[1]
    gradients = tf.gradients(logits, [interpolates])[0]
    slopes = tf.sqrt(0.0001 + tf.reduce_sum(
        tf.square(gradients), reduction_indices=[1, 2, 3]))
    gradient_penalty = tf.reduce_mean(tf.square(slopes - 1.0))
    return gradient_penalty
def wgangp_penalty ( discriminator , x , x_fake , y , is_training ) : with tf . name_scope ( "wgangp_penalty" ) : alpha = ops . random_uniform ( shape = [ x . shape [ 0 ] . value , 1 , 1 , 1 ] , name = "alpha" ) interpolates = x + alpha * ( x_fake - x ) logits = discriminator ( interpolates , y = y , is_training = is_training , reuse = True ) [ 1 ] gradients = tf . gradients ( logits , [ interpolates ] ) [ 0 ] slopes = tf . sqrt ( 0.0001 + tf . reduce_sum ( tf . square ( gradients ) , reduction_indices = [ 1 , 2 , 3 ] ) ) gradient_penalty = tf . reduce_mean ( tf . square ( slopes - 1.0 ) ) return gradient_penalty