-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
76 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
.. _cn_api_vision_transforms_normalize: | ||
.. _cn_api_vision_transforms_Normalize: | ||
|
||
normalize | ||
Normalize | ||
------------------------------- | ||
|
||
.. py:function:: paddle.vision.transforms.normalize(img, mean, std, data_format='CHW', to_rgb=False) | ||
.. py:class:: paddle.vision.transforms.Normalize(mean=0.0, std=1.0, data_format='CHW', to_rgb=False, keys=None) | ||
用均值和标准差归一化输入数据。 | ||
用均值和标准差归一化输入数据。给定 n 个通道的均值(M1,...,Mn)和方差(S1,..,Sn),Normalize 会在每个通道归一化输入数据。output[channel] = (input[channel] - mean[channel]) / std[channel] | ||
|
||
参数 | ||
::::::::: | ||
|
||
- img (PIL.Image|np.array|paddle.Tensor) - 用于归一化的数据。 | ||
|
||
- mean (list|tuple) - 用于每个通道归一化的均值。 | ||
- std (list|tuple) - 用于每个通道归一化的标准差值。 | ||
- data_format (str, optional):数据的格式,必须为 'HWC' 或 'CHW'。默认值:'CHW'。 | ||
- data_format (str, optional): 数据的格式,必须为 'HWC' 或 'CHW'。 默认值: 'CHW'。 | ||
- to_rgb (bool, optional) - 是否转换为 ``rgb`` 的格式。默认值:False。 | ||
|
||
形状 | ||
::::::::: | ||
|
||
- img (PIL.Image|np.ndarray|paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。 | ||
- output (PIL.Image|np.ndarray|Paddle.Tensor) - 返回归一化后的图像数据。 | ||
|
||
返回 | ||
::::::::: | ||
|
||
``numpy array 或 paddle.Tensor``,归一化后的图像。 | ||
计算 ``Normalize`` 的可调用对象。 | ||
|
||
代码示例 | ||
::::::::: | ||
|
||
COPY-FROM: paddle.vision.transforms.normalize | ||
COPY-FROM: paddle.vision.transforms.Normalize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,32 @@ | ||
.. _cn_api_vision_transforms_pad: | ||
.. _cn_api_vision_transforms_Pad: | ||
|
||
pad | ||
Pad | ||
------------------------------- | ||
|
||
.. py:function:: paddle.vision.transforms.pad(img, padding, fill=0, padding_mode='constant') | ||
.. py:class:: paddle.vision.transforms.Pad(padding, fill=0, padding_mode='constant', keys=None) | ||
使用特定的模式和值来对输入图像进行填充。 | ||
|
||
参数 | ||
::::::::: | ||
|
||
- img (PIL.Image|np.ndarray) - 被填充的图像。 | ||
- padding (int|list|tuple) - 在图像边界上进行填充的范围。如果提供的是单个int值,则该值用于填充图像所有边;如果提供的是长度为2的元组/列表,则分别为图像左/右和顶部/底部进行填充;如果提供的是长度为4的元组/列表,则按照左,上,右和下的顺序为图像填充。 | ||
- fill (int|tuple) - 用于填充的像素值。仅当padding_mode为constant时参数值有效。默认值:0。如果参数值是一个长度为3的元组,则会分别用于填充R,G,B通道。 | ||
- padding_mode (string) - 填充模式。支持:constant, edge, reflect 或 symmetric。默认值:constant。 ``constant`` 表示使用常量值进行填充,该值由fill参数指定。``edge`` 表示使用图像边缘像素值进行填充。``reflect`` 表示使用原图像的镜像值进行填充(不使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充2个值,结果是 ``[3, 2, 1, 2, 3, 4, 3, 2]``。``symmetric`` 表示使用原图像的镜像值进行填充(使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充2个值,结果是 ``[2, 1, 1, 2, 3, 4, 4, 3]``。 | ||
- padding (int|list|tuple) - 在图像边界上进行填充的范围。如果提供的是单个 int 值,则该值用于填充图像所有边;如果提供的是长度为 2 的元组/列表,则分别为图像左/右和顶部/底部进行填充;如果提供的是长度为 4 的元组/列表,则按照左,上,右和下的顺序为图像填充。 | ||
- fill (int|list|tuple) - 用于填充的像素值。仅当 padding_mode 为 constant 时参数值有效。 默认值:0。 如果参数值是一个长度为 3 的元组,则会分别用于填充 R,G,B 通道。 | ||
- padding_mode (string) - 填充模式。支持: constant, edge, reflect 或 symmetric。 默认值:constant。 ``constant`` 表示使用常量值进行填充,该值由 fill 参数指定。``edge`` 表示使用图像边缘像素值进行填充。``reflect`` 表示使用原图像的镜像值进行填充(不使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充 2 个值,结果是 ``[3, 2, 1, 2, 3, 4, 3, 2]``。``symmetric`` 表示使用原图像的镜像值进行填充(使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充 2 个值,结果是 ``[2, 1, 1, 2, 3, 4, 4, 3]``。 | ||
- keys (list[str]|tuple[str], optional) - 与 ``BaseTransform`` 定义一致。默认值: None。 | ||
|
||
形状 | ||
::::::::: | ||
|
||
- img (PIL.Image|np.ndarray|Paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。 | ||
- output (PIL.Image|np.ndarray|Paddle.Tensor) - 返回填充后的图像数据。 | ||
|
||
返回 | ||
::::::::: | ||
|
||
``PIL.Image 或 numpy.ndarray``,填充后的图像。 | ||
计算 ``Pad`` 的可调用对象。 | ||
|
||
代码示例 | ||
::::::::: | ||
|
||
.. code-block:: python | ||
import numpy as np | ||
from PIL import Image | ||
from paddle.vision.transforms import functional as F | ||
fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') | ||
fake_img = Image.fromarray(fake_img) | ||
padded_img = F.pad(fake_img, padding=1) | ||
print(padded_img.size) | ||
padded_img = F.pad(fake_img, padding=(2, 1)) | ||
print(padded_img.size) | ||
|
||
COPY-FROM: paddle.vision.transforms.Pad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,44 @@ | ||
.. _cn_api_vision_transforms_resize: | ||
.. _cn_api_vision_transforms_Resize: | ||
|
||
resize | ||
Resize | ||
------------------------------- | ||
|
||
.. py:function:: paddle.vision.transforms.resize(img, size, interpolation='bilinear') | ||
.. py:class:: paddle.vision.transforms.Resize(size, interpolation='bilinear', keys=None) | ||
将输入数据调整为指定大小。 | ||
|
||
参数 | ||
::::::::: | ||
|
||
- img (numpy.ndarray|PIL.Image) - 输入数据,可以是(H, W, C)形状的图像或遮罩。 | ||
- size (int|tuple) - 输出图像大小。如果size是一个序列,例如(h,w),输出大小将与此匹配。如果size为int,图像的较小边缘将与此数字匹配,即如果 height > width,则图像将重新缩放为(size * height / width, size)。 | ||
- interpolation (int|str, optional) - 插值的方法,默认值:'bilinear'。 | ||
- size (int|list|tuple) - 输出图像大小。如果 size 是一个序列,例如(h,w),输出大小将与此匹配。如果 size 为 int,图像的较小边缘将与此数字匹配,即如果 height > width,则图像将重新缩放为(size * height / width, size)。 | ||
- interpolation (int|str, optional) - 插值的方法,默认值: 'bilinear'。 | ||
- 当使用 ``pil`` 作为后端时,支持的插值方法如下 | ||
+ "nearest": Image.NEAREST, | ||
+ "bilinear": Image.BILINEAR, | ||
+ "bicubic": Image.BICUBIC, | ||
+ "box": Image.BOX, | ||
+ "lanczos": Image.LANCZOS, | ||
+ "nearest": Image.NEAREST, | ||
+ "bilinear": Image.BILINEAR, | ||
+ "bicubic": Image.BICUBIC, | ||
+ "box": Image.BOX, | ||
+ "lanczos": Image.LANCZOS, | ||
+ "hamming": Image.HAMMING。 | ||
- 当使用 ``cv2`` 作为后端时,支持的插值方法如下 | ||
+ "nearest": cv2.INTER_NEAREST, | ||
+ "bilinear": cv2.INTER_LINEAR, | ||
+ "area": cv2.INTER_AREA, | ||
+ "bicubic": cv2.INTER_CUBIC, | ||
+ "nearest": cv2.INTER_NEAREST, | ||
+ "bilinear": cv2.INTER_LINEAR, | ||
+ "area": cv2.INTER_AREA, | ||
+ "bicubic": cv2.INTER_CUBIC, | ||
+ "lanczos": cv2.INTER_LANCZOS4。 | ||
|
||
返回 | ||
::::::::: | ||
- keys (list[str]|tuple[str], optional) - 与 ``BaseTransform`` 定义一致。默认值: None。 | ||
|
||
``PIL.Image 或 numpy.ndarray``,调整大小后的图像数据。 | ||
|
||
代码示例 | ||
形状 | ||
::::::::: | ||
|
||
.. code-block:: python | ||
import numpy as np | ||
from PIL import Image | ||
from paddle.vision.transforms import functional as F | ||
- img (PIL.Image|np.ndarray|Paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。 | ||
- output (PIL.Image|np.ndarray|Paddle.Tensor) - 返回调整大小后的图像数据。 | ||
|
||
fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') | ||
返回 | ||
::::::::: | ||
|
||
fake_img = Image.fromarray(fake_img) | ||
计算 ``Resize`` 的可调用对象。 | ||
|
||
converted_img = F.resize(fake_img, 224) | ||
print(converted_img.size) | ||
# (262, 224) | ||
代码示例 | ||
::::::::: | ||
|
||
converted_img = F.resize(fake_img, (200, 150)) | ||
print(converted_img.size) | ||
# (150, 200) | ||
COPY-FROM: paddle.vision.transforms.Resize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters