Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

logging - How do I add an arbitrary value to a TensorFlow summary?

In order to log a simple value val to a TensorBoard summary I need to

val = 5
test_writer.add_summary(sess.run(tf.scalar_summary('test', val)), global_step)

Is

sess.run(tf.scalar_summary('test', val))

really necessary to get val added as a summary?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's another (perhaps slightly more up-to-date) solution with the tf.Summary.FileWriter class:

summary_writer = tf.summary.FileWriter(logdir=output_dir)
value = tf.Summary.Value(tag='variable name', simple_value=value)
summary_writer.add_event(summary=tf.summary.Event(tf.Summary([value]),
                         wall_time=time.time(),
                         step=global_step))

Then you can create your SummarySaverHook as such:

summary_hook = tf.train.SummarySaverHook(
    summary_writer=summary_writer,
    summary_op=your_summary_op)

which you can pass to your MonitoredTrainingSession. An example of a summary_op is tf.summary.merge_all()

NOTE: You will have to wait for the FileWriter to flush for it to appear in your events file. You can force it by calling summary_writer.flush()


A simpler solution:

summary_writer = tf.summary.FileWriter(output_dir)
summary = tf.Summary()
summary.value.add(tag='name of var', simple_value=value)
summary_writer.add_summary(summary, global_step)
summary_writer.flush()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...