Repository navigation
fix(dataset): read the box of YOLO pose labels instead of a polygon - #2655
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Configuration validation remains incomplete for null kpt_shape values and OBB loading.
Review effort: Balanced
Findings: 2
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.
| classes = _extract_class_names(file_path=data_yaml_path) | ||
| pose_value_count = 0 if is_obb else _extract_pose_value_count(data_yaml_path) |
There was a problem hiding this comment.
Fixed in c614ef5: kpt_shape is validated for OBB datasets too; only the keypoint stripping is skipped there.
Codecov Report❌ Patch coverage is 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:
|
c614ef5 to
c8bbcaf
Compare
c8bbcaf to
70c3d29
Compare
[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>
…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>


Description
DetectionDataset.from_yoloreads Ultralytics pose labels as polygons. A pose label isclass x y w hfollowed by theK * Dkeypoint values declared bykpt_shape: [K, D]indata.yaml, so every value after the class went to the polygon parser, and the box and mask came from the keypoints.developprints[[ 0. 0. 1280. 960.]] (1, 480, 640); with this change,[[240. 120. 400. 360.]] None.Motivation and Context
from_yolois 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
data.yamldeclareskpt_shape, a row of exactly5 + K * Dtokens keeps its first five and drops the keypoints before parsing. Rows of any other length are parsed as before.kpt_shapeother than[K, 2]or[K, 3]raisesValueError, as an invalidnamesalready does.from_yolodocstring and a changelog entry.Testing
On
develop, all 9 new cases fail:On Windows, mirroring the
ci-tests.ymlmatrix:pytest src/ tests/on Python 3.10, 3.11, 3.12 and 3.13 (NumPy fallback backend): 4,408 passed, 24 skipped on eachpytest src/ tests/on Python 3.13 withopencv-pythonand withopencv-python-headless(OpenCV 5.0): 4,623 passed, 1 skipped on eachruff check / ruff format (v0.16.6), mypy, docformatter, codespell, mdformat and
check_doctest_fences.pyon the changed files: clean;mkdocs buildrenders the new docstringA 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.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
5 + K * Dtokens in a dataset that declareskpt_shapeis read as a box. With an oddK * D, such as[17, 3], a plain polygon cannot have that count.save_txt(save_conf=True)carry one more token, so they are still parsed as ondevelop. Ultralytics' loader does not read them either.