medusa.crop.align_crop#

Module with an implementation of a “crop model” that aligns an image to a template based on a set of landmarks (based on an implementation from Insightface).

Module Contents#

medusa.crop.align_crop.TEMPLATE#

The 5-landmark template used by Insightface (e.g. in their arcface implementation). The coordinates are relative to an image of size 112 x 112.

class medusa.crop.align_crop.AlignCropModel(output_size=(112, 112), template=TEMPLATE, detector=SCRFDetector, device=DEVICE, **kwargs)[source]#

Cropping model based on functionality from the insightface package, as used by MICA (Zielon/MICA).

Parameters:
  • name (str) – Name of underlying insightface model

  • det_size (tuple) – Image size for detection

  • target_size (tuple) – Length 2 tuple with desired width/heigth of cropped image; should be (112, 112) for MICA

  • det_thresh (float) – Detection threshold (higher = more stringent)

  • device (str) – Either ‘cuda’ (GPU) or ‘cpu’

Examples

To crop an image to be used for MICA reconstruction:

>>> from medusa.data import get_example_image
>>> crop_model = AlignCropModel()
>>> img = get_example_image()  # path to jpg image
>>> out = crop_model(img)
forward(imgs)[source]#

Aligns and crops images to the desired size.

Parameters:

imgs (str, Path, tuple, list, array_like, torch.tensor) – A path to an image, or a tuple/list of them, or already loaded images as a torch.tensor or numpy array

Returns:

out_crop – Dictionary with cropping outputs; includes the keys “imgs_crop” (cropped images) and “crop_mat” (3x3 crop matrices)

Return type:

dict