fix(key_points): preserve empty-joint skeletons during NMS by INo-xious · Pull Request #2639 · roboflow/supervision · GitHub
Skip to content

fix(key_points): preserve empty-joint skeletons during NMS - #2639

Merged
Borda merged 6 commits into
roboflow:developfrom
INo-xious:fix/keypoints-nms-empty-joints
Sep 30, 2026
Merged

Borda merged 6 commits into
roboflow:developfrom
INo-xious:fix/keypoints-nms-empty-joints

Conversation

@INo-xious

Copy link
Copy Markdown
Contributor

Description

KeyPoints.with_nms() raises a zero-size reduction error after boolean filtering removes every joint from a nonempty batch. It now preserves those skeletons and their aligned fields, consistent with skeletons whose joints are all unusable.

import numpy as np
import supervision as sv

key_points = sv.KeyPoints(
    xy=np.array([[[10., 10.], [20., 20.]]]),
    class_id=np.array([0]),
    detection_confidence=np.array([0.9]),
)
filtered = key_points[np.array([[False, False]])]
filtered.with_nms()  # Previously raised ValueError; now keeps the skeleton.

Motivation and Context

Public keypoint filtering can produce valid (N, 0, 2) coordinates. The bounding-box reductions ran before the existing no-valid-joints handling and could not reduce the empty joint axis.

#2401 and merged #2402 addressed indexing and as_detections. Merged #2563 addressed nonfinite joints in NMS. Open #2633 populates detection confidence in pose connectors. This change addresses the separate empty-axis failure.

Changes Made

  • Give the four bounding-box reductions their existing positive/negative infinity sentinels as initial values, allowing empty axes to reach the existing zero-area-box handling.
  • Keep the usual NMS validation and selection path, preserving class-aware and class-agnostic behavior, aligned fields, and returned-object semantics.
  • Add 11 cases covering one/multiple skeletons, boolean filtering, optional fields, required fields, and threshold validation; clarify the method docstring and add an Unreleased changelog entry.

Testing

All commands ran in this branch's independent worktree based on 8c7df2388ce46f16139edc498c2bc3874493b4bc.

  • Clean base: uv run pytest --cov=supervision — 4316 passed, 24 skipped; 91% coverage.

  • New regression class against unchanged implementation: uv run pytest tests/key_points/test_core.py::TestKeyPointsWithNmsEmptyJoints — 8 failed with the expected zero-size reduction error (including two masked threshold-validation errors), 3 existing required-field checks passed.

  • Fixed NMS cases: uv run pytest tests/key_points/test_core.py -k 'nms or Nms' — 33 passed.

  • Full suite: uv run pytest --cov=supervision — 4327 passed, 24 skipped; 91% coverage.

  • Relevant doctests: uv run pytest --doctest-modules src/supervision/key_points/core.py — 10 passed.

  • uv run pre-commit run --all-files — all 22 hooks passed after formatting.

  • git diff --check — passed.

  • 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

Validation used Python 3.13.9 and NumPy 2.3.1 with the supported OpenCV-free backend. The same 24 pre-existing skips remained before and after: 23 require optional OpenCV and one requires optional rasterio. No public API or dependency changes.

@INo-xious
INo-xious requested a review from SkalskiP as a code owner September 29, 2026 05:08
@CLAassistant

CLAassistant commented Sep 29, 2026 •

Copy link
Copy Markdown

@Borda
Borda requested a balanced review from Copilot September 29, 2026 05:51
@Borda Borda added the bug Something isn't working label Sep 29, 2026
@Borda

Borda commented Sep 29, 2026

Copy link
Copy Markdown
Member

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@INo-xious ^^ 🙏

@Borda
Borda marked this pull request as draft September 29, 2026 05:51

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 fix preserves existing validation and NMS behavior with thorough regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes KeyPoints.with_nms() for nonempty skeleton batches with zero joints.

Changes:

  • Uses neutral reduction sentinels for empty joint axes.
  • Adds comprehensive regression and validation tests.
  • Updates documentation and changelog.

Assessment: Code quality 5/5 · Testing 5/5 · Documentation 5/5 · Risk 1/5

File Description
src/​supervision/​key_points/​core.py Handles empty joint-axis reductions safely.
tests/​key_points/​test_core.py Covers preservation, aligned fields, and validation.
docs/​changelog.md Documents the bug fix.

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

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

@Borda
Borda marked this pull request as ready for review September 29, 2026 06:11
Changes:
- Integrate develop updates for float64 COCO-compatible mAP thresholds, in-place dataset exports, and video writer error propagation, with their regression tests.
- Resolve the Unreleased changelog conflict by retaining the PR roboflow#2639 entry and all three target entries.

Impact:
- The PR branch now contains the fetched target fixes and keeps the keypoint NMS release note alongside target release notes.
- The merge preserves target implementations and tests without mixing in review finding changes.

Verification:
- Focused keypoint, dataset, metrics, and video tests: 331 passed.
- git diff --check passed; unresolved merge paths: none.

Residual limits:
- The fresh review's local mypy gate remains failed because the cached environment lacks project dependencies and third-party stubs.
- codecov/project was pending at review collection.

---

Co-authored-by: Codex <codex@openai.com>
@Borda
Borda merged commit 3e1af0e into roboflow:develop Sep 30, 2026
35 checks passed
Borda added a commit that referenced this pull request Oct 4, 2026
* fix(key_points): preserve empty-joint skeletons during NMS
* docs: link empty-joint NMS fix pull request

---------

Co-authored-by: jirka <6035284+borda@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@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.

4 participants