Last active
January 20, 2019 12:22
-
-
Save irhum/65deeb3e99a2e4113308f90501e1b01f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns distance (a float) if face detected in synthesized image, None otherwise | |
def distance_metric(y_pred, x, dlib_models): | |
dist = None | |
face_detector, landmark_detector, face_embedder = dlib_models | |
face_boxes = face_detector(y_pred, 1) | |
if len(face_boxes) == 1: | |
landmarks = landmark_detector(y_pred, face_boxes[0]) | |
embedding = face_embedder.compute_face_descriptor(y_pred, landmarks) | |
dist = np.linalg.norm(np.array(embedding) - np.array(x)) | |
return dist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment