如何将学习率添加到摘要中?

How to add learning rate to summaries?

如何监控 AdamOptimizer 的学习率? 在TensorBoard: Visualizing Learning据说我需要

Collect these by attaching scalar_summary ops to the nodes that output the learning rate and loss respectively.

我该怎么做?

我认为如下图所示的内容可以正常工作:

with tf.name_scope("learning_rate"):
    global_step = tf.Variable(0)
    decay_steps = 1000 # setup your decay step
    decay_rate = .95 # setup your decay rate
    learning_rate = tf.train.exponential_decay(0.01, global_step, decay_steps, decay_rate, staircase=True, "learning_rate")
tf.scalar_summary('learning_rate', learning_rate)

(当然要让它工作,它需要 tf.merge_all_summaries() 并使用 tf.train.SummaryWriter 最后将摘要写入日志)