"tests/git@developer.sourcefind.cn:OpenDAS/mmcv.git" did not exist on "0e14ce2c1dac746831009e757500f77f0db526b5"
Unverified Commit 9e71fdaf authored by Vasilis Vryniotis's avatar Vasilis Vryniotis Committed by GitHub
Browse files

Plural to singular name change. (#3055)

parent 0c445130
...@@ -9,12 +9,12 @@ import torch ...@@ -9,12 +9,12 @@ import torch
import torchvision.transforms.functional_tensor as F_t import torchvision.transforms.functional_tensor as F_t
import torchvision.transforms.functional_pil as F_pil import torchvision.transforms.functional_pil as F_pil
import torchvision.transforms.functional as F import torchvision.transforms.functional as F
from torchvision.transforms import InterpolationModes from torchvision.transforms import InterpolationMode
from common_utils import TransformsTester from common_utils import TransformsTester
NEAREST, BILINEAR, BICUBIC = InterpolationModes.NEAREST, InterpolationModes.BILINEAR, InterpolationModes.BICUBIC NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC
class Tester(TransformsTester): class Tester(TransformsTester):
...@@ -419,7 +419,7 @@ class Tester(TransformsTester): ...@@ -419,7 +419,7 @@ class Tester(TransformsTester):
) )
# assert changed type warning # assert changed type warning
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
res1 = F.resize(tensor, size=32, interpolation=2) res1 = F.resize(tensor, size=32, interpolation=2)
res2 = F.resize(tensor, size=32, interpolation=BILINEAR) res2 = F.resize(tensor, size=32, interpolation=BILINEAR)
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
...@@ -626,7 +626,7 @@ class Tester(TransformsTester): ...@@ -626,7 +626,7 @@ class Tester(TransformsTester):
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
# assert changed type warning # assert changed type warning
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
res1 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=2) res1 = F.affine(tensor, 45, translate=[0, 0], scale=1.0, shear=[0.0, 0.0], interpolation=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)
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
...@@ -714,7 +714,7 @@ class Tester(TransformsTester): ...@@ -714,7 +714,7 @@ class Tester(TransformsTester):
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
# assert changed type warning # assert changed type warning
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
res1 = F.rotate(tensor, 45, interpolation=2) res1 = F.rotate(tensor, 45, interpolation=2)
res2 = F.rotate(tensor, 45, interpolation=BILINEAR) res2 = F.rotate(tensor, 45, interpolation=BILINEAR)
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
...@@ -788,7 +788,7 @@ class Tester(TransformsTester): ...@@ -788,7 +788,7 @@ class Tester(TransformsTester):
# assert changed type warning # assert changed type warning
spoints = [[0, 0], [33, 0], [33, 25], [0, 25]] spoints = [[0, 0], [33, 0], [33, 25], [0, 25]]
epoints = [[3, 2], [32, 3], [30, 24], [2, 25]] epoints = [[3, 2], [32, 3], [30, 24], [2, 25]]
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
res1 = F.perspective(tensor, startpoints=spoints, endpoints=epoints, interpolation=2) res1 = F.perspective(tensor, startpoints=spoints, endpoints=epoints, interpolation=2)
res2 = F.perspective(tensor, startpoints=spoints, endpoints=epoints, interpolation=BILINEAR) res2 = F.perspective(tensor, startpoints=spoints, endpoints=epoints, interpolation=BILINEAR)
self.assertTrue(res1.equal(res2)) self.assertTrue(res1.equal(res2))
......
...@@ -1500,12 +1500,12 @@ class Tester(unittest.TestCase): ...@@ -1500,12 +1500,12 @@ class Tester(unittest.TestCase):
# assert deprecation warning and non-BC # assert deprecation warning and non-BC
with self.assertWarnsRegex(UserWarning, r"Argument resample is deprecated and will be removed"): with self.assertWarnsRegex(UserWarning, r"Argument resample is deprecated and will be removed"):
t = transforms.RandomRotation((-10, 10), resample=2) t = transforms.RandomRotation((-10, 10), resample=2)
self.assertEqual(t.interpolation, transforms.InterpolationModes.BILINEAR) self.assertEqual(t.interpolation, transforms.InterpolationMode.BILINEAR)
# assert changed type warning # assert changed type warning
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
t = transforms.RandomRotation((-10, 10), interpolation=2) t = transforms.RandomRotation((-10, 10), interpolation=2)
self.assertEqual(t.interpolation, transforms.InterpolationModes.BILINEAR) self.assertEqual(t.interpolation, transforms.InterpolationMode.BILINEAR)
def test_random_affine(self): def test_random_affine(self):
...@@ -1547,22 +1547,22 @@ class Tester(unittest.TestCase): ...@@ -1547,22 +1547,22 @@ class Tester(unittest.TestCase):
# Checking if RandomAffine can be printed as string # Checking if RandomAffine can be printed as string
t.__repr__() t.__repr__()
t = transforms.RandomAffine(10, interpolation=transforms.InterpolationModes.BILINEAR) t = transforms.RandomAffine(10, interpolation=transforms.InterpolationMode.BILINEAR)
self.assertIn("bilinear", t.__repr__()) self.assertIn("bilinear", t.__repr__())
# assert deprecation warning and non-BC # assert deprecation warning and non-BC
with self.assertWarnsRegex(UserWarning, r"Argument resample is deprecated and will be removed"): with self.assertWarnsRegex(UserWarning, r"Argument resample is deprecated and will be removed"):
t = transforms.RandomAffine(10, resample=2) t = transforms.RandomAffine(10, resample=2)
self.assertEqual(t.interpolation, transforms.InterpolationModes.BILINEAR) self.assertEqual(t.interpolation, transforms.InterpolationMode.BILINEAR)
with self.assertWarnsRegex(UserWarning, r"Argument fillcolor is deprecated and will be removed"): with self.assertWarnsRegex(UserWarning, r"Argument fillcolor is deprecated and will be removed"):
t = transforms.RandomAffine(10, fillcolor=10) t = transforms.RandomAffine(10, fillcolor=10)
self.assertEqual(t.fill, 10) self.assertEqual(t.fill, 10)
# assert changed type warning # assert changed type warning
with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationModes"): with self.assertWarnsRegex(UserWarning, r"Argument interpolation should be of type InterpolationMode"):
t = transforms.RandomAffine(10, interpolation=2) t = transforms.RandomAffine(10, interpolation=2)
self.assertEqual(t.interpolation, transforms.InterpolationModes.BILINEAR) self.assertEqual(t.interpolation, transforms.InterpolationMode.BILINEAR)
def test_to_grayscale(self): def test_to_grayscale(self):
"""Unit tests for grayscale transform""" """Unit tests for grayscale transform"""
......
...@@ -2,7 +2,7 @@ import os ...@@ -2,7 +2,7 @@ import os
import torch import torch
from torchvision import transforms as T from torchvision import transforms as T
from torchvision.transforms import functional as F from torchvision.transforms import functional as F
from torchvision.transforms import InterpolationModes from torchvision.transforms import InterpolationMode
import numpy as np import numpy as np
...@@ -11,7 +11,7 @@ import unittest ...@@ -11,7 +11,7 @@ import unittest
from common_utils import TransformsTester, get_tmp_dir, int_dtypes, float_dtypes from common_utils import TransformsTester, get_tmp_dir, int_dtypes, float_dtypes
NEAREST, BILINEAR, BICUBIC = InterpolationModes.NEAREST, InterpolationModes.BILINEAR, InterpolationModes.BICUBIC NEAREST, BILINEAR, BICUBIC = InterpolationMode.NEAREST, InterpolationMode.BILINEAR, InterpolationMode.BICUBIC
class Tester(TransformsTester): class Tester(TransformsTester):
......
...@@ -20,7 +20,7 @@ from . import functional_pil as F_pil ...@@ -20,7 +20,7 @@ from . import functional_pil as F_pil
from . import functional_tensor as F_t from . import functional_tensor as F_t
class InterpolationModes(Enum): class InterpolationMode(Enum):
"""Interpolation modes """Interpolation modes
""" """
NEAREST = "nearest" NEAREST = "nearest"
...@@ -33,26 +33,26 @@ class InterpolationModes(Enum): ...@@ -33,26 +33,26 @@ class InterpolationModes(Enum):
# TODO: Once torchscript supports Enums with staticmethod # TODO: Once torchscript supports Enums with staticmethod
# this can be put into InterpolationModes as staticmethod # this can be put into InterpolationMode as staticmethod
def _interpolation_modes_from_int(i: int) -> InterpolationModes: def _interpolation_modes_from_int(i: int) -> InterpolationMode:
inverse_modes_mapping = { inverse_modes_mapping = {
0: InterpolationModes.NEAREST, 0: InterpolationMode.NEAREST,
2: InterpolationModes.BILINEAR, 2: InterpolationMode.BILINEAR,
3: InterpolationModes.BICUBIC, 3: InterpolationMode.BICUBIC,
4: InterpolationModes.BOX, 4: InterpolationMode.BOX,
5: InterpolationModes.HAMMING, 5: InterpolationMode.HAMMING,
1: InterpolationModes.LANCZOS, 1: InterpolationMode.LANCZOS,
} }
return inverse_modes_mapping[i] return inverse_modes_mapping[i]
pil_modes_mapping = { pil_modes_mapping = {
InterpolationModes.NEAREST: 0, InterpolationMode.NEAREST: 0,
InterpolationModes.BILINEAR: 2, InterpolationMode.BILINEAR: 2,
InterpolationModes.BICUBIC: 3, InterpolationMode.BICUBIC: 3,
InterpolationModes.BOX: 4, InterpolationMode.BOX: 4,
InterpolationModes.HAMMING: 5, InterpolationMode.HAMMING: 5,
InterpolationModes.LANCZOS: 1, InterpolationMode.LANCZOS: 1,
} }
_is_pil_image = F_pil._is_pil_image _is_pil_image = F_pil._is_pil_image
...@@ -329,7 +329,7 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool ...@@ -329,7 +329,7 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool
return tensor return tensor
def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = InterpolationModes.BILINEAR) -> Tensor: def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR) -> Tensor:
r"""Resize the input image to the given size. r"""Resize the input image to the given size.
The image can be a PIL Image or a torch Tensor, in which case it is expected The image can be a PIL Image or a torch Tensor, in which case it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
...@@ -343,10 +343,10 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int ...@@ -343,10 +343,10 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`. :math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
In torchscript mode size as single int is not supported, use a tuple or In torchscript mode size as single int is not supported, use a tuple or
list of length 1: ``[size, ]``. list of length 1: ``[size, ]``.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. :class:`torchvision.transforms.InterpolationMode`.
Default is ``InterpolationModes.BILINEAR``. If input is Tensor, only ``InterpolationModes.NEAREST``, Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
``InterpolationModes.BILINEAR`` and ``InterpolationModes.BICUBIC`` are supported. ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported.
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.
Returns: Returns:
...@@ -355,13 +355,13 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int ...@@ -355,13 +355,13 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
if not isinstance(interpolation, InterpolationModes): if not isinstance(interpolation, InterpolationMode):
raise TypeError("Argument interpolation should be a InterpolationModes") raise TypeError("Argument interpolation should be a InterpolationMode")
if not isinstance(img, torch.Tensor): if not isinstance(img, torch.Tensor):
pil_interpolation = pil_modes_mapping[interpolation] pil_interpolation = pil_modes_mapping[interpolation]
...@@ -475,7 +475,7 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor: ...@@ -475,7 +475,7 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
def resized_crop( def resized_crop(
img: Tensor, top: int, left: int, height: int, width: int, size: List[int], img: Tensor, top: int, left: int, height: int, width: int, size: List[int],
interpolation: InterpolationModes = InterpolationModes.BILINEAR interpolation: InterpolationMode = InterpolationMode.BILINEAR
) -> Tensor: ) -> Tensor:
"""Crop the given image and resize it to desired size. """Crop the given image and resize it to desired size.
The image can be a PIL Image or a Tensor, in which case it is expected The image can be a PIL Image or a Tensor, in which case it is expected
...@@ -490,10 +490,10 @@ def resized_crop( ...@@ -490,10 +490,10 @@ def resized_crop(
height (int): Height of the crop box. height (int): Height of the crop box.
width (int): Width of the crop box. width (int): Width of the crop box.
size (sequence or int): Desired output size. Same semantics as ``resize``. size (sequence or int): Desired output size. Same semantics as ``resize``.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. :class:`torchvision.transforms.InterpolationMode`.
Default is ``InterpolationModes.BILINEAR``. If input is Tensor, only ``InterpolationModes.NEAREST``, Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
``InterpolationModes.BILINEAR`` and ``InterpolationModes.BICUBIC`` are supported. ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported.
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.
Returns: Returns:
...@@ -556,7 +556,7 @@ def perspective( ...@@ -556,7 +556,7 @@ def perspective(
img: Tensor, img: Tensor,
startpoints: List[List[int]], startpoints: List[List[int]],
endpoints: List[List[int]], endpoints: List[List[int]],
interpolation: InterpolationModes = InterpolationModes.BILINEAR, interpolation: InterpolationMode = InterpolationMode.BILINEAR,
fill: Optional[int] = None fill: Optional[int] = None
) -> Tensor: ) -> Tensor:
"""Perform perspective transform of the given image. """Perform perspective transform of the given image.
...@@ -569,9 +569,9 @@ def perspective( ...@@ -569,9 +569,9 @@ def perspective(
``[top-left, top-right, bottom-right, bottom-left]`` of the original image. ``[top-left, top-right, bottom-right, bottom-left]`` of the original image.
endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image. ``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.BILINEAR``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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 (n-tuple or int or float): Pixel fill value for area outside the rotated fill (n-tuple or int or float): Pixel fill value for area outside the rotated
image. If int or float, the value is used for all bands respectively. image. If int or float, the value is used for all bands respectively.
...@@ -587,13 +587,13 @@ def perspective( ...@@ -587,13 +587,13 @@ def perspective(
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
if not isinstance(interpolation, InterpolationModes): if not isinstance(interpolation, InterpolationMode):
raise TypeError("Argument interpolation should be a InterpolationModes") raise TypeError("Argument interpolation should be a InterpolationMode")
if not isinstance(img, torch.Tensor): if not isinstance(img, torch.Tensor):
pil_interpolation = pil_modes_mapping[interpolation] pil_interpolation = pil_modes_mapping[interpolation]
...@@ -869,7 +869,7 @@ def _get_inverse_affine_matrix( ...@@ -869,7 +869,7 @@ def _get_inverse_affine_matrix(
def rotate( def rotate(
img: Tensor, angle: float, interpolation: InterpolationModes = InterpolationModes.NEAREST, img: Tensor, angle: float, interpolation: InterpolationMode = InterpolationMode.NEAREST,
expand: bool = False, center: Optional[List[int]] = None, expand: bool = False, center: Optional[List[int]] = None,
fill: Optional[int] = None, resample: Optional[int] = None fill: Optional[int] = None, resample: Optional[int] = None
) -> Tensor: ) -> Tensor:
...@@ -880,9 +880,9 @@ def rotate( ...@@ -880,9 +880,9 @@ def rotate(
Args: Args:
img (PIL Image or Tensor): image to be rotated. img (PIL Image or Tensor): image to be rotated.
angle (float or int): rotation angle value in degrees, counter-clockwise. angle (float or int): rotation angle value in degrees, counter-clockwise.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.NEAREST``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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.
expand (bool, optional): Optional expansion flag. expand (bool, optional): Optional expansion flag.
If true, expands the output image to make it large enough to hold the entire rotated image. If true, expands the output image to make it large enough to hold the entire rotated image.
...@@ -913,8 +913,8 @@ def rotate( ...@@ -913,8 +913,8 @@ def rotate(
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -924,8 +924,8 @@ def rotate( ...@@ -924,8 +924,8 @@ def rotate(
if center is not None and not isinstance(center, (list, tuple)): if center is not None and not isinstance(center, (list, tuple)):
raise TypeError("Argument center should be a sequence") raise TypeError("Argument center should be a sequence")
if not isinstance(interpolation, InterpolationModes): if not isinstance(interpolation, InterpolationMode):
raise TypeError("Argument interpolation should be a InterpolationModes") raise TypeError("Argument interpolation should be a InterpolationMode")
if not isinstance(img, torch.Tensor): if not isinstance(img, torch.Tensor):
pil_interpolation = pil_modes_mapping[interpolation] pil_interpolation = pil_modes_mapping[interpolation]
...@@ -945,7 +945,7 @@ def rotate( ...@@ -945,7 +945,7 @@ def rotate(
def affine( def affine(
img: Tensor, angle: float, translate: List[int], scale: float, shear: List[float], img: Tensor, angle: float, translate: List[int], scale: float, shear: List[float],
interpolation: InterpolationModes = InterpolationModes.NEAREST, fill: Optional[int] = None, interpolation: InterpolationMode = InterpolationMode.NEAREST, fill: Optional[int] = None,
resample: Optional[int] = None, fillcolor: Optional[int] = None resample: Optional[int] = None, fillcolor: Optional[int] = None
) -> Tensor: ) -> Tensor:
"""Apply affine transformation on the image keeping image center invariant. """Apply affine transformation on the image keeping image center invariant.
...@@ -960,9 +960,9 @@ def affine( ...@@ -960,9 +960,9 @@ def affine(
shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction. shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction.
If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while
the second value corresponds to a shear parallel to the y axis. the second value corresponds to a shear parallel to the y axis.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.NEAREST``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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 (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0). fill (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0).
This option is not supported for Tensor input. Fill value for the area outside the transform in the output This option is not supported for Tensor input. Fill value for the area outside the transform in the output
...@@ -984,8 +984,8 @@ def affine( ...@@ -984,8 +984,8 @@ def affine(
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -1010,8 +1010,8 @@ def affine( ...@@ -1010,8 +1010,8 @@ def affine(
if not isinstance(shear, (numbers.Number, (list, tuple))): if not isinstance(shear, (numbers.Number, (list, tuple))):
raise TypeError("Shear should be either a single value or a sequence of two values") raise TypeError("Shear should be either a single value or a sequence of two values")
if not isinstance(interpolation, InterpolationModes): if not isinstance(interpolation, InterpolationMode):
raise TypeError("Argument interpolation should be a InterpolationModes") raise TypeError("Argument interpolation should be a InterpolationMode")
if isinstance(angle, int): if isinstance(angle, int):
angle = float(angle) angle = float(angle)
......
...@@ -14,14 +14,14 @@ except ImportError: ...@@ -14,14 +14,14 @@ except ImportError:
accimage = None accimage = None
from . import functional as F from . import functional as F
from .functional import InterpolationModes, _interpolation_modes_from_int from .functional import InterpolationMode, _interpolation_modes_from_int
__all__ = ["Compose", "ToTensor", "PILToTensor", "ConvertImageDtype", "ToPILImage", "Normalize", "Resize", "Scale", __all__ = ["Compose", "ToTensor", "PILToTensor", "ConvertImageDtype", "ToPILImage", "Normalize", "Resize", "Scale",
"CenterCrop", "Pad", "Lambda", "RandomApply", "RandomChoice", "RandomOrder", "RandomCrop", "CenterCrop", "Pad", "Lambda", "RandomApply", "RandomChoice", "RandomOrder", "RandomCrop",
"RandomHorizontalFlip", "RandomVerticalFlip", "RandomResizedCrop", "RandomSizedCrop", "FiveCrop", "TenCrop", "RandomHorizontalFlip", "RandomVerticalFlip", "RandomResizedCrop", "RandomSizedCrop", "FiveCrop", "TenCrop",
"LinearTransformation", "ColorJitter", "RandomRotation", "RandomAffine", "Grayscale", "RandomGrayscale", "LinearTransformation", "ColorJitter", "RandomRotation", "RandomAffine", "Grayscale", "RandomGrayscale",
"RandomPerspective", "RandomErasing", "GaussianBlur", "InterpolationModes"] "RandomPerspective", "RandomErasing", "GaussianBlur", "InterpolationMode"]
class Compose: class Compose:
...@@ -234,15 +234,15 @@ class Resize(torch.nn.Module): ...@@ -234,15 +234,15 @@ class Resize(torch.nn.Module):
(size * height / width, size). (size * height / width, size).
In torchscript mode padding as single int is not supported, use a tuple or In torchscript mode padding as single int is not supported, use a tuple or
list of length 1: ``[size, ]``. list of length 1: ``[size, ]``.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.BILINEAR``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` and If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` and
``InterpolationModes.BICUBIC`` are supported. ``InterpolationMode.BICUBIC`` are supported.
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.
""" """
def __init__(self, size, interpolation=InterpolationModes.BILINEAR): def __init__(self, size, interpolation=InterpolationMode.BILINEAR):
super().__init__() super().__init__()
if not isinstance(size, (int, Sequence)): if not isinstance(size, (int, Sequence)):
raise TypeError("Size should be int or sequence. Got {}".format(type(size))) raise TypeError("Size should be int or sequence. Got {}".format(type(size)))
...@@ -253,8 +253,8 @@ class Resize(torch.nn.Module): ...@@ -253,8 +253,8 @@ class Resize(torch.nn.Module):
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -663,9 +663,9 @@ class RandomPerspective(torch.nn.Module): ...@@ -663,9 +663,9 @@ class RandomPerspective(torch.nn.Module):
distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1. distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1.
Default is 0.5. Default is 0.5.
p (float): probability of the image being transformed. Default is 0.5. p (float): probability of the image being transformed. Default is 0.5.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.BILINEAR``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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 (n-tuple or int or float): Pixel fill value for area outside the rotated fill (n-tuple or int or float): Pixel fill value for area outside the rotated
image. If int or float, the value is used for all bands respectively. Default is 0. image. If int or float, the value is used for all bands respectively. Default is 0.
...@@ -673,15 +673,15 @@ class RandomPerspective(torch.nn.Module): ...@@ -673,15 +673,15 @@ class RandomPerspective(torch.nn.Module):
input. Fill value for the area outside the transform in the output image is always 0. input. Fill value for the area outside the transform in the output image is always 0.
""" """
def __init__(self, distortion_scale=0.5, p=0.5, interpolation=InterpolationModes.BILINEAR, fill=0): def __init__(self, distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0):
super().__init__() super().__init__()
self.p = p self.p = p
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -758,15 +758,15 @@ class RandomResizedCrop(torch.nn.Module): ...@@ -758,15 +758,15 @@ class RandomResizedCrop(torch.nn.Module):
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]). made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).
scale (tuple of float): scale range of the cropped image before resizing, relatively to the origin image. scale (tuple of float): scale range of the cropped image before resizing, relatively to the origin image.
ratio (tuple of float): aspect ratio range of the cropped image before resizing. ratio (tuple of float): aspect ratio range of the cropped image before resizing.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.BILINEAR``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` and If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` and
``InterpolationModes.BICUBIC`` are supported. ``InterpolationMode.BICUBIC`` are supported.
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.
""" """
def __init__(self, size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), interpolation=InterpolationModes.BILINEAR): def __init__(self, size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), interpolation=InterpolationMode.BILINEAR):
super().__init__() super().__init__()
self.size = _setup_size(size, error_msg="Please provide only two dimensions (h, w) for size.") self.size = _setup_size(size, error_msg="Please provide only two dimensions (h, w) for size.")
...@@ -780,8 +780,8 @@ class RandomResizedCrop(torch.nn.Module): ...@@ -780,8 +780,8 @@ class RandomResizedCrop(torch.nn.Module):
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -1147,9 +1147,9 @@ class RandomRotation(torch.nn.Module): ...@@ -1147,9 +1147,9 @@ class RandomRotation(torch.nn.Module):
degrees (sequence or float or int): Range of degrees to select from. degrees (sequence or float or int): Range of degrees to select from.
If degrees is a number instead of sequence like (min, max), the range of degrees If degrees is a number instead of sequence like (min, max), the range of degrees
will be (-degrees, +degrees). will be (-degrees, +degrees).
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.NEAREST``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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.
expand (bool, optional): Optional expansion flag. expand (bool, optional): Optional expansion flag.
If true, expands the output to make it large enough to hold the entire rotated image. If true, expands the output to make it large enough to hold the entire rotated image.
...@@ -1170,7 +1170,7 @@ class RandomRotation(torch.nn.Module): ...@@ -1170,7 +1170,7 @@ class RandomRotation(torch.nn.Module):
""" """
def __init__( def __init__(
self, degrees, interpolation=InterpolationModes.NEAREST, expand=False, center=None, fill=None, resample=None self, degrees, interpolation=InterpolationMode.NEAREST, expand=False, center=None, fill=None, resample=None
): ):
super().__init__() super().__init__()
if resample is not None: if resample is not None:
...@@ -1182,8 +1182,8 @@ class RandomRotation(torch.nn.Module): ...@@ -1182,8 +1182,8 @@ class RandomRotation(torch.nn.Module):
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -1253,9 +1253,9 @@ class RandomAffine(torch.nn.Module): ...@@ -1253,9 +1253,9 @@ class RandomAffine(torch.nn.Module):
range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values, range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values,
a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied. a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
Will not apply shear by default. Will not apply shear by default.
interpolation (InterpolationModes): Desired interpolation enum defined by interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationModes`. Default is ``InterpolationModes.NEAREST``. :class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationModes.NEAREST``, ``InterpolationModes.BILINEAR`` are supported. If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
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 (tuple or int): Optional fill color (Tuple for RGB Image and int for grayscale) for the area fill (tuple or int): Optional fill color (Tuple for RGB Image and int for grayscale) for the area
outside the transform in the output image (Pillow>=5.0.0). This option is not supported for Tensor outside the transform in the output image (Pillow>=5.0.0). This option is not supported for Tensor
...@@ -1270,7 +1270,7 @@ class RandomAffine(torch.nn.Module): ...@@ -1270,7 +1270,7 @@ class RandomAffine(torch.nn.Module):
""" """
def __init__( def __init__(
self, degrees, translate=None, scale=None, shear=None, interpolation=InterpolationModes.NEAREST, fill=0, self, degrees, translate=None, scale=None, shear=None, interpolation=InterpolationMode.NEAREST, fill=0,
fillcolor=None, resample=None fillcolor=None, resample=None
): ):
super().__init__() super().__init__()
...@@ -1283,8 +1283,8 @@ class RandomAffine(torch.nn.Module): ...@@ -1283,8 +1283,8 @@ class RandomAffine(torch.nn.Module):
# Backward compatibility with integer value # Backward compatibility with integer value
if isinstance(interpolation, int): if isinstance(interpolation, int):
warnings.warn( warnings.warn(
"Argument interpolation should be of type InterpolationModes instead of int. " "Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationModes enum." "Please, use InterpolationMode enum."
) )
interpolation = _interpolation_modes_from_int(interpolation) interpolation = _interpolation_modes_from_int(interpolation)
...@@ -1377,7 +1377,7 @@ class RandomAffine(torch.nn.Module): ...@@ -1377,7 +1377,7 @@ class RandomAffine(torch.nn.Module):
s += ', scale={scale}' s += ', scale={scale}'
if self.shear is not None: if self.shear is not None:
s += ', shear={shear}' s += ', shear={shear}'
if self.interpolation != InterpolationModes.NEAREST: if self.interpolation != InterpolationMode.NEAREST:
s += ', interpolation={interpolation}' s += ', interpolation={interpolation}'
if self.fill != 0: if self.fill != 0:
s += ', fill={fill}' s += ', fill={fill}'
......
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