medusa.containers.results#

A very hack implementation of a container to store results from processing multiple batches of images.

Module Contents#

class medusa.containers.results.BatchResults(n_img=0, device=DEVICE, **kwargs)[source]#

A container to store and process results from processing multiple batches of inputs/images.

Parameters:
  • n_img (int) – Number of images processed thus far

  • device (str) – Device to store/process the data on (either ‘cpu’ or ‘cuda’)

  • **kwargs – Other data that will be set as attributes

add(**kwargs)[source]#

Add data to the container.

Parameters:

**kwargs – Any data that will be added to the

concat(n_max=None)[source]#

Concatenate results form multiple batches.

Parameters:

n_max (None, int) – Whether to only return n_max observations per attribute (ignored if None)

sort_faces(attr='lms', dist_threshold=250)[source]#

‘Sorts’ faces using the medusa.tracking.sort_faces function (and performs some checks of the data).

Parameters:
  • attr (str) – Name of the attribute that needs to be used to sort the faces (e.g., ‘lms’ or ‘v’)

  • dist_threshold (int, float) – Euclidean distance between two sets of landmarks/vertices that we consider comes from two different faces (e.g., if d(lms1, lms2) >= dist_treshold, then we conclude that face 1 (lms1) is a different from face 2 (lms2)

Returns:

face_idx – The face IDs associate with each detection

Return type:

torch.tensor

filter_faces(present_threshold=0.1)[source]#
to_dict(exclude=None)[source]#
visualize(f_out, imgs, video=False, show_cropped=False, face_id=None, fps=24, crop_size=(224, 224), template=None, **kwargs)[source]#

Visualizes the detection/cropping results aggregated by the BatchResults object.

Parameters:
  • f_out (str, Path) – Path of output image/video

  • imgs (torch.tensor) – A tensor with the original (uncropped images); can be a batch of images or a single image

  • video (bool) – Whether to output a video or image (grid)

  • show_cropped (bool) – Whether to visualize the cropped image or the original image

  • face_id (None) – Should be None (used in recursive call)

  • fps (int) – Frames per second of video (only relevant if video=True)

  • crop_size (tuple[int]) – Size of cropped images

  • template (torch.tensor) – Template used in aligment (optional)