我试图预测单张图像的结果,但得到的结果与预期不符。我已经在CIFAR-10数据集上训练了模型,并使用了Keras和TensorFlow来训练这个模型。我认为我提供的输入大小不正确。
这是训练代码的摘要:https://github.com/09rohanchopra/cifar10/blob/master/cifar10-simple-cnn.ipynb预测单张图像的代码
from keras.preprocessing import image
from keras.models import load_model
from scipy.misc import imread,imresize
import numpy as np
model=load_model('augmented_best_model.h5')
im=imread('1.jpg')
im=im/255
im=im.resize(im,(32,32))
pr=model.predict(im.reshape(-1,3,32,32))
回答:
我得到了答案
x=imread('test/2.jpg',mode='RGB')
x=imresize(x,(32,32))
x=np.invert(x)
x=x.reshape(-1,32,32,3)