def summary_gradients(grad_vars, summary_types, collections=None):
"""
Add summary to all gradient tensors
Args:
grads_vars: grads and vars list
summary_type: a list of all sumary types to add
e.g.: ['scalar', 'histogram', 'sparsity', 'mean', 'rms', 'stddev', 'norm', 'max', 'min']
collections: training or validation collections
"""
with tf.name_scope('summary/gradient'):
for grad, var in grad_vars:
ndims = grad.get_shape().ndims
for s_type in summary_types:
summary_param(s_type, grad, ndims, var.op.name +
'/grad', collections=None)
try:
tf.summary.scalar('/global_norm', tf.global_norm(
map(lambda grad_v: grad_v[0], grad_vars)), collections=collections)
except Exception:
return
评论列表
文章目录