feat(keypoints): add keypoint conversion bridge#2277
Conversation
Co-authored-by: Codex <codex@openai.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2277 +/- ##
========================================
Coverage 78% 79%
========================================
Files 66 66
Lines 8416 8567 +151
========================================
+ Hits 6594 6726 +132
- Misses 1822 1841 +19 🚀 New features to boost your workflow:
|
Co-authored-by: Codex <codex@openai.com>
…ilities - Simplify `ValueError` matching in `KeyPoints.from_rfdetr` tests. - Refactor utilities to ensure typed consistency in `merge_data`, `is_data_equal`, and metadata handling. - Add `_optional_array_equal` helper for comparing arrays with `None` values. - Enhance type annotations and casting for clarity and correctness in keypoint operations. - Improve masking logic consistency for conversions and indexing.
…t arrays - Skip rendering ellipses for non-finite confidence values in `VertexEllipseAnnotator`. - Ensure `KeyPoints.from_rfdetr` handles empty keypoint arrays by returning an empty instance. - Add tests for both scenarios for better coverage and validation.
There was a problem hiding this comment.
Pull request overview
Adds an RF-DETR → KeyPoints bridge plus a covariance-ellipse annotator for visualizing per-keypoint uncertainty. KeyPoints.from_rfdetr reads keypoints (and optionally keypoint_precision_cholesky + source_shape) from a Detections instance, converting precision parameters to pixel-space covariance stored under data["covariance"]. The new VertexEllipseAnnotator consumes this covariance to draw solid or dashed ellipses around vertices. Supporting changes loosen is_data_equal / merge_data typing to allow list[Any] data values and switch keypoint equality to a None-safe array comparison.
Changes:
- Add
KeyPoints.from_rfdetrplus internal helpers for source-shape validation and Cholesky-precision-to-pixel-covariance conversion, and make__eq__None-safe. - Add
VertexEllipseAnnotator(solid/dashed ellipses, confidence filtering, configurable covariance data key) and export it fromsupervision. - Relax
is_data_equal/merge_datatype signatures and adjust typing casts inKeyPoints; add tests for the new converter and annotator.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/supervision/key_points/core.py | Adds RF-DETR converter, covariance helpers, _optional_array_equal, and typing-related casts. |
| src/supervision/key_points/annotators.py | Implements VertexEllipseAnnotator with solid/dashed rendering and covariance validation. |
| src/supervision/detection/utils/internal.py | Broadens is_data_equal / merge_data typing to support list[Any] data values. |
| src/supervision/init.py | Exports the new VertexEllipseAnnotator from the top-level package. |
| tests/key_points/test_core.py | Adds RF-DETR fixture and tests for keypoints, covariance, missing-data, and empty cases. |
| tests/key_points/test_from_rfdetr.py | New test module covering the from_rfdetr conversion and downstream annotators. |
| tests/key_points/test_annotators.py | Adds TestVertexEllipseAnnotator covering rendering, validation, and edge cases. |
- Add VertexEllipseAnnotator tab with usage code example - Add mkdocstrings reference block for API docs generation --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Add pycon-style doctest showing basic usage and optional covariance path --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Add Note section to from_rfdetr docstring clarifying (height, width) order - Update _rfdetr_source_shape ValueError message to state (height, width) --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Check precision_cholesky.shape[:2] == keypoints.shape[:2] before covariance computation; raises ValueError with clear message on mismatch --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Count non_finite, singular, and overflow failures per conversion call - Emit aggregated logger.warning when any keypoints are skipped --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Cast np.asarray result in _get_covariances to NDArray[np.float32] - Cast reshape+astype result in VertexLabelAnnotator to NDArray[np.int_] --- Co-authored-by: Claude Code <noreply@anthropic.com>
…seAnnotator - Verify low-confidence keypoint (0.3 < threshold 0.5) is not drawn - Verify high-confidence keypoint (0.7 > threshold 0.5) is drawn --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Test max_axis_length clamps large covariance eigenvalues - Parametrized test for all constructor ValueError guards (sigma, thickness, max_axis_length, dash_length) --- Co-authored-by: Claude Code <noreply@anthropic.com>
…nnotator - Note that near-singular precision can produce frame-spanning ellipses - Recommend setting a pixel bound for production use --- Co-authored-by: Claude Code <noreply@anthropic.com>
…e docstring --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Note that confidence is stored as-is (expected probability 0-1) - Warn about logit-scale output requiring adjusted threshold --- Co-authored-by: Claude Code <noreply@anthropic.com>
… docstring - from_rfdetr accepts sv.Detections (not native RF-DETR output); explain why --- Co-authored-by: Claude Code <noreply@anthropic.com>
- Replace `|` with `Union` for backward compatibility - Update `Optional` usage for clarity in `from_rfdetr` method
- Add explicit check and conversion for None class_id in RF-DETR detections
No description provided.