Skip to content

fix(dataset): round Pascal VOC bndbox corners instead of truncating them - #2748

Merged
Borda merged 5 commits into
roboflow:developfrom
Lingikaushikreddy:fix/pascal-voc-export-rounding
Oct 23, 2026
Merged

Borda merged 5 commits into
roboflow:developfrom
Lingikaushikreddy:fix/pascal-voc-export-rounding

Conversation

@Lingikaushikreddy

Copy link
Copy Markdown
Contributor

Description

object_to_pascal_voc wrote <bndbox> corners with int(), which truncates. A fractional box lost up to a pixel per corner, and a box read from 6-decimal YOLO labels could be written with xmin=0, outside 1-indexed VOC. The corners are now rounded to the nearest integer pixel.

elem = object_to_pascal_voc(np.array([10.9, 10.9, 20.9, 20.9]), name="cat")
[elem.find(f"bndbox/{t}").text for t in ("xmin", "ymin", "xmax", "ymax")]
# develop:  ['11', '11', '21', '21']
# this PR:  ['12', '12', '22', '22']

Motivation and Context

Closes #2747

YOLO → VOC conversion is where this bites. from_yolo returns corners a hair off the integer pixel, so the integer box [0, 0, 37, 29] from an Ultralytics label came back from VOC as [-1, -1, 37, 28]. It now round-trips to [0, 0, 37, 29].

Changes Made

  • src/supervision/dataset/formats/pascal_voc.py: str(round(x)) instead of str(int(x)) for the four <bndbox> corners, and a docstring note.
  • tests/dataset/formats/test_pascal_voc.py: parametrized test for rounding up, rounding down, and the YOLO float-noise box.
  • docs/changelog.md: entry under Unreleased.
  • Left alone: <polygon> points are already written unrounded, as before.

Testing

  • New test on develop: 2 of 3 cases fail (('11', '11', '21', '21') != ('12', '12', '22', '22') and ('0', '0', '38', '29') != ('1', '1', '38', '30')). The rounds-down case passes on both and guards against a ceil-based fix.

  • With this change: uv run pytest tests/dataset/formats/test_pascal_voc.py, 58 passed.

  • Full suite: uv run pytest, 5697 passed, 105 skipped (develop: 5694 passed, 105 skipped).

  • uv run pre-commit run --all-files passes.

  • 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

Additional Notes

Python's round rounds halves to even (10.5 → 10), the same as np.round. An exact half-pixel corner has no better answer either way, so I kept the standard behaviour rather than adding a half-up rule.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (18dbc49) to head (7a3dd69).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2748   +/-   ##
=======================================
- Coverage       94%     94%   -0%     
=======================================
  Files           83      83           
  Lines        13675   13674    -1     
=======================================
- Hits         12883   12882    -1     
  Misses         792     792           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda added the bug Something isn't working label Oct 16, 2026
@Borda
Borda requested a balanced review from Copilot October 16, 2026 20:01

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

The focused correction has regression coverage; the only remaining feedback is a minor missing changelog entry.

1 open finding
What changed in this PR

Corrects Pascal VOC bounding-box exports by rounding fractional corners rather than truncating them, addressing YOLO conversion precision loss.

Changes:

  • Rounds all four bounding-box corners and documents the behavior.
  • Adds regression cases for rounding up, rounding down, and YOLO floating-point noise.
File Description
tests/​dataset/​formats/​test_pascal_voc.py Adds fractional-coordinate regression tests.
src/​supervision/​dataset/​formats/​pascal_voc.py Rounds exported corners and updates the docstring.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Borda added a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 17, 2026
Changes:
- Merge the fetched develop target into the Pascal VOC rounding branch, including the Unreleased notes for PRs roboflow#2740, roboflow#2741, and roboflow#2743.
- Integrate OpenCV-compatible ellipse rasterization and its regression coverage.
- Integrate mask ROI handling that excludes all-False masks and its tests.
- Integrate overflow-safe mean-average-precision box extents and dtype regression tests.

Impact:
- Keeps the PR branch current so the roboflow#2748 changelog note can be added beside the target's Unreleased entries.
- Brings the target's drawing, mask annotation, and metric fixes into the local PR branch.

Verification:
- The three-tree merge completed automatically without conflicts.
- The staged merge diff check passed; all eight staged paths were reviewed.

Residual limits:
- None known.

---

Co-authored-by: Codex <[email protected]>
Borda
Borda previously approved these changes Oct 17, 2026
@t7spotter

Copy link
Copy Markdown

Related: #2756. This PR fixes the truncation, but the +1 is still applied to xmax and ymax. Under the VOC devkit convention (1-based, inclusive), only xmin and ymin need it: the box [0, 0, 37, 29] from #2747 should be written as 1 1 37 29, not 1 1 38 30. It might be easiest to handle both in this PR.

@Lingikaushikreddy

Copy link
Copy Markdown
Contributor Author

Thanks, @t7spotter. You're right about the devkit convention: with 1-based inclusive indices, a box covering 0-based pixels x0 .. x0+w-1 is written xmin = x0 + 1, xmax = x0 + w, while object_to_pascal_voc adds 1 to all four corners.

Fixing it isn't writer-only, though. detections_from_xml_obj subtracts 1 from all four (xyxy_arr -= 1), so the reader has to change in the same PR. After that, every VOC file supervision has already written would load 1 px smaller on the right and bottom. That changes the convention set in #144, so I'd keep this PR to the rounding fix and handle #2756 separately.

@Borda, if you agree with the devkit convention, I'm happy to open a follow-up that changes the reader and writer together, with a changelog note about files written by earlier versions.

Borda added a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 19, 2026
Changes:
- Add a PR roboflow#2748 Unreleased note describing nearest-integer rounding of all four Pascal VOC bndbox corners during YOLO-to-VOC export.

Impact:
- Readers can see that fractional box coordinates are rounded to preserve intended box extent.

Verification:
- Pinned mdformat hook passed; full suite passed: 5726 passed, 123 skipped, 39 warnings.
- git diff --check and parent self-review passed; lint and type checks are not applicable because only Markdown changed.

Residual limits:
- Independent multi-role review coverage remains unvalidated; no fresh review was authorized.

---

Co-authored-by: Codex <[email protected]>
@Borda

Borda commented Oct 19, 2026

Copy link
Copy Markdown
Member

@Lingikaushikreddy, as this seems to be quite connected and better not accidentally release one without the other one, so let's do it within this PR 🦝

Lingikaushikreddy pushed a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 19, 2026
Changes:
- Add a PR roboflow#2748 Unreleased note describing nearest-integer rounding of all four Pascal VOC bndbox corners during YOLO-to-VOC export.

Impact:
- Readers can see that fractional box coordinates are rounded to preserve intended box extent.

Verification:
- Pinned mdformat hook passed; full suite passed: 5726 passed, 123 skipped, 39 warnings.
- git diff --check and parent self-review passed; lint and type checks are not applicable because only Markdown changed.

Residual limits:
- Independent multi-role review coverage remains unvalidated; no fresh review was authorized.

---

Co-authored-by: Codex <[email protected]>
@Lingikaushikreddy
Lingikaushikreddy force-pushed the fix/pascal-voc-export-rounding branch from 356e40a to 44451e9 Compare October 19, 2026 21:00
@Lingikaushikreddy

Copy link
Copy Markdown
Contributor Author

@Borda, done: #2756 is folded in here, and the branch is rebased on develop.

  • The writer now adds 1 to xmin/ymin only and still rounds, so [0, 0, 37, 29] is written 1 1 37 29 and the [Bug]: as_pascal_voc adds 1 to xmax and ymax; the VOC devkit needs the +1 on xmin and ymin only (complements #2747) #2756 example gives 11 21 40 60.
  • The reader subtracts 1 from xmin/ymin only, matching the devkit and Detectron2. Write → read returns the original box, including the YOLO float-noise case.
  • One extra fix was needed so mask exports don't regress: boxes taken from polygons were computed to the last mask pixel, so I add one on the far side. Their XML output is unchanged.
  • I updated the tests and sample XML that assumed +1 on all four corners, and added tests for the writer, the reader, the round trip and the mask box.
  • I rewrote the changelog entry and marked it Breaking. VOC files written by earlier supervision versions will load one pixel larger on the right and bottom. That corrects my earlier comment, where I said smaller.

Full suite and pre-commit pass locally.

Lingikaushikreddy pushed a commit to Lingikaushikreddy/supervision that referenced this pull request Oct 20, 2026
Changes:
- Add a PR roboflow#2748 Unreleased note describing nearest-integer rounding of all four Pascal VOC bndbox corners during YOLO-to-VOC export.

Impact:
- Readers can see that fractional box coordinates are rounded to preserve intended box extent.

Verification:
- Pinned mdformat hook passed; full suite passed: 5726 passed, 123 skipped, 39 warnings.
- git diff --check and parent self-review passed; lint and type checks are not applicable because only Markdown changed.

Residual limits:
- Independent multi-role review coverage remains unvalidated; no fresh review was authorized.

---

Co-authored-by: Codex <[email protected]>
@Lingikaushikreddy
Lingikaushikreddy force-pushed the fix/pascal-voc-export-rounding branch from 44451e9 to 74c7c29 Compare October 20, 2026 22:39
Lingikaushikreddy and others added 3 commits October 20, 2026 21:55
Changes:
- Add a PR roboflow#2748 Unreleased note describing nearest-integer rounding of all four Pascal VOC bndbox corners during YOLO-to-VOC export.

Impact:
- Readers can see that fractional box coordinates are rounded to preserve intended box extent.

Verification:
- Pinned mdformat hook passed; full suite passed: 5726 passed, 123 skipped, 39 warnings.
- git diff --check and parent self-review passed; lint and type checks are not applicable because only Markdown changed.

Residual limits:
- Independent multi-role review coverage remains unvalidated; no fresh review was authorized.

---

Co-authored-by: Codex <[email protected]>
The Pascal VOC devkit uses 1-based, inclusive pixel indices, so a box
covering zero-indexed pixels x1 .. x2 - 1 is written xmin = x1 + 1,
xmax = x2. The writer added 1 to all four corners and the reader
subtracted 1 from all four, so a supervision round trip looked exact
while every exported box was one pixel too wide and tall for devkit
readers such as Detectron2.

Write and read the offset on xmin and ymin only. Mask-derived boxes
come from contour vertices on the outermost mask pixels, so their far
edge is now taken one past the largest vertex; their written bndbox is
unchanged. Update the tests and fixtures that encoded the old offset.
@Lingikaushikreddy
Lingikaushikreddy force-pushed the fix/pascal-voc-export-rounding branch from 74c7c29 to c9cac51 Compare October 21, 2026 01:58

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.

🟡 Changes recommended

Half-pixel rounding remains inconsistent, and subpixel boxes can produce inverted bounds that reload incorrectly.

2 open issues
1 resolved since last review

Review effort: Balanced

Changes:
- Merge fetched develop commit 18dbc49 into the PR branch and resolve the changelog, Pascal VOC conversion, and format-test overlaps.
- Preserve the target VOC far-edge convention, the PR fractional rounding behavior, and both changelog entries while retaining all other fetched develop changes.

Impact:
- Brings the PR branch up to the verified develop target, including recent dataset, metrics, detection, utility, documentation, CI, and dependency-lock updates.
- Keeps target max-corner serialization intact for boxes and mask-derived polygons.

Verification:
- tests/dataset/formats/test_pascal_voc.py: 77 passed.
- git diff --cached --check: passed; no unmerged paths remain.
- The staged index differs from fetched develop only in the three resolved conflict paths.

Residual limits:
- The half-pixel minimum offset ordering still needs the selected remediation finding fix.
- The subpixel collapse behavior needs its exact reviewer case and round-trip regression after scope selection.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit 991784b into roboflow:develop Oct 23, 2026
35 checks passed
Borda added a commit that referenced this pull request Oct 24, 2026
…hem (#2748)

* fix(dataset): round Pascal VOC bndbox corners instead of truncating them
* docs(changelog): document Pascal VOC rounding
* fix(dataset): offset only xmin and ymin in Pascal VOC bndbox

---------

Co-authored-by: Lingikaushikreddy <[email protected]>
Co-authored-by: jirka <[email protected]>
Co-authored-by: Codex <[email protected]>
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.

[Bug]: as_pascal_voc truncates fractional box corners instead of rounding them

4 participants