使用keras训练好了mnist数字识别模型后,准备拿来做预测。
以下是预测代码:
#coding:utf-8
import cv2
import numpy as np
from keras.models import load_model
model = load_model('self.h5')
image = cv2.imread('Predict_image/7.jpg', 0)
img = cv2.imread('Predict_image/7.jpg', 0)
img = (img.reshape(1,28,28,1)).astype("float32")/255
predict = model.predict_classes(img)
print ('识别为:')
print (predict)
cv2.imshow("Image1", image)
cv2.waitKey(0)
之前这个代码是有效的,但是在更换训练模型后,代码出现提示:
AttributeError: 'Model' object has no attribute 'predict_classes'
在这里插入图片描述
在国外网站上找到了解决办法。
The predict_classes method is only available for the Sequential class (which is the class of your first model) but not for the Model class (the class of your seco

最低0.47元/天 解锁文章
1492

被折叠的 条评论
为什么被折叠?



