code: def lossfn(real_input, fake_input, compress, hparams, lsgan, name):
      """Loss function."""
      eps = 1e-12
      with tf.variable_scope(name):
          d1 = discriminator(
              real_input, compress, hparams, "discriminator"
          )
          d2 = discriminator(
              fake_input, compress, hparams, "discriminator", reuse=True
          )
          if lsgan:
              dloss = tf.reduce_mean(
                  tf.squared_difference(d1, 0.9)
              ) + tf.reduce_mean(tf.square(d2))
              gloss = tf.reduce_mean(tf.squared_difference(d2, 0.9))
              loss = (dloss + gloss) / 2
          else:  # cross_entropy
              dloss = -tf.reduce_mean(
                  tf.log(d1 + eps)
              ) - tf.reduce_mean(tf.log1p(eps - d2))
              gloss = -tf.reduce_mean(tf.log(d2 + eps))
              loss = (dloss + gloss) / 2
          return loss
  
file_path: tensor2tensor/tensor2tensor/models/research/cycle_gan.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.models.research import transformer_vae
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 3 for calling a global function with example usage: lossfn(real_input, fake_input, compress, hparams, lsgan, name) and returns: loss