code: def build_graph(self, A, B):
      A = tf.transpose(A / 255.0, [0, 3, 1, 2])
      B = tf.transpose(B / 255.0, [0, 3, 1, 2])
  
      # use the torch initializers
      with argscope(
          [Conv2D, Conv2DTranspose, FullyConnected],
          kernel_initializer=tf.variance_scaling_initializer(
              scale=0.333, distribution="uniform"
          ),
          use_bias=False,
      ), argscope(
          BatchNorm, gamma_init=tf.random_uniform_initializer()
      ), argscope(
          [Conv2D, Conv2DTranspose, BatchNorm], data_format="NCHW"
      ):
          with tf.variable_scope("gen"):
              with tf.variable_scope("B"):
                  AB = self.generator(A)
              with tf.variable_scope("A"):
                  BA = self.generator(B)
                  ABA = self.generator(AB)
              with tf.variable_scope("B"):
                  BAB = self.generator(BA)
  
          viz_A_recon = tf.concat(
              [A, AB, ABA], axis=3, name="viz_A_recon"
          )
          viz_B_recon = tf.concat(
              [B, BA, BAB], axis=3, name="viz_B_recon"
          )
          tf.summary.image(
              "Arecon",
              tf.transpose(viz_A_recon, [0, 2, 3, 1]),
              max_outputs=50,
          )
          tf.summary.image(
              "Brecon",
              tf.transpose(viz_B_recon, [0, 2, 3, 1]),
              max_outputs=50,
          )
  
          with tf.variable_scope("discrim"):
              with tf.variable_scope("A"):
                  A_dis_real, A_feats_real = self.discriminator(A)
                  A_dis_fake, A_feats_fake = self.discriminator(BA)
  
              with tf.variable_scope("B"):
                  B_dis_real, B_feats_real = self.discriminator(B)
                  B_dis_fake, B_feats_fake = self.discriminator(AB)
  
      with tf.name_scope("LossA"):
          # reconstruction loss
          recon_loss_A = tf.reduce_mean(
              tf.squared_difference(A, ABA), name="recon_loss"
          )
          # gan loss
          self.build_losses(A_dis_real, A_dis_fake)
          G_loss_A = self.g_loss
          D_loss_A = self.d_loss
          # feature matching loss
          fm_loss_A = self.get_feature_match_loss(
              A_feats_real, A_feats_fake
          )
  
      with tf.name_scope("LossB"):
          recon_loss_B = tf.reduce_mean(
              tf.squared_difference(B, BAB), name="recon_loss"
          )
          self.build_losses(B_dis_real, B_dis_fake)
          G_loss_B = self.g_loss
          D_loss_B = self.d_loss
          fm_loss_B = self.get_feature_match_loss(
              B_feats_real, B_feats_fake
          )
  
      global_step = get_global_step_var()
      rate = tf.train.piecewise_constant(
          global_step, [np.int64(10000)], [0.01, 0.5]
      )
      rate = tf.identity(rate, name="rate")  # TF issue#8594
      g_loss = tf.add_n(
          [
              (
                  (G_loss_A + G_loss_B) * 0.1
                  + (fm_loss_A + fm_loss_B) * 0.9
              )
              * (1 - rate),
              (recon_loss_A + recon_loss_B) * rate,
          ],
          name="G_loss_total",
      )
      d_loss = tf.add_n([D_loss_A, D_loss_B], name="D_loss_total")
  
      self.collect_variables("gen", "discrim")
      # weight decay
      wd_g = regularize_cost(
          "gen/.*/W", l2_regularizer(1e-5), name="G_regularize"
      )
      wd_d = regularize_cost(
          "discrim/.*/W", l2_regularizer(1e-5), name="D_regularize"
      )
  
      self.g_loss = g_loss + wd_g
      self.d_loss = d_loss + wd_d
  
      add_moving_summary(
          recon_loss_A, recon_loss_B, rate, g_loss, d_loss, wd_g, wd_d
      )
  
file_path: tensorpack/examples/GAN/DiscoGAN-CelebA.py
imports: import argparse
  import numpy
  import os
  import tensorflow
  from tensorpack import *
  from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope
  from tensorpack.tfutils.summary import add_moving_summary
  from GAN import GANModelDesc, SeparateGANTrainer
label_desc: Use image node_id 5 for calling the Model obj's underlying member method code with example usage: obj.build_graph(A, B) without return types