Description
Currently the following interpolation modes are allowed
vision/torchvision/transforms/functional.py
Lines 21 to 32 in 7046e56
Since torch==1.11.0
(pytorch/pytorch#64501 of @vfdev-5 to be exact), torch.nn.functional
also supports mode="nearest-exact"
:
Mode
mode='nearest-exact'
matches Scikit-Image and PIL nearest neighbours interpolation algorithms and fixes known issues withmode='nearest'
. This mode is introduced to keep backward compatibility. Modemode='nearest'
matches buggy OpenCV'sINTER_NEAREST
interpolation algorithm.
Given that we are aligning more with PIL and "nearest"
is described as "buggy", can we add support for "nearest-exact"
?
If yes, we should also think about changing all our default values to it. That might be a bit cumbersome for the users, but we could also remap its name. Meaning after the whole deprecation period is through, "nearest"
just maps to "nearest-exact"
of interpolate
and we have a "nearest-legacy"
or the like that maps to "nearest"
. We already do a name mapping for other interpolation modes:
vision/torchvision/transforms/functional_tensor.py
Lines 412 to 414 in 7046e56
Deprecation process could look like this where r
denotes the current release.
-
r+1
: add"nearest-exact"
as valid interpolation mode and deprecate not passing a value explicitly. Plus, this should add a"nearest-legacy"
that aliases the current"nearest"
. We also need to warn if"nearest"
is passed that the behavior will change in the future.def foo(..., mode=None): if mode is None: warnings.warn("Not passing a default value is deprecated.") mode = "nearest-legacy" elif mode == "nearest": warnings.warn( "Nearest is deprecated. Use nearest-legacy for the current behavior " "or nearest-exact for the future behavior" )
-
r+2
: fail if interpolation mode is not passed explicitly or"nearest"
is passed. -
r+3
: re-introduce"nearest"
as default value for the interpolation mode, but map it internally to"nearest-exact"
.
Activity