meerqat.image.face_detection module#

Usage: face_detection.py <dataset> [–save=<root_path> <model_config> –image_key=<image_key> –disable_caching –batch_size=<n>]

Options: –image_key=<image_key> Used to index the dataset item [default: image] –save=<root_path> Root path to save the detected face(s).

The face will actually be saved with the same file stem as the original image.

--disable_caching

Disables Dataset caching (useless when using save_to_disk), see datasets.set_caching_enabled()

--batch_size=<n>

Batch size for Dataset.map. The actual batches processed by the model are first grouped by image size. [default: 64]

class meerqat.image.face_detection.MTCNN(image_size=160, margin=0, min_face_size=20, thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True, select_largest=True, selection_method=None, keep_all=False, device=None)[source]#

Bases: MTCNN

Simply override forward to allow to return bounding boxes and landmarks

forward(img, save_path=None, return_prob=False, return_box=False, return_landmarks=False)[source]#

Run MTCNN face detection on a PIL image or numpy array. This method performs both detection and extraction of faces.

Parameters:
  • {PIL.Image (img) –

  • np.ndarray

  • image (or list} -- A PIL) –

  • np.ndarray

  • torch.Tensor

  • list. (or) –

Keyword Arguments:
  • when (save_path {str} -- An optional save path for the cropped image. Note that) – self.post_process=True, although the returned tensor is post processed, the saved face image is not, so it is a true representation of the face in the input image. If img is a list of images, save_path should be a list of equal length. (default: {None})

  • probability. (return_prob {bool} -- Whether or not to return the detection) – (default: {False})

  • box. (return_box {bool} -- Whether or not to return the bounding) – (default: {False})

  • landmarks. (return_landmarks {bool} -- Whether or not to return the facial) – (default: {False})

Returns:

Union[torch.Tensor, tuple(torch.tensor, float)] – If detected, cropped image of a face

with dimensions 3 x image_size x image_size. Optionally, the probability that a face was detected, the bounding box coordinates and facial landmarks associated. If self.keep_all is True, n detected faces are returned in an n x 3 x image_size x image_size tensor with an optional list of detection probabilities. If img is a list of images, the item(s) returned have an extra dimension (batch) as the first dimension.

Example: >>> mtcnn = MTCNN() >>> face_tensor, prob, box, landmarks = mtcnn(img, save_path=’face.png’,

return_prob=True, return_box=True, return_landmarks=True)

meerqat.image.face_detection.detect_face(file_names, model, save_root_path=None)[source]#
meerqat.image.face_detection.dataset_detect_face(item, image_key='image', **kwargs)[source]#
meerqat.image.face_detection.dataset_detect_faces(dataset, batch_size=64, **kwargs)[source]#