I'm working on creating a simple toy example in TensorFlow and I've run into a strange error. I have two placeholders defined as follows:
x = tf.placeholder(tf.float32, shape=[None,2]) [two-parameter input]
y_ = tf.placeholder(tf.float32, shape=[None,2]) [one-hot labels]
I later attempt to feed these placeholders with a feed_dict defined as:
feed_dict={x: batch[0].astype(np.float32), y_: batch[1].astype(np.float32)}
Where batch[0]
and batch[1]
are both numpy ndarrays of size (100,2) [verified by printing out their respective sizes]
When I attempt to run the model, I get the error:
"InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float"
caused by my Placeholder "x" defined above
Can anyone tell what I'm doing wrong? I've looked through several examples online and it seems like this should work... Is there another way to feed placeholders with values from numpy arrays?
If it helps, I'm working in Ubuntu, SCL, and Python 2.7, and I have all the standard numpy and tensorflow packages installed.
Without your entire code, it is hard to answer precisely. I tried to reproduce what you described in a toy example and it worked.
import tensorflow as tf
import numpy as np
x = tf.placeholder(tf.float32, shape=[None, 2])
y_ = tf.placeholder(tf.float32, shape=[None, 2])
loss = tf.reduce_sum(tf.abs(tf.sub(x, y_)))#Function chosen arbitrarily
input_x=np.random.randn(100, 2)#Random generation of variable x
input_y=np.random.randn(100, 2)#Random generation of variable y
with tf.Session() as sess:
print(sess.run(loss, feed_dict={x: input_x, y_: input_y}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With