Skip to content

fix(dataset): read the box of YOLO pose labels instead of a polygon - #2655

Merged
Borda merged 17 commits into
roboflow:developfrom
8rulerstar:fix/yolo-pose-labels
Oct 6, 2026
Merged

Borda merged 17 commits into
roboflow:developfrom
8rulerstar:fix/yolo-pose-labels

Conversation

@8rulerstar

Copy link
Copy Markdown
Contributor

Description

DetectionDataset.from_yolo reads Ultralytics pose labels as polygons. A pose label is class x y w h followed by the K * D keypoint values declared by kpt_shape: [K, D] in data.yaml, so every value after the class went to the polygon parser, and the box and mask came from the keypoints.

from pathlib import Path
from PIL import Image
import supervision as sv

Path("images").mkdir(); Path("labels").mkdir()
Image.new("RGB", (640, 480)).save("images/a.png")
Path("data.yaml").write_text("names: ['person']\nkpt_shape: [17, 3]\n")
# class, box, then 17 "x y visibility" triplets; unlabelled keypoints are "0 0 0"
Path("labels/a.txt").write_text(
    "0 0.5 0.5 0.25 0.5 0.45 0.3 2 0.455 0.32 1 0.46 0.34 0 0.44 0.33 2 0.5 0.33 2"
    " 0.42 0.42 2 0.58 0.42 1 0.4 0.52 2 0.6 0.52 0 0.41 0.6 2 0.59 0.6 2"
    " 0.45 0.62 2 0.55 0.62 2 0.45 0.7 1 0.55 0.7 2 0 0 0 0 0 0\n"
)
ds = sv.DetectionDataset.from_yolo("images", "labels", "data.yaml")
print(ds[0][2].xyxy, None if ds[0][2].mask is None else ds[0][2].mask.shape)

develop prints [[ 0. 0. 1280. 960.]] (1, 480, 640); with this change, [[240. 120. 400. 360.]] None.

Motivation and Context

from_yolo is the only way to load these labels today. Ultralytics fixed the same misreading in its own loader in ultralytics/ultralytics#26357, and this applies the same rule. It is a loader fix, not the keypoint dataset of #1438, which #1477's closing comment says should start from a container/API proposal: the keypoints are not loaded.

Changes Made

  • When data.yaml declares kpt_shape, a row of exactly 5 + K * D tokens keeps its first five and drops the keypoints before parsing. Rows of any other length are parsed as before.
  • A kpt_shape other than [K, 2] or [K, 3] raises ValueError, as an invalid names already does.
  • from_yolo docstring and a changelog entry.

Testing

On develop, all 9 new cases fail:

FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_reads_the_box_and_skips_the_keypoints[xy-visibility] - AssertionError:
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_reads_the_box_and_skips_the_keypoints[xy-only] - AssertionError:
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_reads_the_box_and_skips_the_keypoints[whole-number-floats] - AssertionError:
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_forced_masks_cover_the_box_not_the_keypoints - AssertionError:
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_reads_rows_of_other_lengths_as_before - AssertionError:
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_raises_on_an_invalid_kpt_shape[[17]] - Failed: DID NOT RAISE <class 'ValueError'>
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_raises_on_an_invalid_kpt_shape[[17, 4]] - Failed: DID NOT RAISE <class 'ValueError'>
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_raises_on_an_invalid_kpt_shape[[0, 3]] - Failed: DID NOT RAISE <class 'ValueError'>
FAILED tests/dataset/formats/test_yolo.py::TestFromYoloPoseLabels::test_raises_on_an_invalid_kpt_shape[[17.5, 3]] - Failed: DID NOT RAISE <class 'ValueError'>

On Windows, mirroring the ci-tests.yml matrix:

  • pytest src/ tests/ on Python 3.10, 3.11, 3.12 and 3.13 (NumPy fallback backend): 4,408 passed, 24 skipped on each

  • pytest src/ tests/ on Python 3.13 with opencv-python and with opencv-python-headless (OpenCV 5.0): 4,623 passed, 1 skipped on each

  • ruff check / ruff format (v0.16.6), mypy, docformatter, codespell, mdformat and check_doctest_fences.py on the changed files: clean; mkdocs build renders the new docstring

  • A 200-image subset of COCO val2017 person keypoints, converted with Ultralytics' convert_coco(use_keypoints=True): all 834 boxes match the label boxes (develop: none do, and every image gets a mask)

  • 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

  • As in Ultralytics, a polygon row of exactly 5 + K * D tokens in a dataset that declares kpt_shape is read as a box. With an odd K * D, such as [17, 3], a plain polygon cannot have that count.
  • Not covered: pose predictions written by save_txt(save_conf=True) carry one more token, so they are still parsed as on develop. Ultralytics' loader does not read them either.
  • The keypoints are dropped without a warning, as Ultralytics does for box tasks; the place to point users at a keypoint loader is [KeypointsDataset] - create a new dataset format to load keypoints #1438.

@8rulerstar
8rulerstar requested a review from SkalskiP as a code owner October 3, 2026 12:20
@CLAassistant

CLAassistant commented Oct 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Borda
Borda requested a balanced review from Copilot October 3, 2026 23:17
@Borda Borda added the bug Something isn't working label Oct 3, 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

🟡 Changes recommended

Configuration validation remains incomplete for null kpt_shape values and OBB loading.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Fixes YOLO pose-label imports by retaining bounding boxes and discarding undeclared keypoint data.

Changes:

  • Detects and validates kpt_shape, stripping matching keypoint columns.
  • Adds pose-label regression and validation tests.
  • Documents the behavior and updates the changelog.

Review scores: Code quality 4/5 · Testing 4/5 · Documentation 3/5 · Risk 2/5

File Description
src/​supervision/​dataset/​formats/​yolo.py Adds pose metadata validation and keypoint stripping.
src/​supervision/​dataset/​core.py Documents pose-label loading behavior.
tests/​dataset/​formats/​test_yolo.py Tests pose boxes, masks, compatibility, and invalid shapes.
docs/​changelog.md Records the loader fix.

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

Comment thread src/supervision/dataset/formats/yolo.py Resolved
Comment thread src/supervision/dataset/formats/yolo.py Outdated
Comment on lines +375 to +376
classes = _extract_class_names(file_path=data_yaml_path)
pose_value_count = 0 if is_obb else _extract_pose_value_count(data_yaml_path)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c614ef5: kpt_shape is validated for OBB datasets too; only the keypoint stripping is skipped there.

Comment thread docs/changelog.md Resolved
@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92%. Comparing base (594bd0f) to head (ea8539f).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2655   +/-   ##
=======================================
  Coverage       92%     92%           
=======================================
  Files           78      78           
  Lines        11827   11857   +30     
=======================================
+ Hits         10873   10903   +30     
  Misses         954     954           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Borda and others added 11 commits October 6, 2026 11:49
[resolve No.6] Review by foundry:sw-engineer (PR #2655):
"[medium] Polygon rows with exactly 5 + K*D tokens are silently read as b..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.7] Review by foundry:sw-engineer (PR #2655):
"[medium] Invalid or null kpt_shape raises on non-pose and OBB loads befo..."
Challenge: evidence=VALID suggestion=REJECT resolution=self-resolved

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.8] Review by foundry:sw-engineer (PR #2655):
"[medium] Pose rows with trailing confidence or tracker id or mismatched ..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.9] Review by foundry:sw-engineer (PR #2655):
"[medium] Pose-row token rule lives in load_yolo_annotations, not yolo_an..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.10] Review by foundry:sw-engineer (PR #2655):
"[low] data.yaml parsed twice; unreachable non-mapping branch disagrees w..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.11] Review by foundry:qa-specialist (PR #2655):
"[medium] OBB pose bypass has no test with a valid kpt_shape; removing it..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.12] Review by foundry:qa-specialist (PR #2655):
"[low] kpt_shape rejection branches not individually exercised — `tests/d..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.15] Review by foundry:doc-scribe (PR #2655):
"[low] Public docstrings lack Raises ValueError and load_yolo_annotations..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.16] Review by foundry:linting-expert (PR #2655):
"[low] OBB bypass of pose stripping has no why-comment — `src/supervision..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.17] Review by foundry:linting-expert (PR #2655):
"[low] Dense kpt_shape validation predicate and magic numbers — `src/supe..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
[resolve No.18] Review by foundry:linting-expert (PR #2655):
"[low] Parallel ids list in parametrize violates CONTRIBUTING test rules ..."
Challenge: evidence=VALID suggestion=VALID resolution=as-suggested

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda
Borda merged commit 7ecbd4e into roboflow:develop Oct 6, 2026
36 checks passed
Borda added a commit that referenced this pull request Oct 6, 2026
…2655)

* fix(dataset): read the box of YOLO pose labels instead of a polygon
* docs(changelog): link #2655
* fix(dataset): validate kpt_shape when it is null or the dataset is OBB
* document and pin that pose-length polygon rows load as boxes
* say how to fix an invalid kpt_shape in its error
* document unsupported pose rows in from_yolo
* note where pose keypoints are stripped
* share the data.yaml mapping check between readers
* pin OBB corners when kpt_shape matches OBB length
* reject boolean and three-value kpt_shape in tests
* document data.yaml ValueErrors and kpt_shape arg
* explain why OBB loading skips keypoint stripping
* extract the positive whole-number check for kpt_shape
* use pytest.param ids for the is_obb cases

---------

Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@8rulerstar
8rulerstar deleted the fix/yolo-pose-labels branch October 8, 2026 11:00
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