0
$\begingroup$

I'm copying an example directly out of a book I am working through, and I currently getting this error:

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_10' with dtype float and shape [?,2]
 [[{{node Placeholder_10}} = Placeholder[dtype=DT_FLOAT, shape=[?,2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

My tensors and placeholders are declared like so:

XOR_X = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
XOR_Y = [[0.0], [1.0], [1.0], [0.0]]

num_input = 2
num_classes = 1

x_ = tf.placeholder("float", shape=[None, num_input], name='X')
y_ = tf.placeholder("float", shape=[None, num_classes], name='Y')

And the line producing the error is here:

_, summary = sess.run([train_step, merged_summary_op], feed_dict={x_ : XOR_X, y_: XOR_Y})

What exactly is the issue here?

for context, I attach the entire implementation here:

import tensorflow as tf

XOR_X = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
XOR_Y = [[0], [1], [1], [0]]
# XOR_Y = [0.0, 1.0, 1.0, 0.0]

num_input = 2
num_classes = 1

x_ = tf.placeholder("float", shape=[None, num_input], name='X')
y_ = tf.placeholder("float", shape=[None, num_classes], name='Y')

#Model structure
H1 = tf.layers.dense(inputs=x_, units=4, activation=tf.nn.sigmoid)
H2 = tf.layers.dense(inputs=H1, units=8, activation=tf.nn.sigmoid)
H_OUT = tf.layers.dense(inputs=H2, units=num_classes, activation=tf.nn.sigmoid)

#Define cost function
with tf.name_scope("cost") as scope:
    cost = tf.losses.log_loss( labels=y_, predictions=H_OUT)
    # Add loss to tensorboard
    tf.summary.scalar("log_loss", cost)

with tf.name_scope("train") as scope:
    train_step = tf.train.GradientDescentOptimizer(0.1).minimize(cost)

merged_summary_op = tf.summary.merge_all()

# Initialize variables(weights) and session
init = tf.global_variables_initializer()
sess = tf.Session()

# Configure summary to output at given directory
writer = tf.summary.FileWriter("./logs/xor_logs", sess.graph)
sess.run(init)

# Train loop
for step in range(10000):
    # Run train_step and merge summary op
    _, summary = sess.run([train_step, merged_summary_op], feed_dict={x_ : XOR_X, y_: XOR_Y})
    if step % 1000 == 0:
        print("Step/Epoch: {}, Loss: {}".format(step, sess.run(cost, feed_dict={x_ : XOR_X, y_: XOR_Y})))
        writer.add_summary(summary, step)
$\endgroup$
1
$\begingroup$

Try using the number of sample instead of None in the x_ placeholder. Also, try making these changes.

n_samples = len( XOR_X )
x_ = tf.placeholder(dtype=tf.float32 , shape=[n_samples, num_input], name='X')
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.