class_docstr: A GAN trainer which runs two optimization ops with a certain ratio.
class_docstr_tok: ["A","GAN","trainer","which","runs","two","optimization","ops","with","a","certain","ratio","."]
docstr: Args:
      d_period(int): period of each d_opt run
      g_period(int): period of each g_opt run
docstr_tok: ["Args",":","d_period","(","int",")",":","period","of","each","d_opt","run","g_period","(","int",")",":","period","of","each","g_opt","run"]
code: def __init__(self, input, model, d_period=1, g_period=1):
      """
      Args:
          d_period(int): period of each d_opt run
          g_period(int): period of each g_opt run
      """
      super(SeparateGANTrainer, self).__init__()
      self._d_period = int(d_period)
      self._g_period = int(g_period)
      assert min(d_period, g_period) == 1
  
      # Setup input
      cbs = input.setup(model.get_input_signature())
      self.register_callback(cbs)
  
      # Build the graph
      self.tower_func = TowerFunc(model.build_graph, model.inputs())
      with TowerContext("", is_training=True), argscope(
          BatchNorm, ema_update="internal"
      ):
          # should not hook the EMA updates to both train_op, it will hurt training speed.
          self.tower_func(*input.get_input_tensors())
      update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
      if len(update_ops):
          logger.warn(
              "Found {} ops in UPDATE_OPS collection!".format(
                  len(update_ops)
              )
          )
          logger.warn(
              "Using SeparateGANTrainer with UPDATE_OPS may hurt your training speed a lot!"
          )
  
      opt = model.get_optimizer()
      with tf.name_scope("optimize"):
          self.d_min = opt.minimize(
              model.d_loss, var_list=model.d_vars, name="d_min"
          )
          self.g_min = opt.minimize(
              model.g_loss, var_list=model.g_vars, name="g_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 1 to create a new SeparateGANTrainer object from inherited base classes: TowerTrainer with example: obj = SeparateGANTrainer(input, model, d_period, g_period)