Skip to content

fix(dataset): reject or order a reversed box in the remaining loaders - #2683

Merged
Borda merged 8 commits into
roboflow:developfrom
aminmiral:fix/box-extent-remaining-loaders
Oct 8, 2026
Merged

Borda merged 8 commits into
roboflow:developfrom
aminmiral:fix/box-extent-remaining-loaders

Conversation

@aminmiral

Copy link
Copy Markdown
Contributor

Closes #2682. Follow-up to #2663, which covered yolo only.

What changed

The format decides the remedy, following what #2663 established:

  • coco and createml name an extent, so a negative width or height is not representable. Both now reject it, with the same message shape the YOLO loader uses:
    Invalid box extent (-40, 40) in COCO annotation 7; expected a non-negative width and height.
  • pascal_voc names two corners explicitly, so a reversed pair describes the same rectangle rather than being malformed input. It now orders them, as labelme._rectangle_to_xyxy already does.

All three exporters measured the extent from raw corner values, so a reversed Detections exported as a file the loader refuses to read — the asymmetry that review caught on #2663. Each now orders the corners first, and the COCO exporter writes the ordered origin rather than the raw xyxy[0], xyxy[1].

Verification

Import side:

loader before after
coco bbox: [50,50,-40,40] area = -1600 rejected
createml width: -40 area = -1600 rejected
pascal_voc xmin 70, xmax 30 area = -1600 xyxy = [29, 29, 69, 69], area = 1600

Export side, from Detections(xyxy=[[70, 70, 30, 30]]):

exporter before after
coco bbox: [70, 70, -40, -40] bbox: [30, 30, 40, 40]
createml width: -40, height: -40 width: 40, height: 40, centre unchanged at (50, 50)
pascal_voc xmin 71 > xmax 31 xmin 31 < xmax 71

The exported box describes the same rectangle in each case, and normal boxes are unchanged.

10 new tests across the three format test files, mirroring TestYoloAnnotationsToDetectionsBoxExtent. All 10 fail without the src/ change and pass with it. The full tests/dataset/ suite is 554 passing; ruff check and ruff format are clean.

Note

labelme needed no change — it already normalises on load, and I left its export alone since it writes a rectangle's corner list rather than an extent.

roboflow#2663 stopped the YOLO loader building a box with x_min past x_max, but
coco, createml and pascal_voc still did. Such a box makes
Detections.area negative, scores two boxes covering the identical region
at 0.0 under box_iou_batch, and stops with_nms suppressing, so a corrupt
label skews evaluation silently.

The format decides the remedy, following what roboflow#2663 established:

- coco and createml name an extent, so a negative width or height is
  not representable and is now rejected, as the YOLO loader does.
- pascal_voc names two corners explicitly, so a reversed pair describes
  the same rectangle and is now ordered, as labelme already does.

All three exporters measured the extent from raw corner values, so a
reversed Detections exported as a file the loader refuses to read. Each
now orders the corners first, and the COCO exporter writes the ordered
origin rather than the raw one. The exported box describes the same
rectangle and normal boxes are unchanged.
@aminmiral
aminmiral requested a review from SkalskiP as a code owner October 6, 2026 18:27
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93%. Comparing base (3bc0301) to head (459f4d3).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2683   +/-   ##
=======================================
  Coverage       93%     93%           
=======================================
  Files           78      78           
  Lines        11930   11980   +50     
=======================================
+ Hits         11049   11101   +52     
+ Misses         881     879    -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… export

mypy rejected rebinding the ndarray parameter to a list. Order the
corners into locals instead, which also leaves the caller's array
untouched.
@Borda
Borda requested a balanced review from Copilot October 6, 2026 19:30
@Borda Borda added bug Something isn't working and removed has conflicts labels Oct 6, 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

The changelog is future-dated, and API documentation, type annotations, and zero-boundary tests need correction.

Review effort: Balanced
Findings: 4 Low severity

Open (4)
What changed in this PR

Normalizes reversed boxes across remaining dataset formats, preventing invalid geometry during import/export.

Changes:

  • Rejects negative COCO/CreateML extents.
  • Orders Pascal VOC corners and all three exporters.
  • Adds regression tests and changelog documentation.

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

File Description
src/​supervision/​dataset/​formats/​coco.py Validates extents and orders exports.
src/​supervision/​dataset/​formats/​createml.py Rejects negative extents and orders exports.
src/​supervision/​dataset/​formats/​pascal_voc.py Orders corners during loading and export.
tests/​dataset/​formats/​test_coco.py Tests rejection and normalized export.
tests/​dataset/​formats/​test_createml.py Tests rejection and normalized export.
tests/​dataset/​formats/​test_pascal_voc.py Tests corner ordering.
docs/​changelog.md Documents the 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/coco.py Resolved
Comment thread tests/dataset/formats/test_coco.py Resolved
Comment thread tests/dataset/formats/test_createml.py Resolved
…aining-loaders

# Conflicts:
#	docs/changelog.md
aminmiral and others added 4 commits October 7, 2026 09:55
Review notes on roboflow#2683.

The COCO loader gained a ValueError with no Raises entry at all, and the
CreateML loader's existing Raises section documented only missing keys and
conversion failures. Both now state that a negative width or height is
rejected and that a zero extent is accepted.

Both guards use `< 0`, so a degenerate zero-extent box still loads, but
nothing pinned that. Added the zero and negative-zero cases for each
loader, mirroring test_yolo.py's test_loads_a_zero_box_extent. All eight
fail if the guard is tightened to `<= 0`.
Changes:
- Assert exact Pascal VOC coordinates for reversed-box export and clarify
  the test contract.
- Annotate integer extent parameters in COCO and CreateML rejection tests.

Impact:
- Detect shifted or resized rectangles that ordering-only checks accepted.
- Make test parameter contracts explicit without changing production code.

Verification:
- Targeted dataset tests: 198 passed.
- Full suite: 4770 passed, 61 skipped, 39 warnings; 92% coverage.
- Pre-commit, formatting, configured mypy, and git diff --check passed.
- Exact-coordinate regression rejects shifted and resized exporter mutations.

Residual limits:
- Independent five-axis review and isolated blueprint remain unresolved.
- Local tests used NumPy fallback; native CI covers unchanged production.
- Finite geometry coverage is not exhaustive; configured mypy excludes tests.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit 34068b4 into roboflow:develop Oct 8, 2026
36 checks passed
Borda added a commit that referenced this pull request Oct 8, 2026
…#2683)

#2663 stopped the YOLO loader building a box with x_min past x_max, but
coco, createml and pascal_voc still did. Such a box makes
Detections.area negative, scores two boxes covering the identical region
at 0.0 under box_iou_batch, and stops with_nms suppressing, so a corrupt
label skews evaluation silently.

The format decides the remedy, following what #2663 established:

- coco and createml name an extent, so a negative width or height is
  not representable and is now rejected, as the YOLO loader does.
- pascal_voc names two corners explicitly, so a reversed pair describes
  the same rectangle and is now ordered, as labelme already does.

All three exporters measured the extent from raw corner values, so a
reversed Detections exported as a file the loader refuses to read. Each
now orders the corners first, and the COCO exporter writes the ordered
origin rather than the raw one. The exported box describes the same
rectangle and normal boxes are unchanged.

---------

Co-authored-by: jirka <[email protected]>
Co-authored-by: Codex <[email protected]>
@Borda Borda mentioned this pull request Oct 8, 2026
Borda added a commit that referenced this pull request Oct 8, 2026
…#2683)

#2663 stopped the YOLO loader building a box with x_min past x_max, but
coco, createml and pascal_voc still did. Such a box makes
Detections.area negative, scores two boxes covering the identical region
at 0.0 under box_iou_batch, and stops with_nms suppressing, so a corrupt
label skews evaluation silently.

The format decides the remedy, following what #2663 established:

- coco and createml name an extent, so a negative width or height is
  not representable and is now rejected, as the YOLO loader does.
- pascal_voc names two corners explicitly, so a reversed pair describes
  the same rectangle and is now ordered, as labelme already does.

All three exporters measured the extent from raw corner values, so a
reversed Detections exported as a file the loader refuses to read. Each
now orders the corners first, and the COCO exporter writes the ordered
origin rather than the raw one. The exported box describes the same
rectangle and normal boxes are unchanged.

---------

Co-authored-by: jirka <[email protected]>
Co-authored-by: Codex <[email protected]>
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]: coco, pascal_voc and createml still build a reversed box, and their exporters write one

3 participants