in add_summary for value in summary.value: AttributeError: 'Tensor' object has no attribute 'value'

≡放荡痞女 提交于 2019-12-07 21:09:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!