-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2_test.py
More file actions
32 lines (25 loc) · 831 Bytes
/
2_test.py
File metadata and controls
32 lines (25 loc) · 831 Bytes
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
from tensorflow.keras.models import load_model
import cv2
import numpy as np
import os
model = load_model("model_data/model.h5")
label = []
f = open("model_data/model.txt")
for line in f.readlines():
label.append(line.strip())
f.close()
directory = "dataset/test"
for name in os.listdir(directory):
path = os.path.join(directory, name)
frame = cv2.imread(path, cv2.IMREAD_COLOR)
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (100, 100))
image = image.reshape(1, 100, 100, 3)
image = image.astype(np.float32)
image = image / 255
predicts = model.predict(image)
idx = np.argmax(predicts)
print(idx, label[idx])
cv2.putText(frame, label[idx], (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 255), 3)
cv2.imshow("frame", frame)
cv2.waitKey(0)