deeplabcut.pose_estimation_pytorch.data.utils
Functions:
| Name | Description |
|---|---|
apply_transform |
Applies a transformation to the provided image and keypoints. |
bbox_from_keypoints |
Computes bounding boxes from keypoints. |
calc_area_from_keypoints |
Calculate the area from keypoints. |
calc_bbox_overlap |
Calculate the overlap between two bounding boxes. |
map_id_to_annotations |
Maps image IDs to their corresponding annotation indices. |
map_image_path_to_id |
Binds the image paths to their respective IDs. |
merge_list_of_dicts |
Flattens a list of dictionaries into a dictionary with the lists concatenated. |
out_of_bounds_keypoints |
Computes which visible keypoints are outside an image. |
pad_to_length |
Pads the first dimension of an array with a given value. |
read_image_shape_fast |
Blazing fast and does not load the image into memory. |
safe_stack |
Stacks a list of arrays if there are any, otherwise returns an array of zeros of |
apply_transform
apply_transform(
transform: BaseCompose, image: ndarray, keypoints: ndarray, bboxes: ndarray, class_labels: list[str]
) -> dict[str, np.ndarray]
Applies a transformation to the provided image and keypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
BaseCompose
|
The transformation to apply. |
required |
|
ndarray
|
The input image to which the transformation will be applied. |
required |
|
ndarray
|
List of keypoints to be transformed along with the image. Each keypoint is expected to be a tuple or list with at least three values, where the third value indicates the class label index. |
required |
|
ndarray
|
List of bounding boxes to be transformed along with the image. |
required |
|
list[str]
|
List of class labels corresponding to the keypoints. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
transformed |
dict[str, ndarray]
|
A dictionary containing the transformed image and keypoints. |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
bbox_from_keypoints
Computes bounding boxes from keypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
(..., num_keypoints, xy) the keypoints from which to get bboxes |
required |
|
int
|
the height of the image |
required |
|
int
|
the width of the image |
required |
|
int
|
the bounding box margin |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
the bounding boxes for the keypoints, of shape (..., 4) in the xywh format |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
calc_area_from_keypoints
Calculate the area from keypoints.
in the pups benchmark, there are 5 keypoints perfectly aligned so
the area is 0. How do we deal with that? Makes more sense to compute the area from the bboxes (they are padded) Below is a temporary fix, which sets a min height and width to 5 Suggestion: compute min height/width using labeled data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
array of keypoints |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: array containing the computed areas based on the keypoints |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
calc_bbox_overlap
Calculate the overlap between two bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
the first bounding box in the format (x, y, w, h) |
required |
|
ndarray
|
the second bounding box in the format (x, y, w, h) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The overlap between |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
map_id_to_annotations
Maps image IDs to their corresponding annotation indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[dict]
|
List of dictionaries containing annotation data. Each dictionary should have 'image_id' key. |
required |
Returns:
| Type | Description |
|---|---|
dict[int, list[int]]
|
A dictionary mapping image IDs to lists of corresponding annotation indices. |
Examples:
annotations = [{"image_id": 1, ...}, ...]
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
map_image_path_to_id
Binds the image paths to their respective IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[dict]
|
List of dictionaries containing image data in COCO-like format. Each dictionary should have 'file_name' and 'id' keys. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
A dictionary mapping image paths to their respective IDs. |
Examples:
images = [{"file_name": "path/to/image1.jpg", "id": 1}, ...]
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
merge_list_of_dicts
Flattens a list of dictionaries into a dictionary with the lists concatenated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[dict]
|
the dictionaries to merge |
required |
|
list[str]
|
the keys to include in the new dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
the merged dictionary |
Examples:
input: list_of_dicts: [{"id": 0, "num": 1}, {"id": 1, "num": 10}] keys_to_include: ["id", "num"] output:
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
out_of_bounds_keypoints
Computes which visible keypoints are outside an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
A (N, 3) shaped array where N is the number of keypoints and each keypoint is represented as (x, y, visibility). |
required |
|
tuple
|
A tuple representing the shape or bounds as (height, width). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A boolean array of shape (N,) where each element corresponds to whether the respective keypoint is visible (visibility > 0) and outside the image bounds. This mask can be used to set the visibility bit to 0 for keypoints that were kicked off an image due to augmentation. |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
pad_to_length
Pads the first dimension of an array with a given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
array
|
the array to pad, of shape (l, ...), where l <= length |
required |
|
int
|
the desired length of the tensor |
required |
|
float
|
the value to pad with |
required |
Returns:
| Type | Description |
|---|---|
array
|
the padded array of shape (length, ...) |
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
read_image_shape_fast
cached
Blazing fast and does not load the image into memory.
Source code in deeplabcut/pose_estimation_pytorch/data/utils.py
safe_stack
Stacks a list of arrays if there are any, otherwise returns an array of zeros of a desired shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[ndarray]
|
the list of arrays to stack |
required |
|
tuple[int, ...]
|
the shape of the array to return if the list is empty |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
the stacked data or empty array |