Skip to content

properly deprecate legacy implementation #5387

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

Merged
merged 10 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Video classification
:template: class_dataset.rst

HMDB51
Kinetics
Kinetics400
UCF101

Expand Down
26 changes: 22 additions & 4 deletions test/test_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import itertools
import math
import os
import re
from typing import Sequence

import numpy as np
Expand All @@ -23,7 +24,6 @@
)
from torchvision.transforms import InterpolationMode


NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC


Expand Down Expand Up @@ -141,7 +141,13 @@ def test_rotate_batch(self, device, dt):
def test_rotate_deprecation_resample(self):
tensor, _ = _create_data(26, 26)
# assert deprecation warning and non-BC
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
),
):
res1 = F.rotate(tensor, 45, resample=2)
res2 = F.rotate(tensor, 45, interpolation=BILINEAR)
assert_equal(res1, res2)
Expand Down Expand Up @@ -365,7 +371,13 @@ def test_warnings(self, device):
tensor, pil_img = _create_data(26, 26, device=device)

# assert deprecation warning and non-BC
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'resample' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'interpolation' instead."
),
):
res1 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], resample=2)
res2 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=BILINEAR)
assert_equal(res1, res2)
Expand All @@ -376,7 +388,13 @@ def test_warnings(self, device):
res2 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=BILINEAR)
assert_equal(res1, res2)

with pytest.warns(UserWarning, match=r"Argument fillcolor is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'fill' instead."
),
):
res1 = F.affine(pil_img, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], fillcolor=10)
res2 = F.affine(pil_img, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], fill=10)
# we convert the PIL images to numpy as assert_equal doesn't work on PIL images.
Expand Down
25 changes: 22 additions & 3 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
import os
import random
import re
from functools import partial

import numpy as np
Expand Down Expand Up @@ -1828,7 +1829,13 @@ def test_random_rotation():
t.__repr__()

# assert deprecation warning and non-BC
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
),
):
t = transforms.RandomRotation((-10, 10), resample=2)
assert t.interpolation == transforms.InterpolationMode.BILINEAR

Expand Down Expand Up @@ -2167,11 +2174,23 @@ def test_random_affine():
assert "bilinear" in t.__repr__()

# assert deprecation warning and non-BC
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'resample' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'interpolation' instead."
),
):
t = transforms.RandomAffine(10, resample=2)
assert t.interpolation == transforms.InterpolationMode.BILINEAR

with pytest.warns(UserWarning, match=r"Argument fillcolor is deprecated and will be removed"):
with pytest.warns(
UserWarning,
match=re.escape(
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'fill' instead."
),
):
t = transforms.RandomAffine(10, fillcolor=10)
assert t.fill == 10

Expand Down
4 changes: 2 additions & 2 deletions torchvision/csrc/models/modelsimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ inline bool double_compare(double a, double b) {

inline void deprecation_warning() {
TORCH_WARN_ONCE(
"The vision::models namespace is not actively maintained, use at "
"your own discretion. We recommend using Torch Script instead: "
"The vision::models namespace is deprecated since 0.12 and will be "
"removed in 0.14. We recommend using Torch Script instead: "
"https://pytorch.org/tutorials/advanced/cpp_export.html");
}

Expand Down
11 changes: 8 additions & 3 deletions torchvision/datasets/kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _dl_wrap(tarpath: str, videopath: str, line: str) -> None:


class Kinetics(VisionDataset):
"""` Generic Kinetics <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
"""`Generic Kinetics <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
dataset.

Kinetics-400/600/700 are action recognition video datasets.
Expand Down Expand Up @@ -49,6 +49,7 @@ class Kinetics(VisionDataset):
│ ├── class2
│ │ ├── clipx.mp4
│ │ └── ...

Note: split is appended automatically using the split argument.
frames_per_clip (int): number of frames in a clip
num_classes (int): select between Kinetics-400 (default), Kinetics-600, and Kinetics-700
Expand Down Expand Up @@ -247,6 +248,10 @@ class Kinetics400(Kinetics):
`Kinetics-400 <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
dataset.

.. warning::
This class was deprecated in ``0.12`` and will be removed in ``0.14``. Please use
``Kinetics(..., num_classes='400')`` instead.

Kinetics-400 is an action recognition video dataset.
This dataset consider every video as a collection of video clips of fixed size, specified
by ``frames_per_clip``, where the step in frames between each clip is given by
Expand Down Expand Up @@ -300,8 +305,8 @@ def __init__(
**kwargs: Any,
) -> None:
warnings.warn(
"Kinetics400 is deprecated and will be removed in a future release."
'It was replaced by Kinetics(..., num_classes="400").'
"The Kinetics400 class is deprecated since 0.12 and will be removed in 0.14."
"Please use Kinetics(..., num_classes='400') instead."
)
if any(value is not None for value in (num_classes, split, download, num_download_workers)):
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class _DeprecatedConvBNAct(ConvNormActivation):
def __init__(self, *args, **kwargs):
warnings.warn(
"The ConvBNReLU/ConvBNActivation classes are deprecated and will be removed in future versions. "
"The ConvBNReLU/ConvBNActivation classes are deprecated since 0.12 and will be removed in 0.14. "
"Use torchvision.ops.misc.ConvNormActivation instead.",
FutureWarning,
)
Expand Down
4 changes: 2 additions & 2 deletions torchvision/models/segmentation/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


warnings.warn(
"The 'torchvision.models.segmentation.segmentation' module is deprecated. Please use directly the parent module "
"instead."
"The 'torchvision.models.segmentation.segmentation' module is deprecated since 0.12 and will be removed in "
"0.14. Please use the 'torchvision.models.segmentation' directly instead."
)
9 changes: 3 additions & 6 deletions torchvision/ops/poolers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,19 @@ def __init__(
self.canonical_level = canonical_level

def convert_to_roi_format(self, boxes: List[Tensor]) -> Tensor:
# TODO: deprecate eventually
warnings.warn("`convert_to_roi_format` will no loger be public in future releases.", FutureWarning)
warnings.warn("The 'convert_to_roi_format' method is deprecated since 0.12 and will be removed in 0.14.")
return _convert_to_roi_format(boxes)

def infer_scale(self, feature: Tensor, original_size: List[int]) -> float:
# TODO: deprecate eventually
warnings.warn("`infer_scale` will no loger be public in future releases.", FutureWarning)
warnings.warn("The 'infer_scale' method is deprecated since 0.12 and will be removed in 0.14.")
return _infer_scale(feature, original_size)

def setup_setup_scales(
self,
features: List[Tensor],
image_shapes: List[Tuple[int, int]],
) -> None:
# TODO: deprecate eventually
warnings.warn("`setup_setup_scales` will no loger be public in future releases.", FutureWarning)
warnings.warn("The 'setup_setup_scales' method is deprecated since 0.12 and will be removed in 0.14.")
self.scales, self.map_levels = _setup_scales(features, image_shapes, self.canonical_scale, self.canonical_level)

def forward(
Expand Down
5 changes: 4 additions & 1 deletion torchvision/transforms/_functional_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import torch


warnings.warn("The _functional_video module is deprecated. Please use the functional module instead.")
warnings.warn(
"The 'torchvision.transforms._functional_video' module is deprecated since 0.12 and will be removed in 0.14. "
"Please use the 'torchvision.transforms.functional' module instead."
)


def _is_tensor_video_clip(clip):
Expand Down
5 changes: 4 additions & 1 deletion torchvision/transforms/_transforms_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
]


warnings.warn("The _transforms_video module is deprecated. Please use the transforms module instead.")
warnings.warn(
"The 'torchvision.transforms._transforms_video' module is deprecated since 0.12 and will be removed in 0.14. "
"Please use the 'torchvision.transforms' module instead."
)


class RandomCropVideo(RandomCrop):
Expand Down
26 changes: 19 additions & 7 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,10 @@ def rotate(
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
resample (int, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``interpolation``
instead.

Returns:
PIL Image or Tensor: Rotated image.
Expand All @@ -1036,7 +1040,8 @@ def rotate(
_log_api_usage_once(rotate)
if resample is not None:
warnings.warn(
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)

Expand Down Expand Up @@ -1107,10 +1112,13 @@ def affine(
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
fillcolor (sequence, int, float): deprecated argument and will be removed since v0.10.0.
Please use the ``fill`` parameter instead.
resample (int, optional): deprecated argument and will be removed since v0.10.0.
Please use the ``interpolation`` parameter instead.
fillcolor (sequence or number, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``fill`` instead.
resample (int, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``interpolation``
instead.
center (sequence, optional): Optional center of rotation. Origin is the upper left corner.
Default is the center of the image.

Expand All @@ -1121,7 +1129,8 @@ def affine(
_log_api_usage_once(affine)
if resample is not None:
warnings.warn(
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
"The parameter 'resample' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)

Expand All @@ -1134,7 +1143,10 @@ def affine(
interpolation = _interpolation_modes_from_int(interpolation)

if fillcolor is not None:
warnings.warn("Argument fillcolor is deprecated and will be removed since v0.10.0. Please, use fill instead")
warnings.warn(
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'fill' instead."
)
fill = fillcolor

if not isinstance(angle, (int, float)):
Expand Down
26 changes: 17 additions & 9 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,10 @@ class RandomRotation(torch.nn.Module):
Default is the center of the image.
fill (sequence or number): Pixel fill value for the area outside the rotated
image. Default is ``0``. If given a number, the value is used for all bands respectively.
resample (int, optional): deprecated argument and will be removed since v0.10.0.
Please use the ``interpolation`` parameter instead.
resample (int, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``interpolation``
instead.

.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters

Expand All @@ -1286,7 +1288,8 @@ def __init__(
_log_api_usage_once(self)
if resample is not None:
warnings.warn(
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)

Expand Down Expand Up @@ -1383,10 +1386,13 @@ class RandomAffine(torch.nn.Module):
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (sequence or number): Pixel fill value for the area outside the transformed
image. Default is ``0``. If given a number, the value is used for all bands respectively.
fillcolor (sequence or number, optional): deprecated argument and will be removed since v0.10.0.
Please use the ``fill`` parameter instead.
resample (int, optional): deprecated argument and will be removed since v0.10.0.
Please use the ``interpolation`` parameter instead.
fillcolor (sequence or number, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``fill`` instead.
resample (int, optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``interpolation``
instead.
center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner.
Default is the center of the image.

Expand All @@ -1410,7 +1416,8 @@ def __init__(
_log_api_usage_once(self)
if resample is not None:
warnings.warn(
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
"The parameter 'resample' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)

Expand All @@ -1424,7 +1431,8 @@ def __init__(

if fillcolor is not None:
warnings.warn(
"Argument fillcolor is deprecated and will be removed since v0.10.0. Please, use fill instead"
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'fill' instead."
)
fill = fillcolor

Expand Down
10 changes: 8 additions & 2 deletions torchvision/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def make_grid(
value_range (tuple, optional): tuple (min, max) where min and max are numbers,
then these numbers are used to normalize the image. By default, min and max
are computed from the tensor.
range (tuple. optional):
.. warning::
This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``value_range``
instead.
scale_each (bool, optional): If ``True``, scale each image in the batch of
images separately rather than the (min, max) over all images. Default: ``False``.
pad_value (float, optional): Value for the padded pixels. Default: ``0``.
Expand All @@ -56,8 +60,10 @@ def make_grid(
raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}")

if "range" in kwargs.keys():
warning = "range will be deprecated, please use value_range instead."
warnings.warn(warning)
warnings.warn(
"The parameter 'range' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'value_range' instead."
)
value_range = kwargs["range"]

# if list of tensors, convert to a 4D mini-batch Tensor
Expand Down