gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:36:31 25 4
gpt4 key购买 nike

(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com