Skip to content

Share box conversion kernels between ops and transforms v2 - #9651

Open
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:refactor/merge-box-convert-9387
Open

Share box conversion kernels between ops and transforms v2#9651
YeonwooSung wants to merge 1 commit into
pytorch:mainfrom
YeonwooSung:refactor/merge-box-convert-9387

Conversation

@YeonwooSung

Copy link
Copy Markdown

ops.box_convert and F.convert_bounding_box_format both converted boxes, but the arithmetic lived in two places. This keeps the kernels in torchvision/ops/_box_convert.py and has transforms v2 call them.

What is now shared

  • Axis-aligned and rotated conversion math lives in ops/_box_convert.py (_box_* helpers plus _half_wh).
  • ops.box_convert uses those helpers directly, including new first-class xywh ↔ cxcywh kernels instead of a two-step trip through xyxy.
  • v2 convert_bounding_box_format calls the same kernels for the arithmetic.
  • xyxy → cxcywh (and xywh → cxcywh) use overflow-safe origin + size/2 instead of (x1 + x2) / 2 or (x1 * 2 + width) / 2. This does not fight Avoid overflow in box center conversion #9641; it uses the same safer form.

Backward compatibility

Tests

  • ops.box_convert and F.convert_bounding_box_format are checked to agree on float32/float64 for xyxy/xywh/cxcywh pairs.

Fixes #9387

@pytorch-bot

pytorch-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9651

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate merging box conversion utils from ops and transforms

1 participant