-
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
[BC-breaking] Introduced InterpolationModes and deprecated arguments: resample and fillcolor #2952
[BC-breaking] Introduced InterpolationModes and deprecated arguments: resample and fillcolor #2952
Conversation
Replaced by interpolation and fill
Codecov Report
@@ Coverage Diff @@
## master #2952 +/- ##
==========================================
+ Coverage 72.18% 73.49% +1.30%
==========================================
Files 99 99
Lines 8806 8832 +26
Branches 1383 1397 +14
==========================================
+ Hits 6357 6491 +134
+ Misses 2012 1916 -96
+ Partials 437 425 -12
Continue to review full report at Codecov.
|
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.
@vfdev-5 Thanks for the PR.
I added one suggestion to improve BC during the deprecation period and marked all the places where this could happen. Nevertheless, if our policy is typically to only throw warnings feel free to ignore.
Also I noticed that in some methods you throw warnings while in others you directly replace the names. I assume that this is because the first are considered public API while the latter not. If that's true, then all good.
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 review @datumbox
I added one suggestion to improve BC during the deprecation period and marked all the places where this could happen. Nevertheless, if our policy is typically to only throw warnings feel free to ignore.
I agree that it is a good practice to provide until when the argument will remain in the API. I'd say by default, it can be 2 future minor releases, until 0.10.0. @fmassa any thoughts?
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.
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 @vfdev-5 !
I have one comment regarding the warning message, but it is not blocking for merge.
On a separate note that I would like to discuss here:
When was planning for the Tensor support for transforms, I started to wonder if we should move away from the interpolate=0
enums from PIL (= Image.NEAREST
etc), and instead use a more descriptive argument which could work even without the knowledge of PIL.
Two options came to my mind:
- replace
interpolate : int
withmode : str
as we have intorch.nn.functional.interpolate
- provide our own Enum for the interpolation mode in torchvision (and hope it works on torchscript)
Thoughts?
|
||
Returns: | ||
PIL Image or Tensor: Transformed image. | ||
""" | ||
if resample is not None: | ||
warnings.warn( | ||
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" |
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: I'm not a native English speaker, but I feel like since
might not be the best word here. I would have said instead
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" | |
"Argument resample is deprecated and will be removed in v0.10.0. Please, use interpolation instead" |
This is a minor nit (which applies to the other messages as well), so I'm not considering this as a merge-blocking issue.
If we would like to use an enum for interpolate, there can be two potential problems with torchscript: import torch
from enum import Enum
class Modes:
NEAREST = 0
BILINEAR = 1
def func(x: torch.Tensor, mode: Modes) -> torch.Tensor:
if mode == Modes.NEAREST:
return x + 1
elif mode == Modes.BILINEAR:
return x + 2
else:
return x
y = func(torch.rand(3, 4), Modes.NEAREST)
s_func = torch.jit.script(func)
|
However, the following works inside the script file import torch
from enum import Enum
class Modes(Enum):
NEAREST = 0
BILINEAR = 1
def func(x: torch.Tensor, mode: Modes) -> torch.Tensor:
if mode == Modes.NEAREST:
return x + 1
elif mode == Modes.BILINEAR:
return x + 2
else:
return x
if __name__ == "__main__":
y = func(torch.rand(3, 4), Modes.NEAREST)
s_func = torch.jit.script(func)
y = s_func(torch.rand(3, 4), Modes.NEAREST) According to pytorch/pytorch#42963 EDIT: removed |
It's great that we can use Enum's with torchscript, but it's weird that we would need to have it set as a |
Sorry, seems like |
…cate-resample-fillcolor
…nsight/vision into vfdev-5/deprecate-resample-fillcolor
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 PR looks good. Thanks a lot for the changes, they look great.
I understand that it's a design decision to maintain BC on the high-level transforms.py but not with the lower-level functional implementations, correct? Also, I noticed that on the backend implementations you use raw values for default (ints or strings) instead of their enums. Is this because of a JIT limitation?
BC change is "required" to switch from PIL.Image resampling mode. Almost no change in lower-level functional implementations is a sort of minimal change design.
We can certainly find a way to reuse |
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 me if I'm wrong, but I think the BC-breaking change that is introduced in here will break all user code that uses the transforms and I if that's the case I'm not sure this is something we can do in torchvision.
if not isinstance(img, torch.Tensor): | ||
return F_pil.resize(img, size=size, interpolation=interpolation) | ||
pil_interpolation = pil_modes_mapping[interpolation] |
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.
Interesting that accessing this as a global works with torchscript. I suppose torchscript can compile this branch out and then we don't have an error, but I would expect this to fail if that wasn't the case
…nsight/vision into vfdev-5/deprecate-resample-fillcolor
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.
|
||
Returns: | ||
PIL Image or Tensor: Rotated image. | ||
|
||
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters | ||
|
||
""" | ||
if resample is not None: | ||
warnings.warn( | ||
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" |
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.
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead" | |
"Argument resample is deprecated and will be removed in v0.10.0. Please, use interpolation instead" |
@fmassa I think enums are typically singular. Aka On a similar enum, I used |
… resample and fillcolor (pytorch#2952) * Deprecated arguments: resample and fillcolor Replaced by interpolation and fill * Updates according to the review * Added tests to check warnings and asserted BC * [WIP] Interpolation modes * Added InterpolationModes enum * Added supported for int values for interpolation for BC * Removed useless test code * Fix flake8
Related to #2479
InterpolationModes
resample
andfillcolor
interpolation
andfill
Context:
fill
is mainly used: 4 times in transforms and 3 times in functional vsfillcolor
is used 2 times in transforms and functional (RandomAffine and F.affine) => we can decide to replacefillcolor
byfill
and set a warning about argument deprecation.interpolation
is used 6 times in transforms/functional vsresample
is used 4 times in transforms/functional => we can similarly decide to replaceresample
byinterpolation
and set a warning about argument deprecation.