Tensorboard简单使用

1. Problem

我仅仅想查看训练过程中的cost变化曲线。

2. Solution

在训练代码中,插入summary代码:

# data
...
# model
...
# cost
cost_op = ...
# optimizer
...

# summary
tf.summary.scalar('cost', cost_op)

# train
with tf.Session() as sess:
    merged = tf.summary.merge_all()
    train_writer = tf.summary.FileWriter('/tmp/train_demo', sess.graph)
    sess.run(tf.global_variables_initializer())
    iter = 0
    while step < training_iters:
        ...
        summary,_ = sess.run([merged, train_op], feed_dict=[...])
        train_writer.add_summary(summary, step)

运行tensorboard

$ tensorboard --logdir=/tmp/train_demo

打开浏览器,输入提示的ip地址,即可看到曲线了。如下图:

Tensorboard简单使用_第1张图片

你可能感兴趣的:(tensorflow)