python - 当我使用 tflearn 预测测试用例时,它显示 "Cannot feed value of shape (32, 32, 3) for Tensor u' input/X : 0', which has shape ' (? , 32, 32, 3)"

标签 python tensorflow tflearn

(X,Y),(test_x,test_y)=cifar.load_data(one_hot=True)

X=X.reshape([-1,32,32,3])
test_x=test_x.reshape([-1,32,32,3])

convnet=input_data(shape=[None,32,32,3],name='input')

convnet=conv_2d(convnet,32,3,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,64,3,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,128,3,activation='relu')
convnet=conv_2d(convnet,128,3,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=fully_connected(convnet,512,activation='relu')
convnet=fully_connected(convnet,512,activation='relu')
convnet=dropout(convnet,0.8)


convnet=fully_connected(convnet,10,activation='softmax')
convnet=regression(convnet,optimizer='adam',learning_rate=0.001,loss='categorical_crossentropy')

model=tflearn.DNN(convnet)

model.fit(X,Y,n_epoch=1,validation_set=(test_x,test_y),batch_size=100,snapshot_step=1000,show_metric=True)

model.save('tflearn.model')
'''
model.load('tflearn.model')

print(model.predict(test_x[1]))
'''

当我尝试预测时,它显示错误: “无法为张量 u'input/X:0' 提供形状为 (32, 32, 3) 的值,其形状为“(?, 32, 32, 3)”。

请有人帮忙。

最佳答案

您需要对要进行预测的输入使用tf.expand_dims:

# 't2' is a tensor of shape [32, 32, 3]
shape(expand_dims(t2, axis=0)) ==> [1, 32, 32, 3]

关于python - 当我使用 tflearn 预测测试用例时,它显示 "Cannot feed value of shape (32, 32, 3) for Tensor u' input/X : 0', which has shape ' (? , 32, 32, 3)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42473034/

相关文章:

python - 为什么多线程和单线程没有执行时间差异

python - 使用 tweepy 保存推文的全文

python - 如果在 cpu 上完成读取/预处理,Tensorflow 网络会发散

python - 进行预测时得到相同的输出

python - 使用 tflearn 构建 CNN

python - 如何加载和重新训练 tflean 模型

python - 使用 TFlearn 塑造线性回归数据

python - 使用 'is'运算符比较python中的两个字符串切片

python - 在TensorFlow中,字符串常量的打印总是附有 'b'

Python 在 Linux 上请求 403 但在 Windows 上工作