code: def train_op_fun(total_loss, global_step):
      """Train model.
  
      Create an optimizer and apply to all trainable variables. Add moving
      average for all trainable variables.
  
      Args:
        total_loss: Total loss from loss().
        global_step: Integer Variable counting the number of training steps
          processed.
      Returns:
        train_op: op for training.
      """
      # Variables that affect learning rate.
      nb_ex_per_train_epoch = int(60000 / FLAGS.nb_teachers)
  
      num_batches_per_epoch = nb_ex_per_train_epoch / FLAGS.batch_size
      decay_steps = int(num_batches_per_epoch * FLAGS.epochs_per_decay)
  
      initial_learning_rate = float(FLAGS.learning_rate) / 100.0
  
      # Decay the learning rate exponentially based on the number of steps.
      lr = tf.train.exponential_decay(
          initial_learning_rate,
          global_step,
          decay_steps,
          LEARNING_RATE_DECAY_FACTOR,
          staircase=True,
      )
      tf.summary.scalar("learning_rate", lr)
  
      # Generate moving averages of all losses and associated summaries.
      loss_averages_op = moving_av(total_loss)
  
      # Compute gradients.
      with tf.control_dependencies([loss_averages_op]):
          opt = tf.train.GradientDescentOptimizer(lr)
          grads = opt.compute_gradients(total_loss)
  
      # Apply gradients.
      apply_gradient_op = opt.apply_gradients(
          grads, global_step=global_step
      )
  
      # Add histograms for trainable variables.
      for var in tf.trainable_variables():
          tf.summary.histogram(var.op.name, var)
  
      # Track the moving averages of all trainable variables.
      variable_averages = tf.train.ExponentialMovingAverage(
          MOVING_AVERAGE_DECAY, global_step
      )
      variables_averages_op = variable_averages.apply(
          tf.trainable_variables()
      )
  
      with tf.control_dependencies(
          [apply_gradient_op, variables_averages_op]
      ):
          train_op = tf.no_op(name="train")
  
      return train_op
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from datetime import datetime
  import math
  import numpy
  from six.moves import xrange
  import tensorflow.compat.v1
  import time
  import utils
label_desc: Use image node_id 7 for calling a global function with example usage: train_op_fun(total_loss, global_step) and returns: train_op