pipert.utils.structures.keypoints¶
Module Contents¶
Functions¶
|
Encode keypoint locations into a target heatmap for use in SoftmaxWithLoss across space. |
|
Args: |
-
class
pipert.utils.structures.keypoints.Keypoints(keypoints: Union[torch.Tensor, np.ndarray, List[List[float]]])[source]¶ Stores keypoint annotation data. GT Instances have a gt_keypoints property containing the x,y location and visibility flag of each keypoint. This tensor has shape (N, K, 3) where N is the number of instances and K is the number of keypoints per instance.
The visibility flag follows the COCO format and must be one of three integers: * v=0: not labeled (in which case x=y=0) * v=1: labeled but not visible * v=2: labeled and visible
-
to(self, *args: Any, **kwargs: Any) → pipert.utils.structures.keypoints.Keypoints[source]¶
-
to_heatmap(self, boxes: torch.Tensor, heatmap_size: int) → torch.Tensor[source]¶ - Arguments:
boxes: Nx4 tensor, the boxes to draw the keypoints to
- Returns:
- heatmaps:
A tensor of shape (N, K) containing an integer spatial label in the range [0, heatmap_size**2 - 1] for each keypoint in the input.
- valid:
A tensor of shape (N, K) containing whether each keypoint is in the roi or not.
-
__getitem__(self, item: Union[int, slice, torch.BoolTensor]) → pipert.utils.structures.keypoints.Keypoints[source]¶ Create a new Keypoints by indexing on this Keypoints.
The following usage are allowed:
new_kpts = kpts[3]: return a Keypoints which contains only one instance.
new_kpts = kpts[2:10]: return a slice of key points.
new_kpts = kpts[vector], where vector is a torch.ByteTensor with length = len(kpts). Nonzero elements in the vector will be selected.
Note that the returned Keypoints might share storage with this Keypoints, subject to Pytorch’s indexing semantics.
-
-
pipert.utils.structures.keypoints._keypoints_to_heatmap(keypoints: torch.Tensor, rois: torch.Tensor, heatmap_size: int) → Tuple[torch.Tensor, torch.Tensor][source]¶ Encode keypoint locations into a target heatmap for use in SoftmaxWithLoss across space.
Maps keypoints from the half-open interval [x1, x2) on continuous image coordinates to the closed interval [0, heatmap_size - 1] on discrete image coordinates. We use the continuous-discrete conversion from Heckbert 1990 (“What is the coordinate of a pixel?”): d = floor(c) and c = d + 0.5, where d is a discrete coordinate and c is a continuous coordinate.
- Arguments:
keypoints: tensor of keypoint locations in of shape (N, K, 3). rois: Nx4 tensor of rois in xyxy format heatmap_size: integer side length of square heatmap.
- Returns:
- heatmaps: A tensor of shape (N, K) containing an integer spatial label
in the range [0, heatmap_size**2 - 1] for each keypoint in the input.
- valid: A tensor of shape (N, K) containing whether each keypoint is in
the roi or not.
-
pipert.utils.structures.keypoints.heatmaps_to_keypoints(maps: torch.Tensor, rois: torch.Tensor) → torch.Tensor[source]¶ - Args:
maps (Tensor): (#ROIs, #keypoints, POOL_H, POOL_W) rois (Tensor): (#ROIs, 4)
Extract predicted keypoint locations from heatmaps. Output has shape (#rois, #keypoints, 4) with the last dimension corresponding to (x, y, logit, prob) for each keypoint.
Converts a discrete image coordinate in an NxN image to a continuous keypoint coordinate. We maintain consistency with keypoints_to_heatmap by using the conversion from Heckbert 1990: c = d + 0.5, where d is a discrete coordinate and c is a continuous coordinate.