本方法从stack overflow获得
You can create a tf.Summary
object in your Python program and write it to the same tf.summary.FileWriter
object that takes your TensorFlow-produced summaries using the SummaryWriter.add_summary()
method.
The tf.Summary
class is a Python protocol buffer wrapper for the Summary
protocol buffer. Each Summary
contains a list of tf.Summary.Value
protocol buffers, which each have a tag and a either a "simple" (floating-point scalar) value, an image, a histogram, or an audio snippet. For example, you can generate a scalar summary from a Python object as follows:
writer = tf.train.SummaryWriter(...)
value = 37.0
summary = tf.Summary(value=[
tf.Summary.Value(tag="summary_tag", simple_value=value),
])
writer.add_summary(summary)
summary_writer2 = tf.summary.FileWriter("./test", sess.graph)
loss = 0.0
loss_summary = tf.Summary()
loss_summary.value.add(tag='sum cross-entropy', simple_value=loss)
for i in range(MAX_STEPS):
for step1 in range(1, validation_prop):
cross_entropy2 = sess.run(cross_entropy, feed_dict={
x: X[(step1 - 1) * n_steps * batch_size: step1 * n_steps * batch_size],
y_: Y[(step1 - 1) * n_steps * batch_size: step1 * n_steps * batch_size]})
loss += cross_entropy2
loss = loss/(validation_prop)
print("loss: ", loss)
loss_summary.value[0].simple_value = loss
summary_writer2.add_summary(loss_summary, num_step)
这里给写乱了,如果直接使用不妨看我另一篇,直接copy然后使用即可。
tensorflow中针对迭代产生数据和对列表数据不使用feed_dict进行tensorboard表示