code: def define_loss(gan_model, **kwargs):
      """Defines progressive GAN losses.
  
      The generator and discriminator both use wasserstein loss. In addition,
      a small penalty term is added to the discriminator loss to prevent it getting
      too large.
  
      Args:
        gan_model: A `GANModel` namedtuple.
        **kwargs: A dictionary of
            'gradient_penalty_weight': A float of gradient norm target for
                wasserstein loss.
            'gradient_penalty_target': A float of gradient penalty weight for
                wasserstein loss.
            'real_score_penalty_weight': A float of Additional penalty to keep
                the scores from drifting too far from zero.
  
      Returns:
        A `GANLoss` namedtuple.
      """
      gan_loss = tfgan.gan_loss(
          gan_model,
          generator_loss_fn=tfgan.losses.wasserstein_generator_loss,
          discriminator_loss_fn=tfgan.losses.wasserstein_discriminator_loss,
          gradient_penalty_weight=kwargs["gradient_penalty_weight"],
          gradient_penalty_target=kwargs["gradient_penalty_target"],
          gradient_penalty_epsilon=0.0,
      )
  
      real_score_penalty = tf.reduce_mean(
          tf.square(gan_model.discriminator_real_outputs)
      )
      tf.summary.scalar("real_score_penalty", real_score_penalty)
  
      return gan_loss._replace(
          discriminator_loss=(
              gan_loss.discriminator_loss
              + kwargs["real_score_penalty_weight"] * real_score_penalty
          )
      )
  
imports: import os
  import time
  from absl import logging
  from magenta.models.gansynth.lib import networks
  import numpy
  import tensorflow.compat.v1
  import tensorflow_gan
label_desc: Use image node_id 9 for calling a global function with example usage: define_loss(gan_model) and returns: gan_loss