Fix: add clamping to avoid v2.ElasticTransform IndexError when bbox equals canvas size#9436
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! |
|
@jsalvasoler Thanks a lot for creating this PR! Feel free to add a test and I will review it. |
621d3fe to
e736e5a
Compare
@zy1git test is added! |
test/test_transforms_v2.py
Outdated
| H, W = 64, 76 | ||
| bbox = tv_tensors.BoundingBoxes([0, 0, W, H], format=tv_tensors.BoundingBoxFormat.XYXY, canvas_size=(H, W)) | ||
| check_kernel( | ||
| F.elastic_bounding_boxes, |
There was a problem hiding this comment.
We only need to call F.elastic_bounding_boxes, going through check_kernel is a bit overkill for this test.
There was a problem hiding this comment.
Thanks for the feedback! Already updated.
e736e5a to
c508913
Compare
|
Hey @zy1git! You merged this PR, but no labels were added. |
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