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

  Args:
    discriminator: Instance of `AbstractDiscriminator`.
    x: Samples from the true 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 DRAGAN gradient penalty.
Returns the DRAGAN gradient penalty .
def dragan_penalty(discriminator, x, y, is_training):
  """Returns the DRAGAN gradient penalty.

  Args:
    discriminator: Instance of `AbstractDiscriminator`.
    x: Samples from the true 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("dragan_penalty"):
    _, var = tf.nn.moments(x, axes=list(range(len(x.get_shape()))))
    std = tf.sqrt(var)
    x_noisy = x + std * (ops.random_uniform(x.shape) - 0.5)
    x_noisy = tf.clip_by_value(x_noisy, 0.0, 1.0)
    logits = discriminator(x_noisy, y=y, is_training=is_training, reuse=True)[1]
    gradients = tf.gradients(logits, [x_noisy])[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 dragan_penalty ( discriminator , x , y , is_training ) : with tf . name_scope ( "dragan_penalty" ) : _ , var = tf . nn . moments ( x , axes = list ( range ( len ( x . get_shape ( ) ) ) ) ) std = tf . sqrt ( var ) x_noisy = x + std * ( ops . random_uniform ( x . shape ) - 0.5 ) x_noisy = tf . clip_by_value ( x_noisy , 0.0 , 1.0 ) logits = discriminator ( x_noisy , y = y , is_training = is_training , reuse = True ) [ 1 ] gradients = tf . gradients ( logits , [ x_noisy ] ) [ 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