【问题标题】:TensorFlow: Shape errorTensorFlow:形状错误
【发布时间】:2016-05-01 02:08:13
【问题描述】:

在训练我的 MNIST 分类网络后,我想对测试数据进行“预测”,但在测试输入的形状方面出现以下错误

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

ValueError: 无法为具有形状 (Dimension(None), Dimension(784)) 的张量 u'Placeholder_2:0' 提供形状 (1, 28000, 784) 的值

那么形状怎么可能是 (28000, 784)(它应该是),但是当输入到经过训练的网络时,它会显示为 (1, 28000, 784)?

顺便说一句,为了训练,我通过

包含了训练数据
trainlabels = np.array(train["label"])
trainimages = np.array(train.iloc[:, 1:])

因为训练数据的第一列说明了标签。我正在使用 Pandas 进行导入。

【问题讨论】:

    标签: python tensorflow mnist


    【解决方案1】:

    快速回答:从feed_dict = {x: [testimages]} 更改为feed_dict = {'x': testimages}

    在您的输入中,您传递了feed_dict,这是一个字典。不确定是否可以。此外,您标记为x 的内部条目的格式为[testimages]。所以如果testimages.shape = (28000, 784),用数组包裹它会变成(1, 28000, 784)

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多