def gradient_penalty_loss(self, y_true, y_pred, averaged_samples):
    '\n        Computes gradient penalty based on prediction and weighted real / fake samples\n        '
    gradients = K.gradients(y_pred, averaged_samples)[0]
    gradients_sqr = K.square(gradients)
    gradients_sqr_sum = K.sum(gradients_sqr, axis=np.arange(1, len(gradients_sqr.shape)))
    gradient_l2_norm = K.sqrt(gradients_sqr_sum)
    gradient_penalty = K.square((1 - gradient_l2_norm))
    return K.mean(gradient_penalty)
Computes gradient penalty based on prediction and weighted real / fake samples
def gradient_penalty_loss(self, y_true, y_pred, averaged_samples):
    '\n        \n        '
    gradients = K.gradients(y_pred, averaged_samples)[0]
    gradients_sqr = K.square(gradients)
    gradients_sqr_sum = K.sum(gradients_sqr, axis=np.arange(1, len(gradients_sqr.shape)))
    gradient_l2_norm = K.sqrt(gradients_sqr_sum)
    gradient_penalty = K.square((1 - gradient_l2_norm))
    return K.mean(gradient_penalty)