【问题标题】:TensorFlow - Unable to get the value of a variableTensorFlow - 无法获取变量的值
【发布时间】:2017-07-17 11:30:39
【问题描述】:

我是 TensorFlow 的新手。我有两个张量/张量流对象,X 和 Y,它们基本上是两个矩阵。我对它们进行了一些计算并想打印它们的值。

output = tf.reduce_sum(tf.log(tf.exp(tf.matmul(tf.transpose(X), Y))))
print(output.get_shape()) #Shows ()

我想获取output 的值。我无法打印它。

试过这样做:

init = tf.initialize_all_variables()
sess = tf.Session()

output = tf.reduce_sum(tf.log(tf.exp(tf.matmul(tf.transpose(X), Y))))

print(output.get_shape())

sess.run(init)
v = sess.run(output)
print(v)

但无济于事!抛出以下错误:

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype int32 and shape [100]

【问题讨论】:

  • 我在 3 小时前解释了这个过程 here

标签: python tensorflow


【解决方案1】:

错误信息不言自明。 X 和 Y 是placeholders。占位符只是一个预期在运行时包含一个值的对象。在您目前的情况下,您需要执行以下操作:

v = sess.run(output, feed_dict = {X : matrix_for_X, Y: matrix_for_Y})

【讨论】:

  • 谢谢,但这会引发以下错误:TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-09
  • 1970-01-01
相关资源
最近更新 更多