-
Notifications
You must be signed in to change notification settings - Fork 765
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
Ligoml
merged 9 commits into
PaddlePaddle:develop
from
cattidea:restore-same-name-api-docs
Aug 25, 2022
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33270ed
create pr (empty commit, just a placeholder)
SigureMo 6cb627e
restore same name api docs
SigureMo 6923ca3
fix some format issue
SigureMo 057eb8f
fix paddle.metric.Accuracy
SigureMo 7053e99
Accuracy format
SigureMo 62688ec
update accuracy
SigureMo eed81c3
optional -> 可选
SigureMo 6c27b30
blod parameter name
SigureMo ee5e1eb
fix lowercase files
SigureMo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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。 | ||
代码示例 | ||
::::::::: | ||
|
||
**独立使用示例:** | ||
|
||
.. 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 类型。 |
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。 | ||
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 |
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,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 |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里改成copy-from?
另外numpy可以去掉啦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除去这个应该都改好了,这个以后在其他 PR 改吧