Search code examples
pythontensorflowmnist

TensorFlow: Shape error


After training my MNIST classification network, I wanted to "predict" on the test data and got the following error regarding the test input's shape

testimages = np.array(test)
print(testimages.shape)
> (28000, 784)
feed_dict = {x: [testimages]}
classification = sess.run(y, feed_dict)

ValueError: Cannot feed value of shape (1, 28000, 784) for Tensor u'Placeholder_2:0', which has shape (Dimension(None), Dimension(784))

So how can it be that the shape is (28000, 784) (which it should be) but when feeding into the trained network, it shows up as (1, 28000, 784)?

By the way, for training I included the training data via

trainlabels = np.array(train["label"])
trainimages = np.array(train.iloc[:, 1:])

because the training data had a first column stating the label. I'm using Pandas for import.


Solution

  • Quick answer: change from feed_dict = {x: [testimages]} to feed_dict = {'x': testimages}

    In your input, you passed feed_dict which is a dictionary. not sure if that's ok. Also, the entry inside, which you label x has the format [testimages]. So if testimages.shape = (28000, 784), wrapping it around with an array would make it (1, 28000, 784).