Fix: add clamping to avoid v2.ElasticTransform IndexError when bbox equals canvas size#9436
Fix: add clamping to avoid v2.ElasticTransform IndexError when bbox equals canvas size#9436jsalvasoler wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9436
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 @jsalvasoler! 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! |
elastic_bounding_boxes used bbox corner coordinates as direct indices into inv_grid (shape 1×H×W×2) without
clamping. After ceil_(), a coordinate equal to W or H (e.g. a box touching the image edge) produced index W/H,
which is out of bounds.
Fix: clamp index_x and index_y to [0, W-1] / [0, H-1] before the grid lookup, identical to the clamping already
present in elastic_keypoints
vision/torchvision/transforms/v2/functional/_geometry.py
Lines 2398 to 2399 in 6d85459
This was the fix suggested by @zy1git on the issue thread.
Let me know if you want me to add a test to
test/test_transforms_v2.pyFixes #9394