-
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
Fast rotation for right angles #8295
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8295
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New FailuresAs of commit 4260a3b with merge base c7bcfad (): NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hi @gau-nernst! 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 [email protected]. Thanks! |
@NicolasHug I signed the CLA but the status did not change. Not sure what went wrong. Do I need to use the same email as my GitHub account? I signed the CLA with a different email. Then I tried again with my GitHub email. Still no changes here. |
angle = angle % 360 # shift angle to [0, 360) range | ||
|
||
# fast path: transpose without affine transform | ||
if expand or center is None: |
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.
why if expand
?
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.
I was reading the NOTE section of v2.RandomRotation
, and it says that
setting center has no effect if expand=True
From what I understand, if expand=True
, we can ignore center
, and thus we can safely use torch.rot90()
.
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.
I think we can remove expand
from the check
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Regarding testing, I think we should test for angles 0, 90, 180, 270. Should I add them here? vision/test/test_transforms_v2.py Lines 1496 to 1503 in f3298dc
My concern is that it will create many more test cases. The alternative is to write a separate test for angles 0, 90, 180, 270, and we don't use too many values for other parameters ( |
Thanks @gau-nernst
Yes, we can probably create a small separate test to check these specific values, and simply test the output of PIL vs our tensor implementation |
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.
Thanks a lot @gau-nernst for the PR and @vfdev-5 for the reviews. This is good to go on my side, let's just wait for @vfdev-5 's input before merging
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 as well, thanks @gau-nernst !
angle = angle % 360 # shift angle to [0, 360) range | ||
|
||
# fast path: transpose without affine transform | ||
if center is None: |
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 tests are failing and I think it's because we should set expand
to True. When expand
is False we're not supposed to be changing the shape of the output (which is what rot90
does!).
if center is None: | |
if expand and center is None: |
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.
Here is what does PIL here:
https://github.com/python-pillow/Pillow/blob/8f63748e50378424628155994efd7e0739a4d1d1/src/PIL/Image.py#L2287-L2296
Yes, I agree that it is incorrect to omit expand for image with h != w, sorry for an incorrect suggestion previously.
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.
Should we also check for square input then? So even if expand is false, rot90 is still valid.
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.
Following their code they: 1) accept angle 0 and 180 whatever provided expand value and 2) for rotations 90 or 270 they do if angle in (90, 270) and (expand or self.width == self.height)
.
I think this is reasonable and we can do the same
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.
I will update accordingly
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.
I have updated the code. Also updated the test cases to cover everything. I just realized the tests didn't fail on my machine because I was running inside an environment with torchvision installed (big mistake!).
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.
No worries @gau-nernst thanks for the update. I can confirm the tests are passing now (tried locally). let's just wait for the CI to be green before merging
Hey @NicolasHug! You merged this PR, but no labels were added. |
Summary: Co-authored-by: Thien Tran <[email protected]> Reviewed By: vmoens Differential Revision: D55062767 fbshipit-source-id: b67a7f7fecab8a33143b95e6233637c336c74cd4
Fixes #8281
cc @vfdev-5