1
votes

I got an error,InvalidArgumentError like

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype float [[Node: Placeholder_1 = Placeholderdtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]]

I cannot understand what is wrong in my code.And I cannot understand the wrong point is setting or code(syntax).

How can I fix this?

I wrote in my whole code

import tensorflow as tf
import numpy as np

input_dim =2
output_dim =1

x = tf.placeholder("float",[None,input_dim])
#重み
W = tf.Variable(tf.random_uniform([input_dim,output_dim],-1.0,1.0))
#バイアス
b = tf.Variable(tf.random_normal([output_dim]))
#シグモイド活性化調節
y = tf.nn.sigmoid(tf.matmul(x,W)+b)

y_ = tf.placeholder("float",[None,output_dim])
loss = tf.reduce_mean(tf.square(y-y_))
train_step = tf.train.MomentumOptimizer(0.01,0.97).minimize(loss)

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

for i in range(5000):
    batch_xs = np.array([
        [0.,0.],
        [0.,1.],
        [1.,0.],
        [1.,1.]
    ])
    batch_ys = np.array([
        [0.],
        [0.],
        [0.],
        [1.]
    ])
    sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})
    print(i,sess.run(y,feed_dict={x:batch_xs,y:batch_ys}))
1

1 Answers

0
votes

You have placeholder x and y_, not x and y.

so in the sess.run() should be sess.run(train_step,feed_dict={x:batch_xs,y_:batch_ys})