-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed_test.py
54 lines (36 loc) · 1.15 KB
/
speed_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
import os
import cv2
from mtcnn_pytorch.src.detector import Predictor
def get_images():
images_dir = "mtcnn_pytorch/images"
images = []
for file in os.listdir(images_dir):
source_image = os.path.join(images_dir, file)
if file.endswith('.jpg'):
try:
image = cv2.imread(source_image)
images.append(image)
except FileExistsError:
print('Problem with file {}'.format(source_image))
return images
def speed_test():
images = get_images()
detect_time = 0
detect_num = 0
timer = cv2.TickMeter()
predictor = Predictor()
# skip first predict because it may go longer
predictor.predict_bounding_boxes(images[0])
for image in images:
image = cv2.resize(image, (640, 480))
timer.start()
predictor.predict_bounding_boxes(image)
timer.stop()
detect_time += timer.getTimeMilli()
detect_num += 1
timer.reset()
average_time = detect_time / detect_num
print("average mtcnn prediction_time {} msec".format(average_time))
return
if __name__ == "__main__":
speed_test()