I'm newer to tensorflow, I implement the logistic regression using tensorflow, my code is same as the book "Getting started with TensorFlow", but when I run it, occured error: ValueError: Cannot feed value of shape (100,) for Tensor 'Placeholder_1:0', which has shape '(?, 10)'. Could anyone help me?
mnist = input_data.read_data_sets("tmp/data/", one_hot=False)
# set the total number of epochs of the training phase:
training_epochs = 25
learning_rate = 0.01
batch_size = 100
display_step = 1
# building the model
# define 'x' as the input tensor, it represents the MNIST data
# images of size 28 x 28 = 784 pixels:
x = tf.placeholder("float", [None, 784])
y = tf.placeholder("float", [None, 10])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
evidence = tf.matmul(x, W) + b
activation = tf.nn.softmax(evidence)
# error function
cross_entropy = y * tf.lgamma(activation)
# cost function
cost = tf.reduce_mean(-tf.reduce_sum(cross_entropy, reduction_indices = 1))
# minimize the cost function
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
avg_set = []
epoch_set = []
init = tf.global_variables_initializer()
with tf.Session() as sess:
for epoch in range(training_epochs):
avg_cost = 0
total_batch = int(mnist.train.num_examples / batch_size)
for i in range(total_batch):
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
# Fit the training using the batch data:
sess.run(optimizer, feed_dict = {x: batch_xs, y: batch_ys})
# compute the average loss:
avg_cost += sess.run(cost, feed_dict = {x: batch_xs,
y: batch_ys}) / total_batch
# During the computation, we display a log per epoch step:
if epoch % display_step == 0:
print("Epoch: ", '%04d' % (epoch + 1),
"cost=", "{:.9f}".format(avg_cost))
print("Training phase finished.")
correct_prediction = tf.equal(tf.argmax(activation, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print("MODEL accuracy: ", accuracy.eval({x: mnist.test.images,
y: mnist.test.labels}))