【发布时间】:2018-03-26 20:44:33
【问题描述】:
我正在尝试预测单个图像的结果,但它给出了一个不相关的结果。我已经在 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))
【问题讨论】:
-
为什么要先将图像重新塑造成通道?在您的训练代码中,图像输入形状为
input_shape=(IMAGE_SIZE,IMAGE_SIZE,CHANNELS) -
另外,如果 im 的 dtype 为整数,
im/255可能会在 Python 2 中将其归零
标签: python-3.x machine-learning keras computer-vision