美文网首页
基于mnist数据集训练出来的模型,单个图片预测

基于mnist数据集训练出来的模型,单个图片预测

作者: 小猪会飞 | 来源:发表于2018-08-03 00:13 被阅读0次

from __future__ import print_function

from keras.models import load_model
import cv2
import numpy as np


def reserveImg(img):
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            img[i, j] = 255 - img[i, j]
    return img

# 图片可以是白底黑字的 白底红字的
img_rows, img_cols = 28, 28
img = cv2.imread('d:/test/test5.jpg',0)


retval, im_at_fixed = cv2.threshold(img, 130, 255, cv2.THRESH_TOZERO)

cv2.imshow('1',im_at_fixed)


img = reserveImg(im_at_fixed)
cv2.imshow('2',img)
cv2.waitKey()

img = cv2.resize(img, (img_rows, img_cols), interpolation=cv2.INTER_CUBIC)

img = np.array([img])
img = img.astype('float32')


img = img.reshape(img.shape[0], img_rows, img_cols, 1)

img = img/255

model = load_model('my_model.h5')

res = model.predict_classes(img)
print (res)




相关文章

网友评论

      本文标题:基于mnist数据集训练出来的模型,单个图片预测

      本文链接:https://www.haomeiwen.com/subject/gbpevftx.html