Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
7dd4912c
Unverified
Commit
7dd4912c
authored
Apr 20, 2021
by
Nicolas Hug
Committed by
GitHub
Apr 20, 2021
Browse files
Make torchscript parameter constraints more obvious (#3693)
parent
86500c84
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
18 deletions
+42
-18
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+28
-14
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+14
-4
No files found.
torchvision/transforms/functional.py
View file @
7dd4912c
...
@@ -358,6 +358,8 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = Inte
...
@@ -358,6 +358,8 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = Inte
the smaller edge of the image will be matched to this number maintaining
the smaller edge of the image will be matched to this number maintaining
the aspect ratio. i.e, if height > width, then image will be rescaled to
the aspect ratio. i.e, if height > width, then image will be rescaled to
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
.. note::
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
interpolation (InterpolationMode): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode`.
:class:`torchvision.transforms.InterpolationMode`.
...
@@ -413,7 +415,10 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
...
@@ -413,7 +415,10 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
is used to pad all borders. If sequence of length 2 is provided this is the padding
is used to pad all borders. If sequence of length 2 is provided this is the padding
on left/right and top/bottom respectively. If a sequence of length 4 is provided
on left/right and top/bottom respectively. If a sequence of length 4 is provided
this is the padding for the left, top, right and bottom borders respectively.
this is the padding for the left, top, right and bottom borders respectively.
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
.. note::
In torchscript mode padding as single int is not supported, use a sequence of
length 1: ``[padding, ]``.
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0.
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0.
If a tuple of length 3, it is used to fill R, G, B channels respectively.
If a tuple of length 3, it is used to fill R, G, B channels respectively.
This value is only used when the padding_mode is constant.
This value is only used when the padding_mode is constant.
...
@@ -608,9 +613,10 @@ def perspective(
...
@@ -608,9 +613,10 @@ def perspective(
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
image. If given a number, the value is used for all bands respectively.
image. If given a number, the value is used for all bands respectively.
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
of length 1: ``[value, ]``.
If input is PIL Image, the options is only available for ``Pillow>=5.0.0``.
Returns:
Returns:
PIL Image or Tensor: transformed Image.
PIL Image or Tensor: transformed Image.
...
@@ -938,9 +944,10 @@ def rotate(
...
@@ -938,9 +944,10 @@ def rotate(
Default is the center of the image.
Default is the center of the image.
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
image. If given a number, the value is used for all bands respectively.
image. If given a number, the value is used for all bands respectively.
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
of length 1: ``[value, ]``.
If input is PIL Image, the options is only available for ``Pillow>=5.2.0``.
Returns:
Returns:
PIL Image or Tensor: Rotated image.
PIL Image or Tensor: Rotated image.
...
@@ -1010,9 +1017,10 @@ def affine(
...
@@ -1010,9 +1017,10 @@ def affine(
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
image. If given a number, the value is used for all bands respectively.
image. If given a number, the value is used for all bands respectively.
.. note::
In torchscript mode single int/float value is not supported, please use a sequence
In torchscript mode single int/float value is not supported, please use a sequence
of length 1: ``[value, ]``.
of length 1: ``[value, ]``.
If input is PIL Image, the options is only available for ``Pillow>=5.0.0``.
fillcolor (sequence, int, float): deprecated argument and will be removed since v0.10.0.
fillcolor (sequence, int, float): deprecated argument and will be removed since v0.10.0.
Please use the ``fill`` parameter instead.
Please use the ``fill`` parameter instead.
resample (int, optional): deprecated argument and will be removed since v0.10.0.
resample (int, optional): deprecated argument and will be removed since v0.10.0.
...
@@ -1173,12 +1181,18 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa
...
@@ -1173,12 +1181,18 @@ def gaussian_blur(img: Tensor, kernel_size: List[int], sigma: Optional[List[floa
img (PIL Image or Tensor): Image to be blurred
img (PIL Image or Tensor): Image to be blurred
kernel_size (sequence of ints or int): Gaussian kernel size. Can be a sequence of integers
kernel_size (sequence of ints or int): Gaussian kernel size. Can be a sequence of integers
like ``(kx, ky)`` or a single integer for square kernels.
like ``(kx, ky)`` or a single integer for square kernels.
In torchscript mode kernel_size as single int is not supported, use a sequence of length 1: ``[ksize, ]``.
.. note::
In torchscript mode kernel_size as single int is not supported, use a sequence of
length 1: ``[ksize, ]``.
sigma (sequence of floats or float, optional): Gaussian kernel standard deviation. Can be a
sigma (sequence of floats or float, optional): Gaussian kernel standard deviation. Can be a
sequence of floats like ``(sigma_x, sigma_y)`` or a single float to define the
sequence of floats like ``(sigma_x, sigma_y)`` or a single float to define the
same sigma in both X/Y directions. If None, then it is computed using
same sigma in both X/Y directions. If None, then it is computed using
``kernel_size`` as ``sigma = 0.3 * ((kernel_size - 1) * 0.5 - 1) + 0.8``.
``kernel_size`` as ``sigma = 0.3 * ((kernel_size - 1) * 0.5 - 1) + 0.8``.
Default, None. In torchscript mode sigma as single float is
Default, None.
.. note::
In torchscript mode sigma as single float is
not supported, use a sequence of length 1: ``[sigma, ]``.
not supported, use a sequence of length 1: ``[sigma, ]``.
Returns:
Returns:
...
...
torchvision/transforms/transforms.py
View file @
7dd4912c
...
@@ -241,6 +241,8 @@ class Resize(torch.nn.Module):
...
@@ -241,6 +241,8 @@ class Resize(torch.nn.Module):
smaller edge of the image will be matched to this number.
smaller edge of the image will be matched to this number.
i.e, if height > width, then image will be rescaled to
i.e, if height > width, then image will be rescaled to
(size * height / width, size).
(size * height / width, size).
.. note::
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
interpolation (InterpolationMode): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
...
@@ -345,7 +347,10 @@ class Pad(torch.nn.Module):
...
@@ -345,7 +347,10 @@ class Pad(torch.nn.Module):
is used to pad all borders. If sequence of length 2 is provided this is the padding
is used to pad all borders. If sequence of length 2 is provided this is the padding
on left/right and top/bottom respectively. If a sequence of length 4 is provided
on left/right and top/bottom respectively. If a sequence of length 4 is provided
this is the padding for the left, top, right and bottom borders respectively.
this is the padding for the left, top, right and bottom borders respectively.
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
.. note::
In torchscript mode padding as single int is not supported, use a sequence of
length 1: ``[padding, ]``.
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0. If a tuple of
fill (number or str or tuple): Pixel fill value for constant fill. Default is 0. If a tuple of
length 3, it is used to fill R, G, B channels respectively.
length 3, it is used to fill R, G, B channels respectively.
This value is only used when the padding_mode is constant.
This value is only used when the padding_mode is constant.
...
@@ -523,7 +528,10 @@ class RandomCrop(torch.nn.Module):
...
@@ -523,7 +528,10 @@ class RandomCrop(torch.nn.Module):
is used to pad all borders. If sequence of length 2 is provided this is the padding
is used to pad all borders. If sequence of length 2 is provided this is the padding
on left/right and top/bottom respectively. If a sequence of length 4 is provided
on left/right and top/bottom respectively. If a sequence of length 4 is provided
this is the padding for the left, top, right and bottom borders respectively.
this is the padding for the left, top, right and bottom borders respectively.
In torchscript mode padding as single int is not supported, use a sequence of length 1: ``[padding, ]``.
.. note::
In torchscript mode padding as single int is not supported, use a sequence of
length 1: ``[padding, ]``.
pad_if_needed (boolean): It will pad the image if smaller than the
pad_if_needed (boolean): It will pad the image if smaller than the
desired size to avoid raising an exception. Since cropping is done
desired size to avoid raising an exception. Since cropping is done
after padding, the padding seems to be done at a random offset.
after padding, the padding seems to be done at a random offset.
...
@@ -792,6 +800,8 @@ class RandomResizedCrop(torch.nn.Module):
...
@@ -792,6 +800,8 @@ class RandomResizedCrop(torch.nn.Module):
size (int or sequence): expected output size of the crop, for each edge. If size is an
size (int or sequence): expected output size of the crop, for each edge. If size is an
int instead of sequence like (h, w), a square output size ``(size, size)`` is
int instead of sequence like (h, w), a square output size ``(size, size)`` is
made. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).
made. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).
.. note::
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
In torchscript mode size as single int is not supported, use a sequence of length 1: ``[size, ]``.
scale (tuple of float): Specifies the lower and upper bounds for the random area of the crop,
scale (tuple of float): Specifies the lower and upper bounds for the random area of the crop,
before resizing. The scale is defined with respect to the area of the original image.
before resizing. The scale is defined with respect to the area of the original image.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment