Support inplace in ConvertBoundingBoxFormat transform#9508
Open
adityasingh2400 wants to merge 1 commit into
Open
Support inplace in ConvertBoundingBoxFormat transform#9508adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
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
🔗 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8923
Root cause
The functional
convert_bounding_box_formatalready accepts aninplaceargument:https://github.com/pytorch/vision/blob/main/torchvision/transforms/v2/functional/_meta.py
However the
ConvertBoundingBoxFormattransform 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
inplaceparameter toConvertBoundingBoxFormat.__init__, stores it on the instance, and forwards it to the functional intransform. This mirrors exactly howNormalizealready exposes its owninplaceargument (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
XYXYXYXYformat always allocate a new tensor because they change the size of the last dimension.Verification
I extended
TestConvertBoundingBoxFormatwith atest_transform_inplacecase that runs over every old/new format permutation and overfloat32andint64. It checks that:inplace=Truethe output reuses the input storage (samedata_ptr) and bumps the tensor version for conversions that do not involveXYXYXYXYThe 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:
The new test alone:
black(line length 120) reports both changed files unchanged, andflake8 --config=setup.cfgis clean on the changed source.