Fix bounding box center overflow for narrow dtypes - #9595
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9595
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @aswanth-07! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
x1 * 2intermediate inXYXYtoCXCYWHconversionx1 + width / 2uint8andfloat16, in both in-place and out-of-place conversionWhy
_xyxy_to_cxcywhfirst storesx2 - x1as the width, then computes the center through(x1 * 2 + width) / 2. For narrow dtypes,x1 * 2can overflow even when the input coordinates, width, and correct center all fit in the dtype.For example, a valid
uint8box with x coordinates 200 and 220 returns center 82 instead of 210, while a validfloat16box with x coordinates 32768 and 49152 returns infinity instead of 40960. Reordering the same expression tox1 + width / 2avoids the unnecessary intermediate and retains integer floor rounding.Fixes #9594.
Validation
TestConvertBoundingBoxFormat: 184 passed, 30 expected failuresufmt checkon both changed filesgit diff --checkThe affected conversion is pure Python. The local source checkout used the compatible installed TorchVision extension and supplied only the newly introduced
qnmsschema required during import.AI disclosure: I used Codex to help audit the conversion arithmetic, search for duplicates, implement and test the focused patch, and draft this PR. I reviewed and understand the change and will personally handle maintainer follow-up.