You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XYXY to CXCYWH conversion overflows for narrow dtypes #9594
torchvision.transforms.v2.functional.convert_bounding_box_format can return an incorrect center when converting valid XYXY boxes to CXCYWH with a narrow dtype.
The internal _xyxy_to_cxcywh implementation first computes the width, but then evaluates the equivalent expression (x1 * 2 + width) / 2. The intermediate x1 * 2 can overflow even when the input coordinates, width, and mathematically correct center are all representable in the input dtype.
For uint8, the center wraps from 210 to 82. For float16, the center becomes infinity instead of 40960.
The overflow can be avoided by evaluating the equivalent but safer expression x1 + width / 2. I would like to contribute that focused change with regression coverage for both in-place and out-of-place conversions.
I searched open and closed issues and pull requests for bounding-box center, uint8, and float16 conversion overflow and did not find an existing report for this path.
AI disclosure: I used Codex to help audit the conversion arithmetic, search for duplicates, reproduce the failure, test the proposed expression, and draft this report. I reviewed the diagnosis, reproduction, and proposed scope and will personally handle follow-up.
Versions
TorchVision: current main at 34572106ad1f0ea95793e379751f8bb0cfeeac1c
PyTorch: 2.13.0+cpu
Python: 3.10.11 (64-bit)
OS: Microsoft Windows 11 Home Single Language 10.0.26200
CUDA available: False
NumPy: 2.2.6
Activity
modelpath-dev commentedon Sep 4, 2026
I'll work on this. Could you assign it to me?
I'll look at the current code, add a focused test, and send a small PR.
modelpath-dev commentedon Sep 6, 2026
I am still working on this. I will update once I have a PR ready.
modelpath-dev commentedon Sep 8, 2026
I am making progress on the fix. I will update here once the PR is ready for review.