@@ -11,7 +11,7 @@ def _is_tensor_a_torch_image(x: Tensor) -> bool:
11
11
return x .ndim >= 2
12
12
13
13
14
- def _assert_image_tensor (img ) :
14
+ def _assert_image_tensor (img : Tensor ) -> None :
15
15
if not _is_tensor_a_torch_image (img ):
16
16
raise TypeError ("Tensor is not a torch image." )
17
17
@@ -317,7 +317,7 @@ def _blend(img1: Tensor, img2: Tensor, ratio: float) -> Tensor:
317
317
return (ratio * img1 + (1.0 - ratio ) * img2 ).clamp (0 , bound ).to (img1 .dtype )
318
318
319
319
320
- def _rgb2hsv (img ) :
320
+ def _rgb2hsv (img : Tensor ) -> Tensor :
321
321
r , g , b = img .unbind (dim = - 3 )
322
322
323
323
# Implementation is based on https://github.com/python-pillow/Pillow/blob/4174d4267616897df3746d315d5a2d0f82c656ee/
@@ -356,7 +356,7 @@ def _rgb2hsv(img):
356
356
return torch .stack ((h , s , maxc ), dim = - 3 )
357
357
358
358
359
- def _hsv2rgb (img ) :
359
+ def _hsv2rgb (img : Tensor ) -> Tensor :
360
360
h , s , v = img .unbind (dim = - 3 )
361
361
i = torch .floor (h * 6.0 )
362
362
f = (h * 6.0 ) - i
@@ -388,15 +388,15 @@ def _pad_symmetric(img: Tensor, padding: List[int]) -> Tensor:
388
388
389
389
in_sizes = img .size ()
390
390
391
- x_indices = [i for i in range (in_sizes [- 1 ])] # [0, 1, 2, 3, ...]
391
+ _x_indices = [i for i in range (in_sizes [- 1 ])] # [0, 1, 2, 3, ...]
392
392
left_indices = [i for i in range (padding [0 ] - 1 , - 1 , - 1 )] # e.g. [3, 2, 1, 0]
393
393
right_indices = [- (i + 1 ) for i in range (padding [1 ])] # e.g. [-1, -2, -3]
394
- x_indices = torch .tensor (left_indices + x_indices + right_indices , device = img .device )
394
+ x_indices = torch .tensor (left_indices + _x_indices + right_indices , device = img .device )
395
395
396
- y_indices = [i for i in range (in_sizes [- 2 ])]
396
+ _y_indices = [i for i in range (in_sizes [- 2 ])]
397
397
top_indices = [i for i in range (padding [2 ] - 1 , - 1 , - 1 )]
398
398
bottom_indices = [- (i + 1 ) for i in range (padding [3 ])]
399
- y_indices = torch .tensor (top_indices + y_indices + bottom_indices , device = img .device )
399
+ y_indices = torch .tensor (top_indices + _y_indices + bottom_indices , device = img .device )
400
400
401
401
ndim = img .ndim
402
402
if ndim == 3 :
@@ -560,13 +560,13 @@ def resize(
560
560
561
561
562
562
def _assert_grid_transform_inputs (
563
- img : Tensor ,
564
- matrix : Optional [List [float ]],
565
- interpolation : str ,
566
- fill : Optional [List [float ]],
567
- supported_interpolation_modes : List [str ],
568
- coeffs : Optional [List [float ]] = None ,
569
- ):
563
+ img : Tensor ,
564
+ matrix : Optional [List [float ]],
565
+ interpolation : str ,
566
+ fill : Optional [List [float ]],
567
+ supported_interpolation_modes : List [str ],
568
+ coeffs : Optional [List [float ]] = None ,
569
+ ) -> None :
570
570
571
571
if not (isinstance (img , torch .Tensor )):
572
572
raise TypeError ("Input img should be Tensor" )
@@ -612,7 +612,7 @@ def _cast_squeeze_in(img: Tensor, req_dtypes: List[torch.dtype]) -> Tuple[Tensor
612
612
return img , need_cast , need_squeeze , out_dtype
613
613
614
614
615
- def _cast_squeeze_out (img : Tensor , need_cast : bool , need_squeeze : bool , out_dtype : torch .dtype ):
615
+ def _cast_squeeze_out (img : Tensor , need_cast : bool , need_squeeze : bool , out_dtype : torch .dtype ) -> Tensor :
616
616
if need_squeeze :
617
617
img = img .squeeze (dim = 0 )
618
618
@@ -732,7 +732,7 @@ def rotate(
732
732
return _apply_grid_transform (img , grid , interpolation , fill = fill )
733
733
734
734
735
- def _perspective_grid (coeffs : List [float ], ow : int , oh : int , dtype : torch .dtype , device : torch .device ):
735
+ def _perspective_grid (coeffs : List [float ], ow : int , oh : int , dtype : torch .dtype , device : torch .device ) -> Tensor :
736
736
# https://github.com/python-pillow/Pillow/blob/4634eafe3c695a014267eefdce830b4a825beed7/
737
737
# src/libImaging/Geometry.c#L394
738
738
@@ -922,7 +922,7 @@ def autocontrast(img: Tensor) -> Tensor:
922
922
return ((img - minimum ) * scale ).clamp (0 , bound ).to (img .dtype )
923
923
924
924
925
- def _scale_channel (img_chan ) :
925
+ def _scale_channel (img_chan : Tensor ) -> Tensor :
926
926
# TODO: we should expect bincount to always be faster than histc, but this
927
927
# isn't always the case. Once
928
928
# https://github.com/pytorch/pytorch/issues/53194 is fixed, remove the if
0 commit comments