Models.age_gender package

Submodules

Models.age_gender.AgeGenderPredictor module

class Models.age_gender.AgeGenderPredictor.AgeGenderPredictor(age_model_path: Path | None = None, gender_model_path: Path | None = None, do_age: bool = True, do_gender: bool = True, use_cuda: bool = False)[source]

Bases: object

Predict the age and gender of a face image.

Create and load the age and gender models.

Parameters:
  • age_model_path (Optional[Path], optional) – Path to the onnx age model. Defaults to None.

  • gender_model_path (Optional[Path], optional) – Path to the onnx gender model. Defaults to None.

  • do_age (bool, optional) – Enable the age prediction. Defaults to True.

  • do_gender (bool, optional) – Enable the age prediction. Defaults to True.

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

predict(images: List[ndarray] | ndarray) List[Instance][source]

Predict the age and gender of the faces on an image.

Parameters:

images (Union[List[np.ndarray], np.ndarray]) – A single image or a list of face images, BGR uint8 of shape (H, W, 3).

Returns:

An Instance for each image with the following fields:
  • age (float): The age of the face (if do_age is True).

  • gender (Gender): A Gender enum (if do_gender is True).

  • gender_confidence (float) The gender confidence

    (if do_gender is True).

Return type:

List[Instance]

predict_age(images: List[ndarray] | ndarray) List[Instance][source]

Predict the age of a face image.

Parameters:

images (Union[List[np.ndarray], np.ndarray]) – A single image or a list of images of face crops, BGR uint8 of shape (H, W, 3).

Raises:

ValueError – If do_age is set to False.

Returns:

A list of Instances with a float-type “age” field.

Return type:

List[Instance]

predict_gender(images: List[ndarray] | ndarray) List[Instance][source]

Predict the gender of a face image

Parameters:

images (Union[List[np.ndarray], np.ndarray]) – A single image or a list of images of face crops, BGR uint8 of shape (H, W, 3).

Raises:

ValueError – If do_gender is set to False.

Returns:

A list of Instances with a “gender” field storing a

Gender enum and a “confidence” field storing the gender classification confidence.

Return type:

List[Instance]

Module contents