class_docstr: TrainOp.
  
  TrainOp represents a set of operation used for optimizing a network.
  
  A TrainOp is meant to hold all training parameters of an optimizer.
  `Trainer` class will then instantiate them all specifically considering all
  optimizers of the network (set names, scopes... set optimization ops...).
  
  Arguments:
      loss: `Tensor`. Loss operation to evaluate network cost.
          Optimizer will use this cost function to train network.
      optimizer: `Optimizer`. Tensorflow Optimizer. The optimizer to
          use to train network.
      metric:  `Tensor`. The metric tensor to be used for evaluation.
      batch_size: `int`. Batch size for data feeded to this optimizer.
          Default: 64.
      ema: `float`. Exponential moving averages.
      trainable_vars: list of `tf.Variable`. List of trainable variables to
          use for training. Default: all trainable variables.
      shuffle: `bool`. Shuffle data.
      step_tensor: `tf.Tensor`. A variable holding training step. If not
          provided, it will be created. Early defining the step tensor
          might be useful for network creation, such as for learning rate
          decay.
      validation_monitors: `list` of `Tensor` objects.  List of variables
          to compute during validation, which are also used to produce
          summaries for output to TensorBoard.  For example, this can be
          used to periodically record a confusion matrix or AUC metric, 
          during training.  Each variable should have rank 1, i.e. 
          shape [None].
      validation_batch_size: `int` or None. If `int`, specifies the batch
          size to be used for the validation data feed; otherwise 
          defaults to being th esame as `batch_size`.
      name: `str`. A name for this class (optional).
      graph: `tf.Graph`. Tensorflow Graph to use for training. Default:
          default tf graph.
class_docstr_tok: ["TrainOp",".","TrainOp","represents","a","set","of","operation","used","for","optimizing","a","network",".","A","TrainOp","is","meant","to","hold","all","training","parameters","of","an","optimizer",".","`","Trainer","`","class","will","then","instantiate","them","all","specifically","considering","all","optimizers","of","the","network","(","set","names",",","scopes","...","set","optimization","ops","...",")",".","Arguments",":","loss",":","`","Tensor","`",".","Loss","operation","to","evaluate","network","cost",".","Optimizer","will","use","this","cost","function","to","train","network",".","optimizer",":","`","Optimizer","`",".","Tensorflow","Optimizer",".","The","optimizer","to","use","to","train","network",".","metric",":","`","Tensor","`",".","The","metric","tensor","to","be","used","for","evaluation",".","batch_size",":","`","int","`",".","Batch","size","for","data","feeded","to","this","optimizer",".","Default",":","64.","ema",":","`","float","`",".","Exponential","moving","averages",".","trainable_vars",":","list","of","`","tf.Variable","`",".","List","of","trainable","variables","to","use","for","training",".","Default",":","all","trainable","variables",".","shuffle",":","`","bool","`",".","Shuffle","data",".","step_tensor",":","`","tf.Tensor","`",".","A","variable","holding","training","step",".","If","not","provided",",","it","will","be","created",".","Early","defining","the","step","tensor","might","be","useful","for","network","creation",",","such","as","for","learning","rate","decay",".","validation_monitors",":","`","list","`","of","`","Tensor","`","objects",".","List","of","variables","to","compute","during","validation",",","which","are","also","used","to","produce","summaries","for","output","to","TensorBoard",".","For","example",",","this","can","be","used","to","periodically","record","a","confusion","matrix","or","AUC","metric",",","during","training",".","Each","variable","should","have","rank","1",",","i.e",".","shape","[","None","]",".","validation_batch_size",":","`","int","`","or","None",".","If","`","int","`",",","specifies","the","batch","size","to","be","used","for","the","validation","data","feed",";","otherwise","defaults","to","being","th","esame","as","`","batch_size","`",".","name",":","`","str","`",".","A","name","for","this","class","(","optional",")",".","graph",":","`","tf.Graph","`",".","Tensorflow","Graph","to","use","for","training",".","Default",":","default","tf","graph","."]
docstr: _train.
  
  Training process for this optimizer.
  
  Arguments:
      training_step: `int`. The global step.
      snapshot_epoch: `bool`. If True, snapshot network at each epoch.
      snapshot_step: `int`. If not None, snapshot network given 'step'.
      show_metric: `bool`. If True, display accuracy at every step.
code: def _train(
      self, training_step, snapshot_epoch, snapshot_step, show_metric
  ):
      """_train.
  
      Training process for this optimizer.
  
      Arguments:
          training_step: `int`. The global step.
          snapshot_epoch: `bool`. If True, snapshot network at each epoch.
          snapshot_step: `int`. If not None, snapshot network given 'step'.
          show_metric: `bool`. If True, display accuracy at every step.
  
      """
      self.loss_value, self.acc_value = None, None
      self.val_loss, self.val_acc = None, None
      train_summ_str, test_summ_str = None, None
      snapshot = False
      epoch = self.train_dflow.data_status.epoch
  
      feed_batch = self.train_dflow.next()
      tflearn.is_training(True, session=self.session)
      _, train_summ_str = self.session.run(
          [self.train, self.summ_op], feed_batch
      )
  
      # Retrieve loss value from summary string
      sname = "Loss/" + self.scope_name
      self.loss_value = summaries.get_value_from_summary_string(
          sname, train_summ_str
      )
  
      if show_metric and self.metric is not None:
          # Retrieve accuracy value from summary string
          sname = self.metric_summ_name + "/" + self.scope_name
          self.acc_value = summaries.get_value_from_summary_string(
              sname, train_summ_str
          )
  
      if epoch != self.train_dflow.data_status.epoch:
          if snapshot_epoch:
              snapshot = True
  
      # Check if step reached snapshot step
      if snapshot_step:
          if training_step % snapshot_step == 0:
              snapshot = True
  
      # Calculate validation
      if snapshot and self.val_feed_dict:
          tflearn.is_training(False, session=self.session)
          # Evaluation returns the mean over all batches.
          eval_ops = [
              self.loss
          ] + self.validation_monitors  # compute loss as well as any extra validation monotor tensors
          if show_metric and self.metric is not None:
              eval_ops.append(self.metric)
          e = evaluate_flow(self.session, eval_ops, self.test_dflow)
          self.val_loss = e[0]
          if show_metric and self.metric is not None:
              self.validation_monitor_values = e[1:-1]
              self.val_acc = e[-1]
          else:
              self.validation_monitor_values = e[1:]
  
          # Set evaluation results to variables, to be summarized.
          update_val_op = [self.val_loss_assign]
          update_val_feed = {self.val_loss_P: self.val_loss}
          if show_metric:
              update_val_op.append(self.val_acc_assign)
              update_val_feed[self.val_acc_P] = self.val_acc
          if self.validation_monitors:
              update_val_op.append(self.val_monitors_assign)
              for vmp, vmv in zip(
                  self.val_monitors_P, self.validation_monitor_values
              ):
                  update_val_feed[vmp] = vmv
  
          self.session.run(update_val_op, feed_dict=update_val_feed)
  
          # Run summary operation.
          test_summ_str = self.session.run(self.val_summary_op)
  
      # Write to Tensorboard
      # TODO: Delete?
      n_step = self.training_steps.eval(session=self.session)
      if n_step > 1:
          if train_summ_str:
              self.summary_writer.add_summary(train_summ_str, n_step)
          if test_summ_str:
              self.summary_writer.add_summary(test_summ_str, n_step)
  
      return snapshot
  
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 4 for calling the TrainOp obj's underlying member method code with example usage: obj._train(training_step, snapshot_epoch, snapshot_step, show_metric) and returns: snapshot