-
Notifications
You must be signed in to change notification settings - Fork 5
/
predict_v2.py
53 lines (39 loc) · 1.51 KB
/
predict_v2.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
45
46
47
48
49
50
51
52
53
import random
import tensorflow as tf
import get_test_array
import numpy as np
import matplotlib.pyplot as plt
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# 忽略警告:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
def plot_image(i, predictions_array, true_label, img):
predictions_array, true_label, img = predictions_array, true_label[i], img[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
plt.imshow(img, cmap=plt.cm.binary)
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = 'blue'
else:
color = 'red'
plt.xlabel("{} {:2.0f}% ({})".format(class_names[predicted_label],
100 * np.max(predictions_array),
class_names[true_label]),
color=color)
class_names = list(range(100))
model = tf.keras.models.load_model('Chinese_recognition_model_v2.h5')
(test_image, test_label) = get_test_array.load_data('data/test/')
index = [x for x in range(len(test_label))]
random.shuffle(index)
test_image = test_image[index]
test_label = test_label[index]
predictions = model.predict(test_image)
# Plot the first X test images, their predicted labels, and the true labels.
# Color correct predictions in blue and incorrect predictions in red.
plt.figure(figsize=(10, 10))
for i in range(36):
plt.subplot(6, 6, i+1)
plot_image(i, predictions[i], test_label, test_image)
plt.tight_layout()
plt.show()