我用Keras训练了一个图像分类器,最后用代码保存了模型。
model.save('model1.h5')
现在,当我试图用这个模型预测另一个图像时,我使用的是代码
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
# dimensions of our images
img_width, img_height = 231, 172
# load the model we saved
model = load_model('mode
我是CNN和机器学习的新手,我一直在努力学习TensorFlow的图像分类教程。
现在,Google可以找到了。我一直在跟踪 of TensorFlow。我稍微修改了一下,所以它将模型保存为h5格式而不是tf格式,这样我就可以使用Keras‘model.predict_classes了。
现在,我已经训练了模型,模型从保存的模型重新加载,好的。但是,每当我试图预测图像时,我就反复得到list index out of range错误,我就是这样做的:
def predict():
image = tf.io.read_file('target.jpeg')
image
在通过网络传播图像之前,我正在尝试应用从Keras中的resnet50模块导入的预处理。由于在生成器对象中应用它时出现了错误,所以我将其作为lambda层添加到网络中。
但是,由于模型比我以前训练过的模型更糟糕,当我分别对每幅图像进行预处理时,我比较了这两种方法的结果,它们看起来非常不同,尽管我看不出应用的操作有什么不同。
import keras
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input
model = keras.models.Sequent