Skip to content

Support inplace in ConvertBoundingBoxFormat transform#9508

Open
adityasingh2400 wants to merge 1 commit into
pytorch:mainfrom
adityasingh2400:convert-bbox-format-inplace
Open

Support inplace in ConvertBoundingBoxFormat transform#9508
adityasingh2400 wants to merge 1 commit into
pytorch:mainfrom
adityasingh2400:convert-bbox-format-inplace

Conversation

@adityasingh2400
Copy link
Copy Markdown

Fixes #8923

Root cause

The functional convert_bounding_box_format already accepts an inplace argument:

https://github.com/pytorch/vision/blob/main/torchvision/transforms/v2/functional/_meta.py

However the ConvertBoundingBoxFormat transform class never exposed it, so there was no way to request an in-place conversion through the class-based transform API. The issue notes this gap and asks that we wire it through.

Fix

This adds an inplace parameter to ConvertBoundingBoxFormat.__init__, stores it on the instance, and forwards it to the functional in transform. This mirrors exactly how Normalize already exposes its own inplace argument (stored on the instance and passed straight to the kernel), so the pattern is consistent with the rest of the v2 transforms.

The docstring is updated to document the new argument, including the existing caveat that conversions from or to the XYXYXYXY format always allocate a new tensor because they change the size of the last dimension.

Verification

I extended TestConvertBoundingBoxFormat with a test_transform_inplace case that runs over every old/new format permutation and over float32 and int64. It checks that:

  • with inplace=True the output reuses the input storage (same data_ptr) and bumps the tensor version for conversions that do not involve XYXYXYXY
  • the result is identical to the out-of-place path
  • the output format is updated correctly

The new test follows the same structure as the existing test_kernel_inplace, including the same xfail for rotated boxes with integer dtype.

Targeted run of the whole class against a torchvision build:

python -m pytest test/test_transforms_v2.py -k "TestConvertBoundingBoxFormat" -q
154 passed, 56 skipped, 24 xfailed

The new test alone:

python -m pytest test/test_transforms_v2.py -k "TestConvertBoundingBoxFormat and test_transform_inplace" -q
18 passed, 6 xfailed

black (line length 120) reports both changed files unchanged, and flake8 --config=setup.cfg is clean on the changed source.

The functional convert_bounding_box_format already accepts an inplace
argument, but the ConvertBoundingBoxFormat transform class did not expose
it. This wires inplace through the class so it can be passed to the
functional, mirroring how Normalize handles its own inplace argument.

Fixes pytorch#8923
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Jun 2, 2026

🔗 Helpful Links

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

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.

@meta-cla meta-cla Bot added the cla signed label Jun 2, 2026
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.

ConvertBoundingBoxFormat should support inplace

1 participant