torchvision.utils.draw_keypoints(image: Tensor, keypoints: Tensor, connectivity: Optional[List[Tuple[int, int]]] = None, colors: Optional[Union[str, Tuple[int, int, int]]] = None, radius: int = 2, width: int = 3, visibility: Optional[Tensor] = None) Tensor[source]

Draws Keypoints on given RGB image. The image values should be uint8 in [0, 255] or float in [0, 1]. Keypoints can be drawn for multiple instances at a time.

This method allows that keypoints and their connectivity are drawn based on the visibility of this keypoint.

  • image (Tensor) – Tensor of shape (3, H, W) and dtype uint8 or float.

  • keypoints (Tensor) – Tensor of shape (num_instances, K, 2) the K keypoint locations for each of the N instances, in the format [x, y].

  • connectivity (List[Tuple[int, int]]]) – A List of tuple where each tuple contains a pair of keypoints to be connected. If at least one of the two connected keypoints has a visibility of False, this specific connection is not drawn. Exclusions due to invisibility are computed per-instance.

  • colors (str, Tuple) – The color can be represented as PIL strings e.g. “red” or “#FF00FF”, or as RGB tuples e.g. (240, 10, 157).

  • radius (int) – Integer denoting radius of keypoint.

  • width (int) – Integer denoting width of line connecting keypoints.

  • visibility (Tensor) – Tensor of shape (num_instances, K) specifying the visibility of the K keypoints for each of the N instances. True means that the respective keypoint is visible and should be drawn. False means invisible, so neither the point nor possible connections containing it are drawn. The input tensor will be cast to bool. Default None means that all the keypoints are visible. For more details, see Drawing Keypoints with Visibility.


Image Tensor with keypoints drawn.

Return type:

img (Tensor[C, H, W])

Examples using draw_keypoints:

Visualization utilities

Visualization utilities


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources