Skip to content

Commit 21790df

Browse files
pmeierNicolasHug
andauthored
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: Nicolas Hug <[email protected]>
1 parent 97f543f commit 21790df

File tree

13 files changed

+113
-41
lines changed

13 files changed

+113
-41
lines changed

docs/source/datasets.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Video classification
128128
:template: class_dataset.rst
129129

130130
HMDB51
131+
Kinetics
131132
Kinetics400
132133
UCF101
133134

test/test_functional_tensor.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import itertools
33
import math
44
import os
5+
import re
56
from typing import Sequence
67

78
import numpy as np
@@ -23,7 +24,6 @@
2324
)
2425
from torchvision.transforms import InterpolationMode
2526

26-
2727
NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC
2828

2929

@@ -141,7 +141,13 @@ def test_rotate_batch(self, device, dt):
141141
def test_rotate_deprecation_resample(self):
142142
tensor, _ = _create_data(26, 26)
143143
# assert deprecation warning and non-BC
144-
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
144+
with pytest.warns(
145+
UserWarning,
146+
match=re.escape(
147+
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
148+
"Please use 'interpolation' instead."
149+
),
150+
):
145151
res1 = F.rotate(tensor, 45, resample=2)
146152
res2 = F.rotate(tensor, 45, interpolation=BILINEAR)
147153
assert_equal(res1, res2)
@@ -365,7 +371,13 @@ def test_warnings(self, device):
365371
tensor, pil_img = _create_data(26, 26, device=device)
366372

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

379-
with pytest.warns(UserWarning, match=r"Argument fillcolor is deprecated and will be removed"):
391+
with pytest.warns(
392+
UserWarning,
393+
match=re.escape(
394+
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
395+
"Please use 'fill' instead."
396+
),
397+
):
380398
res1 = F.affine(pil_img, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], fillcolor=10)
381399
res2 = F.affine(pil_img, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], fill=10)
382400
# we convert the PIL images to numpy as assert_equal doesn't work on PIL images.

test/test_transforms.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22
import os
33
import random
4+
import re
45
from functools import partial
56

67
import numpy as np
@@ -1828,7 +1829,13 @@ def test_random_rotation():
18281829
t.__repr__()
18291830

18301831
# assert deprecation warning and non-BC
1831-
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
1832+
with pytest.warns(
1833+
UserWarning,
1834+
match=re.escape(
1835+
"The parameter 'resample' is deprecated since 0.12 and will be removed 0.14. "
1836+
"Please use 'interpolation' instead."
1837+
),
1838+
):
18321839
t = transforms.RandomRotation((-10, 10), resample=2)
18331840
assert t.interpolation == transforms.InterpolationMode.BILINEAR
18341841

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

21692176
# assert deprecation warning and non-BC
2170-
with pytest.warns(UserWarning, match=r"Argument resample is deprecated and will be removed"):
2177+
with pytest.warns(
2178+
UserWarning,
2179+
match=re.escape(
2180+
"The parameter 'resample' is deprecated since 0.12 and will be removed in 0.14. "
2181+
"Please use 'interpolation' instead."
2182+
),
2183+
):
21712184
t = transforms.RandomAffine(10, resample=2)
21722185
assert t.interpolation == transforms.InterpolationMode.BILINEAR
21732186

2174-
with pytest.warns(UserWarning, match=r"Argument fillcolor is deprecated and will be removed"):
2187+
with pytest.warns(
2188+
UserWarning,
2189+
match=re.escape(
2190+
"The parameter 'fillcolor' is deprecated since 0.12 and will be removed in 0.14. "
2191+
"Please use 'fill' instead."
2192+
),
2193+
):
21752194
t = transforms.RandomAffine(10, fillcolor=10)
21762195
assert t.fill == 10
21772196

torchvision/csrc/models/modelsimpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ inline bool double_compare(double a, double b) {
3636

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

torchvision/datasets/kinetics.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _dl_wrap(tarpath: str, videopath: str, line: str) -> None:
2020

2121

2222
class Kinetics(VisionDataset):
23-
"""` Generic Kinetics <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
23+
"""`Generic Kinetics <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
2424
dataset.
2525
2626
Kinetics-400/600/700 are action recognition video datasets.
@@ -49,6 +49,7 @@ class Kinetics(VisionDataset):
4949
│ ├── class2
5050
│ │ ├── clipx.mp4
5151
│ │ └── ...
52+
5253
Note: split is appended automatically using the split argument.
5354
frames_per_clip (int): number of frames in a clip
5455
num_classes (int): select between Kinetics-400 (default), Kinetics-600, and Kinetics-700
@@ -247,6 +248,10 @@ class Kinetics400(Kinetics):
247248
`Kinetics-400 <https://deepmind.com/research/open-source/open-source-datasets/kinetics/>`_
248249
dataset.
249250
251+
.. warning::
252+
This class was deprecated in ``0.12`` and will be removed in ``0.14``. Please use
253+
``Kinetics(..., num_classes='400')`` instead.
254+
250255
Kinetics-400 is an action recognition video dataset.
251256
This dataset consider every video as a collection of video clips of fixed size, specified
252257
by ``frames_per_clip``, where the step in frames between each clip is given by
@@ -300,8 +305,8 @@ def __init__(
300305
**kwargs: Any,
301306
) -> None:
302307
warnings.warn(
303-
"Kinetics400 is deprecated and will be removed in a future release."
304-
'It was replaced by Kinetics(..., num_classes="400").'
308+
"The Kinetics400 class is deprecated since 0.12 and will be removed in 0.14."
309+
"Please use Kinetics(..., num_classes='400') instead."
305310
)
306311
if any(value is not None for value in (num_classes, split, download, num_download_workers)):
307312
raise RuntimeError(

torchvision/models/mobilenetv2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class _DeprecatedConvBNAct(ConvNormActivation):
2424
def __init__(self, *args, **kwargs):
2525
warnings.warn(
26-
"The ConvBNReLU/ConvBNActivation classes are deprecated and will be removed in future versions. "
26+
"The ConvBNReLU/ConvBNActivation classes are deprecated since 0.12 and will be removed in 0.14. "
2727
"Use torchvision.ops.misc.ConvNormActivation instead.",
2828
FutureWarning,
2929
)

torchvision/models/segmentation/segmentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66

77
warnings.warn(
8-
"The 'torchvision.models.segmentation.segmentation' module is deprecated. Please use directly the parent module "
9-
"instead."
8+
"The 'torchvision.models.segmentation.segmentation' module is deprecated since 0.12 and will be removed in "
9+
"0.14. Please use the 'torchvision.models.segmentation' directly instead."
1010
)

torchvision/ops/poolers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,19 @@ def __init__(
288288
self.canonical_level = canonical_level
289289

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

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

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

309306
def forward(

torchvision/transforms/_functional_video.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import torch
44

55

6-
warnings.warn("The _functional_video module is deprecated. Please use the functional module instead.")
6+
warnings.warn(
7+
"The 'torchvision.transforms._functional_video' module is deprecated since 0.12 and will be removed in 0.14. "
8+
"Please use the 'torchvision.transforms.functional' module instead."
9+
)
710

811

912
def _is_tensor_video_clip(clip):

torchvision/transforms/_transforms_video.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
]
2323

2424

25-
warnings.warn("The _transforms_video module is deprecated. Please use the transforms module instead.")
25+
warnings.warn(
26+
"The 'torchvision.transforms._transforms_video' module is deprecated since 0.12 and will be removed in 0.14. "
27+
"Please use the 'torchvision.transforms' module instead."
28+
)
2629

2730

2831
class RandomCropVideo(RandomCrop):

0 commit comments

Comments
 (0)