TensorBoard: How to plot histogram for gradients?

后端 未结 2 481
说谎
说谎 2021-02-01 23:32

TensorBoard had the function to plot histograms of Tensors at session-time. I want a histogram for the gradients during training.

tf.gradients(yvars,xvars)

2条回答
  •  长情又很酷
    2021-02-01 23:54

    Another solution (based on this quora answer) is to access the gradients directly from the optimizer you are already using.

    optimizer = tf.train.AdamOptimizer(..)
    grads = optimizer.compute_gradients(loss)
    grad_summ_op = tf.summary.merge([tf.summary.histogram("%s-grad" % g[1].name, g[0]) for g in grads])
    grad_vals = sess.run(fetches=grad_summ_op, feed_dict = feed_dict)
    writer['train'].add_summary(grad_vals)
    

提交回复
热议问题