@@ -421,6 +421,7 @@ def resize(
421
421
Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
422
422
``InterpolationMode.NEAREST_EXACT``, ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are
423
423
supported.
424
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well.
424
425
max_size (int, optional): The maximum allowed for the longer edge of
425
426
the resized image: if the longer edge of the image is greater
426
427
than ``max_size`` after being resized according to ``size``, then
@@ -454,8 +455,12 @@ def resize(
454
455
if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
455
456
_log_api_usage_once (resize )
456
457
457
- if not isinstance (interpolation , InterpolationMode ):
458
- raise TypeError ("Argument interpolation should be a InterpolationMode" )
458
+ if isinstance (interpolation , int ):
459
+ interpolation = _interpolation_modes_from_int (interpolation )
460
+ elif not isinstance (interpolation , InterpolationMode ):
461
+ raise TypeError (
462
+ "Argument interpolation should be a InterpolationMode or a corresponding Pillow integer constant"
463
+ )
459
464
460
465
if isinstance (size , (list , tuple )):
461
466
if len (size ) not in [1 , 2 ]:
@@ -630,6 +635,7 @@ def resized_crop(
630
635
Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
631
636
``InterpolationMode.NEAREST_EXACT``, ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are
632
637
supported.
638
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well.
633
639
antialias (bool, optional): Whether to apply antialiasing.
634
640
It only affects **tensors** with bilinear or bicubic modes and it is
635
641
ignored otherwise: on PIL images, antialiasing is always applied on
@@ -726,6 +732,7 @@ def perspective(
726
732
interpolation (InterpolationMode): Desired interpolation enum defined by
727
733
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
728
734
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
735
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well.
729
736
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
730
737
image. If given a number, the value is used for all bands respectively.
731
738
@@ -741,8 +748,12 @@ def perspective(
741
748
742
749
coeffs = _get_perspective_coeffs (startpoints , endpoints )
743
750
744
- if not isinstance (interpolation , InterpolationMode ):
745
- raise TypeError ("Argument interpolation should be a InterpolationMode" )
751
+ if isinstance (interpolation , int ):
752
+ interpolation = _interpolation_modes_from_int (interpolation )
753
+ elif not isinstance (interpolation , InterpolationMode ):
754
+ raise TypeError (
755
+ "Argument interpolation should be a InterpolationMode or a corresponding Pillow integer constant"
756
+ )
746
757
747
758
if not isinstance (img , torch .Tensor ):
748
759
pil_interpolation = pil_modes_mapping [interpolation ]
@@ -1076,6 +1087,7 @@ def rotate(
1076
1087
interpolation (InterpolationMode): Desired interpolation enum defined by
1077
1088
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
1078
1089
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
1090
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well.
1079
1091
expand (bool, optional): Optional expansion flag.
1080
1092
If true, expands the output image to make it large enough to hold the entire rotated image.
1081
1093
If false or omitted, make the output image the same size as the input image.
@@ -1097,15 +1109,19 @@ def rotate(
1097
1109
if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1098
1110
_log_api_usage_once (rotate )
1099
1111
1112
+ if isinstance (interpolation , int ):
1113
+ interpolation = _interpolation_modes_from_int (interpolation )
1114
+ elif not isinstance (interpolation , InterpolationMode ):
1115
+ raise TypeError (
1116
+ "Argument interpolation should be a InterpolationMode or a corresponding Pillow integer constant"
1117
+ )
1118
+
1100
1119
if not isinstance (angle , (int , float )):
1101
1120
raise TypeError ("Argument angle should be int or float" )
1102
1121
1103
1122
if center is not None and not isinstance (center , (list , tuple )):
1104
1123
raise TypeError ("Argument center should be a sequence" )
1105
1124
1106
- if not isinstance (interpolation , InterpolationMode ):
1107
- raise TypeError ("Argument interpolation should be a InterpolationMode" )
1108
-
1109
1125
if not isinstance (img , torch .Tensor ):
1110
1126
pil_interpolation = pil_modes_mapping [interpolation ]
1111
1127
return F_pil .rotate (img , angle = angle , interpolation = pil_interpolation , expand = expand , center = center , fill = fill )
@@ -1147,6 +1163,7 @@ def affine(
1147
1163
interpolation (InterpolationMode): Desired interpolation enum defined by
1148
1164
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
1149
1165
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
1166
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well.
1150
1167
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
1151
1168
image. If given a number, the value is used for all bands respectively.
1152
1169
@@ -1162,6 +1179,13 @@ def affine(
1162
1179
if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1163
1180
_log_api_usage_once (affine )
1164
1181
1182
+ if isinstance (interpolation , int ):
1183
+ interpolation = _interpolation_modes_from_int (interpolation )
1184
+ elif not isinstance (interpolation , InterpolationMode ):
1185
+ raise TypeError (
1186
+ "Argument interpolation should be a InterpolationMode or a corresponding Pillow integer constant"
1187
+ )
1188
+
1165
1189
if not isinstance (angle , (int , float )):
1166
1190
raise TypeError ("Argument angle should be int or float" )
1167
1191
@@ -1177,9 +1201,6 @@ def affine(
1177
1201
if not isinstance (shear , (numbers .Number , (list , tuple ))):
1178
1202
raise TypeError ("Shear should be either a single value or a sequence of two values" )
1179
1203
1180
- if not isinstance (interpolation , InterpolationMode ):
1181
- raise TypeError ("Argument interpolation should be a InterpolationMode" )
1182
-
1183
1204
if isinstance (angle , int ):
1184
1205
angle = float (angle )
1185
1206
@@ -1524,7 +1545,7 @@ def elastic_transform(
1524
1545
interpolation (InterpolationMode): Desired interpolation enum defined by
1525
1546
:class:`torchvision.transforms.InterpolationMode`.
1526
1547
Default is ``InterpolationMode.BILINEAR``.
1527
- For backward compatibility integer values ( e.g. ``PIL.Image.NEAREST``) are still acceptable .
1548
+ The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well .
1528
1549
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0.
1529
1550
If a tuple of length 3, it is used to fill R, G, B channels respectively.
1530
1551
This value is only used when the padding_mode is constant.
0 commit comments