fastface.FaceDetector

classmethod FaceDetector.build(arch: str, config: str | Dict, preprocess: Dict = {'mean': 0.0, 'normalized_input': True, 'std': 1.0}, hparams: Dict = {}, **kwargs) LightningModule

Classmethod for creating fastface.FaceDetector instance from scratch

Parameters:
  • arch (str) – architecture name

  • config (Union[str, Dict]) – configuration name or configuration dictionary

  • preprocess (Dict, optional) – preprocess arguments of the module. Defaults to {“mean”: 0, “std”: 1, “normalized_input”: True}.

  • hparams (Dict, optional) – hyper parameters for the model. Defaults to {}.

Returns:

fastface.FaceDetector instance with random weights initialization

Return type:

pl.LightningModule

classmethod FaceDetector.build_from_yaml(yaml_file_path: str) LightningModule

Classmethod for creating fastface.FaceDetector instance from scratch using yaml file

Parameters:

yaml_file_path (str) – yaml file path

Returns:

fastface.FaceDetector instance with random weights initialization

Return type:

pl.LightningModule

classmethod FaceDetector.from_checkpoint(ckpt_path: str, **kwargs) LightningModule

Classmethod for creating fastface.FaceDetector instance, using checkpoint file path

Parameters:

ckpt_path (str) – file path of the checkpoint

Returns:

fastface.FaceDetector instance with checkpoint weights

Return type:

pl.LightningModule

classmethod FaceDetector.from_pretrained(model: str, target_path: str | None = None, **kwargs) LightningModule

Classmethod for creating fastface.FaceDetector instance, using model name

Parameters:
  • model (str) – pretrained model name.

  • target_path (str, optional) – path to check for model weights, if not given it will use cache path. Defaults to None.

Returns:

fastface.FaceDetector instance with pretrained weights

Return type:

pl.LightningModule

FaceDetector.predict(data: ndarray | List, target_size: int | None = None, det_threshold: float = 0.4, iou_threshold: float = 0.4, keep_n: int = 200)

Performs face detection using given image or images

Parameters:
  • data (Union[np.ndarray, List]) – numpy RGB image or list of RGB images

  • target_size (int) – if given than images will be up or down sampled using target_size, Default: None

  • det_threshold (float) – detection score threshold, Default: 0.4

  • iou_threshold (float) – iou value threshold for nms, Default: 0.4

  • keep_n (int) – describes how many prediction will be selected for each batch, Default: 200

Returns:

prediction result as list of dictionaries. [

# single image results {

”boxes”: <array>, # List[List[xmin, ymin, xmax, ymax]] “scores”: <array> # List[float]

]

Return type:

List

>>> import fastface as ff
>>> import imageio
>>> model = ff.FaceDetector.from_pretrained('lffd_original').eval()
>>> img = imageio.imread('resources/friends.jpg')[:,:,:3]
>>> model.predict(img, target_size=640)
[{'boxes': [[1057, 181, 1186, 352], [558, 220, 703, 400], [141, 218, 270, 382], [866, 271, 976, 403], [327, 252, 442, 392]], 'scores': [0.9992017149925232, 0.9973644614219666, 0.9416095018386841, 0.8408345580101013, 0.7937759160995483]}]
FaceDetector.add_metric(name: str, metric: Metric)

Adds given metric with name key

Parameters:
  • name (str) – name of the metric

  • metric (torchmetrics.Metric) – Metric object

FaceDetector.get_metrics() Dict[str, Metric]

Return metrics defined in the FaceDetector instance

Returns:

defined model metrics with names

Return type:

Dict[str, torchmetrics.Metric]