1
votes

I was learning Tensorflow from the Tensorflow documentation and was trying to implement MNIST but i keep getting this error.

ValueError: Cannot feed value of shape (100, 1) for Tensor Placeholder_1:0', which has shape '(?, 10)'

Here's the code

# placeholders for the data
x = tf.placeholder(tf.float32, [None, 784])
y = tf.placeholder(tf.float32, [None, 10])

# weights and biases
w = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

# softmax model
activation = tf.nn.softmax_cross_entropy_with_logits(logits = tf.matmul(x, w) + b, labels=y)
# backpropagation
train = tf.train.GradientDescentOptimizer(0.5).minimize(activation)

# creating tensorflow session
s = tf.InteractiveSession()

# i have already initialised the variables

# gradient descent
for i in range(100):
    x_bat, y_bat= create_batch(x_train, y_train, size=100)
    train_step = s.run(train, feed_dict={x: x_bat, y: y_bat})
1

1 Answers

0
votes

The problem is with create_batch function that outputs the wrong y_bat shape. Most probably, you forgot to do one-hot encoding.

I.e., the current y_bat is a [100] vector of integers 0..9, but it should be a [100, 10] vector of 0 and 1.

If you get the data with input_data.read_data_sets function, then simply add one_hot=True.