Shortcuts

sanitize_keypoints

torchvision.transforms.v2.functional.sanitize_keypoints(key_points: Tensor, canvas_size: Optional[tuple[int, int]] = None) tuple[torch.Tensor, torch.Tensor][source]

Remove keypoints outside of the image area and their corresponding labels (if any).

This transform removes keypoints or groups of keypoints and their associated labels that have coordinates outside of their corresponding image. If you would instead like to clamp such keypoints to the image edges, use ClampKeyPoints.

It is recommended to call it at the end of a pipeline, before passing the input to the models.

Keypoints can be passed as a set of individual keypoints or as a set of objects (e.g., polygons or polygonal chains) consisting of a fixed number of keypoints of shape [..., 2]. When groups of keypoints are passed (i.e., an at least 3-dimensional tensor), this transform will only remove entire groups, not individual keypoints within a group.

Parameters:
  • key_points (Tensor or KeyPoints) – The keypoints to be sanitized.

  • canvas_size (tuple of python:int, optional) – The canvas_size of the keypoints (size of the corresponding image/video). Must be left to none if key_points is a KeyPoints object.

Returns:

The subset of valid keypoints, and the corresponding indexing mask. The mask can then be used to subset other tensors (e.g. labels) that are associated with the keypoints.

Return type:

out (tuple of Tensors)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources