Unverified Commit 7b8a6db7 authored by Nicolas Hug's avatar Nicolas Hug Committed by GitHub
Browse files

Remove deprecated APIs for 0.14 (#6258)



* Remove Kinetics400 class

* Remove '2007-test' in VOC

* Remove some MobileNet layer classes

* Remove torchvision/models/segmentation/segmentation.py

* Remove some MultiScaleRoIAlign methods

* Remove torchvision/transforms/_functional_video.py

* Remove torchvision/transforms/_transforms_video.py

* Remove resample parameter in transforms

* Remove 'range' parameter

* Remove 'fill_value' parameter in transforms

* Revert to original warning for C++ models - looks like we should still keep them around?

* pre-commit

* Fix docs

* Remove test/test_transforms_video.py

* Some fixes

* Remove more tests

* Revert changes to C++ models

* Add back _transforms_video and change warning message

* Change back the warning message, and will change the warning message on separate PR
Co-authored-by: default avatarYosuaMichael <yosuamichaelm@gmail.com>
Co-authored-by: default avatarYosua Michael Maranatha <yosuamichael@fb.com>
parent 0fd4736e
......@@ -147,7 +147,6 @@ Video classification
HMDB51
Kinetics
Kinetics400
UCF101
......
......@@ -620,11 +620,7 @@ class VOCSegmentationTestCase(datasets_utils.ImageDatasetTestCase):
)
def inject_fake_data(self, tmpdir, config):
year, is_test_set = (
("2007", True)
if config["year"] == "2007-test" or config["image_set"] == "test"
else (config["year"], False)
)
year, is_test_set = config["year"], config["image_set"] == "test"
image_set = config["image_set"]
base_dir = pathlib.Path(tmpdir)
......@@ -965,25 +961,6 @@ class KineticsTestCase(datasets_utils.VideoDatasetTestCase):
return num_videos_per_class * len(classes)
class Kinetics400TestCase(datasets_utils.VideoDatasetTestCase):
DATASET_CLASS = datasets.Kinetics400
def inject_fake_data(self, tmpdir, config):
classes = ("Abseiling", "Zumba")
num_videos_per_class = 2
digits = string.ascii_letters + string.digits + "-_"
for cls in classes:
datasets_utils.create_video_folder(
tmpdir,
cls,
lambda _: f"{datasets_utils.create_random_string(11, digits)}.avi",
num_videos_per_class,
)
return num_videos_per_class * len(classes)
class HMDB51TestCase(datasets_utils.VideoDatasetTestCase):
DATASET_CLASS = datasets.HMDB51
......
......@@ -245,6 +245,7 @@ def cifar100():
def voc():
# TODO: Also test the "2007-test" key
return itertools.chain(
*[
collect_download_configs(
......@@ -252,7 +253,7 @@ def voc():
name=f"VOC, {year}",
file="voc",
)
for year in ("2007", "2007-test", "2008", "2009", "2010", "2011", "2012")
for year in ("2007", "2008", "2009", "2010", "2011", "2012")
]
)
......
......@@ -139,20 +139,6 @@ class TestRotate:
center = (20, 22)
_test_fn_on_batch(batch_tensors, F.rotate, angle=32, interpolation=NEAREST, expand=True, center=center)
def test_rotate_deprecation_resample(self):
tensor, _ = _create_data(26, 26)
# assert deprecation warning and non-BC
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)
def test_rotate_interpolation_type(self):
tensor, _ = _create_data(26, 26)
# assert changed type warning
......@@ -377,18 +363,6 @@ class TestAffine:
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=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)
# assert changed type warning
with pytest.warns(
UserWarning,
......@@ -401,18 +375,6 @@ class TestAffine:
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=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.
assert_equal(np.asarray(res1), np.asarray(res2))
def _get_data_dims_and_points_for_perspective():
# Ideally we would parametrize independently over data dims and points, but
......
......@@ -1866,17 +1866,6 @@ def test_random_rotation():
# Checking if RandomRotation can be printed as string
t.__repr__()
# assert deprecation warning and non-BC
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
# assert changed type warning
with pytest.warns(
UserWarning,
......@@ -2217,27 +2206,6 @@ def test_random_affine():
t = transforms.RandomAffine(10, interpolation=transforms.InterpolationMode.BILINEAR)
assert "bilinear" in t.__repr__()
# assert deprecation warning and non-BC
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=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
# assert changed type warning
with pytest.warns(
UserWarning,
......
......@@ -31,7 +31,7 @@ from .gtsrb import GTSRB
from .hmdb51 import HMDB51
from .imagenet import ImageNet
from .inaturalist import INaturalist
from .kinetics import Kinetics, Kinetics400
from .kinetics import Kinetics
from .kitti import Kitti
from .lfw import LFWPairs, LFWPeople
from .lsun import LSUN, LSUNClass
......@@ -92,7 +92,6 @@ __all__ = (
"SBDataset",
"VisionDataset",
"USPS",
"Kinetics400",
"Kinetics",
"HMDB51",
"UCF101",
......
......@@ -2,7 +2,6 @@ import csv
import os
import time
import urllib
import warnings
from functools import partial
from multiprocessing import Pool
from os import path
......@@ -246,83 +245,3 @@ class Kinetics(VisionDataset):
video = self.transform(video)
return video, audio, label
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
``step_between_clips``.
To give an example, for 2 videos with 10 and 15 frames respectively, if ``frames_per_clip=5``
and ``step_between_clips=5``, the dataset size will be (2 + 3) = 5, where the first two
elements will come from video 1, and the next three elements from video 2.
Note that we drop clips which do not have exactly ``frames_per_clip`` elements, so not all
frames in a video might be present.
Internally, it uses a VideoClips object to handle clip creation.
Args:
root (string): Root directory of the Kinetics-400 Dataset. Should be structured as follows:
.. code::
root/
├── class1
│ ├── clip1.avi
│ ├── clip2.avi
│ ├── clip3.mp4
│ └── ...
└── class2
├── clipx.avi
└── ...
frames_per_clip (int): number of frames in a clip
step_between_clips (int): number of frames between each clip
transform (callable, optional): A function/transform that takes in a TxHxWxC video
and returns a transformed version.
Returns:
tuple: A 3-tuple with the following entries:
- video (Tensor[T, H, W, C]): the `T` video frames
- audio(Tensor[K, L]): the audio frames, where `K` is the number of channels
and `L` is the number of points
- label (int): class of the video clip
"""
def __init__(
self,
root: str,
frames_per_clip: int,
num_classes: Any = None,
split: Any = None,
download: Any = None,
num_download_workers: Any = None,
**kwargs: Any,
) -> None:
warnings.warn(
"The Kinetics400 class is deprecated since 0.12 and will be removed in 0.14."
"Please use Kinetics(..., num_classes='400') instead."
"Note that Kinetics(..., num_classes='400') returns video in a Tensor[T, C, H, W] format."
)
if any(value is not None for value in (num_classes, split, download, num_download_workers)):
raise RuntimeError(
"Usage of 'num_classes', 'split', 'download', or 'num_download_workers' is not supported in "
"Kinetics400. Please use Kinetics instead."
)
super().__init__(
root=root,
frames_per_clip=frames_per_clip,
_legacy=True,
**kwargs,
)
......@@ -8,7 +8,6 @@ try:
from defusedxml.ElementTree import parse as ET_parse
except ImportError:
from xml.etree.ElementTree import parse as ET_parse
import warnings
from typing import Any, Callable, Dict, List, Optional, Tuple
from PIL import Image
......@@ -77,20 +76,8 @@ class _VOCBase(VisionDataset):
transforms: Optional[Callable] = None,
):
super().__init__(root, transforms, transform, target_transform)
if year == "2007-test":
if image_set == "test":
warnings.warn(
"Accessing the test image set of the year 2007 with year='2007-test' is deprecated "
"since 0.12 and will be removed in 0.14. "
"Please use the combination year='2007' and image_set='test' instead."
)
year = "2007"
else:
raise ValueError(
"In the test image set of the year 2007 only image_set='test' is allowed. "
"For all other image sets use year='2007' instead."
)
self.year = year
self.year = verify_str_arg(year, "year", valid_values=[str(yr) for yr in range(2007, 2013)])
valid_image_sets = ["train", "trainval", "val"]
if year == "2007":
......
import warnings
from functools import partial
from typing import Any, Callable, List, Optional
......@@ -17,24 +16,6 @@ __all__ = ["MobileNetV2", "MobileNet_V2_Weights", "mobilenet_v2"]
# necessary for backwards compatibility
class _DeprecatedConvBNAct(Conv2dNormActivation):
def __init__(self, *args, **kwargs):
warnings.warn(
"The ConvBNReLU/ConvBNActivation classes are deprecated since 0.12 and will be removed in 0.14. "
"Use torchvision.ops.misc.Conv2dNormActivation instead.",
FutureWarning,
)
if kwargs.get("norm_layer", None) is None:
kwargs["norm_layer"] = nn.BatchNorm2d
if kwargs.get("activation_layer", None) is None:
kwargs["activation_layer"] = nn.ReLU6
super().__init__(*args, **kwargs)
ConvBNReLU = _DeprecatedConvBNAct
ConvBNActivation = _DeprecatedConvBNAct
class InvertedResidual(nn.Module):
def __init__(
self, inp: int, oup: int, stride: int, expand_ratio: int, norm_layer: Optional[Callable[..., nn.Module]] = None
......
import warnings
from functools import partial
from typing import Any, Callable, List, Optional, Sequence
......@@ -22,21 +21,6 @@ __all__ = [
]
class SqueezeExcitation(SElayer):
"""DEPRECATED"""
def __init__(self, input_channels: int, squeeze_factor: int = 4):
squeeze_channels = _make_divisible(input_channels // squeeze_factor, 8)
super().__init__(input_channels, squeeze_channels, scale_activation=nn.Hardsigmoid)
self.relu = self.activation
delattr(self, "activation")
warnings.warn(
"This SqueezeExcitation class is deprecated since 0.12 and will be removed in 0.14. "
"Use torchvision.ops.SqueezeExcitation instead.",
FutureWarning,
)
class InvertedResidualConfig:
# Stores information listed at Tables 1 and 2 of the MobileNetV3 paper
def __init__(
......
import warnings
# Import all methods/classes for BC:
from . import * # noqa: F401, F403
warnings.warn(
"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."
)
import warnings
from typing import Dict, List, Optional, Tuple, Union
import torch
......@@ -287,22 +286,6 @@ class MultiScaleRoIAlign(nn.Module):
self.canonical_scale = canonical_scale
self.canonical_level = canonical_level
def convert_to_roi_format(self, boxes: List[Tensor]) -> Tensor:
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:
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:
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(
self,
x: Dict[str, Tensor],
......
......@@ -1051,7 +1051,6 @@ def rotate(
expand: bool = False,
center: Optional[List[int]] = None,
fill: Optional[List[float]] = None,
resample: Optional[int] = None,
) -> Tensor:
"""Rotate the image by angle.
If the image is torch Tensor, it is expected
......@@ -1077,11 +1076,6 @@ 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.
......@@ -1090,12 +1084,6 @@ def rotate(
"""
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(rotate)
if resample is not None:
warnings.warn(
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)
# Backward compatibility with integer value
if isinstance(interpolation, int):
......@@ -1138,8 +1126,6 @@ def affine(
shear: List[float],
interpolation: InterpolationMode = InterpolationMode.NEAREST,
fill: Optional[List[float]] = None,
resample: Optional[int] = None,
fillcolor: Optional[List[float]] = None,
center: Optional[List[int]] = None,
) -> Tensor:
"""Apply affine transformation on the image keeping image center invariant.
......@@ -1165,13 +1151,6 @@ def affine(
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
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.
......@@ -1180,12 +1159,6 @@ def affine(
"""
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(affine)
if resample is not None:
warnings.warn(
"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)
# Backward compatibility with integer value
if isinstance(interpolation, int):
......@@ -1195,13 +1168,6 @@ def affine(
)
interpolation = _interpolation_modes_from_int(interpolation)
if fillcolor is not None:
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)):
raise TypeError("Argument angle should be int or float")
......
......@@ -1289,26 +1289,14 @@ 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):
.. 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
"""
def __init__(
self, degrees, interpolation=InterpolationMode.NEAREST, expand=False, center=None, fill=0, resample=None
):
def __init__(self, degrees, interpolation=InterpolationMode.NEAREST, expand=False, center=None, fill=0):
super().__init__()
_log_api_usage_once(self)
if resample is not None:
warnings.warn(
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
"Please use 'interpolation' instead."
)
interpolation = _interpolation_modes_from_int(resample)
# Backward compatibility with integer value
if isinstance(interpolation, int):
......@@ -1325,7 +1313,7 @@ class RandomRotation(torch.nn.Module):
self.center = center
self.resample = self.interpolation = interpolation
self.interpolation = interpolation
self.expand = expand
if fill is None:
......@@ -1362,7 +1350,7 @@ class RandomRotation(torch.nn.Module):
fill = [float(f) for f in fill]
angle = self.get_params(self.degrees)
return F.rotate(img, angle, self.resample, self.expand, self.center, fill)
return F.rotate(img, angle, self.interpolation, self.expand, self.center, fill)
def __repr__(self) -> str:
interpolate_str = self.interpolation.value
......@@ -1405,13 +1393,6 @@ class RandomAffine(torch.nn.Module):
but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.
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):
.. 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.
......@@ -1427,18 +1408,10 @@ class RandomAffine(torch.nn.Module):
shear=None,
interpolation=InterpolationMode.NEAREST,
fill=0,
fillcolor=None,
resample=None,
center=None,
):
super().__init__()
_log_api_usage_once(self)
if resample is not None:
warnings.warn(
"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)
# Backward compatibility with integer value
if isinstance(interpolation, int):
......@@ -1448,13 +1421,6 @@ class RandomAffine(torch.nn.Module):
)
interpolation = _interpolation_modes_from_int(interpolation)
if fillcolor is not None:
warnings.warn(
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
"Please use 'fill' instead."
)
fill = fillcolor
self.degrees = _setup_angle(degrees, name="degrees", req_sizes=(2,))
if translate is not None:
......@@ -1476,14 +1442,14 @@ class RandomAffine(torch.nn.Module):
else:
self.shear = shear
self.resample = self.interpolation = interpolation
self.interpolation = interpolation
if fill is None:
fill = 0
elif not isinstance(fill, (Sequence, numbers.Number)):
raise TypeError("Fill should be either a sequence or a number.")
self.fillcolor = self.fill = fill
self.fill = fill
if center is not None:
_check_sequence_input(center, "center", req_sizes=(2,))
......
......@@ -45,10 +45,6 @@ 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``.
......@@ -66,13 +62,6 @@ def make_grid(
else:
raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}")
if "range" in kwargs.keys():
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
if isinstance(tensor, list):
tensor = torch.stack(tensor, dim=0)
......
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