class_docstr: Base class for single-cost trainer.
  
  Single-cost trainer has a :meth:`setup_graph` method which takes
  (input_signature, input, get_cost_fn, get_opt_fn), and build the training graph from them.
  
  To use a :class:`SingleCostTrainer` object, call `trainer.setup_graph(...); trainer.train(...)`.
class_docstr_tok: ["Base","class","for","single-cost","trainer",".","Single-cost","trainer","has","a",":","meth",":","`","setup_graph","`","method","which","takes","(","input_signature",",","input",",","get_cost_fn",",","get_opt_fn",")",",","and","build","the","training","graph","from","them",".","To","use","a",":","class",":","`","SingleCostTrainer","`","object",",","call","`","trainer.setup_graph","(","...",")",";","trainer.train","(","...",")","`","."]
docstr: Responsible for building the main training graph for single-cost training.
  
  Args:
      input_signature ([TensorSpec]): list of TensorSpec that describe the inputs
      input (InputSource): an InputSource which has to match the input signature
      get_cost_fn ([tf.Tensor] -> tf.Tensor): callable, takes some input tensors and return a cost tensor.
      get_opt_fn (-> tf.train.Optimizer): callable which returns an
          optimizer. Will only be called once.
  
  Note:
      `get_cost_fn` will be part of the tower function.
      It must follows the `rules of tower function.
      <http://tensorpack.readthedocs.io/tutorial/trainer.html#tower-trainer>`_.
docstr_tok: ["Responsible","for","building","the","main","training","graph","for","single-cost","training",".","Args",":","input_signature","(","[","TensorSpec","]",")",":","list","of","TensorSpec","that","describe","the","inputs","input","(","InputSource",")",":","an","InputSource","which","has","to","match","the","input","signature","get_cost_fn","(","[","tf.Tensor","]","-",">","tf.Tensor",")",":","callable",",","takes","some","input","tensors","and","return","a","cost","tensor",".","get_opt_fn","(","-",">","tf.train.Optimizer",")",":","callable","which","returns","an","optimizer",".","Will","only","be","called","once",".","Note",":","`","get_cost_fn","`","will","be","part","of","the","tower","function",".","It","must","follows","the","`","rules","of","tower","function",".","<","http",":","\/\/tensorpack.readthedocs.io\/tutorial\/trainer.html","#","tower-trainer",">","`","_","."]
code: def setup_graph(
      self, input_signature, input, get_cost_fn, get_opt_fn
  ):
      """
      Responsible for building the main training graph for single-cost training.
  
      Args:
          input_signature ([TensorSpec]): list of TensorSpec that describe the inputs
          input (InputSource): an InputSource which has to match the input signature
          get_cost_fn ([tf.Tensor] -> tf.Tensor): callable, takes some input tensors and return a cost tensor.
          get_opt_fn (-> tf.train.Optimizer): callable which returns an
              optimizer. Will only be called once.
  
      Note:
          `get_cost_fn` will be part of the tower function.
          It must follows the `rules of tower function.
          <http://tensorpack.readthedocs.io/tutorial/trainer.html#tower-trainer>`_.
      """
      get_cost_fn = TowerFunc(get_cost_fn, input_signature)
      get_opt_fn = memoized(get_opt_fn)
      self.tower_func = get_cost_fn
  
      # TODO setup may want to register monitor as well??
      input_callbacks = self._setup_input(input_signature, input)
      train_callbacks = self._setup_graph(
          input, get_cost_fn, get_opt_fn
      )
      self.register_callback(input_callbacks + train_callbacks)
  
imports: from abc import ABCMeta, abstractmethod
  import six
  import tensorflow
  from ..compat import tfv1, is_tfv2
  from ..input_source import PlaceholderInput
  from ..predict.base import OnlinePredictor
  from ..tfutils.gradproc import FilterNoneGrad
  from ..tfutils.tower import PredictTowerContext, TowerFunc, get_current_tower_context
  from ..utils import logger
  from ..utils.argtools import call_only_once, memoized
  from ..utils.develop import HIDE_DOC
  from .base import Trainer
label_desc: Use image node_id 1 for calling the SingleCostTrainer obj's underlying member method code with example usage: obj.setup_graph(input_signature, input, get_cost_fn, get_opt_fn) without return types