class_docstr: This class implements a trainer for TensorFlow algorithms.
  
  A trainer provides a default TensorFlow session using python context.
  This is useful for those experiment components (e.g. policy) that require a
  TensorFlow session during construction.
  
  Use trainer.setup(algo, env) to setup algorithm and environment for trainer
  and trainer.train() to start training.
  
  Args:
      snapshot_config (garage.experiment.SnapshotConfig): The snapshot
          configuration used by Trainer to create the snapshotter.
          If None, it will create one with default settings.
      sess (tf.Session): An optional TensorFlow session.
            A new session will be created immediately if not provided.
  
  Note:
      When resume via command line, new snapshots will be
      saved into the SAME directory if not specified.
  
      When resume programmatically, snapshot directory should be
      specify manually or through @wrap_experiment interface.
  
  Examples:
      # to train
      with TFTrainer() as trainer:
          env = gym.make('CartPole-v1')
          policy = CategoricalMLPPolicy(
              env_spec=env.spec,
              hidden_sizes=(32, 32))
          algo = TRPO(
              env=env,
              policy=policy,
              baseline=baseline,
              max_episode_length=100,
              discount=0.99,
              max_kl_step=0.01)
          trainer.setup(algo, env)
          trainer.train(n_epochs=100, batch_size=4000)
  
      # to resume immediately.
      with TFTrainer() as trainer:
          trainer.restore(resume_from_dir)
          trainer.resume()
  
      # to resume with modified training arguments.
      with TFTrainer() as trainer:
          trainer.restore(resume_from_dir)
          trainer.resume(n_epochs=20)
docstr: Leave session.
  
  Args:
      exc_type (str): Type.
      exc_val (object): Value.
      exc_tb (object): Traceback.
docstr_tok: ["Leave","session",".","Args",":","exc_type","(","str",")",":","Type",".","exc_val","(","object",")",":","Value",".","exc_tb","(","object",")",":","Traceback","."]
code: def __exit__(self, exc_type, exc_val, exc_tb):
      """Leave session.
  
      Args:
          exc_type (str): Type.
          exc_val (object): Value.
          exc_tb (object): Traceback.
  
      """
      if (
          tf.compat.v1.get_default_session() is self.sess
          and self.sess_entered
      ):
          self.sess.__exit__(exc_type, exc_val, exc_tb)
          self.sess_entered = False
  
imports: import copy
  import os
  import time
  import cloudpickle
  from dowel import logger, tabular
  from garage.experiment.deterministic import get_seed, set_seed
  from garage.experiment.experiment import dump_json
  from garage.experiment.snapshotter import Snapshotter
label_desc: Use image node_id 3 for calling the TFTrainer obj's underlying member method code with example usage: obj.__exit__(exc_type, exc_val, exc_tb) without return types