问题
This is a very basic tensorboard scalar log:
import numpy as np
import tensorflow as tf
a = np.arange(10)
x = tf.convert_to_tensor(a, dtype=tf.float32)
x_summ = tf.summary.scalar("X", x)
writer = tf.summary.FileWriter('/tmp/logdir')
writer.add_summary(x_summ)
However, I get an error in add_summary for value in summary.value:
AttributeError: 'Tensor' object has no attribute 'value'.
Any solution for this?
TensorFlow documentation says ValueError is raised when the summary tensor has a wrong shape or type. When I print x_summ
it shows:
Tensor("X:0", shape=(), dtype=string)
I don't understand why is the shape NULL
here.
回答1:
The value error is raised because you have to evaluate the summary node within a session.
with tf.Session() as sess:
s = sess.run(x_summ)
writer.add_summary(s)
But notice that this will raise another error, as you try to track 10 values in a scalar summary. But as I suppose that you will track some meaningful variable during training (like loss), this doesn't matter much.
来源:https://stackoverflow.com/questions/51783265/in-add-summary-for-value-in-summary-value-attributeerror-tensor-object-has-n