Skip to content

fix(key_points): keep YOLO-NAS pose scores as detection confidence - #2909

Merged
Borda merged 5 commits into
roboflow:developfrom
sohailshk:fix/yolo-nas-pose-confidence
Nov 9, 2026
Merged

Borda merged 5 commits into
roboflow:developfrom
sohailshk:fix/yolo-nas-pose-confidence

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

Description

sv.KeyPoints.from_yolo_nas ignores prediction.scores, so detection_confidence is always None on YOLO-NAS pose output. As a result, KeyPoints.with_nms() cannot be used on it, and KeyPoints.as_detections() reports the mean key point confidence instead of the score the model returned.

Minimal repro (the result has the same attributes as super-gradients' PoseEstimationPrediction, which always carries one score per pose):

from types import SimpleNamespace

import numpy as np
import supervision as sv

prediction = SimpleNamespace(
    poses=np.array(
        [[[10, 10, 0.9], [20, 20, 0.8]], [[11, 11, 0.9], [21, 21, 0.8]]], np.float32
    ),
    scores=np.array([0.95, 0.6], np.float32),
)
key_points = sv.KeyPoints.from_yolo_nas(
    SimpleNamespace(prediction=prediction, class_names=None)
)
print(key_points.detection_confidence)        # None
print(key_points.as_detections().confidence)  # [0.85 0.85]
key_points.with_nms(class_agnostic=True)
# ValueError: KeyPoints detection_confidence must be given for NMS to be executed.

With this change: [0.95 0.6], [0.95 0.6], and with_nms keeps 1 of the 2 overlapping poses.

Motivation and Context

#2633 made from_ultralytics, from_inference and from_detectron2 keep the detection score and listed from_yolo_nas as out of scope. This does the same for YOLO-NAS. sv.Detections.from_yolo_nas already keeps its confidence.

Closes #2908

Changes Made

  • KeyPoints.from_yolo_nas: detection_confidence comes from prediction.scores; updated its Returns docstring.
  • tests/helpers.py: _FakeYoloNasKeyPoint takes scores, like the real prediction.
  • test_from_yolo_nas_input now expects the pose score as detection_confidence.
  • Changelog entry under Unreleased.
  • Out of scope: from_transformers and from_mediapipe; ViTPose and MediaPipe results carry no per-pose score.

Testing

  • pytest tests/key_points/test_core.py -k from_yolo_nas on develop with the updated test: 1 failed, 1 passed (assert KeyPoints(...) == KeyPoints(...), detection_confidence is None). With this change: 2 passed.

  • pytest (full suite): 6504 passed, 247 skipped.

  • pre-commit run --files <changed files>: ruff, ruff-format, docformatter, mypy, codespell and the doctest fence check pass.

  • Added/updated tests, and the full suite passes locally

  • 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

prediction.scores is read directly, because it is a required field of PoseEstimationPrediction (unlike labels, which the connector already treats as optional).

`KeyPoints.from_yolo_nas` ignored `prediction.scores`, so
`detection_confidence` was `None` on YOLO-NAS output. `with_nms` then
raised, and `as_detections` reported the mean key point confidence
instead of the model's score.

Read the per-pose score into `detection_confidence`, as the Ultralytics,
Inference and Detectron2 connectors already do.
@sohailshk
sohailshk requested a review from SkalskiP as a code owner November 8, 2026 16:23
@Borda
Borda requested a balanced review from Copilot November 8, 2026 21:07
@Borda Borda added the bug Something isn't working label Nov 8, 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.

🟢 Approval recommended

No active review issues were identified for the change preserving YOLO-NAS per-pose confidence.

No open issues 🎉

What changed in this PR

Extends the pose-score preservation introduced in #2633 to YOLO-NAS, addressing #2908. Keeping model scores enables KeyPoints.with_nms() and makes as_detections() return per-pose confidence instead of mean keypoint confidence.

Changes:

  • Populate detection_confidence from prediction.scores.
  • Update test fixtures and expectations for populated and empty results.
  • Document the behavior in the connector docstring and changelog.
File Description
tests/​key_points/​test_core.py Expect pose scores as detection confidence and supply empty scores for empty results.
tests/​helpers.py Add required per-pose scores to the YOLO-NAS test fixture.
src/​supervision/​key_points/​core.py Preserve YOLO-NAS pose scores and update the return documentation.
docs/​changelog.md Describe the confidence fix and its effects on NMS and detection conversion.

Review effort: Balanced

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95%. Comparing base (432dd17) to head (8c88681).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2909   +/-   ##
=======================================
  Coverage       95%     95%           
=======================================
  Files           83      83           
  Lines        14297   14298    +1     
=======================================
+ Hits         13539   13543    +4     
+ Misses         758     755    -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda
Borda merged commit d0c009e into roboflow:develop Nov 9, 2026
40 checks passed
Borda pushed a commit that referenced this pull request Nov 10, 2026
…2909)

`KeyPoints.from_yolo_nas` ignored `prediction.scores`, so
`detection_confidence` was `None` on YOLO-NAS output. `with_nms` then
raised, and `as_detections` reported the mean key point confidence
instead of the model's score.

Read the per-pose score into `detection_confidence`, as the Ultralytics,
Inference and Detectron2 connectors already do.
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.

[Bug]: KeyPoints.from_yolo_nas drops each pose's score, so with_nms raises on YOLO-NAS output

3 participants