code: def build_graph(self, image_pos):
      image_pos = image_pos / 128.0 - 1
  
      z = tf.random_uniform(
          [args.batch, args.z_dim], minval=-1, maxval=1, name="z_train"
      )
      z = tf.placeholder_with_default(z, [None, args.z_dim], name="z")
  
      def summary_image(name, x):
          x = (x + 1.0) * 128.0
          x = tf.clip_by_value(x, 0, 255)
          tf.summary.image(name, tf.cast(x, tf.uint8), max_outputs=30)
  
      with argscope(
          [Conv2D, FullyConnected],
          kernel_initializer=tf.truncated_normal_initializer(
              stddev=0.02
          ),
      ):
          with tf.variable_scope("gen"):
              image_gen = self.decoder(z)
  
          with tf.variable_scope("discrim"):
              with tf.variable_scope("enc"):
                  hidden_pos = self.encoder(image_pos)
                  hidden_neg = self.encoder(image_gen)
  
              with tf.variable_scope("dec"):
                  recon_pos = self.decoder(hidden_pos)
                  recon_neg = self.decoder(hidden_neg)
  
      with tf.name_scope("viz"):
          summary_image("generated-samples", image_gen)
          summary_image("reconstruct-real", recon_pos)
          summary_image("reconstruct-fake", recon_neg)
  
      with tf.name_scope("losses"):
          L_pos = tf.reduce_mean(
              tf.abs(recon_pos - image_pos), name="loss_pos"
          )
          L_neg = tf.reduce_mean(
              tf.abs(recon_neg - image_gen), name="loss_neg"
          )
  
          eq = tf.subtract(GAMMA * L_pos, L_neg, name="equilibrium")
          measure = tf.add(L_pos, tf.abs(eq), name="measure")
  
          kt = tf.get_variable("kt", dtype=tf.float32, initializer=0.0)
  
          update_kt = kt.assign_add(1e-3 * eq)
          with tf.control_dependencies([update_kt]):
              self.d_loss = tf.subtract(
                  L_pos, kt * L_neg, name="loss_D"
              )
              self.g_loss = L_neg
  
      add_moving_summary(L_pos, L_neg, eq, measure, self.d_loss)
      tf.summary.scalar("kt", kt)
  
      self.collect_variables()
  
file_path: tensorpack/examples/GAN/BEGAN.py
imports: import tensorflow
  from tensorpack import *
  from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope
  from tensorpack.tfutils.summary import add_moving_summary
  from tensorpack.utils.gpu import get_num_gpu
  import DCGAN
  from GAN import GANModelDesc, GANTrainer
label_desc: Use image node_id 4 for calling the Model obj's underlying member method code with example usage: obj.build_graph(image_pos) without return types