@@ -788,66 +788,6 @@ def from_transformers(cls, transformers_results: Any) -> KeyPoints:
788788 else :
789789 return cls .empty ()
790790
791- @classmethod
792- def from_rfdetr (cls , detections : Detections ) -> KeyPoints :
793- """
794- Create a `sv.KeyPoints` object from RF-DETR keypoint predictions.
795-
796- RF-DETR stores keypoints under `sv.Detections.data["keypoints"]` with shape
797- `(N, K, 3)`, where each keypoint is `(x, y, confidence)`.
798-
799- Args:
800- detections: RF-DETR detections containing keypoints in
801- `detections.data["keypoints"]`.
802-
803- Returns:
804- A `sv.KeyPoints` object containing xy coordinates, confidence, and class IDs.
805-
806- Raises:
807- ValueError: If keypoints are missing or have invalid shape.
808-
809- Examples:
810- ```pycon
811- >>> import numpy as np
812- >>> import supervision as sv
813- >>> detections = sv.Detections(
814- ... xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
815- ... class_id=np.array([0], dtype=int),
816- ... data={"keypoints": np.array([[[1, 2, 0.9], [3, 4, 0.8]]], dtype=np.float32)},
817- ... )
818- >>> key_points = sv.KeyPoints.from_rfdetr(detections)
819- >>> key_points.xy.shape
820- (1, 2, 2)
821- >>> key_points.confidence.shape
822- (1, 2)
823-
824- ```
825- """
826- if "keypoints" not in detections .data :
827- raise ValueError (
828- "RF-DETR keypoints are missing. Expected detections.data['keypoints'] with shape (N, K, 3)."
829- )
830-
831- keypoints = np .asarray (detections .data ["keypoints" ], dtype = np .float32 )
832- if keypoints .ndim != 3 or keypoints .shape [- 1 ] != 3 :
833- raise ValueError (
834- "RF-DETR keypoints must have shape (N, K, 3) with (x, y, confidence) values."
835- )
836-
837- xy = keypoints [..., :2 ].astype (np .float32 , copy = False )
838- confidence = keypoints [..., 2 ].astype (np .float32 , copy = False )
839- class_id = (
840- detections .class_id .astype (int , copy = False )
841- if detections .class_id is not None
842- else None
843- )
844-
845- return cls (
846- xy = xy ,
847- confidence = confidence ,
848- class_id = class_id ,
849- )
850-
851791 def _get_by_2d_bool_mask (self , mask : npt .NDArray [np .bool_ ]) -> KeyPoints :
852792 """Filter keypoints using a 2D boolean mask of shape `(n, m)`.
853793
0 commit comments