Human perception algorithms

terran.face.detection

terran.face.detection.face_detection = <Detection(RetinaFace)>

Default entry point to face detection.

This is an instantiation of the Detection class, lazily-loaded in order to avoid reading the checkpoints on import. Refer to that class’ __call__ method for more information.

class terran.face.detection.Detection(checkpoint=None, short_side=416, merge_method='padding', device=device(type='cpu'), lazy=False)

Initializes and loads the model for checkpoint.

Parameters:
  • checkpoint (str) – Checkpoint (and model) to use in order to perform face detection. If None, will use the default one for the task.
  • short_side (int) – Resize images’ short side to short_side before sending over to detection model.
  • merge_method ('padding', 'crop') –

    How to merge images together into a batch when receiving a list. Merge is done after resizing. Options are:

    • padding, which will add padding around images, possibly increasing total image size. If mixing portrait and landscape images, might be inefficient.
    • crop, which will center-crop the images to the smallest size. If images are of very different sizes, might end up cropping too much.
  • device (torch.Device) – Device to load the model on.
  • lazy (bool) – If set, will defer model loading until first call.
__call__(images)

Performs face detection on images.

Derives the actual prediction to the model the Detection object was initialized with.

Parameters:images (list of numpy.ndarray or numpy.ndarray) – Images to perform face detection on.
Returns:List of dictionaries containing face data for a single image, or a list of these entries thereof.

Each entry is of the form:

{
    'bbox': [x_min, y_min, x_max, y_max],
    'landmarks': ...,  # Array of shape (5, 2).
    'score': ... # Confidence score.
}
Return type:list of list of dicts, or list dict

terran.face.recognition

terran.face.recognition.extract_features = <Recognition(ArcFace)>

Default entry point to face recognition.

This is an instantiation of the Recognition class, lazily-loaded in order to avoid reading the checkpoints on import. Refer to that class’ __call__ method for more information.

class terran.face.recognition.Recognition(checkpoint=None, device=device(type='cpu'), lazy=False)

Initializes and loads the model for checkpoint.

Parameters:
  • checkpoint (str) – Checkpoint (and model) to use in order to perform face recognition. If None, will use the default one for the task.
  • device (torch.Device) – Device to load the model on.
  • lazy (bool) – If set, will defer model loading until first call.
__call__(images, faces_per_image=None)

Performs face recognition on images.

Derives the actual prediction to the model the Recognition object was initialized with.

Parameters:
  • images (list of numpy.ndarray or numpy.ndarray) – Images to perform face recognition on.
  • faces_per_image (list of list of dicts.) – Each dict entry must contain bbox and landmarks keys, as returned by a Detection instance.
Returns:

One entry per image, with a numpy array of size (N_i, F), with F being the embedding size returned by the model.

Return type:

list of numpy.ndarray or numpy.ndarray

terran.pose

terran.pose.pose_estimation = <Estimation(OpenPose)>

Default entry point to pose estimation.

This is an instantiation of the Estimation class, lazily-loaded in order to avoid reading the checkpoints on import. Refer to that class’ __call__ method for more information.

class terran.pose.Estimation(checkpoint=None, short_side=184, merge_method='padding', device=device(type='cpu'), lazy=False)

Initializes and loads the model for checkpoint.

Parameters:
  • checkpoint (str or None) – Checkpoint (and model) to use in order to perform pose estimation. If None, will use the default one for the task.
  • short_side (int) – Resize images’ short side to short_side before sending over to the pose estimation model. Default is 184 to keep the model fast enough, though for better results 386 is an appropriate value.
  • merge_method ('padding', 'crop') –

    How to merge images together into a batch when receiving a list. Merge is done after resizing. Options are:

    • padding, which will add padding around images, possibly increasing total image size. If mixing portrait and landscape images, might be inefficient.
    • crop, which will center-crop the images to the smallest size. If images are of very different sizes, might end up cropping too much.
  • device (torch.Device) – Device to load the model on.
  • lazy (bool) – If set, will defer model loading until first call.
__call__(images)

Performs pose estimation on images.

Derives the actual prediction to the model the Estimation object was initialized with.

Parameters:images (list or tuple or np.ndarray) –
Returns:List of dictionaries containing pose data for a single image, or a list of these entries thereof.
Return type:list
class terran.pose.Keypoint

An enumeration.

L_EAR = 17
L_ELBOW = 6
L_EYE = 15
L_FOOT = 13
L_HAND = 7
L_HIP = 11
L_KNEE = 12
L_SHOULDER = 5
NECK = 1
NOSE = 0
R_EAR = 16
R_ELBOW = 3
R_EYE = 14
R_FOOT = 10
R_HAND = 4
R_HIP = 8
R_KNEE = 9
R_SHOULDER = 2