forked from ageitgey/face_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
77 lines (56 loc) · 2.39 KB
/
benchmark.py
File metadata and controls
77 lines (56 loc) · 2.39 KB
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
69
70
71
72
73
74
75
76
77
import timeit
# Note: This example is only tested with Python 3 (not Python 2)
# This is a very simple benchmark to give you an idea of how fast each step of face recognition will run on your system.
# Notice that face detection gets very slow at large image sizes. So you might consider running face detection on a
# scaled down version of your image and then running face encodings on the the full size image.
TEST_IMAGES = [
"obama-240p.jpg",
"obama-480p.jpg",
"obama-720p.jpg",
"obama-1080p.jpg"
]
def run_test(setup, test, iterations_per_test=5, tests_to_run=10):
fastest_execution = min(timeit.Timer(test, setup=setup).repeat(tests_to_run, iterations_per_test))
execution_time = fastest_execution / iterations_per_test
fps = 1.0 / execution_time
return execution_time, fps
setup_locate_faces = """
import face_recognition
image = face_recognition.load_image_file("{}")
"""
test_locate_faces = """
face_locations = face_recognition.face_locations(image)
"""
setup_face_landmarks = """
import face_recognition
image = face_recognition.load_image_file("{}")
face_locations = face_recognition.face_locations(image)
"""
test_face_landmarks = """
landmarks = face_recognition.face_landmarks(image, face_locations=face_locations)[0]
"""
setup_encode_face = """
import face_recognition
image = face_recognition.load_image_file("{}")
face_locations = face_recognition.face_locations(image)
"""
test_encode_face = """
encoding = face_recognition.face_encodings(image, known_face_locations=face_locations)[0]
"""
setup_end_to_end = """
import face_recognition
image = face_recognition.load_image_file("{}")
"""
test_end_to_end = """
encoding = face_recognition.face_encodings(image)[0]
"""
print("Benchmarks (Note: All benchmarks are only using a single CPU core)")
print()
for image in TEST_IMAGES:
size = image.split("-")[1].split(".")[0]
print("Timings at {}:".format(size))
print(" - Face locations: {:.4f}s ({:.2f} fps)".format(*run_test(setup_locate_faces.format(image), test_locate_faces)))
print(" - Face landmarks: {:.4f}s ({:.2f} fps)".format(*run_test(setup_face_landmarks.format(image), test_face_landmarks)))
print(" - Encode face (inc. landmarks): {:.4f}s ({:.2f} fps)".format(*run_test(setup_encode_face.format(image), test_encode_face)))
print(" - End-to-end: {:.4f}s ({:.2f} fps)".format(*run_test(setup_end_to_end.format(image), test_end_to_end)))
print()