KeyPoints¶
inference_models.KeyPoints
dataclass
¶
Attributes¶
Functions¶
to_supervision
¶
Convert keypoints to Supervision KeyPoints format.
Converts the PyTorch tensor-based keypoints to Supervision's NumPy-based format for visualization and analysis. This enables use of Supervision's keypoint annotators and skeleton visualization tools.
Returns:
-
KeyPoints–sv.KeyPoints: Supervision KeyPoints object with:
-
xy: Keypoint coordinates as NumPy array (N, K, 2) where N is number of instances and K is number of keypoints per instance
-
class_id: Class IDs as NumPy array (N,)
-
confidence: Keypoint confidence scores as NumPy array (N, K)
-
Examples:
Convert and visualize keypoints:
>>> import cv2
>>> import supervision as sv
>>> from inference_models import AutoModel
>>>
>>> model = AutoModel.from_pretrained("yolov8n-pose-640")
>>> image = cv2.imread("image.jpg")
>>> results = model(image)
>>> key_points_list, detections_list = results
>>>
>>> # Convert to Supervision format
>>> key_points = key_points_list[0].to_supervision()
>>>
>>> # Use Supervision annotators
>>> vertex_annotator = sv.VertexAnnotator()
>>> edge_annotator = sv.EdgeAnnotator(edges=model.skeletons[0])
>>> annotated = edge_annotator.annotate(image.copy(), key_points)
>>> annotated = vertex_annotator.annotate(annotated, key_points)
Filter by class:
>>> key_points = key_points_list[0].to_supervision()
>>> person_mask = key_points.class_id == 0
>>> person_keypoints = key_points[person_mask]
See Also
- Supervision documentation: https://supervision.roboflow.com