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()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…