tensorflow InvalidArgumentError: You must feed a value for placeholder tensor with dtype float
<p>I am new to tensorflow and want to train a logistic model for classification.</p>

<pre><code># Set model weights
W = tf.Variable(tf.zeros([30, 16]))
b = tf.Variable(tf.zeros([16]))
train_X, train_Y, X, Y = input('train.csv')

#construct model
pred = model(X, W, b)
# Minimize error using cross entropy
cost = tf.reduce_mean(-tf.reduce_sum(Y*tf.log(pred), reduction_indices=1))
# Gradient Descent
learning_rate = 0.1
#optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
# Initializing the variables
init = tf.initialize_all_variables()

get_ipython().magic(u'matplotlib inline')
import collections
import matplotlib.pyplot as plt

training_epochs = 200
batch_size = 300
train_X, train_Y, X, Y = input('train.csv')
acc = []
x = tf.placeholder(tf.float32, [None, 30]) 
y = tf.placeholder(tf.float32, [None, 16])
with tf.Session() as sess:
     sess.run(init)
     # Training cycle
     for epoch in range(training_epochs):
         avg_cost = 0.0
         #print(type(y_train[0][0]))
         print(type(train_X))
         print(type(train_X[0][0]))
         print X
         _, c = sess.run([optimizer, cost], feed_dict = {x: train_X, y: train_Y})
</code></pre>

<p>The feef_dict method does not work, with the complain: <strong>InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_54' with dtype float
     [[Node: Placeholder_54 = Placeholderdtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]]
Caused by op u'Placeholder_54':</strong></p>

<p>I check the data type, for the training feature data X:</p>

<pre><code>  train_X type: &lt;type 'numpy.ndarray'&gt;
  train_X[0][0]: &lt;type 'numpy.float32'&gt;
  train_X size: (300, 30)
  place_holder info : Tensor("Placeholder_56:0", shape=(?, 30), dtype=float32)
</code></pre>

<p>I do not know why it complains. Hope sb could help, thanks</p>

<p>From your error message, the name of the missing placeholder&mdash;<code>'Placeholder_54'</code>&mdash;is suspicious, because that suggests that at least 54 placeholders have been created in the current interpreter session. </p>

<p>There aren't enough details to say for sure, but I have some suspicions.  Are you running the same code multiple times in the same interpreter session (e.g. using IPython/Jupyter or the Python shell)? Assuming that is the case, I suspect that your <code>cost</code> tensor depends on placeholders that were created in a previous execution of that code.</p>

<p>Indeed, your code creates two <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/io_ops.html#placeholder" rel="nofollow"><code>tf.placeholder()</code></a> tensors <code>x</code> and <code>y</code> <strong>after</strong> building the rest of the model, so it seems likely that either:</p>

<ol>
<li><p>The missing placeholder was created in a previous execution of this code, or</p></li>
<li><p>The <code>input()</code> function calls <code>tf.placeholder()</code> internally and it is these placeholders (perhaps the tensors <code>X</code> and <code>Y</code>?) that you should be feeding.</p></li>
</ol>

python types tensorflow