Skip to content

Remove APIs that were deprecated before 0.8 #5386

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 4 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: 0 additions & 1 deletion docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Transforms on PIL Image and torch.\*Tensor
RandomPerspective
RandomResizedCrop
RandomRotation
RandomSizedCrop
RandomVerticalFlip
Resize
TenCrop
Expand Down
6 changes: 0 additions & 6 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,6 @@ def test_frozenbatchnorm2d_eps(self, seed):
bn.load_state_dict(state_dict)
torch.testing.assert_close(fbn(x), bn(x), rtol=1e-5, atol=1e-6)

def test_frozenbatchnorm2d_n_arg(self):
"""Ensure a warning is thrown when passing `n` kwarg
(remove this when support of `n` is dropped)"""
with pytest.warns(DeprecationWarning):
ops.misc.FrozenBatchNorm2d(32, eps=1e-5, n=32)


class TestBoxConversion:
def _get_box_sequences():
Expand Down
14 changes: 1 addition & 13 deletions torchvision/datasets/imagenet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil
import tempfile
import warnings
from contextlib import contextmanager
from typing import Any, Dict, List, Iterator, Optional, Tuple

Expand Down Expand Up @@ -40,18 +39,7 @@ class ImageNet(ImageFolder):
targets (list): The class_index value for each image in the dataset
"""

def __init__(self, root: str, split: str = "train", download: Optional[str] = None, **kwargs: Any) -> None:
if download is True:
msg = (
"The dataset is no longer publicly accessible. You need to "
"download the archives externally and place them in the root "
"directory."
)
raise RuntimeError(msg)
elif download is False:
msg = "The use of the download flag is deprecated, since the dataset is no longer publicly accessible."
warnings.warn(msg, RuntimeWarning)

def __init__(self, root: str, split: str = "train", **kwargs: Any) -> None:
root = self.root = os.path.expanduser(root)
self.split = verify_str_arg(split, "split", ("train", "val"))

Expand Down
36 changes: 0 additions & 36 deletions torchvision/ops/misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import warnings
from typing import Callable, List, Optional

import torch
Expand All @@ -7,36 +6,6 @@
from ..utils import _log_api_usage_once


class Conv2d(torch.nn.Conv2d):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
warnings.warn(
"torchvision.ops.misc.Conv2d is deprecated and will be "
"removed in future versions, use torch.nn.Conv2d instead.",
FutureWarning,
)


class ConvTranspose2d(torch.nn.ConvTranspose2d):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
warnings.warn(
"torchvision.ops.misc.ConvTranspose2d is deprecated and will be "
"removed in future versions, use torch.nn.ConvTranspose2d instead.",
FutureWarning,
)


class BatchNorm2d(torch.nn.BatchNorm2d):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
warnings.warn(
"torchvision.ops.misc.BatchNorm2d is deprecated and will be "
"removed in future versions, use torch.nn.BatchNorm2d instead.",
FutureWarning,
)


interpolate = torch.nn.functional.interpolate


Expand All @@ -54,12 +23,7 @@ def __init__(
self,
num_features: int,
eps: float = 1e-5,
n: Optional[int] = None,
):
# n=None for backward-compatibility
if n is not None:
warnings.warn("`n` argument is deprecated and has been renamed `num_features`", DeprecationWarning)
num_features = n
super().__init__()
_log_api_usage_once(self)
self.eps = eps
Expand Down
7 changes: 0 additions & 7 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ def resize(
return F_t.resize(img, size=size, interpolation=interpolation.value, max_size=max_size, antialias=antialias)


def scale(*args, **kwargs):
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
_log_api_usage_once(scale)
warnings.warn("The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.")
return resize(*args, **kwargs)


def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "constant") -> Tensor:
r"""Pad the given image on all sides with the given "pad" value.
If the image is torch Tensor, it is expected
Expand Down
69 changes: 0 additions & 69 deletions torchvision/transforms/functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import torch
from torch import Tensor
from torch.jit.annotations import BroadcastingList2
from torch.nn.functional import grid_sample, conv2d, interpolate, pad as torch_pad


Expand Down Expand Up @@ -249,74 +248,6 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor:
return result


def center_crop(img: Tensor, output_size: BroadcastingList2[int]) -> Tensor:
"""DEPRECATED"""
warnings.warn(
"This method is deprecated and will be removed in future releases. Please, use ``F.center_crop`` instead."
)

_assert_image_tensor(img)

_, image_width, image_height = img.size()
crop_height, crop_width = output_size
# crop_top = int(round((image_height - crop_height) / 2.))
# Result can be different between python func and scripted func
# Temporary workaround:
crop_top = int((image_height - crop_height + 1) * 0.5)
# crop_left = int(round((image_width - crop_width) / 2.))
# Result can be different between python func and scripted func
# Temporary workaround:
crop_left = int((image_width - crop_width + 1) * 0.5)

return crop(img, crop_top, crop_left, crop_height, crop_width)


def five_crop(img: Tensor, size: BroadcastingList2[int]) -> List[Tensor]:
"""DEPRECATED"""
warnings.warn(
"This method is deprecated and will be removed in future releases. Please, use ``F.five_crop`` instead."
)

_assert_image_tensor(img)

assert len(size) == 2, "Please provide only two dimensions (h, w) for size."

_, image_width, image_height = img.size()
crop_height, crop_width = size
if crop_width > image_width or crop_height > image_height:
msg = "Requested crop size {} is bigger than input size {}"
raise ValueError(msg.format(size, (image_height, image_width)))

tl = crop(img, 0, 0, crop_width, crop_height)
tr = crop(img, image_width - crop_width, 0, image_width, crop_height)
bl = crop(img, 0, image_height - crop_height, crop_width, image_height)
br = crop(img, image_width - crop_width, image_height - crop_height, image_width, image_height)
center = center_crop(img, (crop_height, crop_width))

return [tl, tr, bl, br, center]


def ten_crop(img: Tensor, size: BroadcastingList2[int], vertical_flip: bool = False) -> List[Tensor]:
"""DEPRECATED"""
warnings.warn(
"This method is deprecated and will be removed in future releases. Please, use ``F.ten_crop`` instead."
)

_assert_image_tensor(img)

assert len(size) == 2, "Please provide only two dimensions (h, w) for size."
first_five = five_crop(img, size)

if vertical_flip:
img = vflip(img)
else:
img = hflip(img)

second_five = five_crop(img, size)

return first_five + second_five


def _blend(img1: Tensor, img2: Tensor, ratio: float) -> Tensor:
ratio = float(ratio)
bound = 1.0 if img1.is_floating_point() else 255.0
Expand Down
27 changes: 0 additions & 27 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"ToPILImage",
"Normalize",
"Resize",
"Scale",
"CenterCrop",
"Pad",
"Lambda",
Expand All @@ -37,7 +36,6 @@
"RandomHorizontalFlip",
"RandomVerticalFlip",
"RandomResizedCrop",
"RandomSizedCrop",
"FiveCrop",
"TenCrop",
"LinearTransformation",
Expand Down Expand Up @@ -355,17 +353,6 @@ def __repr__(self):
return self.__class__.__name__ + detail


class Scale(Resize):
"""
Note: This transform is deprecated in favor of Resize.
"""

def __init__(self, *args, **kwargs):
warnings.warn("The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.")
super().__init__(*args, **kwargs)
_log_api_usage_once(self)


class CenterCrop(torch.nn.Module):
"""Crops the given image at the center.
If the image is torch Tensor, it is expected
Expand Down Expand Up @@ -976,20 +963,6 @@ def __repr__(self):
return format_string


class RandomSizedCrop(RandomResizedCrop):
"""
Note: This transform is deprecated in favor of RandomResizedCrop.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"The use of the transforms.RandomSizedCrop transform is deprecated, "
+ "please use transforms.RandomResizedCrop instead."
)
super().__init__(*args, **kwargs)
_log_api_usage_once(self)


class FiveCrop(torch.nn.Module):
"""Crop the given image into four corners and the central crop.
If the image is torch Tensor, it is expected
Expand Down