Skip to content

Instantly share code, notes, and snippets.

@irhum
Last active January 20, 2019 12:22
Show Gist options
  • Save irhum/65deeb3e99a2e4113308f90501e1b01f to your computer and use it in GitHub Desktop.
Save irhum/65deeb3e99a2e4113308f90501e1b01f to your computer and use it in GitHub Desktop.
# 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