Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs][cn] restore same name api docs #5076

Merged
merged 9 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 99 additions & 16 deletions docs/api/paddle/metric/Accuracy__upper_cn.rst
Original file line number Diff line number Diff line change
@@ -1,30 +1,113 @@
.. _cn_api_paddle_metric_accuracy:
.. _cn_api_metric_Accuracy:

accuracy
Accuracy
-------------------------------

.. py:function:: paddle.metric.accuracy(input, label, k=1, correct=None, total=None, name=None)
.. py:class:: paddle.metric.Accuracy(topk=(1, ), name=None, *args, **kwargs)

accuracy layer。参考 https://en.wikipedia.org/wiki/Precision_and_recall

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里改成copy-from?
另外numpy可以去掉啦

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除去这个应该都改好了,这个以后在其他 PR 改吧


**独立使用示例:**

.. code-block:: python

import numpy as np
import paddle
x = paddle.to_tensor(np.array([
[0.1, 0.2, 0.3, 0.4],
[0.1, 0.4, 0.3, 0.2],
[0.1, 0.2, 0.4, 0.3],
[0.1, 0.2, 0.3, 0.4]]))
y = paddle.to_tensor(np.array([[0], [1], [2], [3]]))
m = paddle.metric.Accuracy()
correct = m.compute(x, y)
m.update(correct)
res = m.accumulate()
print(res) # 0.75


**在 Model API 中的示例**

.. code-block:: python

import paddle
from paddle.static import InputSpec
import paddle.vision.transforms as T
from paddle.vision.datasets import MNIST

input = InputSpec([None, 1, 28, 28], 'float32', 'image')
label = InputSpec([None, 1], 'int64', 'label')
transform = T.Compose([T.Transpose(), T.Normalize([127.5], [127.5])])
train_dataset = MNIST(mode='train', transform=transform)

返回
model = paddle.Model(paddle.vision.models.LeNet(), input, label)
optim = paddle.optimizer.Adam(
learning_rate=0.001, parameters=model.parameters())
model.prepare(
optim,
loss=paddle.nn.CrossEntropyLoss(),
metrics=paddle.metric.Accuracy())

model.fit(train_dataset, batch_size=64)


compute(pred, label, *args)
:::::::::

``Tensor``,计算出来的正确率,数据类型为 float32 的 Tensor
计算 top-k(topk 中的最大值)的索引

代码示例
**参数**

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

**返回**

Tensor,shape 是[batch_size, d0, ..., topk], 值为 0 或 1,1 表示预测正确.


update(pred, label, *args)
:::::::::

COPY-FROM: paddle.metric.accuracy
更新 metric 的状态(正确预测的个数和总个数),以便计算累积的准确率。返回当前 step 的准确率。

**参数**

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

**返回**

当前 step 的准确率。

reset()
:::::::::

清空状态和计算结果。

accumulate()
:::::::::

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

**返回**

准确率,一般是个标量 或 多个标量,和 topk 的个数一致。


name()
:::::::::

返回 Metric 实例的名字, 参考上述 name,默认是'acc'。

**返回**

评估的名字,string 类型。
21 changes: 13 additions & 8 deletions docs/api/paddle/vision/transforms/Normalize__upper_cn.rst
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。
SigureMo marked this conversation as resolved.
Show resolved Hide resolved

形状
:::::::::

- 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
24 changes: 15 additions & 9 deletions docs/api/paddle/vision/transforms/Pad__upper_cn.rst
Original file line number Diff line number Diff line change
@@ -1,26 +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。
SigureMo marked this conversation as resolved.
Show resolved Hide resolved

形状
:::::::::

- img (PIL.Image|np.ndarray|Paddle.Tensor) - 输入的图像数据,数据格式为'HWC'。
- output (PIL.Image|np.ndarray|Paddle.Tensor) - 返回填充后的图像数据。

返回
:::::::::

``PIL.Image 或 numpy.ndarray``,填充后的图像
计算 ``Pad`` 的可调用对象

代码示例
:::::::::

COPY-FROM: paddle.vision.transforms.pad
COPY-FROM: paddle.vision.transforms.Pad
22 changes: 14 additions & 8 deletions docs/api/paddle/vision/transforms/Resize__upper_cn.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
.. _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'。
SigureMo marked this conversation as resolved.
Show resolved Hide resolved
- 当使用 ``pil`` 作为后端时,支持的插值方法如下
+ "nearest": Image.NEAREST,
+ "bilinear": Image.BILINEAR,
Expand All @@ -26,13 +25,20 @@ resize
+ "area": cv2.INTER_AREA,
+ "bicubic": cv2.INTER_CUBIC,
+ "lanczos": cv2.INTER_LANCZOS4。
- 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``,调整大小后的图像数据
计算 ``Resize`` 的可调用对象

代码示例
:::::::::

COPY-FROM: paddle.vision.transforms.resize
COPY-FROM: paddle.vision.transforms.Resize
4 changes: 2 additions & 2 deletions docs/api/paddle/vision/transforms/normalize_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ normalize
- 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。
SigureMo marked this conversation as resolved.
Show resolved Hide resolved

返回
:::::::::

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

代码示例
:::::::::
Expand Down
4 changes: 2 additions & 2 deletions docs/api/paddle/vision/transforms/pad_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pad
:::::::::

- img (PIL.Image|np.ndarray) - 被填充的图像。
- padding (int|list|tuple) - 在图像边界上进行填充的范围。如果提供的是单个 int 值,则该值用于填充图像所有边;如果提供的是长度为 2 的元组/列表,则分别为图像左/右和顶部/底部进行填充;如果提供的是长度为 4 的元组/列表,则按照左,上,右和下的顺序为图像填充。
- 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]``。

返回
:::::::::

``PIL.Image 或 numpy.ndarray``,填充后的图像。
``PIL.Image````numpy.ndarray``,填充后的图像。

代码示例
:::::::::
Expand Down
2 changes: 1 addition & 1 deletion docs/api/paddle/vision/transforms/resize_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resize
返回
:::::::::

``PIL.Image 或 numpy.ndarray``,调整大小后的图像数据。
``PIL.Image````numpy.ndarray``,调整大小后的图像数据。

代码示例
:::::::::
Expand Down