20
20
from . import functional_tensor as F_t
21
21
22
22
23
- class InterpolationModes (Enum ):
23
+ class InterpolationMode (Enum ):
24
24
"""Interpolation modes
25
25
"""
26
26
NEAREST = "nearest"
@@ -33,26 +33,26 @@ class InterpolationModes(Enum):
33
33
34
34
35
35
# TODO: Once torchscript supports Enums with staticmethod
36
- # this can be put into InterpolationModes as staticmethod
37
- def _interpolation_modes_from_int (i : int ) -> InterpolationModes :
36
+ # this can be put into InterpolationMode as staticmethod
37
+ def _interpolation_modes_from_int (i : int ) -> InterpolationMode :
38
38
inverse_modes_mapping = {
39
- 0 : InterpolationModes .NEAREST ,
40
- 2 : InterpolationModes .BILINEAR ,
41
- 3 : InterpolationModes .BICUBIC ,
42
- 4 : InterpolationModes .BOX ,
43
- 5 : InterpolationModes .HAMMING ,
44
- 1 : InterpolationModes .LANCZOS ,
39
+ 0 : InterpolationMode .NEAREST ,
40
+ 2 : InterpolationMode .BILINEAR ,
41
+ 3 : InterpolationMode .BICUBIC ,
42
+ 4 : InterpolationMode .BOX ,
43
+ 5 : InterpolationMode .HAMMING ,
44
+ 1 : InterpolationMode .LANCZOS ,
45
45
}
46
46
return inverse_modes_mapping [i ]
47
47
48
48
49
49
pil_modes_mapping = {
50
- InterpolationModes .NEAREST : 0 ,
51
- InterpolationModes .BILINEAR : 2 ,
52
- InterpolationModes .BICUBIC : 3 ,
53
- InterpolationModes .BOX : 4 ,
54
- InterpolationModes .HAMMING : 5 ,
55
- InterpolationModes .LANCZOS : 1 ,
50
+ InterpolationMode .NEAREST : 0 ,
51
+ InterpolationMode .BILINEAR : 2 ,
52
+ InterpolationMode .BICUBIC : 3 ,
53
+ InterpolationMode .BOX : 4 ,
54
+ InterpolationMode .HAMMING : 5 ,
55
+ InterpolationMode .LANCZOS : 1 ,
56
56
}
57
57
58
58
_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
329
return tensor
330
330
331
331
332
- def resize (img : Tensor , size : List [int ], interpolation : InterpolationModes = InterpolationModes .BILINEAR ) -> Tensor :
332
+ def resize (img : Tensor , size : List [int ], interpolation : InterpolationMode = InterpolationMode .BILINEAR ) -> Tensor :
333
333
r"""Resize the input image to the given size.
334
334
The image can be a PIL Image or a torch Tensor, in which case it is expected
335
335
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
343
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
344
344
In torchscript mode size as single int is not supported, use a tuple or
345
345
list of length 1: ``[size, ]``.
346
- interpolation (InterpolationModes ): Desired interpolation enum defined by
347
- :class:`torchvision.transforms.InterpolationModes `.
348
- Default is ``InterpolationModes .BILINEAR``. If input is Tensor, only ``InterpolationModes .NEAREST``,
349
- ``InterpolationModes .BILINEAR`` and ``InterpolationModes .BICUBIC`` are supported.
346
+ interpolation (InterpolationMode ): Desired interpolation enum defined by
347
+ :class:`torchvision.transforms.InterpolationMode `.
348
+ Default is ``InterpolationMode .BILINEAR``. If input is Tensor, only ``InterpolationMode .NEAREST``,
349
+ ``InterpolationMode .BILINEAR`` and ``InterpolationMode .BICUBIC`` are supported.
350
350
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
351
351
352
352
Returns:
@@ -355,13 +355,13 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
355
355
# Backward compatibility with integer value
356
356
if isinstance (interpolation , int ):
357
357
warnings .warn (
358
- "Argument interpolation should be of type InterpolationModes instead of int. "
359
- "Please, use InterpolationModes enum."
358
+ "Argument interpolation should be of type InterpolationMode instead of int. "
359
+ "Please, use InterpolationMode enum."
360
360
)
361
361
interpolation = _interpolation_modes_from_int (interpolation )
362
362
363
- if not isinstance (interpolation , InterpolationModes ):
364
- raise TypeError ("Argument interpolation should be a InterpolationModes " )
363
+ if not isinstance (interpolation , InterpolationMode ):
364
+ raise TypeError ("Argument interpolation should be a InterpolationMode " )
365
365
366
366
if not isinstance (img , torch .Tensor ):
367
367
pil_interpolation = pil_modes_mapping [interpolation ]
@@ -475,7 +475,7 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
475
475
476
476
def resized_crop (
477
477
img : Tensor , top : int , left : int , height : int , width : int , size : List [int ],
478
- interpolation : InterpolationModes = InterpolationModes .BILINEAR
478
+ interpolation : InterpolationMode = InterpolationMode .BILINEAR
479
479
) -> Tensor :
480
480
"""Crop the given image and resize it to desired size.
481
481
The image can be a PIL Image or a Tensor, in which case it is expected
@@ -490,10 +490,10 @@ def resized_crop(
490
490
height (int): Height of the crop box.
491
491
width (int): Width of the crop box.
492
492
size (sequence or int): Desired output size. Same semantics as ``resize``.
493
- interpolation (InterpolationModes ): Desired interpolation enum defined by
494
- :class:`torchvision.transforms.InterpolationModes `.
495
- Default is ``InterpolationModes .BILINEAR``. If input is Tensor, only ``InterpolationModes .NEAREST``,
496
- ``InterpolationModes .BILINEAR`` and ``InterpolationModes .BICUBIC`` are supported.
493
+ interpolation (InterpolationMode ): Desired interpolation enum defined by
494
+ :class:`torchvision.transforms.InterpolationMode `.
495
+ Default is ``InterpolationMode .BILINEAR``. If input is Tensor, only ``InterpolationMode .NEAREST``,
496
+ ``InterpolationMode .BILINEAR`` and ``InterpolationMode .BICUBIC`` are supported.
497
497
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
498
498
499
499
Returns:
@@ -556,7 +556,7 @@ def perspective(
556
556
img : Tensor ,
557
557
startpoints : List [List [int ]],
558
558
endpoints : List [List [int ]],
559
- interpolation : InterpolationModes = InterpolationModes .BILINEAR ,
559
+ interpolation : InterpolationMode = InterpolationMode .BILINEAR ,
560
560
fill : Optional [int ] = None
561
561
) -> Tensor :
562
562
"""Perform perspective transform of the given image.
@@ -569,9 +569,9 @@ def perspective(
569
569
``[top-left, top-right, bottom-right, bottom-left]`` of the original image.
570
570
endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
571
571
``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image.
572
- interpolation (InterpolationModes ): Desired interpolation enum defined by
573
- :class:`torchvision.transforms.InterpolationModes `. Default is ``InterpolationModes .BILINEAR``.
574
- If input is Tensor, only ``InterpolationModes .NEAREST``, ``InterpolationModes .BILINEAR`` are supported.
572
+ interpolation (InterpolationMode ): Desired interpolation enum defined by
573
+ :class:`torchvision.transforms.InterpolationMode `. Default is ``InterpolationMode .BILINEAR``.
574
+ If input is Tensor, only ``InterpolationMode .NEAREST``, ``InterpolationMode .BILINEAR`` are supported.
575
575
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
576
576
fill (n-tuple or int or float): Pixel fill value for area outside the rotated
577
577
image. If int or float, the value is used for all bands respectively.
@@ -587,13 +587,13 @@ def perspective(
587
587
# Backward compatibility with integer value
588
588
if isinstance (interpolation , int ):
589
589
warnings .warn (
590
- "Argument interpolation should be of type InterpolationModes instead of int. "
591
- "Please, use InterpolationModes enum."
590
+ "Argument interpolation should be of type InterpolationMode instead of int. "
591
+ "Please, use InterpolationMode enum."
592
592
)
593
593
interpolation = _interpolation_modes_from_int (interpolation )
594
594
595
- if not isinstance (interpolation , InterpolationModes ):
596
- raise TypeError ("Argument interpolation should be a InterpolationModes " )
595
+ if not isinstance (interpolation , InterpolationMode ):
596
+ raise TypeError ("Argument interpolation should be a InterpolationMode " )
597
597
598
598
if not isinstance (img , torch .Tensor ):
599
599
pil_interpolation = pil_modes_mapping [interpolation ]
@@ -869,7 +869,7 @@ def _get_inverse_affine_matrix(
869
869
870
870
871
871
def rotate (
872
- img : Tensor , angle : float , interpolation : InterpolationModes = InterpolationModes .NEAREST ,
872
+ img : Tensor , angle : float , interpolation : InterpolationMode = InterpolationMode .NEAREST ,
873
873
expand : bool = False , center : Optional [List [int ]] = None ,
874
874
fill : Optional [int ] = None , resample : Optional [int ] = None
875
875
) -> Tensor :
@@ -880,9 +880,9 @@ def rotate(
880
880
Args:
881
881
img (PIL Image or Tensor): image to be rotated.
882
882
angle (float or int): rotation angle value in degrees, counter-clockwise.
883
- interpolation (InterpolationModes ): Desired interpolation enum defined by
884
- :class:`torchvision.transforms.InterpolationModes `. Default is ``InterpolationModes .NEAREST``.
885
- If input is Tensor, only ``InterpolationModes .NEAREST``, ``InterpolationModes .BILINEAR`` are supported.
883
+ interpolation (InterpolationMode ): Desired interpolation enum defined by
884
+ :class:`torchvision.transforms.InterpolationMode `. Default is ``InterpolationMode .NEAREST``.
885
+ If input is Tensor, only ``InterpolationMode .NEAREST``, ``InterpolationMode .BILINEAR`` are supported.
886
886
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
887
887
expand (bool, optional): Optional expansion flag.
888
888
If true, expands the output image to make it large enough to hold the entire rotated image.
@@ -913,8 +913,8 @@ def rotate(
913
913
# Backward compatibility with integer value
914
914
if isinstance (interpolation , int ):
915
915
warnings .warn (
916
- "Argument interpolation should be of type InterpolationModes instead of int. "
917
- "Please, use InterpolationModes enum."
916
+ "Argument interpolation should be of type InterpolationMode instead of int. "
917
+ "Please, use InterpolationMode enum."
918
918
)
919
919
interpolation = _interpolation_modes_from_int (interpolation )
920
920
@@ -924,8 +924,8 @@ def rotate(
924
924
if center is not None and not isinstance (center , (list , tuple )):
925
925
raise TypeError ("Argument center should be a sequence" )
926
926
927
- if not isinstance (interpolation , InterpolationModes ):
928
- raise TypeError ("Argument interpolation should be a InterpolationModes " )
927
+ if not isinstance (interpolation , InterpolationMode ):
928
+ raise TypeError ("Argument interpolation should be a InterpolationMode " )
929
929
930
930
if not isinstance (img , torch .Tensor ):
931
931
pil_interpolation = pil_modes_mapping [interpolation ]
@@ -945,7 +945,7 @@ def rotate(
945
945
946
946
def affine (
947
947
img : Tensor , angle : float , translate : List [int ], scale : float , shear : List [float ],
948
- interpolation : InterpolationModes = InterpolationModes .NEAREST , fill : Optional [int ] = None ,
948
+ interpolation : InterpolationMode = InterpolationMode .NEAREST , fill : Optional [int ] = None ,
949
949
resample : Optional [int ] = None , fillcolor : Optional [int ] = None
950
950
) -> Tensor :
951
951
"""Apply affine transformation on the image keeping image center invariant.
@@ -960,9 +960,9 @@ def affine(
960
960
shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction.
961
961
If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while
962
962
the second value corresponds to a shear parallel to the y axis.
963
- interpolation (InterpolationModes ): Desired interpolation enum defined by
964
- :class:`torchvision.transforms.InterpolationModes `. Default is ``InterpolationModes .NEAREST``.
965
- If input is Tensor, only ``InterpolationModes .NEAREST``, ``InterpolationModes .BILINEAR`` are supported.
963
+ interpolation (InterpolationMode ): Desired interpolation enum defined by
964
+ :class:`torchvision.transforms.InterpolationMode `. Default is ``InterpolationMode .NEAREST``.
965
+ If input is Tensor, only ``InterpolationMode .NEAREST``, ``InterpolationMode .BILINEAR`` are supported.
966
966
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
967
967
fill (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0).
968
968
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
984
# Backward compatibility with integer value
985
985
if isinstance (interpolation , int ):
986
986
warnings .warn (
987
- "Argument interpolation should be of type InterpolationModes instead of int. "
988
- "Please, use InterpolationModes enum."
987
+ "Argument interpolation should be of type InterpolationMode instead of int. "
988
+ "Please, use InterpolationMode enum."
989
989
)
990
990
interpolation = _interpolation_modes_from_int (interpolation )
991
991
@@ -1010,8 +1010,8 @@ def affine(
1010
1010
if not isinstance (shear , (numbers .Number , (list , tuple ))):
1011
1011
raise TypeError ("Shear should be either a single value or a sequence of two values" )
1012
1012
1013
- if not isinstance (interpolation , InterpolationModes ):
1014
- raise TypeError ("Argument interpolation should be a InterpolationModes " )
1013
+ if not isinstance (interpolation , InterpolationMode ):
1014
+ raise TypeError ("Argument interpolation should be a InterpolationMode " )
1015
1015
1016
1016
if isinstance (angle , int ):
1017
1017
angle = float (angle )
0 commit comments