Skip to content

fix(key_points): keep the detection score in pose connectors - #2633

Merged
Borda merged 6 commits into
roboflow:developfrom
MohammadHijjawi97:fix/keypoints-connector-detection-confidence
Sep 29, 2026
Merged

Borda merged 6 commits into
roboflow:developfrom
MohammadHijjawi97:fix/keypoints-connector-detection-confidence

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

Description

sv.KeyPoints.from_ultralytics, sv.KeyPoints.from_inference and sv.KeyPoints.from_detectron2 drop each object's detection score and only keep the per-keypoint scores, so detection_confidence is always None on their output. Two things follow:

  • KeyPoints.with_nms() cannot be used on connector output at all:

    key_points = sv.KeyPoints.from_ultralytics(model("image.jpg")[0])
    key_points.with_nms()
    # ValueError: KeyPoints detection_confidence must be given for NMS to be executed.
  • KeyPoints.as_detections() falls back to the mean keypoint confidence, so the confidence it reports differs from the score the model returned and from sv.Detections.from_ultralytics / sv.Detections.from_inference on the same result. For Inference it is pulled down further: key points below the request's keypoint_confidence are omitted and loaded as zero-confidence slots (fix(key_points): place Inference key points by their skeleton index #2575), so a person scored 0.9 with two of three key points returned at 0.6 and 0.4 became a detection with confidence 0.33.

This PR reads the score each framework already provides (boxes.conf, each prediction's confidence, instances.scores) into detection_confidence.

Motivation and Context

detection_confidence was added in #2286, but none of the connectors populate it, so everything built on it (with_nms, as_detections) only works on hand-built KeyPoints.

Changes Made

  • from_ultralytics: detection_confidence from boxes.conf.
  • from_inference: detection_confidence from each prediction's confidence. A hand-built result dict without a prediction confidence still loads, with detection_confidence=None.
  • from_detectron2: detection_confidence from instances.scores.
  • Updated the Returns docstrings of those connectors.
  • Out of scope: from_yolo_nas, from_transformers and from_mediapipe, and the mean-keypoint fallback in as_detections itself.

Testing

New tests in tests/key_points/test_core.py (Ultralytics, Inference, Detectron2) fail on develop (3 failed: assert None is not None) and pass with this change. pytest tests/key_points: 237 passed; doctests for key_points/core.py pass; ruff check/ruff format, mypy and docformatter --check clean on the changed files.

  • Added/updated tests, and the full suite passes locally (added tests; ran tests/key_points and the doctests, not the full suite)
  • Updated docs (docstrings / mkdocs entry) for new or changed public API
  • Added a changelog entry in docs/changelog.md under Unreleased (skip for lint/type/format-only or pure doc changes)

Additional Notes

as_detections() on connector output now returns the model's detection score instead of the keypoint mean, which is a visible (intended) behavior change noted in the changelog.

`KeyPoints.from_ultralytics`, `from_inference` and `from_detectron2`
dropped each object's detection score and only kept the per-keypoint
scores, leaving `detection_confidence` as `None`. `with_nms` then raised
on their output, and `as_detections` fell back to the mean key point
confidence, which differs from the score the model reported and from
`Detections.from_ultralytics` / `Detections.from_inference`.

Read the score from `boxes.conf`, each prediction's `confidence`, and
`instances.scores` respectively.
@MohammadHijjawi97
MohammadHijjawi97 force-pushed the fix/keypoints-connector-detection-confidence branch from 54fd110 to ba1bd2c Compare September 28, 2026 12:59
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92%. Comparing base (b82d32c) to head (f27e9a8).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2633   +/-   ##
=======================================
  Coverage       92%     92%           
=======================================
  Files           78      78           
  Lines        11703   11707    +4     
=======================================
+ Hits         10721   10728    +7     
+ Misses         982     979    -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda
Borda requested a balanced review from Copilot September 28, 2026 18:35
@Borda Borda added the bug Something isn't working label Sep 28, 2026

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.

Copilot review overview

🟢 Approval recommended

The focused implementation is consistent across connectors and adequately covered by regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Preserves model-level confidence scores across pose connectors, enabling accurate conversion and NMS.

Changes:

  • Populates detection_confidence for Inference, Ultralytics, and Detectron2.
  • Adds focused regression tests.
  • Documents the behavior change in the changelog.

Assessment: Code quality 5/5 · Testing 4/5 · Documentation 5/5

File Description
src/​supervision/​key_points/​core.py Preserves detection scores in pose connectors.
tests/​key_points/​test_core.py Tests confidence propagation and conversion.
docs/​changelog.md Records the user-visible fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Borda and others added 3 commits September 29, 2026 08:05
Changes:
- Merge the refreshed develop target, including its 22 changed files, into the PR branch.
- Preserve the PR keypoint-confidence changelog entry alongside all three target entries.

Impact:
- Brings the PR branch up to the fetched develop tip while retaining both sides' changelog updates.
- Leaves the reviewed confidence finding open for the upcoming scope decision.

Verification:
- git diff --cached --check passed.
- git diff --name-only --diff-filter=U returned no paths.

Residual limits:
- CR-2633-1 and review confidence-gap disposition remain pending.

---

Co-authored-by: Codex <codex@openai.com>
Changes:
- Define `from_inference` object-score availability as all-or-none: any absent or null prediction score leaves `detection_confidence=None` for the batch.
- Document `as_detections()` keypoint-mean fallback for mixed batches and add regressions for absent and null scores.

Impact:
- Consumers receive a consistent object-score vector or `None`; mixed batches use keypoint means for every prediction.
- The policy intentionally drops present model scores when another prediction has no score.

Verification:
- Focused regressions: 2 passed.
- Full suite: 4,539 passed, 1 skipped; lint, format, and configured mypy gates passed.
- Staged diff check: passed.

Residual limits:
- PR roboflow#2633 still has unresolved blind-ordering and fresh-coverage obligations; pytest-cov collected no coverage data.

---

Co-authored-by: Codex <codex@openai.com>
@Borda
Borda merged commit 505cd64 into roboflow:develop Sep 29, 2026
36 checks passed
Borda added a commit that referenced this pull request Sep 29, 2026
`KeyPoints.from_ultralytics`, `from_inference` and `from_detectron2`
dropped each object's detection score and only kept the per-keypoint
scores, leaving `detection_confidence` as `None`. `with_nms` then raised
on their output, and `as_detections` fell back to the mean key point
confidence, which differs from the score the model reported and from
`Detections.from_ultralytics` / `Detections.from_inference`.

Read the score from `boxes.conf`, each prediction's `confidence`, and
`instances.scores` respectively.

---------

Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
Borda added a commit that referenced this pull request Nov 9, 2026
…etections.keypoints field (#2895)

The API design principles still told integrations to use `Detections.keypoints`,
a field added in #2290 and reverted in #2291; `sv.Detections` has no such field.
Point integrations to `sv.KeyPoints` instead, with the instance score in
`KeyPoints.detection_confidence` when the source provides one. The Ultralytics
and Detectron2 connectors, and Inference when every prediction carries a
confidence, already keep the instance score there (#2633); `as_detections()`
derives boxes when a `Detections` object is needed.

Prepared with AI assistance (Claude Code); reviewed by the author.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Borda added a commit that referenced this pull request Nov 10, 2026
…etections.keypoints field (#2895)

The API design principles still told integrations to use `Detections.keypoints`,
a field added in #2290 and reverted in #2291; `sv.Detections` has no such field.
Point integrations to `sv.KeyPoints` instead, with the instance score in
`KeyPoints.detection_confidence` when the source provides one. The Ultralytics
and Detectron2 connectors, and Inference when every prediction carries a
confidence, already keep the instance score there (#2633); `as_detections()`
derives boxes when a `Detections` object is needed.

Prepared with AI assistance (Claude Code); reviewed by the author.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants