class_docstr: Trainer.
  
  Generic class to handle any TensorFlow graph training. It requires
  the use of `TrainOp` to specify all optimization parameters.
  
  Arguments:
      train_ops: list of `TrainOp`. A list of a network training
          operations for performing optimizations.
      graph: `tf.Graph`. The TensorFlow graph to use. Default: default tf
          graph.
      clip_gradients: `float`. Clip gradient. Default: 5.0.
      tensorboard_dir: `str`. Tensorboard log directory.
          Default: "/tmp/tflearn_logs/".
      tensorboard_verbose: `int`. Verbose level. It supports:
          ```python
          0 - Loss, Accuracy. (Best Speed)
          1 - Loss, Accuracy, Gradients.
          2 - Loss, Accuracy, Gradients, Weights.
          3 - Loss, Accuracy, Gradients, Weights, Activations, Sparsity.
              (Best Visualization)
          ```
      checkpoint_path: `str`. Path to store model checkpoints. If None,
          no model checkpoint will be saved. Default: None.
      best_checkpoint_path: `str`. Path to store the model when the validation rate reaches its
          highest point of the current training session and also is above best_val_accuracy. Default: None.
      max_checkpoints: `int` or None. Maximum amount of checkpoints. If
          None, no limit. Default: None.
      keep_checkpoint_every_n_hours: `float`. Number of hours between each
          model checkpoints.
      random_seed: `int`. Random seed, for test reproductivity.
          Default: None.
      session: `Session`. A session for running ops. If None, a new one will
          be created. Note: When providing a session, variables must have been
          initialized already, otherwise an error will be raised.
      best_val_accuracy: `float` The minimum validation accuracy that needs to be
          achieved before a model weight's are saved to the best_checkpoint_path. This
          allows the user to skip early saves and also set a minimum save point when continuing
          to train a reloaded model. Default: 0.0.
class_docstr_tok: ["Trainer",".","Generic","class","to","handle","any","TensorFlow","graph","training",".","It","requires","the","use","of","`","TrainOp","`","to","specify","all","optimization","parameters",".","Arguments",":","train_ops",":","list","of","`","TrainOp","`",".","A","list","of","a","network","training","operations","for","performing","optimizations",".","graph",":","`","tf.Graph","`",".","The","TensorFlow","graph","to","use",".","Default",":","default","tf","graph",".","clip_gradients",":","`","float","`",".","Clip","gradient",".","Default",":","5.0.","tensorboard_dir",":","`","str","`",".","Tensorboard","log","directory",".","Default",":","``","\/tmp\/tflearn_logs\/","''",".","tensorboard_verbose",":","`","int","`",".","Verbose","level",".","It","supports",":","``","`","python","0","-","Loss",",","Accuracy",".","(","Best","Speed",")","1","-","Loss",",","Accuracy",",","Gradients",".","2","-","Loss",",","Accuracy",",","Gradients",",","Weights",".","3","-","Loss",",","Accuracy",",","Gradients",",","Weights",",","Activations",",","Sparsity",".","(","Best","Visualization",")","``","`","checkpoint_path",":","`","str","`",".","Path","to","store","model","checkpoints",".","If","None",",","no","model","checkpoint","will","be","saved",".","Default",":","None",".","best_checkpoint_path",":","`","str","`",".","Path","to","store","the","model","when","the","validation","rate","reaches","its","highest","point","of","the","current","training","session","and","also","is","above","best_val_accuracy",".","Default",":","None",".","max_checkpoints",":","`","int","`","or","None",".","Maximum","amount","of","checkpoints",".","If","None",",","no","limit",".","Default",":","None",".","keep_checkpoint_every_n_hours",":","`","float","`",".","Number","of","hours","between","each","model","checkpoints",".","random_seed",":","`","int","`",".","Random","seed",",","for","test","reproductivity",".","Default",":","None",".","session",":","`","Session","`",".","A","session","for","running","ops",".","If","None",",","a","new","one","will","be","created",".","Note",":","When","providing","a","session",",","variables","must","have","been","initialized","already",",","otherwise","an","error","will","be","raised",".","best_val_accuracy",":","`","float","`","The","minimum","validation","accuracy","that","needs","to","be","achieved","before","a","model","weight","'s","are","saved","to","the","best_checkpoint_path",".","This","allows","the","user","to","skip","early","saves","and","also","set","a","minimum","save","point","when","continuing","to","train","a","reloaded","model",".","Default",":","0.0","."]
code: def __init__(
      self,
      train_ops,
      graph=None,
      clip_gradients=5.0,
      tensorboard_dir="/tmp/tflearn_logs/",
      tensorboard_verbose=0,
      checkpoint_path=None,
      best_checkpoint_path=None,
      max_checkpoints=None,
      keep_checkpoint_every_n_hours=10000.0,
      random_seed=None,
      session=None,
      best_val_accuracy=0.0,
  ):
      self.graph = tf.get_default_graph()
      self.summ_writer = None
      if graph:
          self.graph = graph
  
      with self.graph.as_default():
          init_training_mode()
  
          train_ops = to_list(train_ops)
          duplicate_identical_ops(train_ops)
  
          if random_seed:
              tf.set_random_seed(random_seed)
          self.restored = False
          self.tensorboard_dir = check_dir_name(tensorboard_dir)
          self.training_state = TrainingState()
  
          self.train_ops = to_list(train_ops)
          self.validate_trainop_names()
  
          self.global_step = tf.Variable(
              0.0, name="Global_Step", trainable=False
          )
          self.incr_global_step = tf.assign(
              self.global_step, tf.add(self.global_step, 1)
          )
          self.best_val_accuracy = best_val_accuracy
          self.best_checkpoint_path = best_checkpoint_path
  
          config = None
          tflearn_conf = tf.get_collection(tf.GraphKeys.GRAPH_CONFIG)
          if tflearn_conf:
              config = tflearn_conf[0]
  
          if not session:
              self.session = tf.Session(config=config)
          else:
              self.session = session
              self.restored = True
  
          self.coord = tf.train.Coordinator()
  
          for i, train_op in enumerate(self.train_ops):
              # For display simplicity in Tensorboard, if only one optmizer,
              # we don't display its name
              if len(train_ops) == 1:
                  train_op.scope_name = ""
  
              train_op.initialize_training_ops(
                  i, self.session, tensorboard_verbose, clip_gradients
              )
  
          # Saver for saving a model
          self.saver = tf.train.Saver(
              max_to_keep=max_checkpoints,
              keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
              allow_empty=True,
          )
          # Saver for saving a best validation accuracy model
          if self.best_checkpoint_path:
              self.val_saver = tf.train.Saver(
                  max_to_keep=1,
                  keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
                  allow_empty=True,
              )
          # Saver for restoring a model (With exclude variable list)
          all_vars = variables.get_all_variables()
          excl_vars = tf.get_collection(tf.GraphKeys.EXCL_RESTORE_VARS)
          to_restore = [
              item
              for item in all_vars
              if check_restore_tensor(item, excl_vars)
          ]
          self.restorer = tf.train.Saver(
              var_list=to_restore,
              max_to_keep=max_checkpoints,
              keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
              allow_empty=True,
          )
          # A second Saver, that only restore trainable variables
          to_restore_trainvars = [
              item
              for item in tf.trainable_variables()
              if check_restore_tensor(item, excl_vars)
          ]
          self.restorer_trainvars = tf.train.Saver(
              var_list=to_restore_trainvars,
              max_to_keep=max_checkpoints,
              keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours,
              allow_empty=True,
          )
  
          self.to_restore = to_restore
          self.to_restore_trainvars = to_restore_trainvars
          self.checkpoint_path = checkpoint_path
  
          if not self.restored:
              # TF 0.12 fix
              try:
                  init = tf.group(
                      tf.global_variables_initializer(),
                      tf.local_variables_initializer(),
                  )
                  self.session.run(
                      tf.variables_initializer(
                          tf.get_collection_ref("is_training")
                      )
                  )
              except Exception as e:
                  init = tf.initialize_all_variables()
              self.session.run(init)
  
imports: from __future__ import division, print_function, absolute_import
  import re
  import os
  import numpy
  import tensorflow.compat.v1
  from tensorflow.python.training import optimizer
  import tflearn
  from ..None import callbacks
  from ..config import init_training_mode
  from ..utils import to_list, id_generator, check_dir_name, standarize_dict, get_dict_first_element, make_batches, slice_array, check_scope_path, check_restore_tensor
  from ..None import data_flow
  from ..None import variables
  from ..None import utils
  from .summarizer import summaries, summarize, summarize_gradients, summarize_variables, summarize_activations
label_desc: Use image node_id 1 to create a new Trainer object from inherited base classes: object with example: obj = Trainer(train_ops, graph, clip_gradients, tensorboard_dir, tensorboard_verbose, checkpoint_path, best_checkpoint_path, max_checkpoints, keep_checkpoint_every_n_hours, random_seed, session, best_val_accuracy)