supervision icon indicating copy to clipboard operation
supervision copied to clipboard

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

Open Lingikaushikreddy opened this issue 1 month ago • 0 comments

Search before asking

  • [x] I have searched the issues and discussions and found no similar bug report.

Bug

DetectionDataset.as_pascal_voc writes <bndbox> corners with str(int(x)) (src/supervision/dataset/formats/pascal_voc.py, object_to_pascal_voc), which truncates instead of rounding. A fractional box loses up to a full pixel at every corner. [10.9, 10.9, 20.9, 20.9] is written as 11 11 21 21 (1-indexed) instead of 12 12 22 22.

The common case is a YOLO → VOC conversion. from_yolo reads normalized 6-decimal labels back as floats a hair off the integer pixel, so truncation moves whole corners. With the integer box [0, 0, 37, 29] on a 640×480 image, written by Ultralytics as 0 0.028906 0.030208 0.057813 0.060417:

  • from_yolo gives [-0.00032, -0.00024, 37.0, 28.99992]
  • as_pascal_voc writes xmin=0 ymin=0 xmax=38 ymax=29. xmin=0 is outside 1-indexed VOC, and ymax lost a pixel.
  • from_pascal_voc reads that back as [-1, -1, 37, 28]

Expected: each corner goes to the nearest integer pixel, xmin=1 ymin=1 xmax=38 ymax=30, which reads back as [0, 0, 37, 29]. The loader in the same module already keeps decimals (#2568), so the writer is the only lossy step.

Environment

  • supervision develop @ 927dfeb05 (0.31.0)
  • macOS arm64, Python 3.12.13, NumPy 2.3.1

Minimal Reproducible Example

import numpy as np
import supervision as sv
from supervision.dataset.formats.pascal_voc import object_to_pascal_voc

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

Are you willing to submit a PR?

  • [x] Yes I'd like to help by submitting a PR!

Lingikaushikreddy avatar Oct 16 '26 19:10 Lingikaushikreddy