-
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
Unified input for resize op #2394
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2394 +/- ##
==========================================
- Coverage 70.69% 70.53% -0.16%
==========================================
Files 94 94
Lines 7839 7895 +56
Branches 1221 1241 +20
==========================================
+ Hits 5542 5569 +27
- Misses 1925 1943 +18
- Partials 372 383 +11
Continue to review full report at Codecov.
|
d69e4b1
to
965ad6b
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 a lot for the PR!
I have a couple of minor comments, otherwise the PR looks good to merge
@@ -1,3 +1,5 @@ | |||
from PIL.Image import NEAREST, BILINEAR, BICUBIC |
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.
nit: this doesn't seem to be used?
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.
Correct. Will remove it
"{} element tuple/list".format(len(size))) | ||
|
||
if interpolation not in [0, 1, 2, 3, 4]: | ||
raise ValueError("Interpolation mode should be either constant, edge, reflect or symmetric") |
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.
error message seems off?
size = list(size) | ||
|
||
if isinstance(size, list) and len(size) not in [1, 2]: | ||
raise ValueError("Padding must be an int or a 1 or 2 element tuple/list, not a " + |
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.
error message seems off?
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 !
# E.g. resized_tensor = [[a, a, b, c, d, d, e, ...]] | ||
# E.g. resized_pil_img = [[a, b, c, c, d, e, f, ...]] |
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.
It's a pity that the behavior of nearest
interpolate is different between implementations, I would say it could be worth opening an issue in PyTorch to mention this. I also believe that PIL and OpenCV are consistent, which would make for a case to maybe change the implementation in PyTorch to make this more consistent.
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.
Let me check that between PIL and OpenCV and then we decide about PyTorch.
raise ValueError("Padding must be an int or a 1 or 2 element tuple/list, not a " + | ||
"{} element tuple/list".format(len(size))) | ||
|
||
if interpolation not in [0, 1, 2, 3, 4]: |
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.
Looks like we don't support mode 1
in the _interpolation_modes
?
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!
Let's merge this now, and then discuss if we should open an issue in PyTorch to propose to change the behavior of nearest interpolate.
|
||
if need_cast: | ||
if mode == "bicubic": | ||
img = img.clamp(min=0, max=255) |
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.
nit: for the future, we might want to change the 255
value to be dtype-dependent. But this can be done in a future, maybe using convert_image_dtype
before and after interpolate is called.
* [WIP] F.resize with tensor * Adapted T.Resize and F.resize with a test * According to the review, fixed copy-pasted messages and unused imports
Related to #2292
Description:
T.Resize
,F.resize
andF_t.resize
Remark: