1
1
import numbers
2
2
import warnings
3
- from typing import List , Optional , Sequence , Tuple , Union
3
+ from typing import List , Optional , Tuple , Union
4
4
5
5
import PIL .Image
6
6
import torch
@@ -117,14 +117,12 @@ def resize_image_tensor(
117
117
@torch .jit .unused
118
118
def resize_image_pil (
119
119
img : PIL .Image .Image ,
120
- size : Union [Sequence [int ], int ],
120
+ size : Union [List [int ], int ],
121
121
interpolation : InterpolationMode = InterpolationMode .BILINEAR ,
122
122
max_size : Optional [int ] = None ,
123
123
) -> PIL .Image .Image :
124
124
if isinstance (size , int ):
125
125
size = [size , size ]
126
- # Explicitly cast size to list otherwise mypy issue: incompatible type "Sequence[int]"; expected "List[int]"
127
- size : List [int ] = list (size )
128
126
size = _compute_resized_output_size (img .size [::- 1 ], size = size , max_size = max_size )
129
127
return _FP .resize (img , size , interpolation = pil_modes_mapping [interpolation ])
130
128
@@ -261,7 +259,7 @@ def affine_image_pil(
261
259
scale : float ,
262
260
shear : List [float ],
263
261
interpolation : InterpolationMode = InterpolationMode .NEAREST ,
264
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
262
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
265
263
center : Optional [List [float ]] = None ,
266
264
) -> PIL .Image .Image :
267
265
angle , translate , shear , center = _affine_parse_args (angle , translate , scale , shear , interpolation , center )
@@ -403,15 +401,15 @@ def affine_mask(
403
401
return output
404
402
405
403
406
- def _convert_fill_arg (fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]]) -> Optional [List [float ]]:
404
+ def _convert_fill_arg (fill : Optional [Union [int , float , List [int ], List [float ]]]) -> Optional [List [float ]]:
407
405
# Fill = 0 is not equivalent to None, https://github.com/pytorch/vision/issues/6517
408
406
# So, we can't reassign fill to 0
409
407
# if fill is None:
410
408
# fill = 0
411
409
if fill is None :
412
410
return fill
413
411
414
- # This cast does Sequence -> List[float] to please mypy and torch.jit.script
412
+ # This cast does List -> List[float] to please mypy and torch.jit.script
415
413
if not isinstance (fill , (int , float )):
416
414
fill = [float (v ) for v in list (fill )]
417
415
else :
@@ -427,7 +425,7 @@ def affine(
427
425
scale : float ,
428
426
shear : List [float ],
429
427
interpolation : InterpolationMode = InterpolationMode .NEAREST ,
430
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
428
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
431
429
center : Optional [List [float ]] = None ,
432
430
) -> features .DType :
433
431
if isinstance (inpt , torch .Tensor ) and (torch .jit .is_scripting () or not isinstance (inpt , features ._Feature )):
@@ -503,7 +501,7 @@ def rotate_image_pil(
503
501
angle : float ,
504
502
interpolation : InterpolationMode = InterpolationMode .NEAREST ,
505
503
expand : bool = False ,
506
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
504
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
507
505
center : Optional [List [float ]] = None ,
508
506
) -> PIL .Image .Image :
509
507
if center is not None and expand :
@@ -570,7 +568,7 @@ def rotate(
570
568
angle : float ,
571
569
interpolation : InterpolationMode = InterpolationMode .NEAREST ,
572
570
expand : bool = False ,
573
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
571
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
574
572
center : Optional [List [float ]] = None ,
575
573
) -> features .DType :
576
574
if isinstance (inpt , torch .Tensor ) and (torch .jit .is_scripting () or not isinstance (inpt , features ._Feature )):
@@ -611,7 +609,7 @@ def pad_image_tensor(
611
609
def _pad_with_vector_fill (
612
610
img : torch .Tensor ,
613
611
padding : Union [int , List [int ]],
614
- fill : Sequence [float ] = [ 0.0 ],
612
+ fill : List [float ],
615
613
padding_mode : str = "constant" ,
616
614
) -> torch .Tensor :
617
615
if padding_mode != "constant" :
@@ -677,15 +675,11 @@ def pad_bounding_box(
677
675
678
676
def pad (
679
677
inpt : features .DType ,
680
- padding : Union [int , Sequence [int ]],
681
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
678
+ padding : Union [int , List [int ]],
679
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
682
680
padding_mode : str = "constant" ,
683
681
) -> features .DType :
684
682
if isinstance (inpt , torch .Tensor ) and (torch .jit .is_scripting () or not isinstance (inpt , features ._Feature )):
685
- # This cast does Sequence[int] -> List[int] and is required to make mypy happy
686
- if not isinstance (padding , int ):
687
- padding = list (padding )
688
-
689
683
# TODO: PyTorch's pad supports only scalars on fill. So we need to overwrite the colour
690
684
if isinstance (fill , (int , float )) or fill is None :
691
685
return pad_image_tensor (inpt , padding , fill = fill , padding_mode = padding_mode )
@@ -746,7 +740,7 @@ def perspective_image_pil(
746
740
img : PIL .Image .Image ,
747
741
perspective_coeffs : List [float ],
748
742
interpolation : InterpolationMode = InterpolationMode .BICUBIC ,
749
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
743
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
750
744
) -> PIL .Image .Image :
751
745
return _FP .perspective (img , perspective_coeffs , interpolation = pil_modes_mapping [interpolation ], fill = fill )
752
746
@@ -858,7 +852,7 @@ def perspective(
858
852
startpoints : List [List [int ]],
859
853
endpoints : List [List [int ]],
860
854
interpolation : InterpolationMode = InterpolationMode .BILINEAR ,
861
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
855
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
862
856
) -> features .DType :
863
857
perspective_coeffs = _get_perspective_coeffs (startpoints , endpoints )
864
858
@@ -885,7 +879,7 @@ def elastic_image_pil(
885
879
img : PIL .Image .Image ,
886
880
displacement : torch .Tensor ,
887
881
interpolation : InterpolationMode = InterpolationMode .BILINEAR ,
888
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
882
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
889
883
) -> PIL .Image .Image :
890
884
t_img = pil_to_tensor (img )
891
885
fill = _convert_fill_arg (fill )
@@ -953,7 +947,7 @@ def elastic(
953
947
inpt : features .DType ,
954
948
displacement : torch .Tensor ,
955
949
interpolation : InterpolationMode = InterpolationMode .BILINEAR ,
956
- fill : Optional [Union [int , float , Sequence [int ], Sequence [float ]]] = None ,
950
+ fill : Optional [Union [int , float , List [int ], List [float ]]] = None ,
957
951
) -> features .DType :
958
952
if isinstance (inpt , torch .Tensor ) and (torch .jit .is_scripting () or not isinstance (inpt , features ._Feature )):
959
953
fill = _convert_fill_arg (fill )
0 commit comments