Models.face_recognition_facenet package

Submodules

Models.face_recognition_facenet.FaceRecognition module

class Models.face_recognition_facenet.FaceRecognition.FaceRecognition(distance_threshold: float = 0.75, model_path: Path | None = None, use_cuda: bool = False)[source]

Bases: object

Perform face recognition. Extract features from face images and compare them with a local dataset.

distance_threshold

Maximum distance between two features vector to consider them from the same person.

Type:

float

Create the FaceRecognition model.

Parameters:
  • distance_threshold (float, optional) – Maximum distance between two features vector to consider them from the same person. Defaults to 0.75.

  • model_path (Optional[Path], optional) – Path to the model checkpoint. (.ckpt-…, without the “.data-…”). Defaults to None.

  • use_cuda (bool, optional) – Execute the model on a CUDA device. Defaults to False.

add_features(name: str, features: ndarray)[source]

Store a new features vector.

Parameters:
  • name (str) – Name associated with the features.

  • features (np.ndarray) – A features vector.

property algorithm_name: str

Get the name of the face recognition algorithm.

load_features(features_path: Path)[source]

Load face features from a pickle file.

Parameters:

features_path (Path) – Path to a pickle file (.pkl).

load_model()[source]

Load the model from a checkpoint file.

predict_features(image: ndarray) ndarray[source]

Predict a face image and extract a features vector.

Parameters:

image (np.ndarray) – A BGR uint8 face image of shape (H, W, 3).

Raises:

ValueError – If the model is not loaded (call load_model()).

Returns:

The predicted features vector.

Return type:

np.ndarray

recognize_features(features: ndarray) List[Instance][source]

Search a features vector in the stored face features.

Parameters:

features (np.ndarray) – The features of a face.

Returns:

A list of Instances sorted from most to least

similar, with the following fields: - name (str): The name of the recognized face. - distance (float): The Euclidean distance from the supplied features to the dataset features.

Return type:

List[Instance]

recognize_image(image: ndarray) List[Instance][source]

Recognize a face.

Parameters:

image (np.ndarray) – A BGR uint8 face image of shape (H, W, 3).

Returns:

A list of Instances sorted from most to least

similar, with the following fields: - name (str): The name of the recognized face. - distance (float): The Euclidean distance from the supplied features to the recognized features.

Return type:

List[Instance]

save_features(path: Path)[source]

Save the current face features to a file.

Parameters:

path (Path) – Output pickle file path, ending in “.pkl”.

Module contents