-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_model.py
54 lines (43 loc) · 1.24 KB
/
test_model.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
54
# -*-coding:utf8-*-
__author__ = '万壑'
import cv2
from read_data import read_name_list, read_file
from train_model import Model
def onePicture(path):
model = Model()
model.load()
img = cv2.imread(path)
img = cv2.resize(img, (92, 112))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
picType, prob = model.predict(img)
if picType != -1:
name_list = read_name_list('res')
print(name_list)
print(picType)
print(name_list[picType], prob)
print("done")
else:
print(" Don't know this person")
# 读取文件夹下子文件夹中所有图片进行识别
def Batch(path):
model = Model()
model.load()
index = 0
img_list, label_lsit, counter = read_file(path)
for img in img_list:
picType, prob = model.predict(img)
if picType != -1:
index += 1
name_list = read_name_list('./res')
print("done")
print(name_list)
print(picType)
print(name_list[picType])
else:
print(" Don't know this person")
return index
if __name__ == '__main__':
onePicture('./test/chunmei.jpg')
onePicture('./test/test.jpg')
onePicture('./test/9.pgm')
#Batch(".\\test")