**手書きの0〜9について文字認識を行っています。
model = load_model('mnist_model.h5')
の部分にエラーが出てしまいます。
**
import keras
import numpy as np
from keras.models import load_model
from keras.preprocessing.image import array_to_img,img_to_array,load_img
import os
import re
model = load_model('mnist_model.h5')
def prediction(directory,ext='jpg | jpeg | bmp | png | ppm'):
return [os.path.join(root,f)
for root, _, files in os.walk(directory) for f in files
if re.match(r'([¥w]+¥.(?:'+ ext + '))',f.lower())]
for picture in prediction('./tegaki/'):
X = []
img = img_to_array(
load_img(picture, target_size=(28, 28), grayscale=True))
X.append(img)
X = np.asarray(X)
X = X.astype('float32')
X = X / 255,0
features = model.predict(X)
proba = model.predict_proba(X)
print("proba:", proba)
print('----------')
print(picture)
print(features.argmax())
print('----------')
あなたの回答
tips
プレビュー