Skip to content

Commit 2f3b7ca

Browse files
authored
Various doc fixes for transforms (#3704)
1 parent d9338f3 commit 2f3b7ca

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

torchvision/transforms/functional.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = Inte
370370
the resized image: if the longer edge of the image is greater
371371
than ``max_size`` after being resized according to ``size``, then
372372
the image is resized again so that the longer edge is equal to
373-
``max_size``. As a result, ```size` might be overruled, i.e the
373+
``max_size``. As a result, ``size`` might be overruled, i.e the
374374
smaller edge may be shorter than ``size``. This is only supported
375375
if ``size`` is an int (or a sequence of length 1 in torchscript
376376
mode).
@@ -424,22 +424,21 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
424424
This value is only used when the padding_mode is constant.
425425
Only number is supported for torch Tensor.
426426
Only int or str or tuple value is supported for PIL Image.
427-
padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
427+
padding_mode (str): Type of padding. Should be: constant, edge, reflect or symmetric.
428+
Default is constant.
428429
429430
- constant: pads with a constant value, this value is specified with fill
430431
431-
- edge: pads with the last value on the edge of the image,
432-
if input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2
432+
- edge: pads with the last value at the edge of the image.
433+
If input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2
433434
434-
- reflect: pads with reflection of image (without repeating the last value on the edge)
435+
- reflect: pads with reflection of image without repeating the last value on the edge.
436+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
437+
will result in [3, 2, 1, 2, 3, 4, 3, 2]
435438
436-
padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
437-
will result in [3, 2, 1, 2, 3, 4, 3, 2]
438-
439-
- symmetric: pads with reflection of image (repeating the last value on the edge)
440-
441-
padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
442-
will result in [2, 1, 1, 2, 3, 4, 4, 3]
439+
- symmetric: pads with reflection of image repeating the last value on the edge.
440+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
441+
will result in [2, 1, 1, 2, 3, 4, 4, 3]
443442
444443
Returns:
445444
PIL Image or Tensor: Padded image.

torchvision/transforms/transforms.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class Resize(torch.nn.Module):
253253
the resized image: if the longer edge of the image is greater
254254
than ``max_size`` after being resized according to ``size``, then
255255
the image is resized again so that the longer edge is equal to
256-
``max_size``. As a result, ```size` might be overruled, i.e the
256+
``max_size``. As a result, ``size`` might be overruled, i.e the
257257
smaller edge may be shorter than ``size``. This is only supported
258258
if ``size`` is an int (or a sequence of length 1 in torchscript
259259
mode).
@@ -361,18 +361,16 @@ class Pad(torch.nn.Module):
361361
362362
- constant: pads with a constant value, this value is specified with fill
363363
364-
- edge: pads with the last value at the edge of the image,
365-
if input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2
364+
- edge: pads with the last value at the edge of the image.
365+
If input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2
366366
367-
- reflect: pads with reflection of image without repeating the last value on the edge
367+
- reflect: pads with reflection of image without repeating the last value on the edge.
368+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
369+
will result in [3, 2, 1, 2, 3, 4, 3, 2]
368370
369-
For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
370-
will result in [3, 2, 1, 2, 3, 4, 3, 2]
371-
372-
- symmetric: pads with reflection of image repeating the last value on the edge
373-
374-
For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
375-
will result in [2, 1, 1, 2, 3, 4, 4, 3]
371+
- symmetric: pads with reflection of image repeating the last value on the edge.
372+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
373+
will result in [2, 1, 1, 2, 3, 4, 4, 3]
376374
"""
377375

378376
def __init__(self, padding, fill=0, padding_mode="constant"):
@@ -540,22 +538,21 @@ class RandomCrop(torch.nn.Module):
540538
This value is only used when the padding_mode is constant.
541539
Only number is supported for torch Tensor.
542540
Only int or str or tuple value is supported for PIL Image.
543-
padding_mode (str): Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
544-
545-
- constant: pads with a constant value, this value is specified with fill
546-
547-
- edge: pads with the last value on the edge of the image
548-
549-
- reflect: pads with reflection of image (without repeating the last value on the edge)
541+
padding_mode (str): Type of padding. Should be: constant, edge, reflect or symmetric.
542+
Default is constant.
550543
551-
padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
552-
will result in [3, 2, 1, 2, 3, 4, 3, 2]
544+
- constant: pads with a constant value, this value is specified with fill
553545
554-
- symmetric: pads with reflection of image (repeating the last value on the edge)
546+
- edge: pads with the last value at the edge of the image.
547+
If input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2
555548
556-
padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
557-
will result in [2, 1, 1, 2, 3, 4, 4, 3]
549+
- reflect: pads with reflection of image without repeating the last value on the edge.
550+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
551+
will result in [3, 2, 1, 2, 3, 4, 3, 2]
558552
553+
- symmetric: pads with reflection of image repeating the last value on the edge.
554+
For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
555+
will result in [2, 1, 1, 2, 3, 4, 4, 3]
559556
"""
560557

561558
@staticmethod

0 commit comments

Comments
 (0)