-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlenet_5_isvalid.py
44 lines (30 loc) · 1012 Bytes
/
lenet_5_isvalid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import Mapping
import keras
import cv2
import os
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
os.chdir('D:\Python_ex\lenet_5')
test_model = keras.models.load_model('lenet-5.h5')
file_pathname = './digit_test'
fig = plt.figure()
cnt = 1
for filename in os.listdir(file_pathname):
img = cv2.imread(file_pathname + '\\' + filename)
fig.add_subplot(5,4,cnt)
plt.imshow(img)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = np.expand_dims(img, axis=-1)
img = img.astype(np.float32)/255
img = tf.image.resize(img, [32,32])
img = tf.expand_dims(img, axis = 0)
predict_value = test_model.predict(img)
digit = np.argmax(predict_value)
plt.title("Predict_Digit:{}".format(digit))
plt.axis('off')
cnt += 1
plt.show()