Skip to content

Commit b741e05

Browse files
committed
refactor(keypoints): remove deprecated RF-DETR keypoint conversion logic
1 parent 5c2bd84 commit b741e05

2 files changed

Lines changed: 9 additions & 63 deletions

File tree

src/supervision/key_points/core.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/key_points/test_from_rfdetr.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_keypoints_from_rfdetr_missing_keypoints_raises_clear_error() -> None:
3636
class_id=np.array([0], dtype=int),
3737
)
3838

39-
with pytest.raises(ValueError, match="detections.data\\['keypoints'\\]"):
39+
with pytest.raises(ValueError, match=r"detections\.data\['keypoints'\]"):
4040
sv.KeyPoints.from_rfdetr(detections)
4141

4242

@@ -57,11 +57,17 @@ def test_keypoint_annotator_uses_vertex_and_edge_rendering() -> None:
5757
scene = np.zeros((32, 32, 3), dtype=np.uint8)
5858
detections = sv.Detections(
5959
xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
60-
data={"keypoints": np.array([[[10.0, 10.0, 0.9], [20.0, 20.0, 0.8]]], dtype=np.float32)},
60+
data={
61+
"keypoints": np.array(
62+
[[[10.0, 10.0, 0.9], [20.0, 20.0, 0.8]]], dtype=np.float32
63+
)
64+
},
6165
)
6266
key_points = sv.KeyPoints.from_rfdetr(detections)
6367

6468
scene = sv.VertexAnnotator().annotate(scene=scene, key_points=key_points)
65-
scene = sv.EdgeAnnotator(edges=[(1, 2)]).annotate(scene=scene, key_points=key_points)
69+
scene = sv.EdgeAnnotator(edges=[(1, 2)]).annotate(
70+
scene=scene, key_points=key_points
71+
)
6672

6773
assert np.any(scene != 0)

0 commit comments

Comments
 (0)