Unverified Commit 21790df9 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

Update deprecation messages stating APIs will be removed in 0.14 (#5387)



* properly deprecate legacy implementation

* cleanup

* use warning over deprecation directive

* remove patch version

* fix link in Kinetics docstring

* Some more

* fix affine functional tests
Co-authored-by: default avatarNicolas Hug <nicolashug@fb.com>
parent 97f543f3
...@@ -128,6 +128,7 @@ Video classification ...@@ -128,6 +128,7 @@ Video classification
:template: class_dataset.rst :template: class_dataset.rst
HMDB51 HMDB51
Kinetics
Kinetics400 Kinetics400
UCF101 UCF101
......
...@@ -2,6 +2,7 @@ import colorsys ...@@ -2,6 +2,7 @@ import colorsys
import itertools import itertools
import math import math
import os import os
import re
from typing import Sequence from typing import Sequence
import numpy as np import numpy as np
...@@ -23,7 +24,6 @@ from common_utils import ( ...@@ -23,7 +24,6 @@ from common_utils import (
) )
from torchvision.transforms import InterpolationMode from torchvision.transforms import InterpolationMode
NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC
...@@ -141,7 +141,13 @@ class TestRotate: ...@@ -141,7 +141,13 @@ class TestRotate:
def test_rotate_deprecation_resample(self): def test_rotate_deprecation_resample(self):
tensor, _ = _create_data(26, 26) tensor, _ = _create_data(26, 26)
# assert deprecation warning and non-BC # 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) res1 = F.rotate(tensor, 45, resample=2)
res2 = F.rotate(tensor, 45, interpolation=BILINEAR) res2 = F.rotate(tensor, 45, interpolation=BILINEAR)
assert_equal(res1, res2) assert_equal(res1, res2)
...@@ -365,7 +371,13 @@ class TestAffine: ...@@ -365,7 +371,13 @@ class TestAffine:
tensor, pil_img = _create_data(26, 26, device=device) tensor, pil_img = _create_data(26, 26, device=device)
# assert deprecation warning and non-BC # 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) 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) res2 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=BILINEAR)
assert_equal(res1, res2) assert_equal(res1, res2)
...@@ -376,7 +388,13 @@ class TestAffine: ...@@ -376,7 +388,13 @@ class TestAffine:
res2 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=BILINEAR) res2 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=BILINEAR)
assert_equal(res1, res2) 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) 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) 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. # we convert the PIL images to numpy as assert_equal doesn't work on PIL images.
......
import math import math
import os import os
import random import random
import re
from functools import partial from functools import partial
import numpy as np import numpy as np
...@@ -1828,7 +1829,13 @@ def test_random_rotation(): ...@@ -1828,7 +1829,13 @@ def test_random_rotation():
t.__repr__() t.__repr__()
# assert deprecation warning and non-BC # 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) t = transforms.RandomRotation((-10, 10), resample=2)
assert t.interpolation == transforms.InterpolationMode.BILINEAR assert t.interpolation == transforms.InterpolationMode.BILINEAR
...@@ -2167,11 +2174,23 @@ def test_random_affine(): ...@@ -2167,11 +2174,23 @@ def test_random_affine():
assert "bilinear" in t.__repr__() assert "bilinear" in t.__repr__()
# assert deprecation warning and non-BC # 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) t = transforms.RandomAffine(10, resample=2)
assert t.interpolation == transforms.InterpolationMode.BILINEAR 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) t = transforms.RandomAffine(10, fillcolor=10)
assert t.fill == 10 assert t.fill == 10
......
...@@ -36,8 +36,8 @@ inline bool double_compare(double a, double b) { ...@@ -36,8 +36,8 @@ inline bool double_compare(double a, double b) {
inline void deprecation_warning() { inline void deprecation_warning() {
TORCH_WARN_ONCE( TORCH_WARN_ONCE(
"The vision::models namespace is not actively maintained, use at " "The vision::models namespace is deprecated since 0.12 and will be "
"your own discretion. We recommend using Torch Script instead: " "removed in 0.14. We recommend using Torch Script instead: "
"https://pytorch.org/tutorials/advanced/cpp_export.html"); "https://pytorch.org/tutorials/advanced/cpp_export.html");
} }
......
...@@ -20,7 +20,7 @@ def _dl_wrap(tarpath: str, videopath: str, line: str) -> None: ...@@ -20,7 +20,7 @@ def _dl_wrap(tarpath: str, videopath: str, line: str) -> None:
class Kinetics(VisionDataset): 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. dataset.
Kinetics-400/600/700 are action recognition video datasets. Kinetics-400/600/700 are action recognition video datasets.
...@@ -49,6 +49,7 @@ class Kinetics(VisionDataset): ...@@ -49,6 +49,7 @@ class Kinetics(VisionDataset):
│ ├── class2 │ ├── class2
│ │ ├── clipx.mp4 │ │ ├── clipx.mp4
│ │ └── ... │ │ └── ...
Note: split is appended automatically using the split argument. Note: split is appended automatically using the split argument.
frames_per_clip (int): number of frames in a clip frames_per_clip (int): number of frames in a clip
num_classes (int): select between Kinetics-400 (default), Kinetics-600, and Kinetics-700 num_classes (int): select between Kinetics-400 (default), Kinetics-600, and Kinetics-700
...@@ -247,6 +248,10 @@ class Kinetics400(Kinetics): ...@@ -247,6 +248,10 @@ class Kinetics400(Kinetics):
`Kinetics-400 <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_ `Kinetics-400 <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
dataset. 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. Kinetics-400 is an action recognition video dataset.
This dataset consider every video as a collection of video clips of fixed size, specified 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 by ``frames_per_clip``, where the step in frames between each clip is given by
...@@ -300,8 +305,8 @@ class Kinetics400(Kinetics): ...@@ -300,8 +305,8 @@ class Kinetics400(Kinetics):
**kwargs: Any, **kwargs: Any,
) -> None: ) -> None:
warnings.warn( warnings.warn(
"Kinetics400 is deprecated and will be removed in a future release." "The Kinetics400 class is deprecated since 0.12 and will be removed in 0.14."
'It was replaced by Kinetics(..., num_classes="400").' "Please use Kinetics(..., num_classes='400') instead."
) )
if any(value is not None for value in (num_classes, split, download, num_download_workers)): if any(value is not None for value in (num_classes, split, download, num_download_workers)):
raise RuntimeError( raise RuntimeError(
......
...@@ -23,7 +23,7 @@ model_urls = { ...@@ -23,7 +23,7 @@ model_urls = {
class _DeprecatedConvBNAct(ConvNormActivation): class _DeprecatedConvBNAct(ConvNormActivation):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
warnings.warn( 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.", "Use torchvision.ops.misc.ConvNormActivation instead.",
FutureWarning, FutureWarning,
) )
......
...@@ -5,6 +5,6 @@ from . import * # noqa: F401, F403 ...@@ -5,6 +5,6 @@ from . import * # noqa: F401, F403
warnings.warn( warnings.warn(
"The 'torchvision.models.segmentation.segmentation' module is deprecated. Please use directly the parent module " "The 'torchvision.models.segmentation.segmentation' module is deprecated since 0.12 and will be removed in "
"instead." "0.14. Please use the 'torchvision.models.segmentation' directly instead."
) )
...@@ -288,13 +288,11 @@ class MultiScaleRoIAlign(nn.Module): ...@@ -288,13 +288,11 @@ class MultiScaleRoIAlign(nn.Module):
self.canonical_level = canonical_level self.canonical_level = canonical_level
def convert_to_roi_format(self, boxes: List[Tensor]) -> Tensor: def convert_to_roi_format(self, boxes: List[Tensor]) -> Tensor:
# TODO: deprecate eventually warnings.warn("The 'convert_to_roi_format' method is deprecated since 0.12 and will be removed in 0.14.")
warnings.warn("`convert_to_roi_format` will no loger be public in future releases.", FutureWarning)
return _convert_to_roi_format(boxes) return _convert_to_roi_format(boxes)
def infer_scale(self, feature: Tensor, original_size: List[int]) -> float: def infer_scale(self, feature: Tensor, original_size: List[int]) -> float:
# TODO: deprecate eventually warnings.warn("The 'infer_scale' method is deprecated since 0.12 and will be removed in 0.14.")
warnings.warn("`infer_scale` will no loger be public in future releases.", FutureWarning)
return _infer_scale(feature, original_size) return _infer_scale(feature, original_size)
def setup_setup_scales( def setup_setup_scales(
...@@ -302,8 +300,7 @@ class MultiScaleRoIAlign(nn.Module): ...@@ -302,8 +300,7 @@ class MultiScaleRoIAlign(nn.Module):
features: List[Tensor], features: List[Tensor],
image_shapes: List[Tuple[int, int]], image_shapes: List[Tuple[int, int]],
) -> None: ) -> None:
# TODO: deprecate eventually warnings.warn("The 'setup_setup_scales' method is deprecated since 0.12 and will be removed in 0.14.")
warnings.warn("`setup_setup_scales` will no loger be public in future releases.", FutureWarning)
self.scales, self.map_levels = _setup_scales(features, image_shapes, self.canonical_scale, self.canonical_level) self.scales, self.map_levels = _setup_scales(features, image_shapes, self.canonical_scale, self.canonical_level)
def forward( def forward(
......
...@@ -3,7 +3,10 @@ import warnings ...@@ -3,7 +3,10 @@ import warnings
import torch 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): def _is_tensor_video_clip(clip):
......
...@@ -22,7 +22,10 @@ __all__ = [ ...@@ -22,7 +22,10 @@ __all__ = [
] ]
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): class RandomCropVideo(RandomCrop):
......
...@@ -1025,6 +1025,10 @@ def rotate( ...@@ -1025,6 +1025,10 @@ def rotate(
.. note:: .. note::
In torchscript mode single int/float value is not supported, please use a sequence In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``. 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: Returns:
PIL Image or Tensor: Rotated image. PIL Image or Tensor: Rotated image.
...@@ -1036,7 +1040,8 @@ def rotate( ...@@ -1036,7 +1040,8 @@ def rotate(
_log_api_usage_once(rotate) _log_api_usage_once(rotate)
if resample is not None: if resample is not None:
warnings.warn( 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) interpolation = _interpolation_modes_from_int(resample)
...@@ -1107,10 +1112,13 @@ def affine( ...@@ -1107,10 +1112,13 @@ def affine(
.. note:: .. note::
In torchscript mode single int/float value is not supported, please use a sequence In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``. of length 1: ``[value, ]``.
fillcolor (sequence, int, float): deprecated argument and will be removed since v0.10.0. fillcolor (sequence or number, optional):
Please use the ``fill`` parameter instead. .. warning::
resample (int, optional): deprecated argument and will be removed since v0.10.0. This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``fill`` instead.
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.
center (sequence, optional): Optional center of rotation. Origin is the upper left corner. center (sequence, optional): Optional center of rotation. Origin is the upper left corner.
Default is the center of the image. Default is the center of the image.
...@@ -1121,7 +1129,8 @@ def affine( ...@@ -1121,7 +1129,8 @@ def affine(
_log_api_usage_once(affine) _log_api_usage_once(affine)
if resample is not None: if resample is not None:
warnings.warn( 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) interpolation = _interpolation_modes_from_int(resample)
...@@ -1134,7 +1143,10 @@ def affine( ...@@ -1134,7 +1143,10 @@ def affine(
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
if fillcolor is not None: 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 fill = fillcolor
if not isinstance(angle, (int, float)): if not isinstance(angle, (int, float)):
......
...@@ -1272,8 +1272,10 @@ class RandomRotation(torch.nn.Module): ...@@ -1272,8 +1272,10 @@ class RandomRotation(torch.nn.Module):
Default is the center of the image. Default is the center of the image.
fill (sequence or number): Pixel fill value for the area outside the rotated 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. 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. resample (int, optional):
Please use the ``interpolation`` parameter instead. .. 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 .. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
...@@ -1286,7 +1288,8 @@ class RandomRotation(torch.nn.Module): ...@@ -1286,7 +1288,8 @@ class RandomRotation(torch.nn.Module):
_log_api_usage_once(self) _log_api_usage_once(self)
if resample is not None: if resample is not None:
warnings.warn( 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) interpolation = _interpolation_modes_from_int(resample)
...@@ -1383,10 +1386,13 @@ class RandomAffine(torch.nn.Module): ...@@ -1383,10 +1386,13 @@ class RandomAffine(torch.nn.Module):
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable. 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 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. 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. fillcolor (sequence or number, optional):
Please use the ``fill`` parameter instead. .. warning::
resample (int, optional): deprecated argument and will be removed since v0.10.0. This parameter was deprecated in ``0.12`` and will be removed in ``0.14``. Please use ``fill`` instead.
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.
center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner. center (sequence, optional): Optional center of rotation, (x, y). Origin is the upper left corner.
Default is the center of the image. Default is the center of the image.
...@@ -1410,7 +1416,8 @@ class RandomAffine(torch.nn.Module): ...@@ -1410,7 +1416,8 @@ class RandomAffine(torch.nn.Module):
_log_api_usage_once(self) _log_api_usage_once(self)
if resample is not None: if resample is not None:
warnings.warn( 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) interpolation = _interpolation_modes_from_int(resample)
...@@ -1424,7 +1431,8 @@ class RandomAffine(torch.nn.Module): ...@@ -1424,7 +1431,8 @@ class RandomAffine(torch.nn.Module):
if fillcolor is not None: if fillcolor is not None:
warnings.warn( 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 fill = fillcolor
......
...@@ -43,6 +43,10 @@ def make_grid( ...@@ -43,6 +43,10 @@ def make_grid(
value_range (tuple, optional): tuple (min, max) where min and max are numbers, 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 then these numbers are used to normalize the image. By default, min and max
are computed from the tensor. 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 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``. images separately rather than the (min, max) over all images. Default: ``False``.
pad_value (float, optional): Value for the padded pixels. Default: ``0``. pad_value (float, optional): Value for the padded pixels. Default: ``0``.
...@@ -56,8 +60,10 @@ def make_grid( ...@@ -56,8 +60,10 @@ def make_grid(
raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}") raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}")
if "range" in kwargs.keys(): if "range" in kwargs.keys():
warning = "range will be deprecated, please use value_range instead." warnings.warn(
warnings.warn(warning) "The parameter 'range' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'value_range' instead."
)
value_range = kwargs["range"] value_range = kwargs["range"]
# if list of tensors, convert to a 4D mini-batch Tensor # if list of tensors, convert to a 4D mini-batch Tensor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment