face_trigger.model.deep package¶
Contains the class that performs face-recognition based on Deep Metric Learning.
Submodules¶
face_trigger.model.deep.FaceRecognizer module¶
Deep Learning based face recognition module.
-
class
face_trigger.model.deep.FaceRecognizer.
FaceRecognizer
(dnn_model_path=None, classifier_model_path=None, label_map_path=None)¶ Trains a face recognition model based on deep metric learning. ‘Original paper <https://arxiv.org/abs/1503.03832>’_
-
embed
(images=None, landmarks=None)¶ Generates embeddings for the given images. THe images should be a result of the face detector phase, i.e these images should contain a face detected by the face detector.
Parameters: - images (list of numpy.nadarray: (num_images, image_height, image_width)) – the images to get embeddings of
- landmarks (list, shape: (num_images, 5, 2)) – the facial landmarks of the images
Returns: the face embeddings
Return type: list
Note: The images contain the entire frame, and not just the cropped out face. Alignmnet is taken care of when we generate the embeddings.
-
infer
(embeddings, threshold=0.2, unknown_index=-1)¶ Infer and return a predicted face identity.
Parameters: - embeddings (list) – 128D face embeddings
- threshold (float) – probability threshold to accept a prediction result
- unknown_index (int) – a integer id that denotes an unknown class
Returns: an identity
Return type: int
-
load
(classifier_model_path)¶ Load the saved classifier model.
Parameters: classifier_model_path (string) – path to the trained classifier model
-
load_label_mapping
(label_map_path=None)¶ Loads the mapping between the real labels and the ones used by sklearn during training.
Parameters: label_map_path (str) – path to the pickled label map Returns: a dictionary mapping from encoded label to real label Return type: dict
-
save
(classifier_model_path)¶ Save the trained classifier. Call only after fitting the embeddings, otherwise will throw an exception.
Parameters: classifier_model_path (string) – path along with name specifiying where to save the model. Extension should be .pkl for brevity.
-
train
()¶ Train the recognizer on the training set. Not required when working with pre-trained models. TODO: Implement the training mechanism
-