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","."]
docstr: restore.
  
  Restore a Tensorflow model
  
  Arguments:
      model_file: path of tensorflow model to restore
      trainable_variable_only: If True, only restore trainable variables.
      variable_name_map: - a (pattern, repl) tuple providing a regular expression pattern
                           and replacement, which is applied to variable names, before
                           restoration from the model file
                         - OR, a function map_func, used to perform the mapping, called as:
                           name_in_file = map_func(existing_var_op_name)
                           The function may return None to indicate a variable is not to be
                           restored.
      scope_for_restore: string specifying the scope to limit to, when restoring variables.
                         Also removes the scope name prefix from the var name to use when restoring.
      create_new_session: Set to False if the current session is to be kept.  
                          Set to True (the default) to create a new session, and re-init all variables.
      verbose           : Set to True to see a printout of what variables are being restored,
                          when using scope_for_restore or variable_name_map
code: def restore(
      self,
      model_file,
      trainable_variable_only=False,
      variable_name_map=None,
      scope_for_restore=None,
      create_new_session=True,
      verbose=False,
  ):
      """restore.
  
      Restore a Tensorflow model
  
      Arguments:
          model_file: path of tensorflow model to restore
          trainable_variable_only: If True, only restore trainable variables.
          variable_name_map: - a (pattern, repl) tuple providing a regular expression pattern
                               and replacement, which is applied to variable names, before
                               restoration from the model file
                             - OR, a function map_func, used to perform the mapping, called as:
                               name_in_file = map_func(existing_var_op_name)
                               The function may return None to indicate a variable is not to be
                               restored.
          scope_for_restore: string specifying the scope to limit to, when restoring variables.
                             Also removes the scope name prefix from the var name to use when restoring.
          create_new_session: Set to False if the current session is to be kept.
                              Set to True (the default) to create a new session, and re-init all variables.
          verbose           : Set to True to see a printout of what variables are being restored,
                              when using scope_for_restore or variable_name_map
  
      """
      # TF 0.12 Fix
      if not os.path.isabs(model_file):
          model_file = os.path.abspath(
              os.path.join(os.getcwd(), model_file)
          )
  
      if create_new_session:
          self.close_session()
          config = None
          tflearn_conf = tf.get_collection(tf.GraphKeys.GRAPH_CONFIG)
          if tflearn_conf:
              config = tflearn_conf[0]
          self.session = tf.Session(config=config)
          # TF 0.12 Fix
          try:
              self.session.run(
                  [
                      tf.global_variables_initializer(),
                      tf.local_variables_initializer(),
                  ]
              )
          except Exception:
              self.session.run(tf.initialize_all_variables())
  
      if (
          scope_for_restore is not None
      ):  # allow variables to be restored into a different scope
          sname = scope_for_restore
  
          def vn_map_func(
              existing_name,
          ):  # variable name map function which removes the scope name, e.g.
              if not existing_name.startswith(
                  sname
              ):  # so that "scope_name/var_name/... is retrieved from var_name/...
                  return None  # and variables outside of scope_name are not restored
              name_in_file = re.sub("^%s/" % sname, "", existing_name)
              if verbose:
                  print(
                      "[%s] Restoring %s <- %s"
                      % (sname, existing_name, name_in_file)
                  )
              return name_in_file
  
          variable_name_map = vn_map_func
  
      if (
          variable_name_map is not None
      ):  # general-purpose remapping of variable names (name in file vs existing name)
          if (
              type(variable_name_map) == tuple
          ):  # tuple interpreted as regular expression pattern substitution
              (pattern, repl) = variable_name_map
  
              def vn_map_func(existing_name):
                  name_in_file = re.sub(pattern, repl, existing_name)
                  if verbose:
                      print(
                          "Restoring %s <- %s"
                          % (existing_name, name_in_file)
                      )
                  return name_in_file
  
          else:
              vn_map_func = variable_name_map  # allow arbitrary user-provided mapping function
          if (
              trainable_variable_only
          ):  # restore either trainingable variables only, or all variables
              to_restore = self.to_restore_trainvars
          else:
              to_restore = self.to_restore
          renamed_to_restore = {
              vn_map_func(v.op.name): v for v in to_restore
          }
          if None in renamed_to_restore:
              renamed_to_restore.pop(None)
          restorer = tf.train.Saver(var_list=renamed_to_restore)
          restorer.restore(self.session, model_file)
      elif not trainable_variable_only:
          self.restorer.restore(self.session, model_file)
      else:
          self.restorer_trainvars.restore(self.session, model_file)
      for o in self.train_ops:
          o.session = self.session
      self.restored = True
  
      # Restore the training step
      self.training_state.step = int(
          self.global_step.eval(self.session)
      )
  
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 5 for calling the Trainer obj's underlying member method code with example usage: obj.restore(model_file, trainable_variable_only, variable_name_map, scope_for_restore, create_new_session, verbose) and returns: name_in_file, None, name_in_file