14
14
except ImportError :
15
15
accimage = None
16
16
17
+ from ..utils import _log_api_usage_once
17
18
from . import functional_pil as F_pil
18
19
from . import functional_tensor as F_t
19
20
@@ -67,6 +68,8 @@ def get_image_size(img: Tensor) -> List[int]:
67
68
Returns:
68
69
List[int]: The image size.
69
70
"""
71
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
72
+ _log_api_usage_once (get_image_size )
70
73
if isinstance (img , torch .Tensor ):
71
74
return F_t .get_image_size (img )
72
75
@@ -82,6 +85,8 @@ def get_image_num_channels(img: Tensor) -> int:
82
85
Returns:
83
86
int: The number of channels.
84
87
"""
88
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
89
+ _log_api_usage_once (get_image_num_channels )
85
90
if isinstance (img , torch .Tensor ):
86
91
return F_t .get_image_num_channels (img )
87
92
@@ -110,6 +115,8 @@ def to_tensor(pic):
110
115
Returns:
111
116
Tensor: Converted image.
112
117
"""
118
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
119
+ _log_api_usage_once (to_tensor )
113
120
if not (F_pil ._is_pil_image (pic ) or _is_numpy (pic )):
114
121
raise TypeError (f"pic should be PIL Image or ndarray. Got { type (pic )} " )
115
122
@@ -166,6 +173,8 @@ def pil_to_tensor(pic):
166
173
Returns:
167
174
Tensor: Converted image.
168
175
"""
176
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
177
+ _log_api_usage_once (pil_to_tensor )
169
178
if not F_pil ._is_pil_image (pic ):
170
179
raise TypeError (f"pic should be PIL Image. Got { type (pic )} " )
171
180
@@ -205,6 +214,8 @@ def convert_image_dtype(image: torch.Tensor, dtype: torch.dtype = torch.float) -
205
214
overflow errors since the floating point ``dtype`` cannot store consecutive integers over the whole range
206
215
of the integer ``dtype``.
207
216
"""
217
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
218
+ _log_api_usage_once (convert_image_dtype )
208
219
if not isinstance (image , torch .Tensor ):
209
220
raise TypeError ("Input img should be Tensor Image" )
210
221
@@ -225,6 +236,8 @@ def to_pil_image(pic, mode=None):
225
236
Returns:
226
237
PIL Image: Image converted to PIL Image.
227
238
"""
239
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
240
+ _log_api_usage_once (to_pil_image )
228
241
if not (isinstance (pic , torch .Tensor ) or isinstance (pic , np .ndarray )):
229
242
raise TypeError (f"pic should be Tensor or ndarray. Got { type (pic )} ." )
230
243
@@ -322,6 +335,8 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool
322
335
Returns:
323
336
Tensor: Normalized Tensor image.
324
337
"""
338
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
339
+ _log_api_usage_once (normalize )
325
340
if not isinstance (tensor , torch .Tensor ):
326
341
raise TypeError (f"Input tensor should be a torch tensor. Got { type (tensor )} ." )
327
342
@@ -401,6 +416,8 @@ def resize(
401
416
Returns:
402
417
PIL Image or Tensor: Resized image.
403
418
"""
419
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
420
+ _log_api_usage_once (resize )
404
421
# Backward compatibility with integer value
405
422
if isinstance (interpolation , int ):
406
423
warnings .warn (
@@ -422,6 +439,8 @@ def resize(
422
439
423
440
424
441
def scale (* args , ** kwargs ):
442
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
443
+ _log_api_usage_once (scale )
425
444
warnings .warn ("The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead." )
426
445
return resize (* args , ** kwargs )
427
446
@@ -467,6 +486,8 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
467
486
Returns:
468
487
PIL Image or Tensor: Padded image.
469
488
"""
489
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
490
+ _log_api_usage_once (pad )
470
491
if not isinstance (img , torch .Tensor ):
471
492
return F_pil .pad (img , padding = padding , fill = fill , padding_mode = padding_mode )
472
493
@@ -490,6 +511,8 @@ def crop(img: Tensor, top: int, left: int, height: int, width: int) -> Tensor:
490
511
PIL Image or Tensor: Cropped image.
491
512
"""
492
513
514
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
515
+ _log_api_usage_once (crop )
493
516
if not isinstance (img , torch .Tensor ):
494
517
return F_pil .crop (img , top , left , height , width )
495
518
@@ -510,6 +533,8 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
510
533
Returns:
511
534
PIL Image or Tensor: Cropped image.
512
535
"""
536
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
537
+ _log_api_usage_once (center_crop )
513
538
if isinstance (output_size , numbers .Number ):
514
539
output_size = (int (output_size ), int (output_size ))
515
540
elif isinstance (output_size , (tuple , list )) and len (output_size ) == 1 :
@@ -566,6 +591,8 @@ def resized_crop(
566
591
Returns:
567
592
PIL Image or Tensor: Cropped image.
568
593
"""
594
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
595
+ _log_api_usage_once (resized_crop )
569
596
img = crop (img , top , left , height , width )
570
597
img = resize (img , size , interpolation )
571
598
return img
@@ -583,6 +610,8 @@ def hflip(img: Tensor) -> Tensor:
583
610
Returns:
584
611
PIL Image or Tensor: Horizontally flipped image.
585
612
"""
613
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
614
+ _log_api_usage_once (hflip )
586
615
if not isinstance (img , torch .Tensor ):
587
616
return F_pil .hflip (img )
588
617
@@ -648,6 +677,8 @@ def perspective(
648
677
Returns:
649
678
PIL Image or Tensor: transformed Image.
650
679
"""
680
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
681
+ _log_api_usage_once (perspective )
651
682
652
683
coeffs = _get_perspective_coeffs (startpoints , endpoints )
653
684
@@ -681,6 +712,8 @@ def vflip(img: Tensor) -> Tensor:
681
712
Returns:
682
713
PIL Image or Tensor: Vertically flipped image.
683
714
"""
715
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
716
+ _log_api_usage_once (vflip )
684
717
if not isinstance (img , torch .Tensor ):
685
718
return F_pil .vflip (img )
686
719
@@ -706,6 +739,8 @@ def five_crop(img: Tensor, size: List[int]) -> Tuple[Tensor, Tensor, Tensor, Ten
706
739
tuple: tuple (tl, tr, bl, br, center)
707
740
Corresponding top left, top right, bottom left, bottom right and center crop.
708
741
"""
742
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
743
+ _log_api_usage_once (five_crop )
709
744
if isinstance (size , numbers .Number ):
710
745
size = (int (size ), int (size ))
711
746
elif isinstance (size , (tuple , list )) and len (size ) == 1 :
@@ -753,6 +788,8 @@ def ten_crop(img: Tensor, size: List[int], vertical_flip: bool = False) -> List[
753
788
Corresponding top left, top right, bottom left, bottom right and
754
789
center crop and same for the flipped image.
755
790
"""
791
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
792
+ _log_api_usage_once (ten_crop )
756
793
if isinstance (size , numbers .Number ):
757
794
size = (int (size ), int (size ))
758
795
elif isinstance (size , (tuple , list )) and len (size ) == 1 :
@@ -786,6 +823,8 @@ def adjust_brightness(img: Tensor, brightness_factor: float) -> Tensor:
786
823
Returns:
787
824
PIL Image or Tensor: Brightness adjusted image.
788
825
"""
826
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
827
+ _log_api_usage_once (adjust_brightness )
789
828
if not isinstance (img , torch .Tensor ):
790
829
return F_pil .adjust_brightness (img , brightness_factor )
791
830
@@ -806,6 +845,8 @@ def adjust_contrast(img: Tensor, contrast_factor: float) -> Tensor:
806
845
Returns:
807
846
PIL Image or Tensor: Contrast adjusted image.
808
847
"""
848
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
849
+ _log_api_usage_once (adjust_contrast )
809
850
if not isinstance (img , torch .Tensor ):
810
851
return F_pil .adjust_contrast (img , contrast_factor )
811
852
@@ -826,6 +867,8 @@ def adjust_saturation(img: Tensor, saturation_factor: float) -> Tensor:
826
867
Returns:
827
868
PIL Image or Tensor: Saturation adjusted image.
828
869
"""
870
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
871
+ _log_api_usage_once (adjust_saturation )
829
872
if not isinstance (img , torch .Tensor ):
830
873
return F_pil .adjust_saturation (img , saturation_factor )
831
874
@@ -860,6 +903,8 @@ def adjust_hue(img: Tensor, hue_factor: float) -> Tensor:
860
903
Returns:
861
904
PIL Image or Tensor: Hue adjusted image.
862
905
"""
906
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
907
+ _log_api_usage_once (adjust_hue )
863
908
if not isinstance (img , torch .Tensor ):
864
909
return F_pil .adjust_hue (img , hue_factor )
865
910
@@ -891,6 +936,8 @@ def adjust_gamma(img: Tensor, gamma: float, gain: float = 1) -> Tensor:
891
936
Returns:
892
937
PIL Image or Tensor: Gamma correction adjusted image.
893
938
"""
939
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
940
+ _log_api_usage_once (adjust_gamma )
894
941
if not isinstance (img , torch .Tensor ):
895
942
return F_pil .adjust_gamma (img , gamma , gain )
896
943
@@ -987,6 +1034,8 @@ def rotate(
987
1034
.. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
988
1035
989
1036
"""
1037
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1038
+ _log_api_usage_once (rotate )
990
1039
if resample is not None :
991
1040
warnings .warn (
992
1041
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
@@ -1067,6 +1116,8 @@ def affine(
1067
1116
Returns:
1068
1117
PIL Image or Tensor: Transformed image.
1069
1118
"""
1119
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1120
+ _log_api_usage_once (affine )
1070
1121
if resample is not None :
1071
1122
warnings .warn (
1072
1123
"Argument resample is deprecated and will be removed since v0.10.0. Please, use interpolation instead"
@@ -1151,6 +1202,8 @@ def to_grayscale(img, num_output_channels=1):
1151
1202
- if num_output_channels = 1 : returned image is single channel
1152
1203
- if num_output_channels = 3 : returned image is 3 channel with r = g = b
1153
1204
"""
1205
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1206
+ _log_api_usage_once (to_grayscale )
1154
1207
if isinstance (img , Image .Image ):
1155
1208
return F_pil .to_grayscale (img , num_output_channels )
1156
1209
@@ -1176,6 +1229,8 @@ def rgb_to_grayscale(img: Tensor, num_output_channels: int = 1) -> Tensor:
1176
1229
- if num_output_channels = 1 : returned image is single channel
1177
1230
- if num_output_channels = 3 : returned image is 3 channel with r = g = b
1178
1231
"""
1232
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1233
+ _log_api_usage_once (rgb_to_grayscale )
1179
1234
if not isinstance (img , torch .Tensor ):
1180
1235
return F_pil .to_grayscale (img , num_output_channels )
1181
1236
@@ -1198,6 +1253,8 @@ def erase(img: Tensor, i: int, j: int, h: int, w: int, v: Tensor, inplace: bool
1198
1253
Returns:
1199
1254
Tensor Image: Erased image.
1200
1255
"""
1256
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1257
+ _log_api_usage_once (erase )
1201
1258
if not isinstance (img , torch .Tensor ):
1202
1259
raise TypeError (f"img should be Tensor Image. Got { type (img )} " )
1203
1260
@@ -1234,6 +1291,8 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa
1234
1291
Returns:
1235
1292
PIL Image or Tensor: Gaussian Blurred version of the image.
1236
1293
"""
1294
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1295
+ _log_api_usage_once (gaussian_blur )
1237
1296
if not isinstance (kernel_size , (int , list , tuple )):
1238
1297
raise TypeError (f"kernel_size should be int or a sequence of integers. Got { type (kernel_size )} " )
1239
1298
if isinstance (kernel_size , int ):
@@ -1285,6 +1344,8 @@ def invert(img: Tensor) -> Tensor:
1285
1344
Returns:
1286
1345
PIL Image or Tensor: Color inverted image.
1287
1346
"""
1347
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1348
+ _log_api_usage_once (invert )
1288
1349
if not isinstance (img , torch .Tensor ):
1289
1350
return F_pil .invert (img )
1290
1351
@@ -1304,6 +1365,8 @@ def posterize(img: Tensor, bits: int) -> Tensor:
1304
1365
Returns:
1305
1366
PIL Image or Tensor: Posterized image.
1306
1367
"""
1368
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1369
+ _log_api_usage_once (posterize )
1307
1370
if not (0 <= bits <= 8 ):
1308
1371
raise ValueError (f"The number if bits should be between 0 and 8. Got { bits } " )
1309
1372
@@ -1325,6 +1388,8 @@ def solarize(img: Tensor, threshold: float) -> Tensor:
1325
1388
Returns:
1326
1389
PIL Image or Tensor: Solarized image.
1327
1390
"""
1391
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1392
+ _log_api_usage_once (solarize )
1328
1393
if not isinstance (img , torch .Tensor ):
1329
1394
return F_pil .solarize (img , threshold )
1330
1395
@@ -1345,6 +1410,8 @@ def adjust_sharpness(img: Tensor, sharpness_factor: float) -> Tensor:
1345
1410
Returns:
1346
1411
PIL Image or Tensor: Sharpness adjusted image.
1347
1412
"""
1413
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1414
+ _log_api_usage_once (adjust_sharpness )
1348
1415
if not isinstance (img , torch .Tensor ):
1349
1416
return F_pil .adjust_sharpness (img , sharpness_factor )
1350
1417
@@ -1365,6 +1432,8 @@ def autocontrast(img: Tensor) -> Tensor:
1365
1432
Returns:
1366
1433
PIL Image or Tensor: An image that was autocontrasted.
1367
1434
"""
1435
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1436
+ _log_api_usage_once (autocontrast )
1368
1437
if not isinstance (img , torch .Tensor ):
1369
1438
return F_pil .autocontrast (img )
1370
1439
@@ -1386,6 +1455,8 @@ def equalize(img: Tensor) -> Tensor:
1386
1455
Returns:
1387
1456
PIL Image or Tensor: An image that was equalized.
1388
1457
"""
1458
+ if not torch .jit .is_scripting () and not torch .jit .is_tracing ():
1459
+ _log_api_usage_once (equalize )
1389
1460
if not isinstance (img , torch .Tensor ):
1390
1461
return F_pil .equalize (img )
1391
1462
0 commit comments