-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmy_test.py
68 lines (55 loc) · 2.33 KB
/
my_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import time
import cv2
from detector.cv_face_detector.model import CVFaceDetector
from models.m1.model import M1FaceAntiSpoofing
from models.m2.model import M2FaceAntiSpoofing
from models.m3.model import M3FaceAntiSpoofing
from models.m4.model import M4FaceAntiSpoofing
from models.m5.model import M5FaceAntiSpoofing
import os
face_detector = CVFaceDetector()
spoof_detectors = [M4FaceAntiSpoofing()]
benchmark_dir = "benchmarks"
for spoof_detector in spoof_detectors:
print("Start ----------------------------- ", type(spoof_detector))
total_time = 0
all_count = 0
correct_count = 0
errors = []
for class_name in ["fake", "real"]:
class_path = os.path.join(benchmark_dir, class_name)
for image_name in os.listdir(class_path):
image_path = os.path.join(class_path, image_name)
bgr = cv2.imread(image_path)
face_bboxes = face_detector.get_face_bboxes(bgr)
for bbox in face_bboxes:
start_time = time.time()
real_score = spoof_detector.get_real_score(bgr, bbox)
total_time += time.time() - start_time
print("Real score for image name " + image_name + " in class " + class_name + " is: ",
real_score)
if class_name == "fake":
if real_score < 0.5:
is_correct = True
else:
cv2.imshow("fake", bgr)
cv2.waitKey(0)
is_correct = False
errors.append(real_score)
else:
if real_score >= 0.5:
is_correct = True
else:
cv2.imshow("test", bgr)
cv2.waitKey(0)
is_correct = False
errors.append(1 - real_score)
if is_correct:
correct_count+=1
all_count+=1
print("Correct prediction: ", is_correct)
print("--- Average time for each face: ", total_time/all_count, " seconds")
print("--- Total count: ", all_count)
print("--- Correct count: ", correct_count)
print("--- Average error: ", (sum(errors)/len(errors))*100,"%")
print("End ----------------------------- ", type(spoof_detector))