code: def __average_grads(tower_grads):
      """
      Performs and return the average of the gradients
      :param tower_grads: in form of [[tower_1_grad], [tower_2_grad], ...]
      :return ave_grads: in form of [ave_grad]
      """
      # average gradients computed from multiple GPUs
      ave_grads = []
      for grad_and_vars in zip(*tower_grads):
          grads = [
              tf.expand_dims(g, 0)
              for g, _ in grad_and_vars
              if g is not None
          ]
          if not grads:
              continue
          grad = tf.concat(grads, 0)
          grad = tf.reduce_mean(grad, 0, name="AveOverDevices")
  
          v = grad_and_vars[0][1]
          grad_and_var = (grad, v)
          ave_grads.append(grad_and_var)
      return ave_grads
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import datetime
  import os
  import re
  from functools import partial
  import numpy
  import tensorflow
  from scipy import ndimage
  from six import string_types
label_desc: Use image node_id 5 for calling a global function with example usage: __average_grads(tower_grads) and returns: ave_grads