Reputation: 115
I am having trouble getting this very simple tensorflow code off the ground. I am trying to do a simple line fitting of the form y = theta1 * x + theta2
I created the data for x and y as a numpy float32 array of shape [10], I created their corresponding placeholders as follows:
tf_x = tf.placeholder(tf.float32, [10])
tf_y = tf.placeholder(tf.float32, [10])
I feed them like follows:
sess.run(train, feed_dict={tf_x: x_data, tf_y: y_data})
the full code is bit long so I created a gist: https://gist.github.com/meowmiau/369393f41b679dd95f4ac4e2e16b0782
The issue I am getting is this:
tensorflow.python.framework.errors.InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [10]
[[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[10], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
However, as far as I know there is no mismatch.
Upvotes: 1
Views: 777
Reputation: 46
Try this modification in your code:
for i in range(1000):
x_data, y_data = gen_data()
_, e = sess.run([train, err], feed_dict={tf_x: x_data, tf_y: y_data})
print e
@Meng Sun:
I think to pass the list [train, err] to sess.run() is a possible solution. The following snippet works the same way:
for i in range(1000):
x_data, y_data = gen_data()
feed_dict={tf_x: x_data, tf_y: y_data}
print(sess.run(err, feed_dict=feed_dict))
sess.run(train, feed_dict=feed_dict)
In your code the two placeholders throw the error "You must feed a value for placeholder tensor" because sess.run(err) was executed without a feed.
Upvotes: 1