docstr: Build standard GAN loss and set `self.g_loss` and `self.d_loss`.
  
  D and G play two-player minimax game with value function V(G,D)
  
    min_G max _D V(D, G) = IE_{x ~ p_data} [log D(x)] + IE_{z ~ p_fake} [log (1 - D(G(z)))]
  
  Args:
      logits_real (tf.Tensor): discrim logits from real samples
      logits_fake (tf.Tensor): discrim logits from fake samples produced by generator
docstr_tok: ["Build","standard","GAN","loss","and","set","`","self.g_loss","`","and","`","self.d_loss","`",".","D","and","G","play","two-player","minimax","game","with","value","function","V","(","G",",","D",")","min_G","max","_D","V","(","D",",","G",")","=","IE_","{","x","~","p_data","}","[","log","D","(","x",")","]","+","IE_","{","z","~","p_fake","}","[","log","(","1","-","D","(","G","(","z",")",")",")","]","Args",":","logits_real","(","tf.Tensor",")",":","discrim","logits","from","real","samples","logits_fake","(","tf.Tensor",")",":","discrim","logits","from","fake","samples","produced","by","generator"]
code: def build_losses(self, logits_real, logits_fake):
      """
      Build standard GAN loss and set `self.g_loss` and `self.d_loss`.
  
      D and G play two-player minimax game with value function V(G,D)
  
        min_G max _D V(D, G) = IE_{x ~ p_data} [log D(x)] + IE_{z ~ p_fake} [log (1 - D(G(z)))]
  
      Args:
          logits_real (tf.Tensor): discrim logits from real samples
          logits_fake (tf.Tensor): discrim logits from fake samples produced by generator
      """
      with tf.name_scope("GAN_loss"):
          score_real = tf.sigmoid(logits_real)
          score_fake = tf.sigmoid(logits_fake)
          tf.summary.histogram("score-real", score_real)
          tf.summary.histogram("score-fake", score_fake)
  
          with tf.name_scope("discrim"):
              d_loss_pos = tf.reduce_mean(
                  tf.nn.sigmoid_cross_entropy_with_logits(
                      logits=logits_real,
                      labels=tf.ones_like(logits_real),
                  ),
                  name="loss_real",
              )
              d_loss_neg = tf.reduce_mean(
                  tf.nn.sigmoid_cross_entropy_with_logits(
                      logits=logits_fake,
                      labels=tf.zeros_like(logits_fake),
                  ),
                  name="loss_fake",
              )
  
              d_pos_acc = tf.reduce_mean(
                  tf.cast(score_real > 0.5, tf.float32),
                  name="accuracy_real",
              )
              d_neg_acc = tf.reduce_mean(
                  tf.cast(score_fake < 0.5, tf.float32),
                  name="accuracy_fake",
              )
  
              d_accuracy = tf.add(
                  0.5 * d_pos_acc, 0.5 * d_neg_acc, name="accuracy"
              )
              self.d_loss = tf.add(
                  0.5 * d_loss_pos, 0.5 * d_loss_neg, name="loss"
              )
  
          with tf.name_scope("gen"):
              self.g_loss = tf.reduce_mean(
                  tf.nn.sigmoid_cross_entropy_with_logits(
                      logits=logits_fake,
                      labels=tf.ones_like(logits_fake),
                  ),
                  name="loss",
              )
              g_accuracy = tf.reduce_mean(
                  tf.cast(score_fake > 0.5, tf.float32), name="accuracy"
              )
  
          add_moving_summary(
              self.g_loss, self.d_loss, d_accuracy, g_accuracy
          )
  
imports: import numpy
  import tensorflow
  from tensorpack import BatchNorm, DataFlow, ModelDescBase, StagingInput, TowerTrainer, argscope
  from tensorpack.graph_builder import DataParallelBuilder, LeastLoadedDeviceSetter
  from tensorpack.tfutils.summary import add_moving_summary
  from tensorpack.tfutils.tower import TowerContext, TowerFunc
  from tensorpack.utils import logger
  from tensorpack.utils.argtools import memoized_method
label_desc: Use image node_id 2 for calling the GANModelDesc obj's underlying member method code with example usage: obj.build_losses(logits_real, logits_fake) without return types