【发布时间】:2017-01-02 02:00:11
【问题描述】:
我正在尝试将类型为 : float32 的 numpy ndarray 提供给 TensorFlow 占位符,但它给了我以下错误:
You must feed a value for placeholder tensor 'Placeholder' with dtype float
我的占位符定义为:
n_steps = 10
n_input = 13
n_classes = 1201
x = tf.placeholder("float", [None, n_steps, n_input])
y = tf.placeholder("float", [None, n_classes])
它给我上述错误的那一行是:
sess.run(optimizer, feed_dict={x: batch_x, y: batch_y})
我的 batch_x 和 batch_y 是 dtype('float32') 的 numpy ndarray。以下是我使用 pdb 打印的类型:
(Pdb)batch_x.dtype
dtype('float32')
(Pdb)x.dtype
tf.float32
我也尝试过将 batch_x 和 batch_y 类型转换为 tf.float32,因为 x 似乎属于 dtype tf.float32 但运行带有类型转换的代码:
sess.run(optimizer, feed_dict={x: tf.to_float(batch_x), y: tf.to_float(batch_y)})
给出以下错误:
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.
我应该如何提供占位符?我应该使用什么类型的? 任何帮助/建议将不胜感激!
【问题讨论】:
-
你所拥有的似乎是正确的。你介意尝试一个更小的程序吗?例如,以下是否有效?
z = tf.reduce_sum(x) + tf.reduce_sum(y); sess.run(z, feed_dict={x:np.zeros([1, 10, 13]), y:np.zeros([1, 1201])})
标签: numpy tensorflow