docstr: We need to set tower_func because it's a TowerTrainer,
  and only TowerTrainer supports automatic graph creation for inference during training.
  
  If we don't care about inference during training, using tower_func is
  not needed. Just calling model.build_graph directly is OK.
docstr_tok: ["We","need","to","set","tower_func","because","it","'s","a","TowerTrainer",",","and","only","TowerTrainer","supports","automatic","graph","creation","for","inference","during","training",".","If","we","do","n't","care","about","inference","during","training",",","using","tower_func","is","not","needed",".","Just","calling","model.build_graph","directly","is","OK","."]
code: def _build_gan_trainer(self, input, model):
      """
      We need to set tower_func because it's a TowerTrainer,
      and only TowerTrainer supports automatic graph creation for inference during training.
  
      If we don't care about inference during training, using tower_func is
      not needed. Just calling model.build_graph directly is OK.
      """
      # Build the graph
      self.tower_func = TowerFunc(model.build_graph, model.inputs())
      with TowerContext("", is_training=True):
          self.tower_func(*input.get_input_tensors())
      opt = model.get_optimizer()
  
      # Define the training iteration
      # by default, run one d_min after one g_min
      with tf.name_scope("optimize"):
          g_min = opt.minimize(
              model.g_loss, var_list=model.g_vars, name="g_op"
          )
          with tf.control_dependencies([g_min]):
              d_min = opt.minimize(
                  model.d_loss, var_list=model.d_vars, name="d_op"
              )
      self.train_op = d_min
  
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 GANTrainer obj's underlying member method code with example usage: obj._build_gan_trainer(input, model) without return types