Skip to content

Commit c1a17dc

Browse files
authored
fix 4 same name apis (#5195)
1 parent 3bba9e4 commit c1a17dc

File tree

8 files changed

+128
-172
lines changed

8 files changed

+128
-172
lines changed

docs/api/paddle/metric/Accuracy__upper_cn.rst

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,90 @@
33
Accuracy
44
-------------------------------
55

6-
.. py:class:: paddle.metric.Accuracy()
6+
.. py:class:: paddle.metric.Accuracy(topk=(1, ), name=None, *args, **kwargs)
7+
78
89
计算准确率(accuracy)。
910

1011
参数:
1112
:::::::::
12-
- **topk** (int|tuple(int)) - 计算准确率的top个数,默认是1
13-
- **name** (str, optional) - metric实例的名字,默认是'acc'。
13+
- **topk** (list[int]|tuple[int],可选) - 计算准确率的 top 个数,默认值为 (1,)
14+
- **name** (str,可选) - metric 实例的名字。默认值为 None,表示使用默认名字 'acc'。
1415

1516
代码示例
1617
:::::::::
1718

1819
**独立使用示例:**
19-
20+
2021
.. code-block:: python
2122
2223
import numpy as np
2324
import paddle
24-
2525
x = paddle.to_tensor(np.array([
2626
[0.1, 0.2, 0.3, 0.4],
2727
[0.1, 0.4, 0.3, 0.2],
2828
[0.1, 0.2, 0.4, 0.3],
2929
[0.1, 0.2, 0.3, 0.4]]))
3030
y = paddle.to_tensor(np.array([[0], [1], [2], [3]]))
31-
3231
m = paddle.metric.Accuracy()
3332
correct = m.compute(x, y)
3433
m.update(correct)
3534
res = m.accumulate()
3635
print(res) # 0.75
3736
3837
39-
**在Model API中的示例**
40-
38+
**在 Model API 中的示例**
39+
4140
.. code-block:: python
4241
4342
import paddle
4443
from paddle.static import InputSpec
4544
import paddle.vision.transforms as T
4645
from paddle.vision.datasets import MNIST
47-
46+
4847
input = InputSpec([None, 1, 28, 28], 'float32', 'image')
4948
label = InputSpec([None, 1], 'int64', 'label')
5049
transform = T.Compose([T.Transpose(), T.Normalize([127.5], [127.5])])
5150
train_dataset = MNIST(mode='train', transform=transform)
52-
51+
5352
model = paddle.Model(paddle.vision.models.LeNet(), input, label)
5453
optim = paddle.optimizer.Adam(
5554
learning_rate=0.001, parameters=model.parameters())
5655
model.prepare(
5756
optim,
5857
loss=paddle.nn.CrossEntropyLoss(),
5958
metrics=paddle.metric.Accuracy())
60-
61-
model.fit(train_dataset, batch_size=64)
6259
60+
model.fit(train_dataset, batch_size=64)
6361
6462
6563
compute(pred, label, *args)
6664
:::::::::
6765
68-
计算top-k(topk中的最大值)的索引。
66+
计算 top-k(topk 中的最大值)的索引。
6967

7068
**参数**
71-
72-
- **pred** (Tensor) - 预测结果为是float64或float32类型的Tensor。shape为[batch_size, d0, ..., dN].
73-
- **label** (Tensor) - 真实的标签值是一个int64类型的Tensor,shape为[batch_size, d0, ..., 1] 或one hot表示的形状[batch_size, d0, ..., num_classes].
7469

75-
**返回**: Tensor,shape是[batch_size, d0, ..., topk], 值为0或1,1表示预测正确.
70+
- **pred** (Tensor) - 预测结果为是 float64 或 float32 类型的 Tensor。shape 为[batch_size, d0, ..., dN].
71+
- **label** (Tensor) - 真实的标签值是一个 int64 类型的 Tensor,shape 为[batch_size, d0, ..., 1] 或 one hot 表示的形状[batch_size, d0, ..., num_classes].
72+
73+
**返回**
74+
75+
Tensor,shape 是[batch_size, d0, ..., topk], 值为 0 或 1,1 表示预测正确.
7676

7777

78-
update(pred, label, *args)
78+
update(correct, *args)
7979
:::::::::
8080
81-
更新metric的状态(正确预测的个数和总个数),以便计算累积的准确率。返回当前step的准确率
81+
更新 metric 的状态(正确预测的个数和总个数),以便计算累积的准确率。返回当前 step 的准确率
8282

83-
**参数:**
83+
**参数**
8484

85-
- **correct** (numpy.array | Tensor): 一个值为0或1的Tensor,shape是[batch_size, d0, ..., topk]。
85+
- **correct** (numpy.array | Tensor): 一个值为 0 或 1 的 Tensor,shape 是[batch_size, d0, ..., topk]。
8686

87-
**返回:** 当前step的准确率。
87+
**返回**
8888

89+
当前 step 的准确率。
8990

9091
reset()
9192
:::::::::
@@ -97,12 +98,16 @@ accumulate()
9798

9899
累积的统计指标,计算和返回准确率。
99100

100-
**返回:** 准确率,一般是个标量 或 多个标量,和topk的个数一致。
101+
**返回**
102+
103+
准确率,一般是个标量 或 多个标量,和 topk 的个数一致。
101104

102105

103106
name()
104107
:::::::::
105108

106-
返回Metric实例的名字, 参考上述name,默认是'acc'。
109+
返回 Metric 实例的名字, 参考上述 name,默认是'acc'。
110+
111+
**返回**
107112

108-
**返回:** 评估的名字,string类型
113+
评估的名字,string 类型

docs/api/paddle/metric/accuracy_cn.rst

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,26 @@ accuracy
55

66
.. py:function:: paddle.metric.accuracy(input, label, k=1, correct=None, total=None, name=None)
77
8-
accuracy layer。 参考 https://en.wikipedia.org/wiki/Precision_and_recall
8+
accuracy layer。参考 https://en.wikipedia.org/wiki/Precision_and_recall
99

10-
使用输入和标签计算准确率。 如果正确的标签在topk个预测值里,则计算结果加1。注意:输出正确率的类型由input类型决定,input和lable的类型可以不一样
10+
使用输入和标签计算准确率。如果正确的标签在 topk 个预测值里,则计算结果加 1。注意:输出正确率的类型由 input 类型决定,input 和 lable 的类型可以不一样
1111

1212
参数
1313
:::::::::
1414

15-
- **input** (Tensor)-数据类型为float32,float64。输入为网络的预测值。shape为 ``[sample_number, class_dim]`` 。
16-
- **label** (Tensor)-数据类型为int64,int32。输入为数据集的标签。shape为 ``[sample_number, 1]`` 。
17-
- **k** (int64|int32,可选) - 取每个类别中k个预测值用于计算,默认值为1
18-
- **correct** (int64|int32, 可选)-正确预测值的个数,默认值为None
19-
- **total** (int64|int32,可选)-总共的预测值,默认值为None
20-
- **name** (str,可选) 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None
15+
- **input** (Tensor)-数据类型为 float32,float64。输入为网络的预测值。shape 为 ``[sample_number, class_dim]`` 。
16+
- **label** (Tensor)-数据类型为 int64。输入为数据集的标签。shape 为 ``[sample_number, 1]`` 。
17+
- **k** (int,可选) - 取每个类别中 k 个预测值用于计算,默认值为 1
18+
- **correct** (int,可选) - 正确预测值的个数,默认值为 None
19+
- **total** (int,可选) - 总共的预测值,默认值为 None
20+
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None
2121

2222
返回
2323
:::::::::
2424

25-
``Tensor``,计算出来的正确率,数据类型为float32的Tensor
25+
``Tensor``,计算出来的正确率,数据类型为 float32 的 Tensor
2626

2727
代码示例
2828
:::::::::
2929

30-
.. code-block:: python
31-
32-
import paddle
33-
34-
predictions = paddle.to_tensor([[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], dtype='float32')
35-
label = paddle.to_tensor([[2], [0]], dtype="int64")
36-
result = paddle.metric.accuracy(input=predictions, label=label, k=1)
37-
# [0.5]
30+
COPY-FROM: paddle.metric.accuracy

docs/api/paddle/vision/transforms/Normalize__upper_cn.rst

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,29 @@ Normalize
55

66
.. py:class:: paddle.vision.transforms.Normalize(mean=0.0, std=1.0, data_format='CHW', to_rgb=False, keys=None)
77
8-
图像归一化处理,支持两种方式:
9-
1. 用统一的均值和标准差值对图像的每个通道进行归一化处理;
10-
2. 对每个通道指定不同的均值和标准差值进行归一化处理。
11-
12-
计算过程:
13-
14-
``output[channel] = (input[channel] - mean[channel]) / std[channel]``
8+
用均值和标准差归一化输入数据。给定 n 个通道的均值(M1,...,Mn)和方差(S1,..,Sn),Normalize 会在每个通道归一化输入数据。output[channel] = (input[channel] - mean[channel]) / std[channel]
159

1610
参数
1711
:::::::::
1812

19-
- mean (int|float|list) - 用于每个通道归一化的均值。
20-
- std (int|float|list) - 用于每个通道归一化的标准差值。
21-
- data_format (str, optional): 数据的格式,必须为 'HWC' 或 'CHW'。 默认值: 'CHW'。
22-
- to_rgb (bool, optional) - 是否转换为 ``rgb`` 的格式。默认值:False。
23-
- keys (list[str]|tuple[str], optional) - 与 ``BaseTransform``. 默认值: None。
13+
- **mean** (list|tuple,可选) - 用于每个通道归一化的均值。
14+
- **std** (list|tuple,可选) - 用于每个通道归一化的标准差值。
15+
- **data_format** (str,可选) - 数据的格式,必须为 'HWC' 或 'CHW'。 默认值为 'CHW'。
16+
- **to_rgb** (bool,可选) - 是否转换为 ``rgb`` 的格式。默认值为 False。
17+
- **keys** (list[str]|tuple[str],可选) - 与 ``BaseTransform`` 定义一致。默认值为 None。
2418

2519
形状
2620
:::::::::
2721

28-
- img (PIL.Image|np.ndarray|Paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。
22+
- img (PIL.Image|np.ndarray|paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。
2923
- output (PIL.Image|np.ndarray|Paddle.Tensor) - 返回归一化后的图像数据。
3024

3125
返回
3226
:::::::::
3327

34-
计算 ``Normalize`` 的可调用对象。
28+
计算 ``Normalize`` 的可调用对象。
3529

3630
代码示例
3731
:::::::::
38-
39-
.. code-block:: python
40-
41-
import numpy as np
42-
from PIL import Image
43-
from paddle.vision.transforms import Normalize
44-
45-
normalize = Normalize(mean=[127.5, 127.5, 127.5],
46-
std=[127.5, 127.5, 127.5],
47-
data_format='HWC')
48-
49-
fake_img = Image.fromarray((np.random.rand(300, 320, 3) * 255.).astype(np.uint8))
5032

51-
fake_img = normalize(fake_img)
52-
print(fake_img.shape)
53-
print(fake_img.max, fake_img.max)
54-
33+
COPY-FROM: paddle.vision.transforms.Normalize

docs/api/paddle/vision/transforms/Pad__upper_cn.rst

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ Pad
1010
参数
1111
:::::::::
1212

13-
- padding (int|list|tuple) - 在图像边界上进行填充的范围。如果提供的是单个int值,则该值用于填充图像所有边;如果提供的是长度为2的元组/列表,则分别为图像左/右和顶部/底部进行填充;如果提供的是长度为4的元组/列表,则按照左,上,右和下的顺序为图像填充。
14-
- fill (int|list|tuple) - 用于填充的像素值。仅当padding_mode为constant时参数值有效。 默认值:0。 如果参数值是一个长度为3的元组,则会分别用于填充R,G,B通道。
15-
- 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]``。
16-
- keys (list[str]|tuple[str], optional) - 与 ``BaseTransform`` 定义一致。默认值: None。
13+
- **padding** (int|list|tuple) - 在图像边界上进行填充的范围。如果提供的是单个 int 值,则该值用于填充图像所有边;如果提供的是长度为 2 的元组/列表,则分别为图像左/右和顶部/底部进行填充;如果提供的是长度为 4 的元组/列表,则按照左,上,右和下的顺序为图像填充。
14+
- **fill** (int|list|tuple,可选) - 用于填充的像素值。仅当 padding_mode 为 constant 时参数值有效。 默认值:0。 如果参数值是一个长度为 3 的元组,则会分别用于填充 R,G,B 通道。
15+
- **padding_mode** (string,可选) - 填充模式。支持: constant, edge, reflect 或 symmetric。 默认值:constant。
16+
17+
- ``constant`` 表示使用常量值进行填充,该值由 fill 参数指定;
18+
- ``edge`` 表示使用图像边缘像素值进行填充;
19+
- ``reflect`` 表示使用原图像的镜像值进行填充(不使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充 2 个值,结果是 ``[3, 2, 1, 2, 3, 4, 3, 2]``。
20+
- ``symmetric`` 表示使用原图像的镜像值进行填充(使用边缘上的值);比如:使用该模式对 ``[1, 2, 3, 4]`` 的两端分别填充 2 个值,结果是 ``[2, 1, 1, 2, 3, 4, 4, 3]``。
21+
22+
- **keys** (list[str]|tuple[str],可选) - 与 ``BaseTransform`` 定义一致。默认值: None。
1723

1824
形状
1925
:::::::::
@@ -24,21 +30,9 @@ Pad
2430
返回
2531
:::::::::
2632

27-
计算 ``Pad`` 的可调用对象。
33+
计算 ``Pad`` 的可调用对象。
2834

2935
代码示例
3036
:::::::::
3137

32-
.. code-block:: python
33-
34-
import numpy as np
35-
from PIL import Image
36-
from paddle.vision.transforms import Pad
37-
38-
transform = Pad(2)
39-
40-
fake_img = Image.fromarray((np.random.rand(224, 224, 3) * 255.).astype(np.uint8))
41-
42-
fake_img = transform(fake_img)
43-
print(fake_img.size)
44-
38+
COPY-FROM: paddle.vision.transforms.Pad

docs/api/paddle/vision/transforms/Resize__upper_cn.rst

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@ Resize
1010
参数
1111
:::::::::
1212

13-
- size (int|list|tuple) - 输出图像大小。如果size是一个序列,例如(h,w),输出大小将与此匹配。如果size为int,图像的较小边缘将与此数字匹配,即如果 height > width,则图像将重新缩放为(size * height / width, size)。
14-
- interpolation (int|str, optional) - 插值的方法. 默认值: 'bilinear'. 当使用 ``pil`` 作为后端时, 支持的插值方法如下: - "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, - "lanczos": cv2.INTER_LANCZOS4
15-
- keys (list[str]|tuple[str], optional) - 与 ``BaseTransform`` 定义一致。默认值: None。
13+
- **size** (int|list|tuple) - 输出图像大小。如果 size 是一个序列,例如(h,w),输出大小将与此匹配。如果 size 为 int,图像的较小边缘将与此数字匹配,即如果 height > width,则图像将重新缩放为(size * height / width, size)。
14+
- **interpolation** (int|str,可选) - 插值的方法,默认值: 'bilinear'。
15+
16+
- 当使用 ``pil`` 作为后端时,支持的插值方法如下
17+
18+
+ "nearest": Image.NEAREST,
19+
+ "bilinear": Image.BILINEAR,
20+
+ "bicubic": Image.BICUBIC,
21+
+ "box": Image.BOX,
22+
+ "lanczos": Image.LANCZOS,
23+
+ "hamming": Image.HAMMING。
24+
25+
- 当使用 ``cv2`` 作为后端时,支持的插值方法如下
26+
27+
+ "nearest": cv2.INTER_NEAREST,
28+
+ "bilinear": cv2.INTER_LINEAR,
29+
+ "area": cv2.INTER_AREA,
30+
+ "bicubic": cv2.INTER_CUBIC,
31+
+ "lanczos": cv2.INTER_LANCZOS4。
32+
33+
- **keys** (list[str]|tuple[str],可选) - 与 ``BaseTransform`` 定义一致。默认值: None。
1634

1735
形状
1836
:::::::::
@@ -23,20 +41,9 @@ Resize
2341
返回
2442
:::::::::
2543

26-
计算 ``Resize`` 的可调用对象。
44+
计算 ``Resize`` 的可调用对象。
2745

2846
代码示例
2947
:::::::::
3048

31-
.. code-block:: python
32-
33-
import numpy as np
34-
from PIL import Image
35-
from paddle.vision.transforms import Resize
36-
37-
transform = Resize(size=224)
38-
39-
fake_img = Image.fromarray((np.random.rand(100, 120, 3) * 255.).astype(np.uint8))
40-
41-
fake_img = transform(fake_img)
42-
print(fake_img.size)
49+
COPY-FROM: paddle.vision.transforms.Resize

docs/api/paddle/vision/transforms/normalize_cn.rst

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,25 @@
33
normalize
44
-------------------------------
55

6-
.. py:function:: paddle.vision.transforms.normalize(pic, data_format='CHW')
6+
.. py:function:: paddle.vision.transforms.normalize(img, mean, std, data_format='CHW', to_rgb=False)
77
8-
将 ``PIL.Image`` 或 ``numpy.ndarray`` 转换成 ``paddle.Tensor``
8+
用均值和标准差归一化输入数据。
99

1010
参数
1111
:::::::::
12-
13-
- img (PIL.Image|np.array|paddle.Tensor) - 用于归一化的数据。
14-
- mean (list|tuple) - 用于每个通道归一化的均值。
15-
- std (list|tuple) - 用于每个通道归一化的标准差值。
16-
- data_format (str, optional): 数据的格式,必须为 'HWC' 或 'CHW'。 默认值: 'CHW'。
17-
- to_rgb (bool, optional) - 是否转换为 ``rgb`` 的格式。默认值:False。
12+
13+
- **img** (PIL.Image|np.array|paddle.Tensor) - 用于归一化的数据。
14+
- **mean** (list|tuple) - 用于每个通道归一化的均值。
15+
- **std** (list|tuple) - 用于每个通道归一化的标准差值。
16+
- **data_format** (str,可选) - 数据的格式,必须为 'HWC' 或 'CHW'。默认值'CHW'。
17+
- **to_rgb** (bool,可选) - 是否转换为 ``rgb`` 的格式。默认值:False。
1818

1919
返回
2020
:::::::::
2121

22-
``numpy array 或 paddle.Tensor``,归一化后的图像。
22+
``numpy array````paddle.Tensor``,归一化后的图像。
2323

2424
代码示例
2525
:::::::::
2626

27-
.. code-block:: python
28-
29-
import numpy as np
30-
from PIL import Image
31-
from paddle.vision.transforms import functional as F
32-
33-
fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8')
34-
35-
fake_img = Image.fromarray(fake_img)
36-
37-
mean = [127.5, 127.5, 127.5]
38-
std = [127.5, 127.5, 127.5]
39-
40-
normalized_img = F.normalize(fake_img, mean, std, data_format='HWC')
41-
print(normalized_img.max(), normalized_img.min())
42-
27+
COPY-FROM: paddle.vision.transforms.normalize

0 commit comments

Comments
 (0)