-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanup affine grid image kernels #8004
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in principle, although I haven't double checked that all the new logic is strictly equivalent (hopefully it would be caught by the test). One Q below, but non-blocking as long as it's adressed / or if it's a non-issue
|
||
return output | ||
grid = _create_identity_grid((height, width), device=device, dtype=dtype).add_( | ||
displacement.to(dtype=dtype, device=device) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it equivalent to cast to float16 before the call to _apply_grid_transform
? It used to be done after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why is to(device)
needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The float16 handling above is untouched and deals with the image. Here we are just aligning the displacement
with the grid
. This is the same as
vision/torchvision/transforms/v2/functional/_geometry.py
Lines 1794 to 1795 in f96deba
if displacement.dtype != dtype or displacement.device != device: | |
displacement = displacement.to(dtype=dtype, device=device) |
but relying on the noop behavior of .to()
to avoid the check on our side.
Reviewed By: vmoens Differential Revision: D50789094 fbshipit-source-id: 08418d28f3c67527a58fbb2dbc32fc1490213a00
Factoring out the changes to
_apply_grid_transform
from #7979. This pulls the squashing / unsquashing logic as well as theimage.numel() == 0
handling into_apply_grid_transform
to avoid repeating it in every kernel that uses it.cc @vfdev-5