Skip to content

Commit 99641c5

Browse files
JKCooper2ageitgey
authored andcommitted
Replace _face_distance with more efficient calculation (ageitgey#19)
From http://stackoverflow.com/questions/7741878/how-to-apply-numpy-linalg-norm-to-each-row-of-a-matrix Running time comparisons (prev vs. new, performed using faces = np.random.rand(n, 128), face_to_compare = np.random.rand(1, 128)) n = 1M: 5.3s vs. 1.1s n = 5M: 26.9s vs. 6.6s n = 10M: 52.6s vs. 23s
1 parent 03a1679 commit 99641c5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

face_recognition/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _face_distance(faces, face_to_compare):
6161
:param face_to_compare: A face encoding to compare against
6262
:return: A list with the distance for each face in the same order as the 'faces' array
6363
"""
64-
return np.array([np.linalg.norm(face - face_to_compare) for face in faces])
64+
return np.linalg.norm(faces - face_to_compare, axis=1)
6565

6666

6767
def load_image_file(filename, mode='RGB'):

0 commit comments

Comments
 (0)