训练我的 MNIST 分类网络后,我想“预测”测试数据,并得到以下关于测试输入形状的错误
testimages = np.array(test)
print(testimages.shape)
> (28000, 784)
feed_dict = {x: [testimages]}
classification = sess.run(y, feed_dict)
ValueError:无法为张量 u'Placeholder_2:0' 提供形状 (1, 28000, 784) 的值,该张量的形状为 (Dimension(None), Dimension(784))
那么,为什么形状是 (28000, 784)(它应该是),但是当输入经过训练的网络时,它会显示为 (1, 28000, 784)?
顺便说一句,对于训练,我通过以下方式包含了训练数据
trainlabels = np.array(train["label"])
trainimages = np.array(train.iloc[:, 1:])
因为训练数据的第一列说明了标签。我使用 Pandas 进行导入。
最佳答案
快速回答:从 feed_dict = {x: [testimages]}
更改为 feed_dict = {'x': testimages}
在您的输入中,您传递了 feed_dict
这是一个字典。不确定这样是否可以。此外,您标记为 x
的内部条目的格式为 [testimages]
。因此,如果 testimages.shape = (28000, 784)
,用数组将其包裹起来将使其变为 (1, 28000, 784)
。
关于python - TensorFlow:形状错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36957766/