-
Notifications
You must be signed in to change notification settings - Fork 7k
Unified input for F.affine #2444
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
Conversation
d7ae44c
to
f33b391
Compare
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 for the PR!
Test failures seems related, but otherwise the PR looks good to me.
torchvision/transforms/functional.py
Outdated
@@ -1,12 +1,11 @@ | |||
import math | |||
import numbers | |||
import warnings | |||
from collections.abc import Iterable | |||
from typing import Any | |||
from typing import Any, Optional, Sequence | |||
|
|||
import numpy as np | |||
from numpy import sin, cos, tan |
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.
maybe this import is not needed anymore?
test/test_transforms.py
Outdated
# Accept 3 wrong pixels | ||
self.assertLess(n_diff_pixels, 3, | ||
# Accept 7 wrong pixels | ||
self.assertLess(n_diff_pixels, 7, |
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.
Was this test flaky before? Or is this needed due to the change in the center of the transform pixel (the +0.5
is added in a different location now)
|
||
if need_cast: | ||
# it is better to round before cast | ||
img = torch.round(img).to(out_dtype) |
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 saw you did this round
for a couple of functions, does it make results closer to PIL?
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.
Yes, rounding makes sense for example when floating results is
tensor([[ 0.09, 1.01, 1.97, 2.96, 3.99],
[10.94, 12.15, 13.35, 14.56, 15.77],
[22.92, 24.13, 25.34, 26.54, 27.75],
[34.90, 36.11, 37.32, 38.53, 39.73],
[46.88, 48.09, 49.30, 50.51, 51.72]])
and so casting without round gives
tensor([[ 0, 1, 1, 2, 3],
[10, 12, 13, 14, 15],
[22, 24, 25, 26, 27],
[34, 36, 37, 38, 39],
[46, 48, 49, 50, 51]], dtype=torch.uint8)
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 @vfdev-5 !
Related to #2292
Description:
=> adapted corresponding tests on PIL images.