Skip to content

refactor: enrich KeyPoints with visibility mask, split confidence fields, and redesign uncertainty annotator#2286

Merged
Borda merged 17 commits into
developfrom
refactor/keypoints-visibility-confidence-split
Jun 11, 2026
Merged

refactor: enrich KeyPoints with visibility mask, split confidence fields, and redesign uncertainty annotator#2286
Borda merged 17 commits into
developfrom
refactor/keypoints-visibility-confidence-split

Conversation

@SkalskiP

@SkalskiP SkalskiP commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Split confidence into two fields: keypoint_confidence (per-keypoint, shape (N, M)) and detection_confidence (per-detection, shape (N,)). The old confidence attribute is preserved as a deprecated property that forwards to keypoint_confidence.
  • Add visible mask: A boolean array (N, M) that lets callers mark keypoints as occluded/invisible without dropping data. VertexAnnotator and EdgeAnnotator now skip keypoints (and edges) where visible is False.
  • Redesign uncertainty annotator: Replace VertexEllipseAnnotator with VertexUncertaintyAnnotator, which draws concentric filled ellipses at configurable sigma levels with opacity blending and a red-yellow-green color gradient.
  • Clean up validators: Remove deprecated shims (validate_keypoint_confidence, validate_keypoints_fields), rename validate_confidence to validate_detection_confidence, and add validate_visible. Improve error messages with dimension-specific diagnostics.

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.76812% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 80%. Comparing base (b8ebc14) to head (e6f8827).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2286   +/-   ##
=======================================
  Coverage       80%     80%           
=======================================
  Files           66      66           
  Lines         8787    8879   +92     
=======================================
+ Hits          7046    7126   +80     
- Misses        1741    1753   +12     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/supervision/key_points/core.py
SkalskiP and others added 4 commits June 4, 2026 12:16
* fix: resolve ruff line-length and mypy union syntax errors in keypoints module

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: add API design principles to CONTRIBUTING.md

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
… add API design principles to CONTRIBUTING.md
#2293)

* feat: support per-class skeleton edges in EdgeAnnotator via dict[int, edges] mapping

* fix(pre_commit): 🎨 auto format pre-commit hooks

* docs: simplify EdgeAnnotator edges parameter docstring

* test: add multi-skeleton EdgeAnnotator tests and demo script

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(pre_commit): 🎨 auto format pre-commit hooks

* refactor: add multi-skeleton support to EdgeAnnotator and VertexLabelAnnotator

* fix(pre_commit): 🎨 auto format pre-commit hooks

* chore: remove test script from tracking and gitignore it

* mypy passes

* Add unified docstring examples for all keypoint annotators with Python syntax highlighting and multi-skeleton demos

* Add label validation to VertexLabelAnnotator and parametrized tests for _resolve_labels

* fix(pre_commit): 🎨 auto format pre-commit hooks

* Add label validation and parametrized tests for VertexLabelAnnotator._resolve_labels

* Add color list length validation to _resolve_color_list and parametrized tests

* Cast NumPy class_id to int and raise ValueError on misconfigured edge dicts

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the KeyPoints container to better represent keypoint- and detection-level confidence while adding a per-keypoint visible mask, and then propagates those semantics through keypoint annotators (including a redesign of the uncertainty visualizer). It also refreshes validators, tests, and documentation to match the new API, and adds explicit API design principles to CONTRIBUTING.

Changes:

  • Refactors KeyPoints to add keypoint_confidence, detection_confidence, and optional visible, while keeping confidence as a deprecated forwarder.
  • Updates keypoint annotators (VertexAnnotator, EdgeAnnotator, VertexLabelAnnotator) to honor visible, adds multi-skeleton support (per-class edges/labels), and replaces VertexEllipseAnnotator with VertexUncertaintyAnnotator.
  • Cleans up validators and adjusts tests/docs to cover and demonstrate the new behavior.

Quality (n/5):

  • Code quality: 4/5
  • Testing: 4/5
  • Docs: 3/5

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Bumps dev version metadata and relaxes pydeprecate upper bound.
tests/key_points/test_from_rfdetr.py Removes RF-DETR conversion tests (conversion path removed).
tests/key_points/test_core.py Adds coverage for detection_confidence filtering and visible propagation; updates confidence naming.
tests/key_points/test_annotators.py Adds visibility behavior tests; updates uncertainty annotator tests to new class.
tests/helpers.py Updates KeyPoints factory helper to support detection_confidence and visible.
src/supervision/validators/__init__.py Splits detection vs keypoint confidence validation and adds validate_visible.
src/supervision/key_points/core.py Implements new KeyPoints fields, deprecates .confidence, updates slicing/filtering behavior.
src/supervision/key_points/annotators.py Honors visible, adds per-class skeleton/labels support, and introduces VertexUncertaintyAnnotator.
src/supervision/__init__.py Exports VertexUncertaintyAnnotator instead of VertexEllipseAnnotator.
docs/keypoint/annotators.md Renames the uncertainty annotator section and API references.
.gitignore Ignores a local test script.
.github/CONTRIBUTING.md Adds explicit API design principles for integrations/annotators/containers.

Comment thread src/supervision/key_points/core.py Outdated
Comment on lines +912 to +916
detection_confidence_selected = (
self.detection_confidence[i]
if self.detection_confidence is not None
else None
)
Comment thread docs/keypoint/annotators.md Outdated
@SkalskiP SkalskiP marked this pull request as ready for review June 5, 2026 00:06
Comment thread docs/keypoint/annotators.md Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread src/supervision/key_points/core.py
Comment thread src/supervision/key_points/core.py
Comment thread src/supervision/key_points/core.py Outdated
Comment thread src/supervision/key_points/core.py Outdated
Comment thread src/supervision/key_points/core.py
Comment thread src/supervision/key_points/core.py
Comment thread src/supervision/validators/__init__.py
Comment thread src/supervision/validators/__init__.py Outdated
Comment thread src/supervision/validators/__init__.py Outdated
…split

Co-authored-by: Cursor <cursoragent@cursor.com>
@SkalskiP SkalskiP force-pushed the refactor/keypoints-visibility-confidence-split branch from d095a78 to b8aa64f Compare June 10, 2026 17:58
SkalskiP added 2 commits June 11, 2026 12:21
…r` to `VertexEllipseAnnotator`, simplifying its parameters (`sigma`, `color`, removing `covariance_data_key`), unifying `opacity` docstrings across all annotators, removing the `opacity` validation guard, and converting all keypoint annotator examples into executable doctests.
@SkalskiP SkalskiP force-pushed the refactor/keypoints-visibility-confidence-split branch from 4c32bc6 to ce4c5a6 Compare June 11, 2026 10:58
SkalskiP added 3 commits June 11, 2026 13:12
…into a ``!!!` warning admonition, renamed `max_axis_length` to `max_axis`, and fixed the `VertexEllipseAnnotator` docs example by removing the manual covariance block and invalid `thickness` parameter.
max_axis_length: float | None = None,
line_style: Literal["solid", "dashed"] = "solid",
dash_length: int = 16,
sigma: float | Sequence[float] = (1.0, 2.0, 3.0),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably go with just one as default but that is also fine

line_style: Literal["solid", "dashed"] = "solid",
dash_length: int = 16,
sigma: float | Sequence[float] = (1.0, 2.0, 3.0),
color: Color | Sequence[Color] = (Color.GREEN, Color.YELLOW, Color.RED),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be good to have also just palet as input and colours will be sapled based on nb sigmas

color: The color for each sigma level. Accepts a single
``Color`` or a sequence of colors (one per sigma level).
Defaults to ``(Color.GREEN, Color.YELLOW, Color.RED)``.
opacity: Opacity of the overlay mask. Must be between ``0`` and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the colors, can we also have optical for each sigma?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

docs/keypoint/annotators.md:96

  • The VertexEllipseAnnotator example no longer sets key_points.data['covariance'], but VertexEllipseAnnotator.annotate() raises a ValueError when covariance is missing. As written, this snippet won’t run.
    ```python
    import supervision as sv

    image = ...
    key_points = sv.KeyPoints(...)

    ellipse_annotator = sv.VertexEllipseAnnotator(
        color=sv.Color.GREEN,
        sigma=2.0,
    )
    annotated_frame = ellipse_annotator.annotate(
        scene=image.copy(),
        key_points=key_points,
    )
    ```

Comment thread src/supervision/validators/__init__.py
Comment thread src/supervision/key_points/annotators.py
Comment thread src/supervision/key_points/annotators.py
Comment thread src/supervision/key_points/core.py
Comment thread src/supervision/key_points/core.py Outdated
Comment thread src/supervision/key_points/annotators.py Outdated
Comment thread tests/helpers.py
Comment on lines +456 to +459
color: The color to use for each keypoint label. If a list is
provided, the colors will be used in order for each keypoint.
text_color: The color to use for the labels. If a list is
provided, the colors will be used in order for each keypoint.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like your IDE does not follow max docsting length

Comment thread src/supervision/validators/__init__.py Outdated
Borda
Borda previously approved these changes Jun 11, 2026
SkalskiP and others added 3 commits June 11, 2026 17:38
[resolve group] PR #2286 — items 25 26

Add _normalize_row_index() to handle np.integer scalars, 0-d arrays,
and bool arrays when indexing 1-D per-object fields (class_id, data).
The np.ix_ path for 2D fancy indexing now uses row_i for class_id
and data, preventing 2-D class_id output and data alignment errors.

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
QA gate caught two issues in the _normalize_row_index fix:
- detection_confidence was still indexed with un-normalized `i` instead
  of `row_i`, causing ValueError for np.integer and 0-d ndarray inputs
- bool dtype check must precede ndim==0 check so 0-d bool arrays use
  flatnonzero rather than reshape(1)

Also annotate `composite` in annotators.py to satisfy mypy var-annotated
and add parametrized tests for np.integer/0-d ndarray index paths that
exercise detection_confidence.

[resolve group] PR #2286 — QA gate pass 1

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
@Borda Borda merged commit caf0605 into develop Jun 11, 2026
29 checks passed
@Borda Borda deleted the refactor/keypoints-visibility-confidence-split branch June 11, 2026 16:34
@Borda Borda mentioned this pull request Jun 11, 2026
Borda added a commit that referenced this pull request Jun 16, 2026
VertexEllipseAreaAnnotator, VertexEllipseOutlineAnnotator, and
VertexEllipseHaloAnnotator appeared in both Added (#2277, #2286) and
Changed (#2325). Consolidate into one Added entry listing all three PRs.

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants