class_docstr: Base class for a trainer.
      
docstr: Run the main training loop.
  
  Args:
      steps_per_epoch, starting_epoch, max_epoch (int):
docstr_tok: ["Run","the","main","training","loop",".","Args",":","steps_per_epoch",",","starting_epoch",",","max_epoch","(","int",")",":"]
code: def main_loop(self, steps_per_epoch, starting_epoch, max_epoch):
      """
      Run the main training loop.
  
      Args:
          steps_per_epoch, starting_epoch, max_epoch (int):
      """
      with self.sess.as_default():
          self.loop.config(steps_per_epoch, starting_epoch, max_epoch)
          self.loop.update_global_step()
          try:
              self._callbacks.before_train()
              # refresh global step (might have changed by callbacks) TODO ugly
              # what if gs is changed later?
              self.loop.update_global_step()
              for self.loop._epoch_num in range(
                  self.loop.starting_epoch, self.loop.max_epoch + 1
              ):
                  logger.info(
                      "Start Epoch {} ...".format(self.loop.epoch_num)
                  )
                  self._callbacks.before_epoch()
                  start_time = time.time()
                  for self.loop._local_step in range(
                      self.loop.steps_per_epoch
                  ):
                      if self.hooked_sess.should_stop():
                          return
                      self.run_step()  # implemented by subclass
                      self._callbacks.trigger_step()
                  self._callbacks.after_epoch()
                  logger.info(
                      "Epoch {} (global_step {}) finished, time:{}.".format(
                          self.loop.epoch_num,
                          self.loop.global_step,
                          humanize_time_delta(time.time() - start_time),
                      )
                  )
  
                  # trigger epoch outside the timing region.
                  self._callbacks.trigger_epoch()
              logger.info("Training has finished!")
          except (StopTraining, tf.errors.OutOfRangeError) as e:
              logger.info(
                  "Training was stopped by exception {}.".format(str(e))
              )
          except KeyboardInterrupt:
              logger.info("Detected Ctrl-C and exiting main loop.")
              raise
          except Exception:
              logger.error(
                  "Training failed at global_step={}".format(
                      self.loop.global_step
                  )
              )
              raise
          finally:
              self._callbacks.after_train()
              self.hooked_sess.close()
  
imports: import copy
  import time
  import weakref
  import tensorflow
  from ..compat import tfv1
  from ..callbacks import Callback, Callbacks, Monitors, MonitorBase
  from ..callbacks.steps import MaintainStepCounter
  from ..tfutils import get_global_step_value
  from ..tfutils.model_utils import describe_trainable_vars
  from ..tfutils.sesscreate import NewSessionCreator, ReuseSessionCreator
  from ..tfutils.sessinit import JustCurrentSession, SessionInit
  from ..utils import logger
  from ..utils.argtools import call_only_once
  from ..utils.utils import humanize_time_delta
  from .config import DEFAULT_CALLBACKS, DEFAULT_MONITORS, TrainConfig
label_desc: Use image node_id 7 for calling the Trainer obj's underlying member method code with example usage: obj.main_loop(steps_per_epoch, starting_epoch, max_epoch) without return types