未验证 提交 4f54891c 编写于 作者: L LielinJiang 提交者: GitHub

add input and output description docs for vision transform (#34926)

* add input and output docs for vision transform
上级 5eefc8c7
...@@ -309,7 +309,14 @@ class ToTensor(BaseTransform): ...@@ -309,7 +309,14 @@ class ToTensor(BaseTransform):
data_format (str, optional): Data format of output tensor, should be 'HWC' or data_format (str, optional): Data format of output tensor, should be 'HWC' or
'CHW'. Default: 'CHW'. 'CHW'. Default: 'CHW'.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray): The input image with shape (H x W x C).
- output(np.ndarray): A tensor with shape (C x H x W) or (H x W x C) according option data_format.
Returns:
A callable object of ToTensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -368,6 +375,13 @@ class Resize(BaseTransform): ...@@ -368,6 +375,13 @@ class Resize(BaseTransform):
- "lanczos": cv2.INTER_LANCZOS4 - "lanczos": cv2.INTER_LANCZOS4
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A resized image.
Returns:
A callable object of Resize.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -422,6 +436,13 @@ class RandomResizedCrop(BaseTransform): ...@@ -422,6 +436,13 @@ class RandomResizedCrop(BaseTransform):
- "lanczos": cv2.INTER_LANCZOS4 - "lanczos": cv2.INTER_LANCZOS4
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A cropped image.
Returns:
A callable object of RandomResizedCrop.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -503,6 +524,13 @@ class CenterCrop(BaseTransform): ...@@ -503,6 +524,13 @@ class CenterCrop(BaseTransform):
size (int|list|tuple): Target size of output image, with (height, width) shape. size (int|list|tuple): Target size of output image, with (height, width) shape.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A cropped image.
Returns:
A callable object of CenterCrop.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -537,6 +565,13 @@ class RandomHorizontalFlip(BaseTransform): ...@@ -537,6 +565,13 @@ class RandomHorizontalFlip(BaseTransform):
prob (float, optional): Probability of the input data being flipped. Should be in [0, 1]. Default: 0.5 prob (float, optional): Probability of the input data being flipped. Should be in [0, 1]. Default: 0.5
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A horiziotal flipped image.
Returns:
A callable object of RandomHorizontalFlip.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -571,6 +606,13 @@ class RandomVerticalFlip(BaseTransform): ...@@ -571,6 +606,13 @@ class RandomVerticalFlip(BaseTransform):
prob (float, optional): Probability of the input data being flipped. Default: 0.5 prob (float, optional): Probability of the input data being flipped. Default: 0.5
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A vertical flipped image.
Returns:
A callable object of RandomVerticalFlip.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -579,7 +621,7 @@ class RandomVerticalFlip(BaseTransform): ...@@ -579,7 +621,7 @@ class RandomVerticalFlip(BaseTransform):
from PIL import Image from PIL import Image
from paddle.vision.transforms import RandomVerticalFlip from paddle.vision.transforms import RandomVerticalFlip
transform = RandomVerticalFlip(224) transform = RandomVerticalFlip()
fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8)) fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
...@@ -612,7 +654,14 @@ class Normalize(BaseTransform): ...@@ -612,7 +654,14 @@ class Normalize(BaseTransform):
'CHW'. Default: 'CHW'. 'CHW'. Default: 'CHW'.
to_rgb (bool, optional): Whether to convert to rgb. Default: False. to_rgb (bool, optional): Whether to convert to rgb. Default: False.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A normalized array or tensor.
Returns:
A callable object of Normalize.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -665,7 +714,15 @@ class Transpose(BaseTransform): ...@@ -665,7 +714,15 @@ class Transpose(BaseTransform):
Args: Args:
order (list|tuple, optional): Target order of input data. Default: (2, 0, 1). order (list|tuple, optional): Target order of input data. Default: (2, 0, 1).
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(np.ndarray|Paddle.Tensor): A transposed array or tensor. If input
is a PIL.Image, output will be converted to np.ndarray automatically.
Returns:
A callable object of Transpose.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -707,6 +764,13 @@ class BrightnessTransform(BaseTransform): ...@@ -707,6 +764,13 @@ class BrightnessTransform(BaseTransform):
non negative number. 0 gives the original image non negative number. 0 gives the original image
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in brghtness.
Returns:
A callable object of BrightnessTransform.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -743,6 +807,13 @@ class ContrastTransform(BaseTransform): ...@@ -743,6 +807,13 @@ class ContrastTransform(BaseTransform):
non negative number. 0 gives the original image non negative number. 0 gives the original image
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in contrast.
Returns:
A callable object of ContrastTransform.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -781,6 +852,13 @@ class SaturationTransform(BaseTransform): ...@@ -781,6 +852,13 @@ class SaturationTransform(BaseTransform):
non negative number. 0 gives the original image non negative number. 0 gives the original image
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in saturation.
Returns:
A callable object of SaturationTransform.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -817,6 +895,13 @@ class HueTransform(BaseTransform): ...@@ -817,6 +895,13 @@ class HueTransform(BaseTransform):
between 0 and 0.5, 0 gives the original image between 0 and 0.5, 0 gives the original image
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): An image with a transform in hue.
Returns:
A callable object of HueTransform.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -860,6 +945,13 @@ class ColorJitter(BaseTransform): ...@@ -860,6 +945,13 @@ class ColorJitter(BaseTransform):
Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5. Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A color jittered image.
Returns:
A callable object of ColorJitter.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -938,7 +1030,14 @@ class RandomCrop(BaseTransform): ...@@ -938,7 +1030,14 @@ class RandomCrop(BaseTransform):
pad_if_needed (boolean|optional): It will pad the image if smaller than the pad_if_needed (boolean|optional): It will pad the image if smaller than the
desired size to avoid raising an exception. Default: False. desired size to avoid raising an exception. Default: False.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A random cropped image.
Returns:
A callable object of RandomCrop.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -1040,7 +1139,14 @@ class Pad(BaseTransform): ...@@ -1040,7 +1139,14 @@ class Pad(BaseTransform):
padding ``[1, 2, 3, 4]`` with 2 elements on both sides in symmetric mode padding ``[1, 2, 3, 4]`` with 2 elements on both sides in symmetric mode
will result in ``[2, 1, 1, 2, 3, 4, 4, 3]``. will result in ``[2, 1, 1, 2, 3, 4, 4, 3]``.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A paded image.
Returns:
A callable object of Pad.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -1113,7 +1219,14 @@ class RandomRotation(BaseTransform): ...@@ -1113,7 +1219,14 @@ class RandomRotation(BaseTransform):
Origin is the upper left corner. Origin is the upper left corner.
Default is the center of the image. Default is the center of the image.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): A rotated image.
Returns:
A callable object of RandomRotation.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -1180,11 +1293,15 @@ class Grayscale(BaseTransform): ...@@ -1180,11 +1293,15 @@ class Grayscale(BaseTransform):
Args: Args:
num_output_channels (int): (1 or 3) number of channels desired for output image num_output_channels (int): (1 or 3) number of channels desired for output image
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
- img(PIL.Image|np.ndarray|Paddle.Tensor): The input image with shape (H x W x C).
- output(PIL.Image|np.ndarray|Paddle.Tensor): Grayscale version of the input image.
- If output_channels == 1 : returned image is single channel
- If output_channels == 3 : returned image is 3 channel with r == g == b
Returns: Returns:
CV Image: Grayscale version of the input. A callable object of Grayscale.
- If output_channels == 1 : returned image is single channel
- If output_channels == 3 : returned image is 3 channel with r == g == b
Examples: Examples:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册