Skip to content

Commit 7dd4912

Browse files
authored
Make torchscript parameter constraints more obvious (#3693)
1 parent 86500c8 commit 7dd4912

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

torchvision/transforms/functional.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = Inte
358358
the smaller edge of the image will be matched to this number maintaining
359359
the aspect ratio. i.e, if height > width, then image will be rescaled to
360360
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
361-
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
361+
362+
.. note::
363+
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
362364
interpolation (InterpolationMode): Desired interpolation enum defined by
363365
:class:`torchvision.transforms.InterpolationMode`.
364366
Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
@@ -413,7 +415,10 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
413415
is used to pad all borders. If sequence of length 2 is provided this is the padding
414416
on left/right and top/bottom respectively. If a sequence of length 4 is provided
415417
this is the padding for the left, top, right and bottom borders respectively.
416-
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
418+
419+
.. note::
420+
In torchscript mode padding as single int is not supported, use a sequence of
421+
length 1: ``[padding, ]``.
417422
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0.
418423
If a tuple of length 3, it is used to fill R, G, B channels respectively.
419424
This value is only used when the padding_mode is constant.
@@ -608,9 +613,10 @@ def perspective(
608613
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
609614
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
610615
image. If given a number, the value is used for all bands respectively.
611-
In torchscript mode single int/float value is not supported, please use a sequence
612-
of length 1: ``[value, ]``.
613-
If input is PIL Image, the options is only available for ``Pillow>=5.0.0``.
616+
617+
.. note::
618+
In torchscript mode single int/float value is not supported, please use a sequence
619+
of length 1: ``[value, ]``.
614620
615621
Returns:
616622
PIL Image or Tensor: transformed Image.
@@ -938,9 +944,10 @@ def rotate(
938944
Default is the center of the image.
939945
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
940946
image. If given a number, the value is used for all bands respectively.
941-
In torchscript mode single int/float value is not supported, please use a sequence
942-
of length 1: ``[value, ]``.
943-
If input is PIL Image, the options is only available for ``Pillow>=5.2.0``.
947+
948+
.. note::
949+
In torchscript mode single int/float value is not supported, please use a sequence
950+
of length 1: ``[value, ]``.
944951
945952
Returns:
946953
PIL Image or Tensor: Rotated image.
@@ -1010,9 +1017,10 @@ def affine(
10101017
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
10111018
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
10121019
image. If given a number, the value is used for all bands respectively.
1013-
In torchscript mode single int/float value is not supported, please use a sequence
1014-
of length 1: ``[value, ]``.
1015-
If input is PIL Image, the options is only available for ``Pillow>=5.0.0``.
1020+
1021+
.. note::
1022+
In torchscript mode single int/float value is not supported, please use a sequence
1023+
of length 1: ``[value, ]``.
10161024
fillcolor (sequence, int, float): deprecated argument and will be removed since v0.10.0.
10171025
Please use the ``fill`` parameter instead.
10181026
resample (int, optional): deprecated argument and will be removed since v0.10.0.
@@ -1173,13 +1181,19 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa
11731181
img (PIL Image or Tensor): Image to be blurred
11741182
kernel_size (sequence of ints or int): Gaussian kernel size. Can be a sequence of integers
11751183
like ``(kx, ky)`` or a single integer for square kernels.
1176-
In torchscript mode kernel_size as single int is not supported, use a sequence of length 1: ``[ksize, ]``.
1184+
1185+
.. note::
1186+
In torchscript mode kernel_size as single int is not supported, use a sequence of
1187+
length 1: ``[ksize, ]``.
11771188
sigma (sequence of floats or float, optional): Gaussian kernel standard deviation. Can be a
11781189
sequence of floats like ``(sigma_x, sigma_y)`` or a single float to define the
11791190
same sigma in both X/Y directions. If None, then it is computed using
11801191
``kernel_size`` as ``sigma = 0.3 * ((kernel_size - 1) * 0.5 - 1) + 0.8``.
1181-
Default, None. In torchscript mode sigma as single float is
1182-
not supported, use a sequence of length 1: ``[sigma, ]``.
1192+
Default, None.
1193+
1194+
.. note::
1195+
In torchscript mode sigma as single float is
1196+
not supported, use a sequence of length 1: ``[sigma, ]``.
11831197
11841198
Returns:
11851199
PIL Image or Tensor: Gaussian Blurred version of the image.

torchvision/transforms/transforms.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ class Resize(torch.nn.Module):
241241
smaller edge of the image will be matched to this number.
242242
i.e, if height > width, then image will be rescaled to
243243
(size * height / width, size).
244-
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
244+
245+
.. note::
246+
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
245247
interpolation (InterpolationMode): Desired interpolation enum defined by
246248
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
247249
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` and
@@ -345,7 +347,10 @@ class Pad(torch.nn.Module):
345347
is used to pad all borders. If sequence of length 2 is provided this is the padding
346348
on left/right and top/bottom respectively. If a sequence of length 4 is provided
347349
this is the padding for the left, top, right and bottom borders respectively.
348-
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
350+
351+
.. note::
352+
In torchscript mode padding as single int is not supported, use a sequence of
353+
length 1: ``[padding, ]``.
349354
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0. If a tuple of
350355
length 3, it is used to fill R, G, B channels respectively.
351356
This value is only used when the padding_mode is constant.
@@ -523,7 +528,10 @@ class RandomCrop(torch.nn.Module):
523528
is used to pad all borders. If sequence of length 2 is provided this is the padding
524529
on left/right and top/bottom respectively. If a sequence of length 4 is provided
525530
this is the padding for the left, top, right and bottom borders respectively.
526-
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
531+
532+
.. note::
533+
In torchscript mode padding as single int is not supported, use a sequence of
534+
length 1: ``[padding, ]``.
527535
pad_if_needed (boolean): It will pad the image if smaller than the
528536
desired size to avoid raising an exception. Since cropping is done
529537
after padding, the padding seems to be done at a random offset.
@@ -792,7 +800,9 @@ class RandomResizedCrop(torch.nn.Module):
792800
size (int or sequence): expected output size of the crop, for each edge. If size is an
793801
int instead of sequence like (h, w), a square output size ``(size, size)`` is
794802
made. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).
795-
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
803+
804+
.. note::
805+
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
796806
scale (tuple of float): Specifies the lower and upper bounds for the random area of the crop,
797807
before resizing. The scale is defined with respect to the area of the original image.
798808
ratio (tuple of float): lower and upper bounds for the random aspect ratio of the crop, before

0 commit comments

Comments
 (0)