I am learning TensorFLow. So to understand how to make something, I tried to copy some code from a source and execute it. But I\'m hitting an error message. So I tried some
When you define a placeholder in TensorFlow, the shape of the input during the session should be the same as the shape of the placeholder.
In batch_X, batch_Y = mnist.train.next_batch(100)
, the batch_x
is a 2D array of pixel values, which will have a shape of [batch_size, 28*28]
.
In X = tf.placeholder(tf.float32,[None, 28, 28, 1])
, the input placeholder is defined to have a 4D shape of [batch_size, 28, 28, 1]
You can either 1) reshape batch_x
before the feeding to TensorFlow. e.g.batch_x = np.reshape(batch_x, [-1, 28, 28, 1])
or 2) Change the shape of the placeholder. e.g. X = tf.placeholder(tf.float32,[None, 784])
I would recommend 2), since this saves you from doing any reshaping operations both in and outside of the TensorFlow graph.