def _add_gradients_summaries(grads_and_vars):
 summaries = []
 for (grad, var) in grads_and_vars:
  if (grad is not None):
   if isinstance(grad, tf.IndexedSlices):
    grad_values = grad.values
   else:
    grad_values = grad
   summaries.append(tf.histogram_summary((var.op.name + ':gradient'), grad_values))
   summaries.append(tf.histogram_summary((var.op.name + ':gradient_norm'), tf.global_norm([grad_values])))
  else:
   tf.logging.info('Var %s has no gradient', var.op.name)
 return summaries

def _add_gradients_summaries ( grads_and_vars ) : summaries = [ ] for ( grad , var ) in grads_and_vars : if ( grad is not None ) : if isinstance ( grad , tf . IndexedSlices ) : grad_values = grad . values else : grad_values = grad summaries . append ( tf . histogram_summary ( ( var . op . name + ':gradient' ) , grad_values ) ) summaries . append ( tf . histogram_summary ( ( var . op . name + ':gradient_norm' ) , tf . global_norm ( [ grad_values ] ) ) ) else : tf . logging . info ( 'Var %s has no gradient' , var . op . name ) return summaries
add histogram summaries to gradients .