import numpy as np
from PIL import Image
from keras.models import load_model

img_gray = Image.open('1002.png')
number = np.array(img_gray)
print(number.shape)
print('准备的图片的shape：',number.flatten().shape)
print('原number:',number)
number = number.astype('float32')
number = number/255   #归一化
number = number.flatten()
print('处理过后的number.shape:',number.shape)

model = load_model('mnist-dnn.h5')
# model.load_weights('mnist.model.best.hdf5')
# def recognize(photo_data):
#     return clf.predict(photo_data)

print(model.predict_classes(np.array([number])))
#print('测试标签为：',test_target[8000])
[((5, 11, 5, 33), 'PIL.Image.open', 'Image.open', ({(5, 22, 5, 32): '"""1002.png"""'}, {}), "('1002.png')", False, 'from PIL import Image\n'), ((6, 9, 6, 27), 'numpy.array', 'np.array', ({(6, 18, 6, 26): 'img_gray'}, {}), '(img_gray)', True, 'import numpy as np\n'), ((15, 8, 15, 34), 'keras.models.load_model', 'load_model', ({(15, 19, 15, 33): '"""mnist-dnn.h5"""'}, {}), "('mnist-dnn.h5')", False, 'from keras.models import load_model\n'), ((20, 28, 20, 46), 'numpy.array', 'np.array', ({(20, 37, 20, 45): '[number]'}, {}), '([number])', True, 'import numpy as np\n')]