diff --git a/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl.md b/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl.md index 77d1756eafe1a55e8b470543398a02e05fc0b109..df0149674045239242735bad0c778d74f9d17811 100644 --- a/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl.md +++ b/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl.md @@ -1,4 +1,3 @@ - # VisualDL 工具简介 @@ -8,14 +7,26 @@ -VisualDL是深度学习模型可视化分析工具,以丰富的图表呈现训练参数变化趋势、模型结构、数据样本、高维数据分布等。可帮助用户更清晰直观地理解深度学习模型训练过程及模型结构,进而实现高效的模型优化。 +VisualDL是飞桨可视化分析工具,以丰富的图表呈现训练参数变化趋势、模型结构、数据样本、直方图、PR曲线及高维数据分布。可帮助用户更清晰直观地理解深度学习模型训练过程及模型结构,进而实现高效的模型优化。 + +具体功能使用方式请参见**VisualDL使用指南**。项目正处于高速迭代中,敬请期待新组件的加入。 -VisualDL提供丰富的可视化功能,支持实时训练参数分析、图结构、数据样本可视化及高维数据降维呈现等诸多功能。具体功能使用方式,请参见 **VisualDL 使用指南**。项目正处于高速迭代中,敬请期待新组件的加入。 +VisualDL支持浏览器种类:Chrome(81和83)、Safari 13、FireFox(77和78)、Edge(Chromium版)。 VisualDL原生支持python的使用, 通过在模型的Python配置中添加几行代码,便可为训练过程提供丰富的可视化支持。 +## 目录 + +* [核心亮点](#核心亮点) +* [安装方式](#安装方式) +* [使用方式](#使用方式) +* [可视化功能概览](#可视化功能概览) +* [开源贡献](#开源贡献) +* [更多细节](#更多细节) +* [技术交流](#技术交流) + ## 核心亮点 @@ -26,7 +37,7 @@ API设计简洁易懂,使用简单。模型结构一键实现可视化。 ### 功能丰富 -功能覆盖训练参数、图结构、数据样本及数据降维可视化。 +功能覆盖标量、数据样本、图结构、直方图、PR曲线及数据降维可视化。 ### 高兼容性 @@ -40,13 +51,23 @@ API设计简洁易懂,使用简单。模型结构一键实现可视化。 ## 安装方式 -使用pip安装 VisualDL 运行范例: +### 使用pip安装 ```shell -pip install --upgrade visualdl==2.0.0a2 +pip install --upgrade --pre visualdl ``` +### 使用代码安装 +``` +git clone https://github.com/PaddlePaddle/VisualDL.git +cd VisualDL + +python setup.py bdist_wheel +pip install --upgrade dist/visualdl-*.whl +``` + +需要注意,官方自2020年1月1日起不再维护Python2,为了保障代码可用性,VisualDL现仅支持Python3 ## 使用方式 @@ -57,15 +78,13 @@ VisualDL将训练过程中的数据、参数等信息储存至日志文件中后 VisualDL的后端提供了Python SDK,可通过LogWriter定制一个日志记录器,接口如下: ```python -class LogWriter( - logdir=None, +class LogWriter(logdir=None, comment='', max_queue=10, flush_secs=120, filename_suffix='', write_to_disk=True, - **kwargs - ) + **kwargs) ``` #### 接口参数 @@ -103,16 +122,21 @@ with LogWriter(logdir="./log/scalar_test/train") as writer: 使用命令行启动VisualDL面板,命令格式如下: ```python -visualdl --logdir --host --port +visualdl --logdir --host --port --cache-timeout --language --public-path --api-only ``` 参数详情: -| 参数 | 意义 | -| -------- | ------------------------------------------------------------ | -| --logdir | 设定日志所在目录,可以指定多个目录,VisualDL将遍历并且迭代寻找指定目录的子目录,将所有实验结果进行可视化 | -| --host | 设定IP,默认为`127.0.0.1` | -| --port | 设定端口,默认为`8040` | +| 参数 | 意义 | +| --------------- | ------------------------------------------------------------ | +| --logdir | 设定日志所在目录,可以指定多个目录,VisualDL将遍历并且迭代寻找指定目录的子目录,将所有实验结果进行可视化 | +| --model | 设定模型文件路径(非文件夹路径),VisualDL将在此路径指定的模型文件进行可视化,目前可支持PaddlePaddle、ONNX、Keras、Core ML、Caffe等多种模型结构,详情可查看[graph支持模型种类]([https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--%E7%BD%91%E7%BB%9C%E7%BB%93%E6%9E%84%E7%BB%84%E4%BB%B6](https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--网络结构组件)) | +| --host | 设定IP,默认为`127.0.0.1` | +| --port | 设定端口,默认为`8040` | +| --cache-timeout | 后端缓存时间,在缓存时间内前端多次请求同一url,返回的数据从缓存中获取,默认为20秒 | +| --language | VisualDL面板语言,可指定为'EN'或'ZH',默认为浏览器使用语言 | +| --public-path | VisualDL面板URL路径,默认是'/app',即访问地址为'http://<host>:<port>/app' | +| --api-only | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://<host>:<port>/<public_path>/api';若没有设置public_path参数,则默认为'http://<host>:<port>/api' | 针对上一步生成的日志,启动命令为: @@ -130,19 +154,26 @@ visualdl.server.app.run(logdir, port=8080, cache_timeout=20, language=None, + public_path=None, + api_only=False, open_browser=False) ``` -接口参数: +请注意:除`logdir`外,其他参数均为不定参数,传递时请指明参数名。 + +接口参数具体如下: | 参数 | 格式 | 含义 | | ------------- | ------------------------------------------------ | ------------------------------------------------------------ | | logdir | string或list[string_1, string_2, ... , string_n] | 日志文件所在的路径,VisualDL将在此路径下递归搜索日志文件并进行可视化,可指定单个或多个路径 | +| model | string | 模型文件路径(非文件夹路径),VisualDL将在此路径指定的模型文件进行可视化 | | host | string | 指定启动服务的ip,默认为`127.0.0.1` | | port | int | 启动服务端口,默认为`8040` | | cache_timeout | int | 后端缓存时间,在缓存时间内前端多次请求同一url,返回的数据从缓存中获取,默认为20秒 | -| language | string | VisualDL面板语言,可指定为'EN'或'CN',默认自动匹配操作系统使用语言 | -| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板 | +| language | string | VisualDL面板语言,可指定为'en'或'zh',默认为浏览器使用语言 | +| public_path | string | VisualDL面板URL路径,默认是'/app',即访问地址为'http://:/app' | +| api_only | boolean | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://://api';若没有设置public_path参数,则默认为http://:/api' | +| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板,若设置api_only,则忽略此参数 | 针对上一步生成的日志,我们的启动脚本为: @@ -155,7 +186,7 @@ app.run(logdir="./log") 在使用任意一种方式启动VisualDL面板后,打开浏览器访问VisualDL面板,即可查看日志的可视化结果,如图:

- +

@@ -163,27 +194,31 @@ app.run(logdir="./log") ## 可视化功能概览 ### Scalar + 以图表形式实时展示训练过程参数,如loss、accuracy。让用户通过观察单组或多组训练参数变化,了解训练过程,加速模型调优。具有两大特点: #### 动态展示 -在启动VisualDL Board后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图: +在启动VisualDL后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图:

+ #### 多实验对比 -只需在启动VisualDL Board的时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图: +只需在启动VisualDL时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图:

+ ### Image + 实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。

@@ -191,6 +226,56 @@ app.run(logdir="./log")

+ +### Audio + +实时查看训练过程中的音频数据,监控语音识别与合成等任务的训练过程。 + +

+ +

+ + + +### Graph + +一键可视化模型的网络结构。可查看模型属性、节点信息、节点输入输出等,并支持节点搜索,辅助用户快速分析模型结构与了解数据流向。 + +

+ +

+ + + +### Histogram + +以直方图形式展示Tensor(weight、bias、gradient等)数据在训练过程中的变化趋势。深入了解模型各层效果,帮助开发者精准调整模型结构。 + +- Offset模式 + +

+ +

+ + + +- Overlay模式 + +

+ +

+ + + +### PR Curve + +精度-召回率曲线,帮助开发者权衡模型精度和召回率之间的平衡,设定最佳阈值。 + +

+ +

+ + ### High Dimensional 将高维数据进行降维展示,目前支持T-SNE、PCA两种降维方式,用于深入分析高维数据间的关系,方便用户根据数据特征进行算法优化。 @@ -201,9 +286,15 @@ app.run(logdir="./log") ## 开源贡献 -VisualDL 是由 [PaddlePaddle](http://www.paddlepaddle.org/) 和 [ECharts](http://echarts.baidu.com/) 合作推出的开源项目。欢迎所有人使用,提意见以及贡献代码。 +VisualDL 是由 [PaddlePaddle](https://www.paddlepaddle.org/) 和 [ECharts](https://echarts.apache.org/) 合作推出的开源项目。 +Graph 相关功能由 [Netron](https://github.com/lutzroeder/netron) 提供技术支持。 +欢迎所有人使用,提意见以及贡献代码。 ## 更多细节 -想了解更多关于VisualDL可视化功能的使用详情介绍,请查看**Visual DL 使用指南**。 +想了解更多关于VisualDL可视化功能的使用详情介绍,请查看**VisualDL使用指南**。 + +## 技术交流 + +欢迎您加入VisualDL官方QQ群:1045783368 与飞桨团队以及其他用户共同针对VisualDL进行讨论与交流。 diff --git a/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl_usage.md b/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl_usage.md index f191aa8cef12caf67d2e42666683fb2155aae437..e6a6445e3d4a89501f236bba6cf5623304ab3024 100644 --- a/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl_usage.md +++ b/doc/fluid/advanced_guide/evaluation_debugging/debug/visualdl_usage.md @@ -1,20 +1,20 @@ - - # VisualDL 使用指南 ### 概述 VisualDL 是一个面向深度学习任务设计的可视化工具。VisualDL 利用了丰富的图表来展示数据,用户可以更直观、清晰地查看数据的特征与变化趋势,有助于分析数据、及时发现错误,进而改进神经网络模型的设计。 -目前,VisualDL 支持 scalar, image, high dimensional 三个组件,项目正处于高速迭代中,敬请期待新组件的加入。 - -| 组件名称 | 展示图表 | 作用 | -| :----------------------------------------------------------: | :--------: | :----------------------------------------------------------- | -| [ Scalar](#Scalar -- 折线图组件) | 折线图 | 动态展示损失函数值、准确率等标量数据 | -| [Image](#Image -- 图片可视化组件) | 图片可视化 | 显示图片,可显示输入图片和处理后的结果,便于查看中间过程的变化 | -| [High Dimensional](#High Dimensional -- 数据降维组件) | 数据降维 | 将高维数据映射到 2D/3D 空间来可视化嵌入,便于观察不同数据的相关性 | - +目前,VisualDL 支持 scalar, image, audio, graph, histogram, pr curve, high dimensional 七个组件,项目正处于高速迭代中,敬请期待新组件的加入。 +| 组件名称 | 展示图表 | 作用 | +| :-------------------------------------------------: | :--------: | :----------------------------------------------------------- | +| [ Scalar](#Scalar--标量组件) | 折线图 | 动态展示损失函数值、准确率等标量数据 | +| [Image](#Image--图片可视化组件) | 图片可视化 | 显示图片,可显示输入图片和处理后的结果,便于查看中间过程的变化 | +| [Audio](#Audio--音频播放组件) | 音频播放 | 播放训练过程中的音频数据,监控语音识别与合成等任务的训练过程 | +| [Graph](#Graph--网络结构组件) | 网络结构 | 展示网络结构、节点属性及数据流向,辅助学习、优化网络结构 | +| [Histogram](#Histogram--直方图组件) | 直方图 | 展示训练过程中权重、梯度等张量的分布 | +| [PR Curve](#PR-Curve--PR曲线组件) | 折线图 | 权衡精度与召回率之间的平衡关系,便于选择最佳阈值 | +| [High Dimensional](#High-Dimensional--数据降维组件) | 数据降维 | 将高维数据映射到 2D/3D 空间来可视化嵌入,便于观察不同数据的相关性 | ## Scalar -- 折线图组件 @@ -29,16 +29,22 @@ Scalar 组件的记录接口如下: ```python add_scalar(tag, value, step, walltime=None) ``` + 接口参数说明如下: -|参数|格式|含义| -|-|-|-| -|tag|string|记录指标的标志,如`train/loss`,不能含有`%`| -|value|float|要记录的数据值| -|step|int|记录的步数| -|walltime|int|记录数据的时间戳,默认为当前时间戳| + +| 参数 | 格式 | 含义 | +| -------- | ------ | ------------------------------------------- | +| tag | string | 记录指标的标志,如`train/loss`,不能含有`%` | +| value | float | 要记录的数据值 | +| step | int | 记录的步数 | +| walltime | int | 记录数据的时间戳,默认为当前时间戳 | ### Demo -下面展示了使用 Scalar 组件记录数据的示例,代码见[Scalar组件](../../demo/components/scalar_test.py) + +- 基础使用 + +下面展示了使用 Scalar 组件记录数据的示例,代码文件请见[Scalar组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/scalar_test.py) + ```python from visualdl import LogWriter @@ -52,7 +58,9 @@ if __name__ == '__main__': # 向记录器添加一个tag为`loss`的数据 writer.add_scalar(tag="loss", step=step, value=1/(value[step] + 1)) ``` + 运行上述程序后,在命令行执行 + ```shell visualdl --logdir ./log --port 8080 ``` @@ -60,11 +68,58 @@ visualdl --logdir ./log --port 8080 接着在浏览器打开`http://127.0.0.1:8080`,即可查看以下折线图。

- +

+- 多组实验对比 + +下面展示了使用Scalar组件实现多组实验对比 + +多组实验对比的实现分为两步: + +1. 创建子日志文件储存每组实验的参数数据 +2. 将数据写入scalar组件时,**使用相同的tag**,即可实现对比**不同实验**的**同一类型参数** + +```python +from visualdl import LogWriter + +if __name__ == '__main__': + value = [i/1000.0 for i in range(1000)] + # 步骤一:创建父文件夹:log与子文件夹:scalar_test + with LogWriter(logdir="./log/scalar_test") as writer: + for step in range(1000): + # 步骤二:向记录器添加一个tag为`train/acc`的数据 + writer.add_scalar(tag="train/acc", step=step, value=value[step]) + # 步骤二:向记录器添加一个tag为`train/loss`的数据 + writer.add_scalar(tag="train/loss", step=step, value=1/(value[step] + 1)) + # 步骤一:创建第二个子文件夹scalar_test2 + value = [i/500.0 for i in range(1000)] + with LogWriter(logdir="./log/scalar_test2") as writer: + for step in range(1000): + # 步骤二:在同样名为`train/acc`下添加scalar_test2的accuracy的数据 + writer.add_scalar(tag="train/acc", step=step, value=value[step]) + # 步骤二:在同样名为`train/loss`下添加scalar_test2的loss的数据 + writer.add_scalar(tag="train/loss", step=step, value=1/(value[step] + 1)) +``` + +运行上述程序后,在命令行执行 + +```shell +visualdl --logdir ./log --port 8080 +``` + +接着在浏览器打开`http://127.0.0.1:8080`,即可查看以下折线图,对比「scalar_test」和「scalar_test2」的Accuracy和Loss。 + +

+ +

+ + +*多组实验对比的应用案例可参考AI Studio项目:[VisualDL 2.0--眼疾识别训练可视化](https://aistudio.baidu.com/aistudio/projectdetail/502834) + + ### 功能操作说明 * 支持数据卡片「最大化」、「还原」、「坐标系转化」(y轴对数坐标)、「下载」折线图 @@ -75,6 +130,8 @@ visualdl --logdir ./log --port 8080 + + * 数据点Hover展示详细信息

@@ -83,6 +140,8 @@ visualdl --logdir ./log --port 8080 + + * 可搜索卡片标签,展示目标图像

@@ -91,6 +150,8 @@ visualdl --logdir ./log --port 8080 + + * 可搜索打点数据标签,展示特定数据

@@ -98,6 +159,8 @@ visualdl --logdir ./log --port 8080

+ + * X轴有三种衡量尺度 1. Step:迭代次数 @@ -107,6 +170,8 @@ visualdl --logdir ./log --port 8080

+ + * 可调整曲线平滑度,以便更好的展现参数整体的变化趋势

@@ -114,6 +179,8 @@ visualdl --logdir ./log --port 8080

+ + ## Image -- 图片可视化组件 ### 介绍 @@ -127,16 +194,20 @@ Image 组件的记录接口如下: ```python add_image(tag, img, step, walltime=None) ``` + 接口参数说明如下: -|参数|格式|含义| -|-|-|-| -|tag|string|记录指标的标志,如`train/loss`,不能含有`%`| -|img|numpy.ndarray|以ndarray格式表示的图片| -|step|int|记录的步数| -|walltime|int|记录数据的时间戳,默认为当前时间戳| + +| 参数 | 格式 | 含义 | +| -------- | ------------- | ------------------------------------------- | +| tag | string | 记录指标的标志,如`train/loss`,不能含有`%` | +| img | numpy.ndarray | 以ndarray格式表示的图片 | +| step | int | 记录的步数 | +| walltime | int | 记录数据的时间戳,默认为当前时间戳 | ### Demo -下面展示了使用 Image 组件记录数据的示例,代码文件请见[Image组件](../../demo/components/image_test.py) + +下面展示了使用 Image 组件记录数据的示例,代码文件请见[Image组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/image_test.py) + ```python import numpy as np from PIL import Image @@ -159,11 +230,13 @@ if __name__ == '__main__': with LogWriter(logdir="./log/image_test/train") as writer: for step in range(6): # 添加一个图片数据 - writer.add_image(tag="doge", + writer.add_image(tag="eye", img=random_crop("../../docs/images/eye.jpg"), step=step) ``` + 运行上述程序后,在命令行执行 + ```shell visualdl --logdir ./log --port 8080 ``` @@ -171,10 +244,12 @@ visualdl --logdir ./log --port 8080 在浏览器输入`http://127.0.0.1:8080`,即可查看图片数据。

- +

+ + ### 功能操作说明 可搜索图片标签显示对应图片数据 @@ -184,6 +259,8 @@ visualdl --logdir ./log --port 8080

+ + 支持滑动Step/迭代次数查看不同迭代次数下的图片数据

@@ -191,6 +268,442 @@ visualdl --logdir ./log --port 8080

+ + +## Audio--音频播放组件 + +### 介绍 + +Audio组件实时查看训练过程中的音频数据,监控语音识别与合成等任务的训练过程。 + +### 记录接口 + +Audio 组件的记录接口如下: + +```python +add_audio(tag, audio_array, step, sample_rate) +``` + +接口参数说明如下: + +| 参数 | 格式 | 含义 | +| ----------- | ------------- | ------------------------------------------ | +| tag | string | 记录指标的标志,如`audio_tag`,不能含有`%` | +| audio_arry | numpy.ndarray | 以ndarray格式表示的音频 | +| step | int | 记录的步数 | +| sample_rate | int | 采样率,**注意正确填写对应音频的原采样率** | + +### Demo + +下面展示了使用 Audio 组件记录数据的示例,代码文件请见[Audio组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/audio_test.py) + +```python +from visualdl import LogWriter +import numpy as np +import wave + + +def read_audio_data(audio_path): + """ + Get audio data. + """ + CHUNK = 4096 + f = wave.open(audio_path, "rb") + wavdata = [] + chunk = f.readframes(CHUNK) + while chunk: + data = np.frombuffer(chunk, dtype='uint8') + wavdata.extend(data) + chunk = f.readframes(CHUNK) + # 8k sample rate, 16bit frame, 1 channel + shape = [8000, 2, 1] + return shape, wavdata + + +if __name__ == '__main__': + with LogWriter(logdir="./log") as writer: + audio_shape, audio_data = read_audio_data("./testing.wav") + audio_data = np.array(audio_data) + writer.add_audio(tag="audio_tag", + audio_array=audio_data, + step=0, + sample_rate=8000) +``` + +运行上述程序后,在命令行执行 + +```shell +visualdl --logdir ./log --port 8080 +``` + +在浏览器输入`http://127.0.0.1:8080`,即可查看音频数据。 + +

+ +

+ + + +### 功能操作说明 + +- 可搜索音频标签显示对应音频数据 + +

+ +

+ + + +- 支持滑动Step/迭代次数试听不同迭代次数下的音频数据 + +

+ +

+ + + +- 支持播放/暂停音频数据 + +

+ +

+ + + +- 支持音量调节 + +

+ +

+ + + +- 支持音频下载 + +

+ +

+ + + + +## Graph--网络结构组件 + +### 介绍 + +Graph组件一键可视化模型的网络结构。用于查看模型属性、节点信息、节点输入输出等,并进行节点搜索,协助开发者们快速分析模型结构与了解数据流向。 + +### Demo + +共有两种启动方式: + +- 前端模型文件拖拽上传: + + - 如只需使用Graph组件,则无需添加任何参数,在命令行执行`visualdl`后即可启动面板进行上传。 + - 如果同时需使用其他功能,在命令行指定日志文件路径(以`./log`为例)即可启动面板进行上传: + + ```shell + visualdl --logdir ./log --port 8080 + ``` + +

+ +

+ + + +- 后端启动Graph: + + - 在命令行加入参数`--model`并指定**模型文件**路径(非文件夹路径),即可启动并查看网络结构可视化: + + ```shell + visualdl --model ./log/model --port 8080 + ``` + +

+ +

+ + + +### 功能操作说明 + +- 一键上传模型 + - 支持模型格式:PaddlePaddle、ONNX、Keras、Core ML、Caffe、Caffe2、Darknet、MXNet、ncnn、TensorFlow Lite + - 实验性支持模型格式:TorchScript、PyTorch、Torch、 ArmNN、BigDL、Chainer、CNTK、Deeplearning4j、MediaPipe、ML.NET、MNN、OpenVINO、Scikit-learn、Tengine、TensorFlow.js、TensorFlow + +

+ +

+ + + +- 支持上下左右任意拖拽模型、放大和缩小模型 + +

+ +

+ + + +- 搜索定位到对应节点 + +

+ +

+ + + +- 点击查看模型属性 + +

+ +

+ + + +

+ +

+ + + +- 支持选择模型展示的信息 + +

+ +

+ + + +- 支持以PNG、SVG格式导出模型结构图 + +

+ +

+ + + +- 点击节点即可展示对应属性信息 + +

+ +

+ + + +- 支持一键更换模型 + +

+ +

+ + + +## Histogram--直方图组件 + +### 介绍 + +Histogram组件以直方图形式展示Tensor(weight、bias、gradient等)数据在训练过程中的变化趋势。深入了解模型各层效果,帮助开发者精准调整模型结构。 + +### 记录接口 + +Histogram 组件的记录接口如下: + +```python +add_histogram(tag, values, step, walltime=None, buckets=10) +``` + +接口参数说明如下: + +| 参数 | 格式 | 含义 | +| -------- | --------------------- | ------------------------------------------- | +| tag | string | 记录指标的标志,如`train/loss`,不能含有`%` | +| values | numpy.ndarray or list | 以ndarray或list格式表示的数据 | +| step | int | 记录的步数 | +| walltime | int | 记录数据的时间戳,默认为当前时间戳 | +| buckets | int | 生成直方图的分段数,默认为10 | + +### Demo + +下面展示了使用 Histogram组件记录数据的示例,代码文件请见[Histogram组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/histogram_test.py) + +```python +from visualdl import LogWriter +import numpy as np + + +if __name__ == '__main__': + values = np.arange(0, 1000) + with LogWriter(logdir="./log/histogram_test/train") as writer: + for index in range(1, 101): + interval_start = 1 + 2 * index / 100.0 + interval_end = 6 - 2 * index / 100.0 + data = np.random.uniform(interval_start, interval_end, size=(10000)) + writer.add_histogram(tag='default tag', + values=data, + step=index, + buckets=10) +``` + +运行上述程序后,在命令行执行 + +```shell +visualdl --logdir ./log --port 8080 +``` + +在浏览器输入`http://127.0.0.1:8080`,即可查看训练参数直方图。 + +### 功能操作说明 + +- 支持数据卡片「最大化」、直方图「下载」 + +

+ +

+ +- 可选择Offset或Overlay模式 + +

+ +

+ + + - Offset模式 + +

+ +

+ + + + - Overlay模式 + +

+ +

+ + +- 数据点Hover展示参数值、训练步数、频次 + + - 在第240次训练步数时,权重为-0.0031,且出现的频次是2734次 + +

+ +

+ +- 可搜索卡片标签,展示目标直方图 + +

+ +

+ +- 可搜索打点数据标签,展示特定数据流 + +

+ +

+ +## PR Curve--PR曲线组件 + +### 介绍 + +PR Curve以折线图形式呈现精度与召回率的权衡分析,清晰直观了解模型训练效果,便于分析模型是否达到理想标准。 + +### 记录接口 + +PR Curve组件的记录接口如下: + +```python +add_pr_curve(tag, labels, predictions, step=None, num_thresholds=10) +``` + +接口参数说明如下: + +| 参数 | 格式 | 含义 | +| -------------- | --------------------- | ------------------------------------------- | +| tag | string | 记录指标的标志,如`train/loss`,不能含有`%` | +| labels | numpy.ndarray or list | 以ndarray或list格式表示的实际类别 | +| predictions | numpy.ndarray or list | 以ndarray或list格式表示的预测类别 | +| step | int | 记录的步数 | +| num_thresholds | int | 阈值设置的个数,默认为10,最大值为127 | + +### Demo + +下面展示了使用 PR Curve 组件记录数据的示例,代码文件请见[PR Curve组件](#https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/pr_curve_test.py) + +```python +from visualdl import LogWriter +import numpy as np + +with LogWriter("./log/pr_curve_test/train") as writer: + for step in range(3): + labels = np.random.randint(2, size=100) + predictions = np.random.rand(100) + writer.add_pr_curve(tag='pr_curve', + labels=labels, + predictions=predictions, + step=step, + num_thresholds=5) +``` + +运行上述程序后,在命令行执行 + +```shell +visualdl --logdir ./log --port 8080 +``` + +接着在浏览器打开`http://127.0.0.1:8080`,即可查看PR Curve + +

+ +

+ + + +### 功能操作说明 + +- 支持数据卡片「最大化」,「还原」、「下载」PR曲线 + +

+ +

+ +- 数据点Hover展示详细信息:阈值对应的TP、TN、FP、FN + +

+ +

+ +- 可搜索卡片标签,展示目标图表 + +

+ +

+ +- 可搜索打点数据标签,展示特定数据 + +

+ +

+ + +- 支持查看不同训练步数下的PR曲线 + +

+ +

+ +- X轴-时间显示类型有三种衡量尺度 + + - Step:迭代次数 + - Walltime:训练绝对时间 + - Relative:训练时长 + +

+ +

+ ## High Dimensional -- 数据降维组件 ### 介绍 @@ -207,16 +720,20 @@ High Dimensional 组件的记录接口如下: ```python add_embeddings(tag, labels, hot_vectors, walltime=None) ``` + 接口参数说明如下: -|参数|格式|含义| -|-|-|-| -|tag|string|记录指标的标志,如`default`,不能含有`%`| -|labels|numpy.array 或 list|一维数组表示的标签,每个元素是一个string类型的字符串| -|hot_vectors|numpy.array or list|与labels一一对应,每个元素可以看作是某个标签的特征| -|walltime|int|记录数据的时间戳,默认为当前时间戳| + +| 参数 | 格式 | 含义 | +| ----------- | ------------------- | ---------------------------------------------------- | +| tag | string | 记录指标的标志,如`default`,不能含有`%` | +| labels | numpy.array 或 list | 一维数组表示的标签,每个元素是一个string类型的字符串 | +| hot_vectors | numpy.array or list | 与labels一一对应,每个元素可以看作是某个标签的特征 | +| walltime | int | 记录数据的时间戳,默认为当前时间戳 | ### Demo -下面展示了使用 High Dimensional 组件记录数据的示例,代码见[High Dimensional组件](../../demo/components/high_dimensional_test.py) + +下面展示了使用 High Dimensional 组件记录数据的示例,代码文件请见[High Dimensional组件](https://github.com/PaddlePaddle/VisualDL/blob/develop/demo/components/high_dimensional_test.py) + ```python from visualdl import LogWriter @@ -237,7 +754,9 @@ if __name__ == '__main__': labels=labels, hot_vectors=hot_vectors) ``` + 运行上述程序后,在命令行执行 + ```shell visualdl --logdir ./log --port 8080 ``` @@ -245,5 +764,11 @@ visualdl --logdir ./log --port 8080 接着在浏览器打开`http://127.0.0.1:8080`,即可查看降维后的可视化数据。

- +

+ + + + + +# diff --git a/doc/fluid/advanced_guide/flags/memory_cn.rst b/doc/fluid/advanced_guide/flags/memory_cn.rst index cbafa94a0e5b28570cbb16a92f17a947bd3458fd..94676721c2d0baca9a2d744e7dbc7064c7eed279 100644 --- a/doc/fluid/advanced_guide/flags/memory_cn.rst +++ b/doc/fluid/advanced_guide/flags/memory_cn.rst @@ -11,13 +11,14 @@ FLAGS_allocator_strategy 取值范围 --------------- -String型,['naive_best_fit', 'auto_growth']中的一个。缺省值为'naive_best_fit'。 +String型,['naive_best_fit', 'auto_growth']中的一个。缺省值如果编译Paddle CMake时使用-DON_INFER=ON为'naive_best_fit'。 +其他默认情况为'auto_growth'。PaddlePaddle pip安装包的默认策略也是'auto_growth' 示例 -------- -FLAGS_allocator_strategy=naive_best_fit - 使用预分配best fit分配器。 +FLAGS_allocator_strategy=naive_best_fit - 使用预分配best fit分配器,PaddlePaddle会先占用大多比例的可用内存/显存,在Paddle具体数据使用时分配,这种方式预占空间较大,但内存/显存碎片较少(比如能够支持模型的最大batch size会变大)。 -FLAGS_allocator_strategy=auto_growth - 使用auto growth分配器。 +FLAGS_allocator_strategy=auto_growth - 使用auto growth分配器。PaddlePaddle会随着真实数据需要再占用内存/显存,但内存/显存可能会产生碎片(比如能够支持模型的最大batch size会变小)。 FLAGS_eager_delete_scope diff --git a/doc/fluid/advanced_guide/flags/memory_en.rst b/doc/fluid/advanced_guide/flags/memory_en.rst index 8702a4082006ab05b0a983f3b117fba7617b558f..0e630e7d93d51e668397b9c88fbfd75ad45f9395 100644 --- a/doc/fluid/advanced_guide/flags/memory_en.rst +++ b/doc/fluid/advanced_guide/flags/memory_en.rst @@ -11,13 +11,13 @@ Use to choose allocator strategy of PaddlePaddle. Values accepted --------------- -String, enum in ['naive_best_fit', 'auto_growth']. The default value is 'naive_best_fit'. +String, enum in ['naive_best_fit', 'auto_growth']. The default value will be 'naive_best_fit' if users compile PaddlePaddle with -DON_INFER=ON CMake flag, otherwise is 'auto_growth'. The default PaddlePaddle pip package uses 'auto_growth'. Example -------- -FLAGS_allocator_strategy=naive_best_fit would use the pre-allocated best fit allocator. +FLAGS_allocator_strategy=naive_best_fit would use the pre-allocated best fit allocator. 'naive_best_fit' strategy would occupy almost all GPU memory by default but leads to less memory fragmentation (i.e., maximum batch size of models may be larger). -FLAGS_allocator_strategy=auto_growth would use the auto growth allocator. +FLAGS_allocator_strategy=auto_growth would use the auto growth allocator. 'auto_growth' strategy would allocate GPU memory on demand but may lead to more memory fragmentation (i.e., maximum batch size of models may be smaller). diff --git a/doc/fluid/api/gen_doc.sh b/doc/fluid/api/gen_doc.sh index 2e4874c8dd8b974ab746d446af406683611763d0..f30d5560880385d42b6cd0b60d8b619a90ed771b 100644 --- a/doc/fluid/api/gen_doc.sh +++ b/doc/fluid/api/gen_doc.sh @@ -10,7 +10,7 @@ python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_na python gen_module_index.py fluid fluid # tensor -for module in math random stat linalg +for module in math random stat linalg search do python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name tensor --to_multiple_files True --output_dir tensor python gen_module_index.py tensor.${module} ${module} diff --git a/doc/fluid/api/gen_index.py b/doc/fluid/api/gen_index.py index 16bea3fd471e4d08ceb71d8a1150589f041292c9..4cc7272b03aa0fec3eefe543d7ff7ad791d6e1fd 100644 --- a/doc/fluid/api/gen_index.py +++ b/doc/fluid/api/gen_index.py @@ -4,7 +4,7 @@ import glob import os if __name__ == '__main__': - with open('index_en.rst', 'w') as file_object: + with open('index_en.rst', 'w') as file_object: file_object = open('index_en.rst', 'w') file_object.write('''============= API Reference @@ -25,16 +25,16 @@ API Reference else: pattern = target_dir + '/*.rst' file_names.extend(glob.glob(pattern)) - + for file_name in sorted(file_names): - with open(file_name, 'r')as f: + with open(file_name, 'r') as f: for i in range(2): line = f.readline().strip() if line.find('paddle.') != -1: - file_object.write(' '+file_name + "\n") + file_object.write(' ' + file_name + "\n") file_names.remove(file_name) - file_object.write(' '+'fluid.rst' + "\n") + file_object.write(' ' + 'fluid.rst' + "\n") for file_name in sorted(file_names): - if file_name not in ['index_en.rst', 'fluid.rst']: - file_object.write(' '+file_name + "\n") + if file_name not in ['index_en.rst']: + file_object.write(' ' + file_name + "\n") diff --git a/doc/fluid/api/index_en.rst b/doc/fluid/api/index_en.rst index efbe319fb04e9ad1cce54a760e955b51c311943f..f360715383903c2f6efae7a01e662a710fafc340 100644 --- a/doc/fluid/api/index_en.rst +++ b/doc/fluid/api/index_en.rst @@ -6,15 +6,30 @@ API Reference :maxdepth: 1 ../api_guides/index_en.rst - paddle.rst dataset.rst - tensor.rst - nn.rst - imperative.rst declarative.rst - optimizer.rst - metric.rst framework.rst + imperative.rst io.rst - utils.rst - incubate.rst + metric.rst + nn.rst + optimizer.rst + tensor.rst + fluid.rst + backward.rst + clip.rst + data/data_reader.rst + data/dataset.rst + dygraph.rst + executor.rst + fluid.rst + initializer.rst + layers.rst + metrics.rst + nets.rst + paddle.rst + profiler.rst + regularizer.rst + transpiler.rst + unique_name.rst + review_tmp.rst diff --git a/doc/fluid/api/nn.rst b/doc/fluid/api/nn.rst index 50b2e95158d27e3904cec0e670084721db151c51..3d8ad814db7dfe9da66f6324117ad7c6c83c18fb 100644 --- a/doc/fluid/api/nn.rst +++ b/doc/fluid/api/nn.rst @@ -49,6 +49,7 @@ paddle.nn nn/exponential_decay.rst nn/filter_by_instag.rst nn/fsp_matrix.rst + nn/functional.rst nn/gather_tree.rst nn/gelu.rst nn/generate_mask_labels.rst @@ -67,6 +68,7 @@ paddle.nn nn/huber_loss.rst nn/image_resize.rst nn/image_resize_short.rst + nn/initializer.rst nn/inverse_time_decay.rst nn/iou_similarity.rst nn/kldiv_loss.rst @@ -82,24 +84,22 @@ paddle.nn nn/logsigmoid.rst nn/loss.rst nn/lrn.rst - nn/margin_rank_loss.rst + nn/matrix_nms.rst nn/maxout.rst nn/mse_loss.rst nn/multiclass_nms.rst - nn/matrix_nms.rst nn/natural_exp_decay.rst nn/noam_decay.rst nn/npair_loss.rst nn/one_hot.rst nn/pad.rst - nn/pad_constant_like.rst nn/pad2d.rst + nn/pad_constant_like.rst nn/ParameterList.rst nn/piecewise_decay.rst nn/pixel_shuffle.rst nn/polygon_box_transform.rst nn/polynomial_decay.rst - nn/pool2d.rst nn/Pool2D.rst nn/pool3d.rst nn/prior_box.rst @@ -149,3 +149,5 @@ paddle.nn nn/while_loop.rst nn/yolo_box.rst nn/yolov3_loss.rst + nn/functional/loss/margin_ranking_loss.rst + nn/layer/loss/MarginRankingLoss.rst diff --git a/doc/fluid/api/nn/functional.rst b/doc/fluid/api/nn/functional.rst new file mode 100644 index 0000000000000000000000000000000000000000..551924348e956066edf7affedb78a60e7adf2df4 --- /dev/null +++ b/doc/fluid/api/nn/functional.rst @@ -0,0 +1,9 @@ +========== +functional +========== + +.. toctree:: + :maxdepth: 1 + + functional/l1_loss.rst + functional/nll_loss.rst diff --git a/doc/fluid/api/nn/functional/l1_loss.rst b/doc/fluid/api/nn/functional/l1_loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..01a3ea06e7d034eb70744146816e6d0a166b749d --- /dev/null +++ b/doc/fluid/api/nn/functional/l1_loss.rst @@ -0,0 +1,10 @@ +.. _api_nn_functional_l1_loss: + +l1_loss +------ + +.. autoclass:: paddle.nn.functional.l1_loss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/functional/loss/margin_ranking_loss.rst b/doc/fluid/api/nn/functional/loss/margin_ranking_loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..e92eadc126a49d8a46bcfc06960eb39dcdc35fec --- /dev/null +++ b/doc/fluid/api/nn/functional/loss/margin_ranking_loss.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_functional_loss_margin_ranking_loss: + +margin_ranking_loss +------------------- + +.. autofunction:: paddle.nn.functional.loss.margin_ranking_loss + :noindex: + diff --git a/doc/fluid/api/nn/functional/nll_loss.rst b/doc/fluid/api/nn/functional/nll_loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..6f0ce4093ac8a9cefc202e4346457edd4b2c6ae1 --- /dev/null +++ b/doc/fluid/api/nn/functional/nll_loss.rst @@ -0,0 +1,10 @@ +.. _api_nn_functional_nll_loss: + +nll_loss +------------------------------- + +.. autoclass:: paddle.nn.functional.nll_loss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/layer/loss/MarginRankingLoss.rst b/doc/fluid/api/nn/layer/loss/MarginRankingLoss.rst new file mode 100644 index 0000000000000000000000000000000000000000..d69d1deff5defab24b2f12ea877c3a208a801478 --- /dev/null +++ b/doc/fluid/api/nn/layer/loss/MarginRankingLoss.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_layer_loss_MarginRankingLoss: + +MarginRankingLoss +----------------- + +.. autoclass:: paddle.nn.layer.loss.MarginRankingLoss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/loss/NLLLoss.rst b/doc/fluid/api/nn/loss/NLLLoss.rst new file mode 100644 index 0000000000000000000000000000000000000000..c1a0c26de51b8869a8eccb2150c8e5635159f1de --- /dev/null +++ b/doc/fluid/api/nn/loss/NLLLoss.rst @@ -0,0 +1,13 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_nn_loss_NLLLoss: + +NLLLoss +------------------------------- + +.. autoclass:: paddle.nn.loss.NLLLoss + :members: + :inherited-members: + :noindex: + diff --git a/doc/fluid/api/nn/margin_rank_loss.rst b/doc/fluid/api/nn/margin_rank_loss.rst deleted file mode 100644 index 1ef924d8728dce215f20372bd4f6ea4a87a27874..0000000000000000000000000000000000000000 --- a/doc/fluid/api/nn/margin_rank_loss.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_nn_margin_rank_loss: - -margin_rank_loss -------------------------------- -:doc_source: paddle.fluid.layers.margin_rank_loss - - diff --git a/doc/fluid/api/nn/softmax.rst b/doc/fluid/api/nn/softmax.rst index 5eba38ad90a2d587f09a01a653dc01c7f3f877bb..bb18407af36005b23ab911390b8be880c9695101 100644 --- a/doc/fluid/api/nn/softmax.rst +++ b/doc/fluid/api/nn/softmax.rst @@ -1,7 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + .. _api_nn_softmax: softmax -------------------------------- -:doc_source: paddle.fluid.layers.softmax +------- +.. autofunction:: paddle.nn.functional.softmax + :noindex: diff --git a/doc/fluid/api/paddle.rst b/doc/fluid/api/paddle.rst index c4af7870125e5c794621f8d828bc29db91e29efe..1d69e4df54808d97d7876289469b0b5e6cf7fa91 100644 --- a/doc/fluid/api/paddle.rst +++ b/doc/fluid/api/paddle.rst @@ -45,10 +45,7 @@ paddle paddle/dot.rst paddle/elementwise_add.rst paddle/elementwise_div.rst - paddle/elementwise_equal.rst paddle/elementwise_floordiv.rst - paddle/elementwise_max.rst - paddle/elementwise_min.rst paddle/elementwise_mod.rst paddle/elementwise_mul.rst paddle/elementwise_pow.rst @@ -56,6 +53,7 @@ paddle paddle/elementwise_sum.rst paddle/enable_imperative.rst paddle/equal.rst + paddle/equal_all.rst paddle/erf.rst paddle/ExecutionStrategy.rst paddle/Executor.rst @@ -99,9 +97,11 @@ paddle paddle/manual_seed.rst paddle/matmul.rst paddle/max.rst + paddle/maximum.rst paddle/mean.rst paddle/meshgrid.rst paddle/min.rst + paddle/minimum.rst paddle/mm.rst paddle/mul.rst paddle/multiplex.rst diff --git a/doc/fluid/api/paddle/cumsum.rst b/doc/fluid/api/paddle/cumsum.rst index 26211d9321da87942f4469ef47bfd78fa7173d64..673296e8836d1116f16d65b73a4f781241538dd4 100644 --- a/doc/fluid/api/paddle/cumsum.rst +++ b/doc/fluid/api/paddle/cumsum.rst @@ -2,6 +2,6 @@ cumsum ------------------------------- -:doc_source: paddle.fluid.layers.cumsum +:doc_source: paddle.tensor.cumsum diff --git a/doc/fluid/api/paddle/elementwise_equal.rst b/doc/fluid/api/paddle/elementwise_equal.rst deleted file mode 100644 index 485738ee2b32b6735e3209638b2fa162546a41fc..0000000000000000000000000000000000000000 --- a/doc/fluid/api/paddle/elementwise_equal.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_paddle_elementwise_equal: - -elementwise_equal -------------------------------- -:doc_source: paddle.fluid.layers.equal - - diff --git a/doc/fluid/api/paddle/elementwise_max.rst b/doc/fluid/api/paddle/elementwise_max.rst deleted file mode 100644 index 76f9148ef2f600ada77f099fdd69a781aa72ab40..0000000000000000000000000000000000000000 --- a/doc/fluid/api/paddle/elementwise_max.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_paddle_elementwise_max: - -elementwise_max -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_max - - diff --git a/doc/fluid/api/paddle/elementwise_min.rst b/doc/fluid/api/paddle/elementwise_min.rst deleted file mode 100644 index f2258a309201d5ea23a518a70d79dd8ca9d06929..0000000000000000000000000000000000000000 --- a/doc/fluid/api/paddle/elementwise_min.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_paddle_elementwise_min: - -elementwise_min -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_min - - diff --git a/doc/fluid/api/paddle/equal_all.rst b/doc/fluid/api/paddle/equal_all.rst new file mode 100644 index 0000000000000000000000000000000000000000..58fc331acc2b3f564dc73bb8c039c17b9b4720f2 --- /dev/null +++ b/doc/fluid/api/paddle/equal_all.rst @@ -0,0 +1,7 @@ +.. _api_paddle_equal_all + +equal_all +------------------------------- +:doc_source: paddle.tensor.equal_all + + diff --git a/doc/fluid/api/paddle/greater_equal.rst b/doc/fluid/api/paddle/greater_equal.rst index 8739113f3208d15efdd9c00a2619ae612a6e1873..54afe57ffab5185fc2c3fb92a671e0b726108ab3 100644 --- a/doc/fluid/api/paddle/greater_equal.rst +++ b/doc/fluid/api/paddle/greater_equal.rst @@ -2,6 +2,6 @@ greater_equal ------------------------------- -:doc_source: paddle.fluid.layers.greater_equal +:doc_source: paddle.tensor.greater_equal diff --git a/doc/fluid/api/paddle/greater_than.rst b/doc/fluid/api/paddle/greater_than.rst index f54f0e026f520176bc60b00a59e28adc69358915..04a874dd929d7dae274898c87029059b1b1d6261 100644 --- a/doc/fluid/api/paddle/greater_than.rst +++ b/doc/fluid/api/paddle/greater_than.rst @@ -2,6 +2,6 @@ greater_than ------------------------------- -:doc_source: paddle.fluid.layers.greater_than +:doc_source: paddle.tensor.greater_than diff --git a/doc/fluid/api/paddle/less_equal.rst b/doc/fluid/api/paddle/less_equal.rst index 16cc1a647457e370ed105172936b61afad04f00c..3fc5e2ce2b819dfed7ca8b64841836229c86d3e4 100644 --- a/doc/fluid/api/paddle/less_equal.rst +++ b/doc/fluid/api/paddle/less_equal.rst @@ -2,6 +2,6 @@ less_equal ------------------------------- -:doc_source: paddle.fluid.layers.less_equal +:doc_source: paddle.tensor.less_equal diff --git a/doc/fluid/api/paddle/less_than.rst b/doc/fluid/api/paddle/less_than.rst index 2c13074ad988e5a5138a76cff50619963964d55d..7df6eb441d37a2fe8bf95e43a48df8471115ad2c 100644 --- a/doc/fluid/api/paddle/less_than.rst +++ b/doc/fluid/api/paddle/less_than.rst @@ -2,6 +2,6 @@ less_than ------------------------------- -:doc_source: paddle.fluid.layers.less_than +:doc_source: paddle.tensor.less_than diff --git a/doc/fluid/api/paddle/max.rst b/doc/fluid/api/paddle/max.rst index 695f4d5b6bd97f460624650a206affe6b2140c41..0d28148a8dcc0ac31744450c954e9a125e475add 100644 --- a/doc/fluid/api/paddle/max.rst +++ b/doc/fluid/api/paddle/max.rst @@ -2,6 +2,6 @@ max ------------------------------- -:doc_source: paddle.fluid.layers.reduce_max +:doc_source: paddle.tensor.max diff --git a/doc/fluid/api/paddle/maximum.rst b/doc/fluid/api/paddle/maximum.rst new file mode 100644 index 0000000000000000000000000000000000000000..c85f8a97710efb559e5f73c586eb45798224e8db --- /dev/null +++ b/doc/fluid/api/paddle/maximum.rst @@ -0,0 +1,7 @@ +.. _api_paddle_maximum: + +maximum +------------------------------- +:doc_source: paddle.tensor.maximum + + diff --git a/doc/fluid/api/paddle/min.rst b/doc/fluid/api/paddle/min.rst index a05dd553f4827dd8feeb4ddc56ccfa3ce7d11eb9..bb99109471c0ab684fdd7646fc446abe8aafe6cb 100644 --- a/doc/fluid/api/paddle/min.rst +++ b/doc/fluid/api/paddle/min.rst @@ -2,6 +2,6 @@ min ------------------------------- -:doc_source: paddle.fluid.layers.reduce_min +:doc_source: paddle.tensor.min diff --git a/doc/fluid/api/paddle/minimum.rst b/doc/fluid/api/paddle/minimum.rst new file mode 100644 index 0000000000000000000000000000000000000000..41391741da78620231f5fe1a9c5ee3ea73ce70be --- /dev/null +++ b/doc/fluid/api/paddle/minimum.rst @@ -0,0 +1,7 @@ +.. _api_paddle_minimum: + +minimum +------------------------------- +:doc_source: paddle.tensor.minimum + + diff --git a/doc/fluid/api/paddle/not_equal.rst b/doc/fluid/api/paddle/not_equal.rst index fb5de71d0a79ec9be46c43c02414492acd087f89..4fd1cbe809d9dded938f2014124ee9b738b1d9cd 100644 --- a/doc/fluid/api/paddle/not_equal.rst +++ b/doc/fluid/api/paddle/not_equal.rst @@ -2,6 +2,6 @@ not_equal ------------------------------- -:doc_source: paddle.fluid.layers.not_equal +:doc_source: paddle.tensor.not_equal diff --git a/doc/fluid/api/review_tmp.rst b/doc/fluid/api/review_tmp.rst new file mode 100644 index 0000000000000000000000000000000000000000..e39366bcef08a15baa15c3cfbb318022a2dc47b2 --- /dev/null +++ b/doc/fluid/api/review_tmp.rst @@ -0,0 +1,9 @@ +================= +paddle.review_tmp +================= + +.. toctree:: + :maxdepth: 1 + + review_tmp/MarginRankingLoss.rst + review_tmp/margin_ranking_loss.rst diff --git a/doc/fluid/api/review_tmp/MarginRankingLoss.rst b/doc/fluid/api/review_tmp/MarginRankingLoss.rst new file mode 100644 index 0000000000000000000000000000000000000000..edc5d1cc57c85be5eb37312c6dc9b8b204b4d9b1 --- /dev/null +++ b/doc/fluid/api/review_tmp/MarginRankingLoss.rst @@ -0,0 +1,9 @@ +.. _api_nn_loss_MarginRankingLoss_tmp: + +MarginRankingLoss +----------------- + +.. autoclass:: paddle.nn.loss.MarginRankingLoss + :members: + :inherited-members: + :noindex: diff --git a/doc/fluid/api/review_tmp/margin_ranking_loss.rst b/doc/fluid/api/review_tmp/margin_ranking_loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..289d1928bf05925dc81238c7ff0dad2623a4d3fc --- /dev/null +++ b/doc/fluid/api/review_tmp/margin_ranking_loss.rst @@ -0,0 +1,7 @@ +.. _api_nn_functional_margin_ranking_loss_tmp: + +margin_ranking_loss +------------------- + +.. autofunction:: paddle.nn.functional.margin_ranking_loss + :noindex: diff --git a/doc/fluid/api/tensor.rst b/doc/fluid/api/tensor.rst index 73ce3e9d698fc54bd2ee5ba6591de1e6c8d695c4..a8eb2516782826e475c067311c765b50fddf4aaa 100644 --- a/doc/fluid/api/tensor.rst +++ b/doc/fluid/api/tensor.rst @@ -26,14 +26,12 @@ paddle.tensor tensor/div.rst tensor/elementwise_add.rst tensor/elementwise_div.rst - tensor/elementwise_equal.rst tensor/elementwise_floordiv.rst - tensor/elementwise_max.rst - tensor/elementwise_min.rst tensor/elementwise_mod.rst tensor/elementwise_mul.rst tensor/elementwise_pow.rst tensor/elementwise_sub.rst + tensor/equal_all.rst tensor/erf.rst tensor/exp.rst tensor/expand.rst @@ -64,8 +62,10 @@ paddle.tensor tensor/logical_xor.rst tensor/math.rst tensor/max.rst + tensor/maximum.rst tensor/mean.rst tensor/min.rst + tensor/minimum.rst tensor/mm.rst tensor/mul.rst tensor/multiplex.rst @@ -93,6 +93,7 @@ paddle.tensor tensor/scatter.rst tensor/scatter_nd.rst tensor/scatter_nd_add.rst + tensor/search.rst tensor/shape.rst tensor/shard_index.rst tensor/shuffle.rst diff --git a/doc/fluid/api/tensor/cumsum.rst b/doc/fluid/api/tensor/cumsum.rst index 835c7231150c7cf6d9de61f4907aca2cd558a192..96c1bf0abf8c06621b93624941025e4929652add 100644 --- a/doc/fluid/api/tensor/cumsum.rst +++ b/doc/fluid/api/tensor/cumsum.rst @@ -2,6 +2,6 @@ cumsum ------------------------------- -:doc_source: paddle.fluid.layers.cumsum +:doc_source: paddle.tensor.cumsum diff --git a/doc/fluid/api/tensor/elementwise_equal.rst b/doc/fluid/api/tensor/elementwise_equal.rst deleted file mode 100644 index ae7944446507328d83969df26d22427aabee1777..0000000000000000000000000000000000000000 --- a/doc/fluid/api/tensor/elementwise_equal.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_tensor_cn_elementwise_equal: - -elementwise_equal -------------------------------- -:doc_source: paddle.fluid.layers.equal - - diff --git a/doc/fluid/api/tensor/elementwise_max.rst b/doc/fluid/api/tensor/elementwise_max.rst deleted file mode 100644 index 5f96581bba4dba88df4bfd4676e0e81050004844..0000000000000000000000000000000000000000 --- a/doc/fluid/api/tensor/elementwise_max.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_tensor_cn_elementwise_max: - -elementwise_max -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_max - - diff --git a/doc/fluid/api/tensor/elementwise_min.rst b/doc/fluid/api/tensor/elementwise_min.rst deleted file mode 100644 index 9b5641099c4afc4738bd6b495d61a323387a74d9..0000000000000000000000000000000000000000 --- a/doc/fluid/api/tensor/elementwise_min.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _api_tensor_cn_elementwise_min: - -elementwise_min -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_min - - diff --git a/doc/fluid/api/tensor/equal_all.rst b/doc/fluid/api/tensor/equal_all.rst new file mode 100644 index 0000000000000000000000000000000000000000..5149e6101d64b1e2c8626a1d35693fd503b2d230 --- /dev/null +++ b/doc/fluid/api/tensor/equal_all.rst @@ -0,0 +1,7 @@ +.. _api_tensor_cn_equal_all: + +equal_all +------------------------------- +:doc_source: paddle.tensor.equal_all + + diff --git a/doc/fluid/api/tensor/greater_equal.rst b/doc/fluid/api/tensor/greater_equal.rst index ab967838e629e67052ae574e93098ebcae00c0bf..1a1394de05e7b4bf7b4cbfb463e3c9e79206d9cc 100644 --- a/doc/fluid/api/tensor/greater_equal.rst +++ b/doc/fluid/api/tensor/greater_equal.rst @@ -2,6 +2,6 @@ greater_equal ------------------------------- -:doc_source: paddle.fluid.layers.greater_equal +:doc_source: paddle.tensor.greater_equal diff --git a/doc/fluid/api/tensor/greater_than.rst b/doc/fluid/api/tensor/greater_than.rst index 789f212a75130d76546833207afd5761fea499ee..b0ff74910eb094120568dc4f3c7f792e221c91b7 100644 --- a/doc/fluid/api/tensor/greater_than.rst +++ b/doc/fluid/api/tensor/greater_than.rst @@ -2,6 +2,6 @@ greater_than ------------------------------- -:doc_source: paddle.fluid.layers.greater_than +:doc_source: paddle.tensor.greater_than diff --git a/doc/fluid/api/tensor/less_equal.rst b/doc/fluid/api/tensor/less_equal.rst index 5e7c7180a4899d380c6c1f2d49aba9597e8b456b..4adbeb1ccf2972ccb30cb1fb762dbea7a74114a4 100644 --- a/doc/fluid/api/tensor/less_equal.rst +++ b/doc/fluid/api/tensor/less_equal.rst @@ -2,6 +2,6 @@ less_equal ------------------------------- -:doc_source: paddle.fluid.layers.less_equal +:doc_source: paddle.tensor.less_equal diff --git a/doc/fluid/api/tensor/less_than.rst b/doc/fluid/api/tensor/less_than.rst index c4614acf5f666af3242b01027aa379a1b4ad0cfc..592dc48d66bbdd4c6506e118c98b654bd55e93fe 100644 --- a/doc/fluid/api/tensor/less_than.rst +++ b/doc/fluid/api/tensor/less_than.rst @@ -2,6 +2,6 @@ less_than ------------------------------- -:doc_source: paddle.fluid.layers.less_than +:doc_source: paddle.tensor.less_than diff --git a/doc/fluid/api/tensor/max.rst b/doc/fluid/api/tensor/max.rst index cdd8e4239bf6e73b64775a9858ec0b9661e4d73c..61a8667f8cab06a8433d9ab9e143390d3c1ccbc8 100644 --- a/doc/fluid/api/tensor/max.rst +++ b/doc/fluid/api/tensor/max.rst @@ -2,6 +2,6 @@ max ------------------------------- -:doc_source: paddle.fluid.layers.reduce_max +:doc_source: paddle.tensor.max diff --git a/doc/fluid/api/tensor/maximum.rst b/doc/fluid/api/tensor/maximum.rst new file mode 100644 index 0000000000000000000000000000000000000000..7c91c5f2bd465a17ceae3a2f602addbd115ed273 --- /dev/null +++ b/doc/fluid/api/tensor/maximum.rst @@ -0,0 +1,7 @@ +.. _api_tensor_cn_maximum: + +maximum +------------------------------- +:doc_source: paddle.tensor.maximum + + diff --git a/doc/fluid/api/tensor/mean.rst b/doc/fluid/api/tensor/mean.rst index dce657a2e57aa3b8d78136c9b9c311f8d23c76aa..d226a37107af8e67ef4d8ea0bf9a17e536fede36 100644 --- a/doc/fluid/api/tensor/mean.rst +++ b/doc/fluid/api/tensor/mean.rst @@ -1,7 +1,11 @@ -.. _api_tensor_cn_mean: +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_mean: mean -------------------------------- -:doc_source: paddle.fluid.layers.mean +--------- +.. autofunction:: paddle.tensor.mean + :noindex: diff --git a/doc/fluid/api/tensor/min.rst b/doc/fluid/api/tensor/min.rst index ea16448a6752464a582e3a2ea63960dcdcee6e40..cdb8df5c370ce66a5e8e39555699e09730bdcf23 100644 --- a/doc/fluid/api/tensor/min.rst +++ b/doc/fluid/api/tensor/min.rst @@ -2,6 +2,6 @@ min ------------------------------- -:doc_source: paddle.fluid.layers.reduce_min +:doc_source: paddle.tensor.min diff --git a/doc/fluid/api/tensor/minimum.rst b/doc/fluid/api/tensor/minimum.rst new file mode 100644 index 0000000000000000000000000000000000000000..725aaeb8a7f2fa0cf7b1a7fa1d8611a4c4967ac7 --- /dev/null +++ b/doc/fluid/api/tensor/minimum.rst @@ -0,0 +1,7 @@ +.. _api_tensor_cn_minimum: + +minimum +------------------------------- +:doc_source: paddle.tensor.minimum + + diff --git a/doc/fluid/api/tensor/not_equal.rst b/doc/fluid/api/tensor/not_equal.rst index d4f506f99e814b0a578d474a2bcb78cc6dd7c582..8aeac42d73c7683ba037bef31a6b68c2acf01064 100644 --- a/doc/fluid/api/tensor/not_equal.rst +++ b/doc/fluid/api/tensor/not_equal.rst @@ -2,6 +2,6 @@ not_equal ------------------------------- -:doc_source: paddle.fluid.layers.not_equal +:doc_source: paddle.tensor.not_equal diff --git a/doc/fluid/api_cn/dygraph_cn/Conv2D_cn.rst b/doc/fluid/api_cn/dygraph_cn/Conv2D_cn.rst index c09cb6548135d5b713d3c63f01ca321311e09187..3e81c4a31738d78234527178a1408c7cc03519ef 100644 --- a/doc/fluid/api_cn/dygraph_cn/Conv2D_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn/Conv2D_cn.rst @@ -46,7 +46,7 @@ Conv2D 参数: - **num_channels** (int) - 输入图像的通道数。 - - **num_fliters** (int) - 滤波器的个数,和输出特征图个数相同。 + - **num_filters** (int) - 滤波器的个数,和输出特征图个数相同。 - **filter_size** (int|tuple) - 滤波器大小。如果 ``filter_size`` 是一个元组,则必须包含两个整型数,分别表示滤波器高度和宽度。否则,表示滤波器高度和宽度均为 ``filter_size`` 。 - **stride** (int|tuple, 可选) - 步长大小。如果 ``stride`` 为元组,则必须包含两个整型数,分别表示垂直和水平滑动步长。否则,表示垂直和水平滑动步长均为 ``stride`` 。默认值:1。 - **padding** (int|tuple, 可选) - 填充大小。如果 ``padding`` 为元组,则必须包含两个整型数,分别表示竖直和水平边界填充大小。否则,表示竖直和水平边界填充大小均为 ``padding`` 。默认值:0。 diff --git a/doc/fluid/api_cn/dygraph_cn/no_grad_cn.rst b/doc/fluid/api_cn/dygraph_cn/no_grad_cn.rst index e93287287b29e61256e51249792d57390033d040..b58357ae1c122d72f2a1b94ee0ee0a9bfbd02135 100644 --- a/doc/fluid/api_cn/dygraph_cn/no_grad_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn/no_grad_cn.rst @@ -4,48 +4,51 @@ no_grad ------------------------------- -.. py:method:: paddle.fluid.dygraph.no_grad(func=None) +.. py:class:: paddle.fluid.dygraph.no_grad :api_attr: 命令式编程模式(动态图) - +:alias_main: paddle.no_grad +:alias: paddle.no_grad +:old_api: paddle.fluid.dygraph.no_grad 创建一个上下文来禁用动态图梯度计算。在此模式下,每次计算的结果都将具有stop_gradient=True。 -也可以用作一个装饰器(确保不要用括号来初始化)。 +也可以用作一个装饰器(需要创建实例对象作为装饰器)。 **代码示例** .. code-block:: python - import numpy as np import paddle.fluid as fluid + paddle.enable_imperative() + # 用作生成器 + data = np.array([[2, 3], [4, 5]]).astype('float32') - with fluid.dygraph.guard(): - l0 = fluid.Linear(2, 2) # l0.weight.gradient() is None - l1 = fluid.Linear(2, 2) - with fluid.dygraph.no_grad(): - # l1.weight.stop_gradient is False - tmp = l1.weight * 2 # tmp.stop_gradient is True - x = fluid.dygraph.to_variable(data) - y = l0(x) + tmp - o = l1(y) - o.backward() - print(tmp.gradient() is None) # True - print(l0.weight.gradient() is None) # False - + l0 = fluid.Linear(2, 2) # l0.weight.gradient() is None + l1 = fluid.Linear(2, 2) + with fluid.no_grad(): + # l1.weight.stop_gradient is False + tmp = l1.weight * 2 # tmp.stop_gradient is True + x = fluid.dygraph.to_variable(data) + y = l0(x) + tmp + o = l1(y) + o.backward() + print(tmp.gradient() is None) # True + print(l0.weight.gradient() is None) # False + # 用作装饰器 - @fluid.dygraph.no_grad + + @fluid.no_grad() def test_layer(): - with fluid.dygraph.guard(): - inp = np.ones([3, 1024], dtype='float32') - t = fluid.dygraph.base.to_variable(inp) - linear1 = fluid.Linear(1024, 4, bias_attr=False) - linear2 = fluid.Linear(4, 4) - ret = linear1(t) - dy_ret = linear2(ret) + inp = np.ones([3, 1024], dtype='float32') + t = fluid.dygraph.base.to_variable(inp) + linear1 = fluid.Linear(1024, 4, bias_attr=False) + linear2 = fluid.Linear(4, 4) + ret = linear1(t) + dy_ret = linear2(ret) test_layer() diff --git a/doc/fluid/api_cn/executor_cn/Executor_cn.rst b/doc/fluid/api_cn/executor_cn/Executor_cn.rst index 7e98d3d4ec9f89208b3810823be4015c940f0fc0..273b6bc79031e78ee56f65b4f7dbf575748d6f6b 100644 --- a/doc/fluid/api_cn/executor_cn/Executor_cn.rst +++ b/doc/fluid/api_cn/executor_cn/Executor_cn.rst @@ -39,7 +39,7 @@ Executor支持单GPU、多GPU以及CPU运行。 train_program = fluid.Program() startup_program = fluid.Program() with fluid.program_guard(train_program, startup_program): - data = fluid.layers.data(name='X', shape=[1], dtype='float32') + data = fluid.data(name='X', shape=[None, 1], dtype='float32') hidden = fluid.layers.fc(input=data, size=10) loss = fluid.layers.mean(hidden) fluid.optimizer.SGD(learning_rate=0.01).minimize(loss) @@ -130,7 +130,7 @@ Executor支持单GPU、多GPU以及CPU运行。 place = fluid.CPUPlace() # fluid.CUDAPlace(0) exe = fluid.Executor(place) - data = fluid.layers.data(name='X', shape=[1], dtype='float32') + data = fluid.data(name='X', shape=[None, 1], dtype='float32') hidden = fluid.layers.fc(input=data, size=10) loss = fluid.layers.mean(hidden) adam = fluid.optimizer.Adam() @@ -175,8 +175,8 @@ train_from_dataset可以非常容易扩展到大规模分布式在线和离线 place = fluid.CPUPlace() # 通过设置place = fluid.CUDAPlace(0)使用GPU exe = fluid.Executor(place) - x = fluid.layers.data(name="x", shape=[10, 10], dtype="int64") - y = fluid.layers.data(name="y", shape=[1], dtype="int64", lod_level=1) + x = fluid.data(name="x", shape=[None, 10, 10], dtype="int64") + y = fluid.data(name="y", shape=[None, 1], dtype="int64", lod_level=1) dataset = fluid.DatasetFactory().create_dataset() dataset.set_use_var([x, y]) dataset.set_thread(1) @@ -210,12 +210,13 @@ train_from_dataset可以非常容易扩展到大规模分布式在线和离线 import paddle.fluid as fluid place = fluid.CPUPlace() # 使用GPU时可设置place = fluid.CUDAPlace(0) exe = fluid.Executor(place) - x = fluid.layers.data(name="x", shape=[10, 10], dtype="int64") - y = fluid.layers.data(name="y", shape=[1], dtype="int64", lod_level=1) + x = fluid.data(name="x", shape=[None, 10, 10], dtype="int64") + y = fluid.data(name="y", shape=[None, 1], dtype="int64", lod_level=1) dataset = fluid.DatasetFactory().create_dataset() dataset.set_use_var([x, y]) dataset.set_thread(1) filelist = [] # 您可以设置您自己的filelist,如filelist = ["dataA.txt"] dataset.set_filelist(filelist) exe.run(fluid.default_startup_program()) - exe.infer_from_dataset(program=fluid.default_main_program(),dataset=dataset) + exe.infer_from_dataset(program=fluid.default_main_program(), + dataset=dataset) diff --git a/doc/fluid/api_cn/index_cn.rst b/doc/fluid/api_cn/index_cn.rst index c45a09e4de6b9568dad91b5e3e10f5f0dbf87558..94e629783cd3595519c7c42188c97b81ac55c29d 100644 --- a/doc/fluid/api_cn/index_cn.rst +++ b/doc/fluid/api_cn/index_cn.rst @@ -107,3 +107,21 @@ Note。 io_cn.rst utils_cn.rst incubate_cn.rst + fluid_cn.rst + backward_cn.rst + clip_cn.rst + data_cn/data_reader_cn.rst + data_cn/dataset_cn.rst + dataset_cn.rst + dygraph_cn.rst + executor_cn.rst + initializer_cn.rst + io_cn.rst + layers_cn.rst + metrics_cn.rst + nets_cn.rst + optimizer_cn.rst + profiler_cn.rst + regularizer_cn.rst + transpiler_cn.rst + unique_name_cn.rst diff --git a/doc/fluid/api_cn/initializer_cn/MSRAInitializer_cn.rst b/doc/fluid/api_cn/initializer_cn/MSRAInitializer_cn.rst index b002b655a7ff6df93e50ad48963eac6fe7de1dfe..ac42f93ff6bf15bb95d7a1d6db68ba96705d8eca 100644 --- a/doc/fluid/api_cn/initializer_cn/MSRAInitializer_cn.rst +++ b/doc/fluid/api_cn/initializer_cn/MSRAInitializer_cn.rst @@ -11,7 +11,7 @@ MSRAInitializer 该接口实现MSRA方式的权重初始化(a.k.a. Kaiming初始化) 该接口为权重初始化函数,方法来自Kaiming He,Xiangyu Zhang,Shaoqing Ren 和 Jian Sun所写的论文: `Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification `_ 。这是一个鲁棒性特别强的初始化方法,并且适应了非线性激活函数(rectifier nonlinearities)。 -可以选择使用均匀分布或者正太分布初始化权重; +可以选择使用均匀分布或者正态分布初始化权重; 在均匀分布中,范围为[-x,x],其中: .. math:: diff --git a/doc/fluid/api_cn/layers_cn/concat_cn.rst b/doc/fluid/api_cn/layers_cn/concat_cn.rst index 31f6d2cb67cdc9c718102e31ba5154a66d61e7fb..46b1b3c3d6b17cdd9eebd5959372756499ede8ff 100644 --- a/doc/fluid/api_cn/layers_cn/concat_cn.rst +++ b/doc/fluid/api_cn/layers_cn/concat_cn.rst @@ -3,24 +3,24 @@ concat ------------------------------- -.. py:function:: paddle.fluid.layers.concat(input,axis=0,name=None) +.. py:function:: paddle.fluid.layers.concat(input, axis=0, name=None) -:alias_main: paddle.concat -:alias: paddle.concat,paddle.tensor.concat,paddle.tensor.manipulation.concat -:old_api: paddle.fluid.layers.concat - - -该OP对输入沿 ``axis`` 轴进行联结。 +该OP对输入沿 ``axis`` 轴进行联结,返回一个新的Tensor。 参数: - - **input** (list) - 输入是待联结的多维 ``Tensor`` 组成的 ``list`` ,支持的数据类型为:float32、float64、int32、int64。 - - **axis** (int|Variable,可选) - 整数或者形状为[1]的 ``Tensor``,数据类型为 ``int32``。指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 中 ``Tensor`` 的维度, ``axis`` 为负值时与 :math:`axis + R` 等价。默认值为0。 + - **input** (list|tuple|Tensor) - 待联结的Tensor list,Tensor tuple或者Tensor,支持的数据类型为:bool、float16、 float32、float64、int32、int64。 ``input`` 中所有Tensor的数据类型必须一致。 + - **axis** (int|Tensor,可选) - 指定对输入Tensor进行运算的轴,可以是整数或者形状为[1]的Tensor,数据类型为int32或者int64。 ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 中Tensor 的维度, ``axis`` 为负值时与 :math:`axis + R` 等价。默认值为0。 - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回:联结后的 ``Tensor`` ,数据类型和 ``input`` 相同。 +返回:联结后的 ``Tensor`` ,数据类型和 ``input`` 中的Tensor相同。 + -返回类型:Variable +抛出异常: + - ``TypeError``: - 当输入 ``input`` 的类型不是list、tuple或者Tensor的时候。 + - ``TypeError``: - 当输入 ``input`` 的数据类型不是 bool,float16, float32, float64, int32, int64时。 + - ``TypeError``: - 当 ``axis`` 的类型不是int或者Tensor时。当 ``axis`` 是Tensor的时候其数据类型不是int32或者int64时。 + - ``TypeError``: - 当输入 ``input`` 中的Tensor存在数据类型不一致时。 **代码示例**: @@ -29,18 +29,18 @@ concat import paddle.fluid as fluid import numpy as np - in1 = np.array([[1,2,3], - [4,5,6]]) - in2 = np.array([[11,12,13], - [14,15,16]]) - in3 = np.array([[21,22], - [23,24]]) + in1 = np.array([[1, 2, 3], + [4, 5, 6]]) + in2 = np.array([[11, 12, 13], + [14, 15, 16]]) + in3 = np.array([[21, 22], + [23, 24]]) with fluid.dygraph.guard(): x1 = fluid.dygraph.to_variable(in1) x2 = fluid.dygraph.to_variable(in2) x3 = fluid.dygraph.to_variable(in3) - out1 = fluid.layers.concat(input=[x1,x2,x3], axis=-1) - out2 = fluid.layers.concat(input=[x1,x2], axis=0) + out1 = fluid.layers.concat(input=[x1, x2, x3], axis=-1) + out2 = fluid.layers.concat(input=[x1, x2], axis=0) print(out1.numpy()) # [[ 1 2 3 11 12 13 21 22] # [ 4 5 6 14 15 16 23 24]] diff --git a/doc/fluid/api_cn/layers_cn/cumsum_cn.rst b/doc/fluid/api_cn/layers_cn/cumsum_cn.rst index fd9238e64bd85b90f4a54ced20b6dda1266b4e60..8e6f238b87381651e08b0a0dac4fa441b7605683 100644 --- a/doc/fluid/api_cn/layers_cn/cumsum_cn.rst +++ b/doc/fluid/api_cn/layers_cn/cumsum_cn.rst @@ -5,11 +5,6 @@ cumsum .. py:function:: paddle.fluid.layers.cumsum(x,axis=None,exclusive=None,reverse=None) -:alias_main: paddle.cumsum -:alias: paddle.cumsum,paddle.tensor.cumsum,paddle.tensor.math.cumsum -:old_api: paddle.fluid.layers.cumsum - - 沿给定轴(axis)的元素的累加和。默认结果的第一个元素和输入的第一个元素一致。如果exlusive为True,结果的第一个元素则为0。 diff --git a/doc/fluid/api_cn/layers_cn/equal_cn.rst b/doc/fluid/api_cn/layers_cn/equal_cn.rst index 14b36d0947ecf2ffb7d858db93175a80e93db7d8..9a66e76cedc7d3997fe8e6cbfefca91232f5734b 100644 --- a/doc/fluid/api_cn/layers_cn/equal_cn.rst +++ b/doc/fluid/api_cn/layers_cn/equal_cn.rst @@ -3,9 +3,7 @@ equal ------------------------------- -.. py:function:: paddle.fluid.layers.equal(x,y,cond=None) - - +.. py:function:: paddle.fluid.layers.equal(x, y, cond=None, name=None) 该OP返回 :math:`x==y` 逐元素比较x和y是否相等,x和y的维度应该相同。 @@ -13,7 +11,8 @@ equal 参数: - **x** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 - **y** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 - - **cond** (Variable,可选) - 逐元素比较的结果Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **cond** (Variable,可选) – 如果为None,则创建一个Tensor来作为进行比较的输出结果,该Tensor的shape和数据类型和输入x一致;如果不为None,则将Tensor作为该OP的输出,数据类型和数据shape需要和输入x一致。默认值为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 diff --git a/doc/fluid/api_cn/layers_cn/eye_cn.rst b/doc/fluid/api_cn/layers_cn/eye_cn.rst index 3d9909df3b7d47bfa7280f826286fbe162767048..b0fb8b5ecb68711e3d196c92beaa87f9bb6e10fc 100644 --- a/doc/fluid/api_cn/layers_cn/eye_cn.rst +++ b/doc/fluid/api_cn/layers_cn/eye_cn.rst @@ -3,25 +3,20 @@ eye ------------------------------- -.. py:function:: paddle.fluid.layers.eye(num_rows, num_columns=None, batch_shape=None, dtype='float32') +.. py:function:: paddle.fluid.layers.eye(num_rows, num_columns=None, batch_shape=None, dtype='float32', name=None) -:alias_main: paddle.eye -:alias: paddle.eye,paddle.tensor.eye,paddle.tensor.creation.eye -:update_api: paddle.fluid.layers.eye - - -该OP用来构建二维张量,或一个批次的二维张量。 +该OP用来构建二维Tensor,或一个批次的二维Tensor。 参数: - - **num_rows** (int) - 该批次二维张量的行数,数据类型为非负int32。 - - **num_columns** (int, 可选) - 该批次二维张量的列数,数据类型为非负int32。若为None,则默认等于num_rows。 - - **batch_shape** (list(int), 可选) - 如若提供,则返回向量的主批次维度将为batch_shape。 - - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) - 返回张量的数据类型,可为int32,int64,float16,float32,float64,默认数据类型为float32。 + - **num_rows** (int) - 该批次二维Tensor的行数,数据类型为非负int32。 + - **num_columns** (int, 可选) - 该批次二维Tensor的列数,数据类型为非负int32。若为None,则默认等于num_rows。 + - **batch_shape** (list(int), 可选) - 如若提供,则返回Tensor的主批次维度将为batch_shape。 + - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) - 返回Tensor的数据类型,可为int32,int64,float16,float32,float64,默认数据类型为float32。 + - **name** (str) – 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None。 -返回:shape为batch_shape + [num_rows, num_columns]的张量。 +返回: ``shape`` 为batch_shape + [num_rows, num_columns]的Tensor。 -返回类型:Variable(Tensor|LoDTensor)数据类型为int32,int64,float16,float32,float64的Tensor或者LoDTensor。 抛出异常: - ``TypeError``: - 如果 ``dtype`` 的类型不是float16, float32, float64, int32, int64其中之一。 diff --git a/doc/fluid/api_cn/layers_cn/fill_constant_cn.rst b/doc/fluid/api_cn/layers_cn/fill_constant_cn.rst index 5dd9044f1f746272a8a519b3869e9d1cdb6b535b..f7af206495c0640ef87b2806666fdf919015463e 100644 --- a/doc/fluid/api_cn/layers_cn/fill_constant_cn.rst +++ b/doc/fluid/api_cn/layers_cn/fill_constant_cn.rst @@ -44,6 +44,6 @@ fill_constant positive_2 = fluid.layers.fill_constant([1], "int32", 2) data3 = fluid.layers.fill_constant(shape=[1, positive_2], dtype='float32', value=1.5) # data3=[1.5, 1.5] - # attr shape is an Variable Tensor. + # attr shape is a Variable Tensor. shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2] data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]] diff --git a/doc/fluid/api_cn/layers_cn/greater_equal_cn.rst b/doc/fluid/api_cn/layers_cn/greater_equal_cn.rst index 607e3ab0b02b3b2bfbdb8e28744c3187f5fd3f00..7141718419cc55b0fdb4546dcd16bc89c92a2e35 100644 --- a/doc/fluid/api_cn/layers_cn/greater_equal_cn.rst +++ b/doc/fluid/api_cn/layers_cn/greater_equal_cn.rst @@ -3,7 +3,7 @@ greater_equal ------------------------------- -.. py:function:: paddle.fluid.layers.greater_equal(x, y, cond=None) +.. py:function:: paddle.fluid.layers.greater_equal(x, y, cond=None, name=None) :alias_main: paddle.greater_equal :alias: paddle.greater_equal,paddle.tensor.greater_equal,paddle.tensor.logic.greater_equal @@ -18,6 +18,7 @@ greater_equal - **x** (Variable) – 进行比较的第一个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **y** (Variable) – 进行比较的第二个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **cond** (Variable,可选) – 如果为None,则创建一个Tensor来作为进行比较的输出结果,该Tensor的shape,数据类型和输入x一致;如果不为None,则将Tensor作为该OP的输出,数据shape和数据类型需要和输入x一致。默认值为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的Tensor,数据的shape和输入x一致。 diff --git a/doc/fluid/api_cn/layers_cn/greater_than_cn.rst b/doc/fluid/api_cn/layers_cn/greater_than_cn.rst index 29bb93d9284cf69796c51a9ac05b05ba440a1592..3f208e21ad5433125b3c22fa76ee06968a7c8153 100644 --- a/doc/fluid/api_cn/layers_cn/greater_than_cn.rst +++ b/doc/fluid/api_cn/layers_cn/greater_than_cn.rst @@ -3,7 +3,7 @@ greater_than ------------------------------- -.. py:function:: paddle.fluid.layers.greater_than(x, y, cond=None) +.. py:function:: paddle.fluid.layers.greater_than(x, y, cond=None, name=None) :alias_main: paddle.greater_than :alias: paddle.greater_than,paddle.tensor.greater_than,paddle.tensor.logic.greater_than @@ -17,6 +17,7 @@ greater_than - **x** (Variable) – 进行比较的第一个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **y** (Variable) – 进行比较的第二个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **cond** (Variable,可选) – 如果为None,则创建一个Tensor来作为进行比较的输出结果,该Tensor的shape和数据类型和输入x一致;如果不为None,则将Tensor作为该OP的输出,数据类型和数据shape需要和输入x一致。默认值为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的Tensor,数据的shape和输入x一致。 diff --git a/doc/fluid/api_cn/layers_cn/less_equal_cn.rst b/doc/fluid/api_cn/layers_cn/less_equal_cn.rst index 88add2c7fb86d395727ffbe16a97fd01dd31d33a..da8b1b83343ec06b21738177555c79855efbdb2f 100644 --- a/doc/fluid/api_cn/layers_cn/less_equal_cn.rst +++ b/doc/fluid/api_cn/layers_cn/less_equal_cn.rst @@ -3,7 +3,7 @@ less_equal ------------------------------- -.. py:function:: paddle.fluid.layers.less_equal(x, y, cond=None) +.. py:function:: paddle.fluid.layers.less_equal(x, y, cond=None, name=None) :alias_main: paddle.less_equal :alias: paddle.less_equal,paddle.tensor.less_equal,paddle.tensor.logic.less_equal @@ -17,6 +17,7 @@ less_equal - **x** (Variable) – 进行比较的第一个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **y** (Variable) – 进行比较的第二个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **cond** (Variable,可选) – 如果为None,则创建一个Tensor来作为进行比较的输出结果,该Tensor的shape和数据类型和输入x一致;如果不为None,则将Tensor作为该OP的输出,数据类型和数据shape需要和输入x一致。默认值为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的Tensor,数据的shape和输入x一致。 diff --git a/doc/fluid/api_cn/layers_cn/less_than_cn.rst b/doc/fluid/api_cn/layers_cn/less_than_cn.rst index be39cae55422cb9beb27c040c41704696b01ccdd..6ad37577315a293779e5b1da1a9e449179c9b52f 100644 --- a/doc/fluid/api_cn/layers_cn/less_than_cn.rst +++ b/doc/fluid/api_cn/layers_cn/less_than_cn.rst @@ -3,7 +3,7 @@ less_than ------------------------------- -.. py:function:: paddle.fluid.layers.less_than(x, y, force_cpu=None, cond=None) +.. py:function:: paddle.fluid.layers.less_than(x, y, force_cpu=None, cond=None, name=None) :alias_main: paddle.less_than :alias: paddle.less_than,paddle.tensor.less_than,paddle.tensor.logic.less_than @@ -20,6 +20,7 @@ less_than - **y** (Variable) - 进行比较的第二个输入,是一个多维的LoDTensor/Tensor,数据类型可以是float32,float64,int32,int64。 - **force_cpu** (bool) – 如果为True则强制将输出变量写入CPU内存中,否则将其写入目前所在的运算设备上。默认值为False。注意:该属性已弃用,其值始终是False。 - **cond** (Variable,可选) – 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的LoDTensor/Tensor,数据的shape和输入x一致。 diff --git a/doc/fluid/api_cn/layers_cn/linspace_cn.rst b/doc/fluid/api_cn/layers_cn/linspace_cn.rst index 9105b2ae95c5f0df7184edc377ceee6087ed576a..ca9775016b06c55b7504d31d913aeaad1df76466 100644 --- a/doc/fluid/api_cn/layers_cn/linspace_cn.rst +++ b/doc/fluid/api_cn/layers_cn/linspace_cn.rst @@ -3,22 +3,27 @@ linspace ------------------------------- -.. py:function:: paddle.fluid.layers.linspace(start, stop, num, dtype) +.. py:function:: paddle.fluid.layers.linspace(start, stop, num, dtype=None, name=None) -该OP在给定区间内返回固定数目的均匀间隔的值。 +该OP返回一个Tensor,Tensor的值为在区间start和stop上均匀间隔的num个值,输出Tensor的长度为num。 +**注意:该OP不进行梯度计算** 参数: - - **start** (float|Variable) – start是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **stop** (float|Variable) – end是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **num** (int|Variable) – num是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 - - **dtype** (string) – 输出Tensor的数据类型,可以是‘float32’或者是‘float64’。 + - **start** (float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **stop** (float|Tensor) – ``end`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **num** (int|Tensor) – ``num`` 是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 + - **dtype** (string, 可选) – 输出Tensor的数据类型,可以是float32或者是float64,如果dtype的数据类型为None,输出Tensor数据类型为float32。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。 -返回类型:Variable +抛出异常: + - ``TypeError`` - 当start或者stop的数据类型不是float32或者float64。 + - ``TypeError`` - 当num的数据类型不是float32或者float64。 + - ``TypeError`` - 当dtype的类型不是float32或者float64。 **代码示例**: diff --git a/doc/fluid/api_cn/layers_cn/not_equal_cn.rst b/doc/fluid/api_cn/layers_cn/not_equal_cn.rst index 9ec0336e9eb3ad320bfb7c842fa96bb7e651e47f..5a9cedf60cc03d67d8571424cffc2af62a583184 100644 --- a/doc/fluid/api_cn/layers_cn/not_equal_cn.rst +++ b/doc/fluid/api_cn/layers_cn/not_equal_cn.rst @@ -3,7 +3,7 @@ not_equal ------------------------------- -.. py:function:: paddle.fluid.layers.not_equal(x, y, cond=None) +.. py:function:: paddle.fluid.layers.not_equal(x, y, cond=None, name=None) :alias_main: paddle.not_equal :alias: paddle.not_equal,paddle.tensor.not_equal,paddle.tensor.logic.not_equal @@ -17,7 +17,7 @@ not_equal - **x** (Variable) – 进行比较的第一个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **y** (Variable) – 进行比较的第二个输入,是一个多维的Tensor,数据类型可以是float32,float64,int32,int64。 - **cond** (Variable,可选) – 如果为None,则创建一个Tensor来作为进行比较的输出结果,该Tensor的shape和数据类型和输入x一致;如果不为None,则将Tensor作为该OP的输出,数据类型和数据shape需要和输入x一致。默认值为None。 - + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的Tensor,数据的shape和输入x一致。 返回类型:变量(Variable),数据类型为bool类型。 diff --git a/doc/fluid/api_cn/layers_cn/ones_cn.rst b/doc/fluid/api_cn/layers_cn/ones_cn.rst index bc4b9fcc32637eba0d1e842f1f7fa593c3d23620..647b8d8c7caa1896a4a958712af7df325b986718 100644 --- a/doc/fluid/api_cn/layers_cn/ones_cn.rst +++ b/doc/fluid/api_cn/layers_cn/ones_cn.rst @@ -5,21 +5,18 @@ ones .. py:function:: paddle.fluid.layers.ones(shape,dtype,force_cpu=False) - - - -**ones** - -该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor,该OP会将stop_gradient设置为True,即停止梯度更新。 +该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor。 参数: - - **shape** (tuple|list) - 输出Tensor的形状。 - - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。 - - **force_cpu** (bool) – 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 + - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 + - **force_cpu** (bool, 可选) – 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。 -返回类型:Variable +抛出异常: + - ``TypeError`` - 当 ``dtype`` 不是bool、 float16、float32、float64、int32、int64和None时。 + - ``TypeError`` - 当 ``shape`` 不是tuple、list、或者Tensor时, 当 ``shape`` 为Tensor,其数据类型不是int32或者int64时。 **代码示例**: diff --git a/doc/fluid/api_cn/layers_cn/softmax_cn.rst b/doc/fluid/api_cn/layers_cn/softmax_cn.rst index a11f955072ab19183abde10ce55469e81bc1c696..21052f227cd42db24536fd67b97c77cb6bdc5057 100755 --- a/doc/fluid/api_cn/layers_cn/softmax_cn.rst +++ b/doc/fluid/api_cn/layers_cn/softmax_cn.rst @@ -5,12 +5,6 @@ softmax .. py:function:: paddle.fluid.layers.softmax(input, use_cudnn=False, name=None, axis=-1) -:alias_main: paddle.nn.functional.softmax -:alias: paddle.nn.functional.softmax,paddle.nn.functional.activation.softmax -:old_api: paddle.fluid.layers.softmax - - - 该OP实现了softmax层。OP的计算过程如下: 步骤1:输入 ``input`` 的 ``axis`` 维会被置换到最后一维; diff --git a/doc/fluid/api_cn/layers_cn/split_cn.rst b/doc/fluid/api_cn/layers_cn/split_cn.rst index c05da2a5cae6586df69edcb14e49889299270400..ca1607ee55c07488cd3a343ec72bf5c216ae2614 100644 --- a/doc/fluid/api_cn/layers_cn/split_cn.rst +++ b/doc/fluid/api_cn/layers_cn/split_cn.rst @@ -3,7 +3,7 @@ split ------------------------------- -.. py:function:: paddle.fluid.layers.split(input,num_or_sections,dim=-1,name=None) +.. py:function:: paddle.fluid.layers.split(input, num_or_sections, dim=-1, name=None) @@ -11,18 +11,18 @@ split 该OP将输入Tensor分割成多个子Tensor。 参数: - - **input** (Variable) - 输入变量,数据类型为float32,float64,int32,int64的多维Tensor或者LoDTensor。 + - **input** (Tensor) - 输入变量,数据类型为bool, float16,float32,float64,int32,int64的多维Tensor。 - **num_or_sections** (int|list|tuple) - 如果 ``num_or_sections`` 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。如果 ``num_or_sections`` 是一个list或tuple,那么它的长度代表子Tensor的数量,它的元素可以是整数或者形状为[1]的Tensor,依次代表子Tensor需要分割成的维度的大小。list或tuple的长度不能超过输入Tensor待分割的维度的大小。至多有一个元素值为-1,-1表示该值是由 ``input`` 待分割的维度值和 ``num_or_sections`` 的剩余元素推断出来的。 - - **dim** (int|Variable,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果dim < 0,则划分的维度为rank(input) + dim。默认值为-1。 + - **dim** (int|Tenspr,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果 ``dim < 0`` ,则划分的维度为 ``rank(input) + dim`` 。默认值为-1。 - **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:分割后的Tensor列表。 -返回类型:列表(Variable(Tensor|LoDTensor)),数据类型为int32,int64,float32,float64。 抛出异常: - - :code:`TypeError`:``num_or_sections`` 不是int、list 或 tuple。 - - :code:`TypeError`:``dim`` 不是 int 或 Variable。 + - :code:`TypeError`:``input`` 的数据类型不是bool、float16、float32、float64、int32或int64时 。 + - :code:`TypeError`:``num_or_sections`` 不是int、list 或 tuple时。 + - :code:`TypeError`:``dim`` 不是 int 或 Tensor时。当 ``dim`` 为Tensor,其数据类型不是int32或int64时。 **代码示例**: @@ -30,27 +30,31 @@ split import paddle.fluid as fluid - # 输入是维度为[3, 9, 5]的Tensor: + # input is a Tensor which shape is [3, 9, 5] input = fluid.data( name="input", shape=[3, 9, 5], dtype="float32") - # 传入num_or_sections为一个整数 - x0, x1, x2 = fluid.layers.split(input, num_or_sections=3, dim=1) - x0.shape # [3, 3, 5] - x1.shape # [3, 3, 5] - x2.shape # [3, 3, 5] - - # 传入num_or_sections为一个整数列表 - x0, x1, x2 = fluid.layers.split(input, num_or_sections=[2, 3, 4], dim=1) - x0.shape # [3, 2, 5] - x1.shape # [3, 3, 5] - x2.shape # [3, 4, 5] - - # 传入num_or_sections为一个整数列表,其中有一个元素为-1 - x0, x1, x2 = fluid.layers.split(input, num_or_sections=[2, 3, -1], dim=1) - x0.shape # [3, 2, 5] - x1.shape # [3, 3, 5] - x2.shape # [3, 4, 5] + out0, out1, out2 = fluid.layers.split(input, num_or_sections=3, dim=1) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 3, 5] + + out0, out1, out2 = fluid.layers.split(input, num_or_sections=[2, 3, 4], dim=1) + # out0.shape [3, 2, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 4, 5] + + out0, out1, out2 = fluid.layers.split(input, num_or_sections=[2, 3, -1], dim=1) + # out0.shape [3, 2, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 4, 5] + + # dim is negative, the real dim is (rank(input) + axis) which real + # value is 1. + out0, out1, out2 = fluid.layers.split(input, num_or_sections=3, dim=-2) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 3, 5] diff --git a/doc/fluid/api_cn/layers_cn/unstack_cn.rst b/doc/fluid/api_cn/layers_cn/unstack_cn.rst index cc4324c6b5764b7a03cfe509345e14aa43e505ee..00b8cfe97a1409bc9b845690ba7ec3dd29a77c86 100644 --- a/doc/fluid/api_cn/layers_cn/unstack_cn.rst +++ b/doc/fluid/api_cn/layers_cn/unstack_cn.rst @@ -14,7 +14,7 @@ unstack 该OP将单个dim为 ``D`` 的Tensor沿 ``axis`` 轴unpack为 ``num`` 个dim为 ``(D-1)`` 的Tensor 参数: - - **x** (Variable) – 输入x为 ``dim > 0`` 的Tensor, + - **x** (Tensor) – 输入x为 ``dim > 0`` 的Tensor, 支持的数据类型: float32,float64,int32,int64。 - **axis** (int | 可选) – 输入Tensor进行unpack运算所在的轴,axis的范围为:``[-D, D)`` , @@ -24,7 +24,7 @@ unstack 返回: 长度为num的Tensor列表, 数据类型与输入Tensor相同,dim为 ``(D-1)``。 -返回类型: list(Variable) +返回类型: list(Tensor) 抛出异常: - :code:`ValueError`:``x.shape[axis]`` <= 0 或 ``axis`` 不在[-D, D)范围内 @@ -34,7 +34,7 @@ unstack .. code-block:: python import paddle.fluid as fluid - x = fluid.layers.data(name='x', shape=[2, 3, 5], dtype='float32') #创建一个shape=[2, 3, 5]的Tensor + x = fluid.data(name='x', shape=[2, 3, 5], dtype='float32') #创建一个shape=[2, 3, 5]的Tensor y = fluid.layers.unstack(x, axis=1) #沿着第1轴进行unpack, unpack后为3个shape=[2,5]的Tensor diff --git a/doc/fluid/api_cn/layers_cn/zeros_cn.rst b/doc/fluid/api_cn/layers_cn/zeros_cn.rst index a3c7d2929b66ee6a9e83193c54dd2068595dcef2..7e9973e1080d68abd2d9d2a0ccbe1e8733b02a98 100644 --- a/doc/fluid/api_cn/layers_cn/zeros_cn.rst +++ b/doc/fluid/api_cn/layers_cn/zeros_cn.rst @@ -5,21 +5,18 @@ zeros .. py:function:: paddle.fluid.layers.zeros(shape,dtype,force_cpu=False) - - - -**zeros** - -该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为0的Tensor,该OP会将stop_gradient设置为True,即停止梯度更新。 +该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为0的Tensor。 参数: - - **shape** (tuple|list) - 输出Tensor的形状。 - - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。 - - **force_cpu** (bool) - 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 + - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。 + - **force_cpu** (bool, 可选) - 是否强制将输出Tensor写入CPU内存。如果 ``force_cpu`` 为False,则将输出Tensor写入当前所在运算设备的内存,默认为False。 返回:值全为0的Tensor,数据类型和 ``dtype`` 定义的类型一致。 -返回类型:Variable +抛出异常: + - ``TypeError`` - 当 ``dtype`` 不是bool、 float16、float32、float64、int32、int64。 + - ``TypeError`` - 当 ``shape`` 不是tuple、list、或者Tensor时。 当 ``shape`` 为Tensor,其数据类型不是int32或者int64时。 **代码示例**: diff --git a/doc/fluid/api_cn/nn_cn.rst b/doc/fluid/api_cn/nn_cn.rst index fd6aa4c90670eafa3a35c3a3705d9d5f59ae6507..b42ec565b8cdb613db774a5630cfa6e7575d850e 100644 --- a/doc/fluid/api_cn/nn_cn.rst +++ b/doc/fluid/api_cn/nn_cn.rst @@ -18,6 +18,7 @@ paddle.nn nn_cn/Upsample_cn.rst nn_cn/activation_cn.rst nn_cn/loss_cn.rst + nn_cn/functional_cn.rst nn_cn/adaptive_pool2d_cn.rst nn_cn/adaptive_pool3d_cn.rst nn_cn/add_position_encoding_cn.rst @@ -94,7 +95,7 @@ paddle.nn nn_cn/logsigmoid_cn.rst nn_cn/log_loss_cn.rst nn_cn/lrn_cn.rst - nn_cn/margin_rank_loss_cn.rst + nn_cn/margin_ranking_loss_cn.rst nn_cn/maxout_cn.rst nn_cn/mse_loss_cn.rst nn_cn/multiclass_nms_cn.rst @@ -105,6 +106,7 @@ paddle.nn nn_cn/pad2d_cn.rst nn_cn/pad_cn.rst nn_cn/pad_constant_like_cn.rst + nn_cn/PairwiseDistance_cn.rst nn_cn/ParameterList_cn.rst nn_cn/piecewise_decay_cn.rst nn_cn/pixel_shuffle_cn.rst @@ -160,3 +162,6 @@ paddle.nn nn_cn/while_loop_cn.rst nn_cn/yolov3_loss_cn.rst nn_cn/yolo_box_cn.rst + nn_cn/loss_cn/MarginRankingLoss_cn.rst + nn_cn/functional_cn/margin_ranking_loss_cn.rst + diff --git a/doc/fluid/api_cn/nn_cn/PairwiseDistance_cn.rst b/doc/fluid/api_cn/nn_cn/PairwiseDistance_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..94e1d04bbe23d9c5e49277902c9fd206a6e02c12 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/PairwiseDistance_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_nn_PairwiseDistance: + +PairwiseDistance +------------------------------- + +.. py:class:: paddle.nn.PairwiseDistance(p=2., epsilon=1e-6, keepdim=False, name=None) + +该OP计算两个向量(输入 ``x``、``y`` )之间pairwise的距离。该距离通过p范数计算: + + .. math:: + + \Vert x \Vert _p = \left( \sum_{i=1}^n \vert x_i \vert ^ p \right ) ^ {1/p}. + +参数 +:::::::: + - **p** (float,可选)- 指定p阶的范数。默认值为2。 + - **epsilon** (float,可选)- 添加到分母的一个很小值,避免发生除零错误。默认值为1e-6。 + - **keepdim** (bool,可选)- 是否保留输出张量减少的维度。输出结果相对于 ``|x-y|`` 的结果减少一维,除非 :attr:`keepdim` 为True,默认值为False。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +:::::::: + - **x** (Tensor) - :math:`(N, D)` ,其中D是向量的维度,数据类型为float32或float64。 + - **y** (Tensor) - :math:`(N, D)` ,与 ``x`` 的形状、数据类型相同。 + - **output** (Tensor) - :math:`(N)` ,如果 :attr:`keepdim` 为True,则形状为 :math:`(N, 1)` 。数据类型与 ``x``、 ``y`` 相同。 + +代码示例 +:::::::: + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + x_np = np.array([[1., 3.], [3., 5.]]).astype(np.float64) + y_np = np.array([[5., 6.], [7., 8.]]).astype(np.float64) + x = paddle.to_variable(x_np) + y = paddle.to_variable(y_np) + dist = paddle.nn.PairwiseDistance() + distance = dist(x, y) + print(distance.numpy()) # [5. 5.] + diff --git a/doc/fluid/api_cn/nn_cn/activation_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn.rst index 9bd3fa86689a40936ccccd5acae95a6ab433c2cd..79d1258944cf3cc467ec059b87a5ffeaea6ba678 100644 --- a/doc/fluid/api_cn/nn_cn/activation_cn.rst +++ b/doc/fluid/api_cn/nn_cn/activation_cn.rst @@ -8,4 +8,5 @@ activation .. toctree:: :maxdepth: 1 + activation_cn/LeakyReLU_cn.rst activation_cn/Sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..9b9c61818c72a4a8aefcaa356ffd0b0fbf4d81df --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/LeakyReLU_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_nn_LeakyReLU: + +LeakyReLU +------------------------------- +.. py:class:: paddle.nn.LeakyReLU(alpha=0.01, name=None) + +ReLU (Rectified Linear Unit)激活层 + +.. math:: + + \\Out = max(x, alpha*x)\\ + +其中,:math:`x` 为输入的 Tensor + +参数 +:::::::::: + - alpha (float,可选) - :math:`x < 0` 时的斜率。默认值为0.01。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状: + - input: 任意形状的Tensor。 + - output: 和input具有相同形状的Tensor。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + lrelu = paddle.nn.LeakyReLU() + x = paddle.imperative.to_variable(np.array([-2, 0, 1], 'float32')) + out = lrelu(x) # [-0.02, 0, 1] diff --git a/doc/fluid/api_cn/nn_cn/functional_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b314bbe0ef25f09151745db0d91bdc8404eb540f --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn.rst @@ -0,0 +1,13 @@ +======================= +functional +======================= + + + + +.. toctree:: + :maxdepth: 1 + + functional_cn/l1_loss_cn.rst + functional_cn/nll_loss_cn.rst + functional_cn/margin_ranking_loss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/l1_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/l1_loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d7bf747f4d1720f65bfbab23738cc0ddc2389b3f --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/l1_loss_cn.rst @@ -0,0 +1,63 @@ +l1_loss +------------------------------- + +.. py:function:: paddle.nn.functional.l1_loss(x, label, reduction='mean', name=None) + +该接口计算输入 ``x`` 和标签 ``label`` 间的 `L1 loss` 损失。 + +该损失函数的数学计算公式如下: + +当 `reduction` 设置为 ``'none'`` 时, + + .. math:: + Out = \lvert x - label\rvert + +当 `reduction` 设置为 ``'mean'`` 时, + + .. math:: + Out = MEAN(\lvert x - label\rvert) + +当 `reduction` 设置为 ``'sum'`` 时, + + .. math:: + Out = SUM(\lvert x - label\rvert) + + +参数 +::::::::: + - **x** (Tensor): - 输入的Tensor,维度是[N, *], 其中N是batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64、int32、int64。 + - **label** (Tensor): - 标签,维度是[N, *], 与 ``x`` 相同。数据类型为:float32、float64、int32、int64。 + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回 `L1Loss`。 + - **name** (str,可选): - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +::::::::: +``Tensor``, 输入 ``x`` 和标签 ``label`` 间的 `L1 loss` 损失。如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入 ``x`` 相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。 + + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + x_data = np.array([[1.5, 0.8], [0.2, 1.3]]).astype("float32") + label_data = np.array([[1.7, 1], [0.4, 0.5]]).astype("float32") + x = paddle.to_variable(x_data) + label = paddle.to_variable(label_data) + + l1_loss = paddle.nn.functional.l1_loss(x, label) + print(l1_loss.numpy()) + # [0.35] + + l1_loss = paddle.nn.functional.l1_loss(x, label, reduction='none') + print(l1_loss.numpy()) + # [[0.20000005 0.19999999] + # [0.2 0.79999995]] + + l1_loss = paddle.nn.functional.l1_loss(x, label, reduction='sum') + print(l1_loss.numpy()) + # [1.4] diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/margin_ranking_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/margin_ranking_loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..edc1d7c7d1ffe659255e1f92a6a43e0d78af1bcf --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/margin_ranking_loss_cn.rst @@ -0,0 +1,52 @@ +.. _cn_api_nn_cn_margin_ranking_loss: + +margin_ranking_loss +------------------------------- + +.. py:function:: paddle.nn.functional.margin_ranking_loss(input, other, label, margin=0.0, reduction='mean', name=None) + +该算子计算输入input,other 和 标签label间的 `margin rank loss` 损失。该损失函数的数学计算公式如下: + + .. math:: + margin\_rank\_loss = max(0, -label * (input - other) + margin) + +当 `reduction` 设置为 ``'mean'`` 时, + + .. math:: + Out = MEAN(margin\_rank\_loss) + +当 `reduction` 设置为 ``'sum'`` 时, + + .. math:: + Out = SUM(margin\_rank\_loss) + +当 `reduction` 设置为 ``'none'`` 时,直接返回最原始的 `margin_rank_loss` 。 + +参数 +:::::::: + - **input** (Tensor):第一个输入的 `Tensor` ,数据类型为:float32、float64。 + - **other** (Tensor):第二个输入的 `Tensor` ,数据类型为:float32、float64。 + - **label** (Tensor):训练数据的标签,数据类型为:float32, float64。 + - **margin** (float,可选): - 用于加和的margin值,默认值为0。 + - **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'`` 、 ``'mean'`` 、 ``'sum'`` 。如果设置为 ``'none'`` ,则直接返回 最原始的 ``margin_rank_loss`` 。如果设置为 ``'sum'`` ,则返回 ``margin_rank_loss`` 的总和。如果设置为 ``'mean'`` ,则返回 ``margin_rank_loss`` 的平均值。默认值为 ``'none'`` 。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::: +Tensor, 如果 :attr:`reduction` 为 ``'sum'`` 或者是 ``'mean'`` ,则形状为 :math:`[1]` ,否则shape和输入 `input` 保持一致 。数据类型与 ``input``、 ``other`` 相同。 + +代码示例 +:::::::: + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + + input = paddle.to_variable(np.array([[1, 2], [3, 4]]).astype('float32')) + other = paddle.to_variable(np.array([[2, 1], [2, 4]]).astype('float32')) + label = paddle.to_variable(np.array([[1, -1], [-1, -1]]).astype('float32')) + loss = paddle.nn.functional.margin_ranking_loss(input, other, label) + print(loss.numpy()) # [0.75] diff --git a/doc/fluid/api_cn/nn_cn/functional_cn/nll_loss_cn.rst b/doc/fluid/api_cn/nn_cn/functional_cn/nll_loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..59a1c6355e304b7ac6d9dca44031408bda008f78 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/functional_cn/nll_loss_cn.rst @@ -0,0 +1,45 @@ +.. _cn_api_nn_functional_nll_loss: + +nll_loss +------------------------------- +.. py:function:: paddle.nn.functional.nll_loss(input, label, weight=None, ignore_index=-100, reduction='mean', name=None) + +该接口返回 `negative log likelihood` 。可在 :ref:`cn_api_nn_loss_NLLLoss` 查看详情。 + +参数 +::::::::: + - **input** (Tensor): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。 + - **label** (Tensor): - 输入x对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。 + - **weight** (Tensor, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。 + - **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。 + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。 + - **name** (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +`Tensor` ,返回存储表示 `negative log likelihood loss` 的损失值。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + from paddle.nn.functional import nll_loss + log_softmax = paddle.nn.LogSoftmax(axis=1) + + input_np = np.array([[0.88103855, 0.9908683 , 0.6226845 ], + [0.53331435, 0.07999352, 0.8549948 ], + [0.25879037, 0.39530203, 0.698465 ], + [0.73427284, 0.63575995, 0.18827209], + [0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32) + label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64) + + place = paddle.CPUPlace() + paddle.disable_static(place) + input = paddle.to_variable(input_np) + log_out = log_softmax(input) + label = paddle.to_variable(label_np) + result = nll_loss(log_out, label) + print(result.numpy()) # [1.0720209] diff --git a/doc/fluid/api_cn/nn_cn/loss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn.rst index 3c4c2c33fbb37343f91713b25bba8af86f8943a5..c463d12c463c9a0b686687a3cf09f4b66b44759a 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn.rst @@ -11,5 +11,6 @@ loss loss_cn/BCELoss_cn.rst loss_cn/CrossEntropyLoss_cn.rst loss_cn/L1Loss_cn.rst + loss_cn/MarginRankingLoss_cn.rst loss_cn/MSELoss_cn.rst loss_cn/NLLLoss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst index c2cc4e38e6ffbb6322dce8ca29656b49cd12705a..71f366e326e910ee35528ee4c299cc2175a8e329 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst @@ -1,67 +1,66 @@ L1Loss ------------------------------- -.. py:function:: paddle.nn.loss.L1Loss(reduction='mean') +.. py:class:: paddle.nn.loss.L1Loss(reduction='mean', name=None) -该接口用于创建一个L1Loss的可调用类,L1Loss计算输入input和标签label间的 `L1 loss` 损失。 +该接口用于创建一个L1Loss的可调用类,L1Loss计算输入x和标签label间的 `L1 loss` 损失。 该损失函数的数学计算公式如下: 当 `reduction` 设置为 ``'none'`` 时, .. math:: - Out = |input - label| + Out = \lvert x - label\rvert 当 `reduction` 设置为 ``'mean'`` 时, .. math:: - Out = MEAN(|input - label|) + Out = MEAN(\lvert x - label\rvert) 当 `reduction` 设置为 ``'sum'`` 时, .. math:: - Out = SUM(|input - label|) + Out = SUM(\lvert x - label\rvert) -输入input和标签label的维度是[N, *], 其中N是batch_size, `*` 是任意其他维度。 -如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入input相同。 -如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。 -参数: - - **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回L1Loss。数据类型为string。 +参数 +::::::::: + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回 `L1Loss`。 + - **name** (str,可选): - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 -返回:返回计算L1Loss的可调用对象。 +形状 +::::::::: + - **x** (Tensor): - 输入的Tensor,维度是[N, *], 其中N是batch size, `*` 是任意数量的额外维度。数据类型为:float32、float64、int32、int64。 + - **label** (Tensor): - 标签,维度是[N, *], 与 ``x`` 相同。数据类型为:float32、float64、int32、int64。 + - **output** (Tensor): - 输入 ``x`` 和标签 ``label`` 间的 `L1 loss` 损失。如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入 ``x`` 相同。如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。 -**代码示例** +代码示例 +::::::::: .. code-block:: python - # declarative mode - import paddle.fluid as fluid - import numpy as np import paddle - input = fluid.data(name="input", shape=[1]) - label = fluid.data(name="label", shape=[1]) - l1_loss = paddle.nn.loss.L1Loss(reduction='mean') - output = l1_loss(input,label) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) - - input_data = np.array([1.5]).astype("float32") - label_data = np.array([1.7]).astype("float32") - output_data = exe.run(fluid.default_main_program(), - feed={"input":input_data, "label":label_data}, - fetch_list=[output], - return_numpy=True) - - print(output_data) # [array([0.2], dtype=float32)] - - # imperative mode - import paddle.fluid.dygraph as dg - with dg.guard(place) as g: - input = dg.to_variable(input_data) - label = dg.to_variable(label_data) - l1_loss = paddle.nn.loss.L1Loss(reduction='mean') - output = l1_loss(input,label) - print(output.numpy()) # [0.2] + import numpy as np + + paddle.disable_static() + x_data = np.array([[1.5, 0.8], [0.2, 1.3]]).astype("float32") + label_data = np.array([[1.7, 1], [0.4, 0.5]]).astype("float32") + x = paddle.to_variable(x_data) + label = paddle.to_variable(label_data) + + l1_loss = paddle.nn.loss.L1Loss() + output = l1_loss(x, label) + print(output.numpy()) + # [0.35] + + l1_loss = paddle.nn.loss.L1Loss(reduction='sum') + output = l1_loss(x, label) + print(output.numpy()) + # [1.4] + + l1_loss = paddle.nn.loss.L1Loss(reduction='none') + output = l1_loss(x, label) + print(output.numpy()) + # [[0.20000005 0.19999999] + # [0.2 0.79999995]] diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst index 4dfa7bfba423c2a12005da89c07fe562442b6a5a..3ddeca33f5034d569fdf9362ceb83e05f1b35943 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst @@ -1,7 +1,7 @@ MSELoss ------------------------------- -.. py:function:: paddle.nn.loss.MSELoss(input,label) +.. py:function:: paddle.nn.loss.MSELoss(reduction='mean') 该OP用于计算预测值和目标值的均方差误差。 @@ -23,13 +23,15 @@ MSELoss Out = \operatorname{sum}((input - label)^2) 参数: - - **input** (Variable) - 预测值,维度为 :math:`[N_1, N_2, ..., N_k, D]` 的多维Tensor,其中最后一维D是类别数目。数据类型为float32或float64。 - - **label** (Variable) - 目标值,维度为 :math:`[N_1, N_2, ..., N_k, D]` 的多维Tensor,其中最后一维D是类别数目。数据类型为float32或float64。 - **reduction** (str, 可选) - 约简方式,可以是 'none' | 'mean' | 'sum'。设为'none'时不使用约简,设为'mean'时返回loss的均值,设为'sum'时返回loss的和。 -返回:预测值和目标值的均方差 +形状: + - **input** (Tensor) - 预测值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。 + - **label** (Tensor) - 目标值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。 + + +返回:变量(Tensor), 预测值和目标值的均方差, 数值类型与输入相同 -返回类型:变量(Variable) **代码示例**: @@ -37,32 +39,32 @@ MSELoss import numpy as np import paddle - from paddle import fluid - import paddle.fluid.dygraph as dg + + # static graph mode + paddle.enable_static() mse_loss = paddle.nn.loss.MSELoss() - input = fluid.data(name="input", shape=[1]) - label = fluid.data(name="label", shape=[1]) - place = fluid.CPUPlace() + input = paddle.data(name="input", shape=[1]) + label = paddle.data(name="label", shape=[1]) + place = paddle.CPUPlace() input_data = np.array([1.5]).astype("float32") label_data = np.array([1.7]).astype("float32") - # declarative mode output = mse_loss(input,label) - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) output_data = exe.run( - fluid.default_main_program(), + paddle.static.default_main_program(), feed={"input":input_data, "label":label_data}, fetch_list=[output], return_numpy=True) print(output_data) # [array([0.04000002], dtype=float32)] - # imperative mode - with dg.guard(place) as g: - input = dg.to_variable(input_data) - label = dg.to_variable(label_data) - output = mse_loss(input, label) - print(output.numpy()) - # [0.04000002] + # dynamic graph mode + paddle.disable_static() + input = paddle.to_variable(input_data) + label = paddle.to_variable(label_data) + output = mse_loss(input, label) + print(output.numpy()) + # [0.04000002] diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/MarginRankingLoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/MarginRankingLoss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ab7cd2175d25e3f3e724c3417e1b02db2158a895 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/loss_cn/MarginRankingLoss_cn.rst @@ -0,0 +1,60 @@ +.. _cn_api_nn_loss_MarginRankingLoss: + +MarginRankingLoss +------------------------------- + +.. py:class:: paddle.nn.loss.MarginRankingLoss(margin=0.0, reduction='mean', name=None) + +该接口用于创建一个 ``MarginRankingLoss`` 的可调用类,计算输入input,other 和 标签label间的 `margin rank loss` 损失。 + +该损失函数的数学计算公式如下: + + .. math:: + margin\_rank\_loss = max(0, -label * (input - other) + margin) + +当 `reduction` 设置为 ``'mean'`` 时, + + .. math:: + Out = MEAN(margin\_rank\_loss) + +当 `reduction` 设置为 ``'sum'`` 时, + + .. math:: + Out = SUM(margin\_rank\_loss) + +当 `reduction` 设置为 ``'none'`` 时,直接返回最原始的 `margin_rank_loss` 。 + +参数 +:::::::: + - **margin** (float,可选): - 用于加和的margin值,默认值为0。 + - **reduction** (string,可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'`` 、 ``'mean'`` 、 ``'sum'`` 。如果设置为 ``'none'`` ,则直接返回 最原始的 ``margin_rank_loss`` 。如果设置为 ``'sum'`` ,则返回 ``margin_rank_loss`` 的总和。如果设置为 ``'mean'`` ,则返回 ``margin_rank_loss`` 的平均值。默认值为 ``'none'`` 。 + - **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +形状 +:::::::: + - **input** - N-D Tensor, 维度是[N,*] 其中N 是batch size,`*` 是任意数量的额外维度,数据类型为float32或float64。 + - **other** - 与 ``input`` 的形状、数据类型相同。 + - **label** - 与 ``input`` 的形状、数据类型相同。 + - **output** - 如果 :attr:`reduction` 为 ``'sum'`` 或者是 ``'mean'`` ,则形状为 :math:`[1]` ,否则shape和输入 `input` 保持一致 。数据类型与 ``input``、 ``other`` 相同。 + +返回 +:::::::: +返回计算MarginRankingLoss的可调用对象。 + +代码示例 +:::::::: + +.. code-block:: python + + + import numpy as np + import paddle + + paddle.disable_static() + + input = paddle.to_variable(np.array([[1, 2], [3, 4]]).astype("float32")) + other = paddle.to_variable(np.array([[2, 1], [2, 4]]).astype("float32")) + label = paddle.to_variable(np.array([[1, -1], [-1, -1]]).astype("float32")) + margin_rank_loss = paddle.nn.MarginRankingLoss() + loss = margin_rank_loss(input, other, label) + print(loss.numpy()) # [0.75] diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst index 7d3e46dc66a0a6587f786de999cae3ddbcc9c5fc..f2b1559091cc5c6f211a4fa64f2eaa77e869fc3a 100644 --- a/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst @@ -1,9 +1,11 @@ +.. _cn_api_nn_loss_NLLLoss: + NLLLoss ------------------------------- -.. py:function:: paddle.nn.loss.NLLLoss(weight=None, reduction='mean', ignore_index=-100) +.. py:class:: paddle.nn.loss.NLLLoss(weight=None, ignore_index=-100, reduction='mean', name=None) -该OP计算输入input和标签label间的 `negative log likelihood loss` 损失 ,可用于训练一个 `n` 类分类器。 +该接口可创建一个NLLLoss可调用类,计算输入x和标签label间的 `negative log likelihood loss` 损失 ,可用于训练一个 `n` 类分类器。 如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 里面的值对应类别的权重。当你的训练集样本 不均衡的话,使用这个参数是非常有用的。 @@ -28,48 +30,41 @@ NLLLoss \text{if reduction} = \text{'sum'.} \end{cases} -参数: - - **input** (Variable): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。 - - **label** (Variable): - 输入input对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。 - - **weight** (Variable, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。 - - **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。 +参数 +::::::::: + - **weight** (Tensor, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。 - **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。 + - **reduction** (str, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。 + - **name** (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +形状 +::::::::: + - **input** (Tensor): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。 + - **label** (Tensor): - 输入 `input` 对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。 + - **output** (Tensor): - 输入 `input` 和 `label` 间的 `negative log likelihood loss` 损失。如果 `reduction` 为 `'none'` ,则输出Loss形状为 `[N, *]` 。 如果 `reduction` 为 `'sum'` 或者 `'mean'` ,则输出Loss形状为 `'[1]'` 。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + nll_loss = paddle.nn.layer.NLLLoss() + log_softmax = paddle.nn.LogSoftmax(axis=1) -返回:返回存储表示 `negative log likihood loss` 的损失值。 - -返回类型:Variable - -**代码示例** - -.. code-block:: python - - # declarative mode - import paddle.fluid as fluid - import numpy as np - import paddle - input_np = np.random.random(size=(10, 10)).astype(np.float32) - label_np = np.random.randint(0, 10, size=(10,)).astype(np.int64) - prog = fluid.Program() - startup_prog = fluid.Program() - place = fluid.CPUPlace() - with fluid.program_guard(prog, startup_prog): - input = fluid.data(name='input', shape=[10, 10], dtype='float32') - label = fluid.data(name='label', shape=[10], dtype='int64') - nll_loss = paddle.nn.loss.NLLLoss() - res = nll_loss(input, label) - exe = fluid.Executor(place) - static_result = exe.run( - prog, - feed={"input": input_np, - "label": label_np}, - fetch_list=[res]) - print(static_result) - - # imperative mode - import paddle.fluid.dygraph as dg - with dg.guard(place) as g: - input = dg.to_variable(input_np) - label = dg.to_variable(label_np) - output = nll_loss(input, label) - print(output.numpy()) + input_np = np.array([[0.88103855, 0.9908683 , 0.6226845 ], + [0.53331435, 0.07999352, 0.8549948 ], + [0.25879037, 0.39530203, 0.698465 ], + [0.73427284, 0.63575995, 0.18827209], + [0.05689114, 0.0862954 , 0.6325046 ]]).astype(np.float32) + label_np = np.array([0, 2, 1, 1, 0]).astype(np.int64) + place = paddle.CPUPlace() + paddle.disable_static(place) + input = paddle.to_variable(input_np) + log_out = log_softmax(input) + label = paddle.to_variable(label_np) + result = nll_loss(log_out, label) + print(result.numpy()) # [1.0720209] diff --git a/doc/fluid/api_cn/nn_cn/margin_rank_loss_cn.rst b/doc/fluid/api_cn/nn_cn/margin_rank_loss_cn.rst deleted file mode 100644 index 9669e8b1431eee9df9fcfe8850ed67894390f053..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/nn_cn/margin_rank_loss_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_nn_cn_margin_rank_loss: - -margin_rank_loss -------------------------------- -:doc_source: paddle.fluid.layers.margin_rank_loss - - diff --git a/doc/fluid/api_cn/nn_cn/softmax_cn.rst b/doc/fluid/api_cn/nn_cn/softmax_cn.rst index 0b0139b0f5b54489c91bcbe1db01d64f71273cfe..5879cfa4368af1de5b006a02e533a6b46627eb7f 100644 --- a/doc/fluid/api_cn/nn_cn/softmax_cn.rst +++ b/doc/fluid/api_cn/nn_cn/softmax_cn.rst @@ -2,6 +2,118 @@ softmax ------------------------------- -:doc_source: paddle.fluid.layers.softmax +.. py:class:: paddle.nn.functional.softmax(x, axis=-1, name=None) +该OP实现了softmax层。OP的计算过程如下: +步骤1:输入 ``x`` 的 ``axis`` 维会被置换到最后一维; + +步骤2:将输入 ``x`` 在逻辑上变换为二维矩阵。二维矩阵第一维(列长度)是输入除最后一维之外的其他维度值的乘积,第二维(行长度)和输入 ``axis`` 维的长度相同;对于矩阵的每一行,softmax操作对其进行重新缩放,使得该行的每个元素在 \[0,1\] 范围内,并且总和为1; + +步骤3:softmax操作执行完成后,执行步骤1和步骤2的逆运算,将二维矩阵恢复至和输入 ``x`` 相同的维度。 + +上述步骤2中softmax操作计算过程如下: + + - 对于二维矩阵的每一行,计算K维向量(K是输入第 ``axis`` 维的长度)中指定位置的指数值和全部位置指数值的和。 + + - 指定位置指数值与全部位置指数值之和的比值就是softmax操作的输出。 + +对于二维矩阵中的第i行和第j列有: + +.. math:: + + + Out[i,j] = \frac{exp(X[i,j])}{\sum_j exp(X[i,j])} + +- 示例1(矩阵一共有三维。axis = -1,表示沿着最后一维(即第三维)做softmax操作) + +.. code-block:: python + + 输入 + + x.shape = [2, 3, 4] + + x.data = [[[2.0, 3.0, 4.0, 5.0], + [3.0, 4.0, 5.0, 6.0], + [7.0, 8.0, 8.0, 9.0]], + [[1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0], + [6.0, 7.0, 8.0, 9.0]]] + + axis = -1 + + 输出 + + out.shape = [2, 3, 4] + + out.data = [[[0.0320586 , 0.08714432, 0.23688282, 0.64391426], + [0.0320586 , 0.08714432, 0.23688282, 0.64391426], + [0.07232949, 0.19661193, 0.19661193, 0.53444665]], + [[0.0320586 , 0.08714432, 0.23688282, 0.64391426], + [0.0320586 , 0.08714432, 0.23688282, 0.64391426], + [0.0320586 , 0.08714432, 0.23688282, 0.64391426]]] + +- 示例2(矩阵一共有三维。axis = 1,表示沿着第二维做softmax操作) + +.. code-block:: python + + 输入 + + x.shape = [2, 3, 4] + + x.data = [[[2.0, 3.0, 4.0, 5.0], + [3.0, 4.0, 5.0, 6.0], + [7.0, 8.0, 8.0, 9.0]], + [[1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0], + [6.0, 7.0, 8.0, 9.0]]] + + axis = 1 + + 输出 + + out.shape = [2, 3, 4] + + out.data = [[[0.00657326, 0.00657326, 0.01714783, 0.01714783], + [0.01786798, 0.01786798, 0.04661262, 0.04661262], + [0.97555875, 0.97555875, 0.93623955, 0.93623955]], + [[0.00490169, 0.00490169, 0.00490169, 0.00490169], + [0.26762315, 0.26762315, 0.26762315, 0.26762315], + [0.72747516, 0.72747516, 0.72747516, 0.72747516]]] + + +参数 +:::::::::: + - x (Tensor) - 输入的多维 ``Tensor`` ,数据类型为:float32、float64。 + - axis (int, 可选) - 指定对输入 ``x`` 进行运算的轴。``axis`` 的有效范围是[-D, D),D是输入 ``x`` 的维度, ``axis`` 为负值时与 :math:`axis + D` 等价。默认值为-1。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,数据类型和形状同 ``x`` 一致。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import paddle.nn.functional as F + import numpy as np + + paddle.enable_imperative() + + x = np.array([[[2.0, 3.0, 4.0, 5.0], + [3.0, 4.0, 5.0, 6.0], + [7.0, 8.0, 8.0, 9.0]], + [[1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0], + [6.0, 7.0, 8.0, 9.0]]], 'float32') + x = paddle.imperative.to_variable(x) + out = F.softmax(x) + # [[[0.0320586 , 0.08714432, 0.23688282, 0.64391426], + # [0.0320586 , 0.08714432, 0.23688282, 0.64391426], + # [0.07232949, 0.19661193, 0.19661193, 0.53444665]], + # [[0.0320586 , 0.08714432, 0.23688282, 0.64391426], + # [0.0320586 , 0.08714432, 0.23688282, 0.64391426], + # [0.0320586 , 0.08714432, 0.23688282, 0.64391426]]] diff --git a/doc/fluid/api_cn/paddle_cn.rst b/doc/fluid/api_cn/paddle_cn.rst index de355d4708ead0cddf1f940fbea59ffba8c898c6..7497eb21ac79150aa3284c151896158813524989 100644 --- a/doc/fluid/api_cn/paddle_cn.rst +++ b/doc/fluid/api_cn/paddle_cn.rst @@ -5,7 +5,7 @@ paddle .. toctree:: :maxdepth: 1 - paddle_cn/abs_cn.rst + paddle_cn/abs_cn.rst paddle_cn/acos_cn.rst paddle_cn/addcmul_cn.rst paddle_cn/addmm_cn.rst @@ -44,8 +44,6 @@ paddle paddle_cn/elementwise_add_cn.rst paddle_cn/elementwise_div_cn.rst paddle_cn/elementwise_floordiv_cn.rst - paddle_cn/elementwise_max_cn.rst - paddle_cn/elementwise_min_cn.rst paddle_cn/elementwise_mod_cn.rst paddle_cn/elementwise_mul_cn.rst paddle_cn/elementwise_pow_cn.rst @@ -95,11 +93,16 @@ paddle paddle_cn/log_cn.rst paddle_cn/manual_seed_cn.rst paddle_cn/matmul_cn.rst + paddle_cn/max_cn.rst + paddle_cn/maximum_cn.rst paddle_cn/mean_cn.rst paddle_cn/meshgrid_cn.rst + paddle_cn/min_cn.rst + paddle_cn/minimum_cn.rst paddle_cn/multiplex_cn.rst paddle_cn/mul_cn.rst - paddle_cn/name_scope_cn.rst + paddle_cn/name_scope_cn.rst + paddle_cn/no_grad_cn.rst paddle_cn/nonzero_cn.rst paddle_cn/not_equal_cn.rst paddle_cn/ones_cn.rst diff --git a/doc/fluid/api_cn/paddle_cn/cumsum_cn.rst b/doc/fluid/api_cn/paddle_cn/cumsum_cn.rst index 4422de0e441e93db84d2990c4936b46c9757ab68..89fbc20a319e12b7ffff36e2b241d316f9616dbe 100644 --- a/doc/fluid/api_cn/paddle_cn/cumsum_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/cumsum_cn.rst @@ -2,6 +2,6 @@ cumsum ------------------------------- -:doc_source: paddle.fluid.layers.cumsum +:doc_source: paddle.tensor.cumsum diff --git a/doc/fluid/api_cn/paddle_cn/elementwise_equal_cn.rst b/doc/fluid/api_cn/paddle_cn/elementwise_equal_cn.rst deleted file mode 100644 index 4c0f65404fed01682b9c9e1fff82c48c775e0539..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/paddle_cn/elementwise_equal_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_paddle_cn_elementwise_equal: - -elementwise_equal -------------------------------- -:doc_source: paddle.fluid.layers.equal - - diff --git a/doc/fluid/api_cn/paddle_cn/elementwise_max_cn.rst b/doc/fluid/api_cn/paddle_cn/elementwise_max_cn.rst deleted file mode 100644 index 7c4af7dd578acbab01be37dc8da25dc793bf9be6..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/paddle_cn/elementwise_max_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_paddle_cn_elementwise_max: - -elementwise_max -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_max - - diff --git a/doc/fluid/api_cn/paddle_cn/elementwise_min_cn.rst b/doc/fluid/api_cn/paddle_cn/elementwise_min_cn.rst deleted file mode 100644 index 0b4a2d8ec667e04b4b4d644438764589c8fb4cdc..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/paddle_cn/elementwise_min_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_paddle_cn_elementwise_min: - -elementwise_min -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_min - - diff --git a/doc/fluid/api_cn/paddle_cn/equal_all_cn.rst b/doc/fluid/api_cn/paddle_cn/equal_all_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..72c333de05f5fc7ea25242077485211fe07c8e8e --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/equal_all_cn.rst @@ -0,0 +1,7 @@ +.. _cn_api_paddle_cn_equal_all: + +equal_all +------------------------------- +:doc_source: paddle.tensor.equal_all + + diff --git a/doc/fluid/api_cn/paddle_cn/greater_equal_cn.rst b/doc/fluid/api_cn/paddle_cn/greater_equal_cn.rst index 8fb516705e2749abcfb9ef216456f45a213ea2fb..1f4367acce3364471e5c5ab8cb5a91ede96de6a2 100644 --- a/doc/fluid/api_cn/paddle_cn/greater_equal_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/greater_equal_cn.rst @@ -2,6 +2,6 @@ greater_equal ------------------------------- -:doc_source: paddle.fluid.layers.greater_equal +:doc_source: paddle.tensor.greater_equal diff --git a/doc/fluid/api_cn/paddle_cn/greater_than_cn.rst b/doc/fluid/api_cn/paddle_cn/greater_than_cn.rst index f228df1de80ff5ae2113bbc0ead958f50e84d06b..f15865d063c8f972e040d24c3d508a6dd11d2264 100644 --- a/doc/fluid/api_cn/paddle_cn/greater_than_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/greater_than_cn.rst @@ -2,6 +2,6 @@ greater_than ------------------------------- -:doc_source: paddle.fluid.layers.greater_than +:doc_source: paddle.tensor.greater_than diff --git a/doc/fluid/api_cn/paddle_cn/less_equal_cn.rst b/doc/fluid/api_cn/paddle_cn/less_equal_cn.rst index ca9bb26b766bbada944852be00bd3bd37b6f597d..481e3f2863f10cee11765e97eb46ae5f252a3357 100644 --- a/doc/fluid/api_cn/paddle_cn/less_equal_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/less_equal_cn.rst @@ -2,6 +2,6 @@ less_equal ------------------------------- -:doc_source: paddle.fluid.layers.less_equal +:doc_source: paddle.tensor.less_equal diff --git a/doc/fluid/api_cn/paddle_cn/less_than_cn.rst b/doc/fluid/api_cn/paddle_cn/less_than_cn.rst index 0085d27a7d1016d6e36dd1feed4f56477d420ac2..3f0802843bed23a6547b36efb3abe1d51a8e1519 100644 --- a/doc/fluid/api_cn/paddle_cn/less_than_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/less_than_cn.rst @@ -2,6 +2,6 @@ less_than ------------------------------- -:doc_source: paddle.fluid.layers.less_than +:doc_source: paddle.tensor.less_than diff --git a/doc/fluid/api_cn/paddle_cn/no_grad_cn.rst b/doc/fluid/api_cn/paddle_cn/no_grad_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..afd06deffa35a3d71c4a23593d1caedcdea21b67 --- /dev/null +++ b/doc/fluid/api_cn/paddle_cn/no_grad_cn.rst @@ -0,0 +1,5 @@ +.. _cn_api_paddle_cn_name_scope: + +name_scope +------------------------------- +:doc_source: paddle.fluid.dygraph.no_grad diff --git a/doc/fluid/api_cn/paddle_cn/not_equal_cn.rst b/doc/fluid/api_cn/paddle_cn/not_equal_cn.rst index 987d966970a6c2b05effc4b5c156580ec0745216..872637f9e816a7fd1fa910d91441994b58c884f8 100644 --- a/doc/fluid/api_cn/paddle_cn/not_equal_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/not_equal_cn.rst @@ -2,6 +2,6 @@ not_equal ------------------------------- -:doc_source: paddle.fluid.layers.not_equal +:doc_source: paddle.tensor.not_equal diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index d150b30019b30c8c9c3492ff62fd66d89a4e48bc..259cf4ab97da44815ff7a40a24ff959eae8bf8c8 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -38,16 +38,14 @@ paddle.tensor tensor_cn/einsum_cn.rst tensor_cn/elementwise_add_cn.rst tensor_cn/elementwise_div_cn.rst - tensor_cn/elementwise_equal_cn.rst tensor_cn/elementwise_floordiv_cn.rst - tensor_cn/elementwise_max_cn.rst - tensor_cn/elementwise_min_cn.rst tensor_cn/elementwise_mod_cn.rst tensor_cn/elementwise_mul_cn.rst tensor_cn/elementwise_pow_cn.rst tensor_cn/elementwise_sub_cn.rst tensor_cn/elementwise_sum_cn.rst tensor_cn/equal_cn.rst + tensor_cn/equal_all_cn.rst tensor_cn/erf_cn.rst tensor_cn/exp_cn.rst tensor_cn/expand_as_cn.rst @@ -89,9 +87,11 @@ paddle.tensor tensor_cn/math_cn.rst tensor_cn/matmul_cn.rst tensor_cn/max_cn.rst + tensor_cn/maximum_cn.rst tensor_cn/mean_cn.rst tensor_cn/meshgrid_cn.rst tensor_cn/min_cn.rst + tensor_cn/minimum_cn.rst tensor_cn/mm_cn.rst tensor_cn/mul_cn.rst tensor_cn/multiplex_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/argsort_cn.rst b/doc/fluid/api_cn/tensor_cn/argsort_cn.rst index 3e1c2c49b70d25d9ccf7cb9ce38c870a249b7439..43d2dd420eb8fa255e35ff229272f7b3aeb50df0 100644 --- a/doc/fluid/api_cn/tensor_cn/argsort_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/argsort_cn.rst @@ -8,7 +8,7 @@ argsort :alias_main: paddle.argsort :alias: paddle.argsort,paddle.tensor.argsort,paddle.tensor.search.argsort -对输入变量沿给定轴进行排序,输出排序好的数据的相应索引,其维度和输入相同。**默认升序排列,如果需要降序排列设置** ``descending=True`` 。 +对输入变量沿给定轴进行排序,输出排序好的数据的相应索引,其维度和输入相同。默认升序排列,如果需要降序排列设置 ``descending=True`` 。 参数: @@ -17,9 +17,8 @@ argsort - **descending** (bool,可选) - 指定算法排序的方向。如果设置为True,算法按照降序排序。如果设置为False或者不设置,按照升序排序。默认值为False。 - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回:排序后索引信息(与 ``x`` 维度信息一致),数据类型为int64。 +返回:Tensor, 排序后索引信息(与 ``x`` 维度信息一致),数据类型为int64。 -返回类型:Tensor **代码示例**: diff --git a/doc/fluid/api_cn/tensor_cn/concat_cn.rst b/doc/fluid/api_cn/tensor_cn/concat_cn.rst index e439959e9f07df7ad3bcafc6269692485b9d9958..aa36dd238d01ef6804bb8e4175650ab3b0244429 100644 --- a/doc/fluid/api_cn/tensor_cn/concat_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/concat_cn.rst @@ -1,3 +1,54 @@ +.. _cn_api_tensor_concat: + concat ------------------------------- -**版本升级,文档正在开发中** + +.. py:function:: paddle.tensor.concat(x, axis=0, name=None) + + +该OP对输入沿 ``axis`` 轴进行联结,返回一个新的Tensor。 + +参数: + - **x** (list|tuple) - 待联结的Tensor list或者Tensor tuple ,支持的数据类型为:bool, float16, float32、float64、int32、int64, ``x`` 中所有Tensor的数据类型应该一致。 + - **axis** (int|Tensor,可选) - 指定对输入 ``x`` 进行运算的轴,可以是整数或者形状为[1]的Tensor,数据类型为int32或者int64。 ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 中Tensor的维度, ``axis`` 为负值时与 :math:`axis + R` 等价。默认值为0。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:联结后的Tensor ,数据类型和 ``x`` 中的Tensor相同。 + +抛出异常: + - ``TypeError``: - 当输入 ``x`` 的类型不是list或者tuple时。 + - ``TypeError``: - 当输入 ``x`` 的数据类型不是 bool,float16, float32, float64, int32, int64时。 + - ``TypeError``: - 当 ``axis`` 的类型不是int或者Tensor时。 当 ``axis`` 是Tensor的时候其数据类型不是int32或者int64时。 + - ``TypeError``: - 当输入 ``x`` 中的Tensor存在数据类型不一致时。 + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() # Now we are in imperative mode + in1 = np.array([[1, 2, 3], + [4, 5, 6]]) + in2 = np.array([[11, 12, 13], + [14, 15, 16]]) + in3 = np.array([[21, 22], + [23, 24]]) + x1 = paddle.imperative.to_variable(in1) + x2 = paddle.imperative.to_variable(in2) + x3 = paddle.imperative.to_variable(in3) + zero = paddle.full(shape=[1], dtype='int32', fill_value=0) + # When the axis is negative, the real axis is (axis + Rank(x)) + # As follow, axis is -1, Rank(x) is 2, the real axis is 1 + out1 = paddle.concat(x=[x1, x2, x3], axis=-1) + out2 = paddle.concat(x=[x1, x2], axis=0) + out3 = paddle.concat(x=[x1, x2], axis=zero) + # out1 + # [[ 1 2 3 11 12 13 21 22] + # [ 4 5 6 14 15 16 23 24]] + # out2 out3 + # [[ 1 2 3] + # [ 4 5 6] + # [11 12 13] + # [14 15 16]] diff --git a/doc/fluid/api_cn/tensor_cn/cumsum_cn.rst b/doc/fluid/api_cn/tensor_cn/cumsum_cn.rst index 5aadad95718195f4ae391051bb7f2e04a92d0ec1..71896b1bc17808d6b70873ef45a5587d1ad6cce1 100644 --- a/doc/fluid/api_cn/tensor_cn/cumsum_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/cumsum_cn.rst @@ -2,6 +2,53 @@ cumsum ------------------------------- -:doc_source: paddle.fluid.layers.cumsum + +.. py:function:: paddle.cumsum(x, axis=None, dtype=None, name=None) + + + +沿给定 ``axis`` 计算张量 ``x`` 的累加和。结果的第一个元素和输入的第一个元素相同。 + +参数: + - **x** (Tensor) - 累加的输入,需要进行累加操作的Tensor. + - **axis** (int,可选) - 指明需要累加的维度。-1代表最后一维。默认:None,将输入展开为一维变量再进行累加计算。 + - **dtype** (str,可选) - 输出Tensor的数据类型,支持int32、int64、float32、float64. 如果指定了,那么在执行操作之前,输入张量将被转换为dtype. 这对于防止数据类型溢出非常有用。默认为:None. + - **name** (str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回:累加的结果,即累加器的输出。 + +返回类型:Tensor + +**代码示例**: + +.. code-block:: python + + import paddle + from paddle.imperative import to_variable + import numpy as np + + paddle.enable_imperative() + data_np = np.arange(12).reshape(3, 4) + data = to_variable(data_np) + + y = paddle.cumsum(data) + print(y.numpy()) + # [ 0 1 3 6 10 15 21 28 36 45 55 66] + + y = paddle.cumsum(data, axis=0) + print(y.numpy()) + # [[ 0 1 2 3] + # [ 4 6 8 10] + # [12 15 18 21]] + + y = paddle.cumsum(data, axis=-1) + print(y.numpy()) + # [[ 0 1 3 6] + # [ 4 9 15 22] + # [ 8 17 27 38]] + + y = paddle.cumsum(data, dtype='float64') + print(y.dtype) + # VarType.FP64 diff --git a/doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst b/doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst deleted file mode 100644 index c7006ffda4aefe7bc10a8ece96d2b3ed2f30f883..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. _cn_api_tensor_elementwise_equal: - -elementwise_equal -------------------------------- - -.. py:function:: paddle.elementwise_equal(x, y, name=None) - -:alias_main: paddle.elementwise_equal -:alias: paddle.elementwise_equal,paddle.tensor.elementwise_equal,paddle.tensor.logic.elementwise_equal -:update_api: paddle.fluid.layers.equal - - - -该OP返回 :math:`x==y` 逐元素比较x和y是否相等。 - -参数: - - **x** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 - - **y** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 - - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - -返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 - -返回类型:变量(Variable) - -**代码示例**: - -.. code-block:: python - - import paddle - import paddle.fluid as fluid - import numpy as np - - label = fluid.layers.assign(np.array([3, 3], dtype="int32")) - limit = fluid.layers.assign(np.array([3, 2], dtype="int32")) - out1 = paddle.elementwise_equal(x=label, y=limit) #out1=[True, False] diff --git a/doc/fluid/api_cn/tensor_cn/elementwise_max_cn.rst b/doc/fluid/api_cn/tensor_cn/elementwise_max_cn.rst deleted file mode 100644 index 12c2246e6d9c9dc0ca3e33b0f77c1bdb3511ac76..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/tensor_cn/elementwise_max_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_tensor_cn_elementwise_max: - -elementwise_max -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_max - - diff --git a/doc/fluid/api_cn/tensor_cn/elementwise_min_cn.rst b/doc/fluid/api_cn/tensor_cn/elementwise_min_cn.rst deleted file mode 100644 index b7b81110936a3226ff9b978e018c42ae8b90ec6b..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/tensor_cn/elementwise_min_cn.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. _cn_api_tensor_cn_elementwise_min: - -elementwise_min -------------------------------- -:doc_source: paddle.fluid.layers.elementwise_min - - diff --git a/doc/fluid/api_cn/tensor_cn/equal_all_cn.rst b/doc/fluid/api_cn/tensor_cn/equal_all_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b1269776011012b2c33df1101ad6c97948728a3d --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/equal_all_cn.rst @@ -0,0 +1,40 @@ +.. _cn_api_tensor_equal_all: + +equal_all +------------------------------- + +.. py:function:: paddle.equal_all(x, y, name=None) + +:alias_main: paddle.equal_all +:alias: paddle.equal_all,paddle.tensor.equal_all,paddle.tensor.logic.equal_all + +该OP返回:返回的结果只有一个元素值,如果所有相同位置的元素相同返回True,否则返回False。 + +**注:该OP输出的结果不返回梯度。** + + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:输出结果为Tensor,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 2, 3])) + z = imperative.to_variable(np.array([1, 4, 3])) + result1 = paddle.equal_all(x, y) + print(result1.numpy()) # result1 = [True ] + result2 = paddle.equal_all(x, z) + print(result2.numpy()) # result2 = [False ] diff --git a/doc/fluid/api_cn/tensor_cn/equal_cn.rst b/doc/fluid/api_cn/tensor_cn/equal_cn.rst index d25ec01088b79dea39cb3f9af2930f650660feb7..e8b1dff6087609b56b406dc5680e176a48faca22 100644 --- a/doc/fluid/api_cn/tensor_cn/equal_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/equal_cn.rst @@ -2,54 +2,35 @@ equal ------------------------------- -.. py:function:: paddle.equal(x, y, axis=-1, name=None) +.. py:function:: paddle.equal(x, y, name=None) :alias_main: paddle.equal :alias: paddle.equal,paddle.tensor.equal,paddle.tensor.logic.equal +该OP返回 :math:`x==y` 逐元素比较x和y是否相等,相同位置的元素相同则返回True,否则返回False。使用重载算子 `==` 可以有相同的计算函数效果 - -该OP返回 :math:`x==y` 逐元素比较x和y是否相等,所有的元素都相同则返回True,否则返回False。 +**注:该OP输出的结果不返回梯度。** 参数: - - **x** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 - - **y** (Variable) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 - - **axis** (int, 可选) - 如果输入的两个Tensor的维度不相同,并且如果y的维度是x的一部分, 那就可以通过broadcast的方式来进行op计算。axis是进行broadcast的开始的维度,具体broadcast的方式可以参考elementwise_add。 + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回:输出结果的Tensor,输出Tensor只有一个元素值,元素值是True或者False,Tensor数据类型为bool。 +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 -返回类型:变量(Variable) +返回类型:变量(Tensor) **代码示例**: .. code-block:: python - import paddle.fluid as fluid - import paddle - import numpy as np - label = fluid.layers.assign(np.array([3, 4], dtype="int32")) - label_1 = fluid.layers.assign(np.array([1, 2], dtype="int32")) - limit = fluid.layers.assign(np.array([3, 4], dtype="int32")) - out1 = paddle.equal(x=label, y=limit) #out1=[True] - out2 = paddle.equal(x=label_1, y=limit) #out2=[False] - -.. code-block:: python + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.equal(x, y) + print(result1.numpy()) # result1 = [True False False] - import paddle.fluid as fluid - import paddle - import numpy as np - def gen_data(): - return { - "x": np.ones((2, 3, 4, 5)).astype('float32'), - "y": np.zeros((3, 4)).astype('float32') - } - x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') - y = fluid.data(name="y", shape=[3,4], dtype='float32') - out = paddle.equal(x, y, axis=1) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - res = exe.run(feed=gen_data(), - fetch_list=[out]) - print(res[0]) #[False] diff --git a/doc/fluid/api_cn/tensor_cn/eye_cn.rst b/doc/fluid/api_cn/tensor_cn/eye_cn.rst index fc2eb9620e6b03662174be87edf4ea3f84a513c1..87e746f90024e97ad56e1bc05dc89ca683e10018 100644 --- a/doc/fluid/api_cn/tensor_cn/eye_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/eye_cn.rst @@ -5,17 +5,16 @@ eye .. py:function:: paddle.tensor.eye(num_rows, num_columns=None, dtype=None, name=None) -该OP用来构建二维张量(主对角线元素为1,其他元素为0)。 +该OP用来构建二维Tensor(主对角线元素为1,其他元素为0)。 参数: - - **num_rows** (int) - 生成二维张量的行数,数据类型为非负int32。 - - **num_columns** (int,可选) - 生成二维张量的列数,数据类型为非负int32。若为None,则默认等于num_rows。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 返回张量的数据类型,可为float16,float32,float64, int32, int64。若为None, 则默认等于float32。 + - **num_rows** (int) - 生成二维Tensor的行数,数据类型为非负int32。 + - **num_columns** (int,可选) - 生成二维Tensor的列数,数据类型为非负int32。若为None,则默认等于num_rows。 + - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 返回Tensor的数据类型,可为float16,float32,float64, int32, int64。若为None, 则默认等于float32。 - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回:shape为 [num_rows, num_columns]的张量。 +返回: ``shape`` 为 [num_rows, num_columns]的Tensor。 -返回类型:Variable(Tensor),数据类型为dtype指定的类型。 抛出异常: - ``TypeError``: - 如果 ``dtype`` 的类型不是float16, float32, float64, int32, int64其中之一。 @@ -26,8 +25,8 @@ eye .. code-block:: python import paddle - paddle.enable_imperative() - data = paddle.eye(3, dtype='int32') # paddle.eye 等价于 paddle.tensor.eye + paddle.enable_imperative() # Now we are in imperative mode + data = paddle.eye(3, dtype='int32') # [[1 0 0] # [0 1 0] # [0 0 1]] diff --git a/doc/fluid/api_cn/tensor_cn/full_cn.rst b/doc/fluid/api_cn/tensor_cn/full_cn.rst index a99eb47db38b26d8bf7098d85ed8512310ce930c..68dc4d658d9fe4b33ac852f1a8c91191a56363bf 100644 --- a/doc/fluid/api_cn/tensor_cn/full_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/full_cn.rst @@ -5,27 +5,22 @@ full .. py:function:: paddle.full(shape, fill_value, dtype=None, name=None) -:alias_main: paddle.full -:alias: paddle.full,paddle.tensor.full,paddle.tensor.creation.full -:update_api: paddle.fluid.layers.fill_constant - -该OP创建形状大小为shape并且数据类型为dtype的张量,其中元素值均为 ``fill_value``。 +该OP创建形状大小为shape并且数据类型为dtype的Tensor,其中元素值均为 ``fill_value``。 参数: - - **shape** (list|tuple|Variable) – 指定创建张量的形状(shape), 数据类型为int32 或者int64。 - - **fill_value** (bool|float|int|Variable) - 用于初始化输出张量的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。 + - **shape** (list|tuple|Tensor) – 指定创建Tensor的形状(shape), 数据类型为int32 或者int64。 + - **fill_value** (bool|float|int|Tensor) - 用于初始化输出Tensor的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。 - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若为None,则输出变量的数据类型和输入变量相同,默认值为None。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:返回一个存储结果的Tensor,数据类型和dtype相同。 -返回类型:Variable 抛出异常: - ``TypeError``: - 如果 ``dtype`` 的类型不是bool, float16, float32, float64, int32, int64其中之一。 - - ``TypeError``: - 如果 ``shape`` 的类型不是list或tuple或Variable。 + - ``TypeError``: - 如果 ``shape`` 的类型不是list或tuple或Tensor。当 ``shape`` 是Tensor的时候,其数据类型不是int32或者int64时。 **代码示例**: @@ -38,18 +33,18 @@ full #[[0] # [0]] - # attr shape is a list which contains Variable Tensor. + # attr shape is a list which contains Tensor. positive_3 = paddle.fill_constant([1], "int32", 2) data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5) # [[1.5 1.5]] - # attr shape is an Variable Tensor. + # attr shape is a Tensor. shape = paddle.fill_constant([2], "int32", 2) data4 = paddle.full(shape=shape, dtype='bool', fill_value=True) # [[True True] # [True True]] - # attr fill_value is an Variable Tensor. + # attr fill_value is a Tensor. val = paddle.fill_constant([1], "float32", 2.0) data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') i # [[2.0] diff --git a/doc/fluid/api_cn/tensor_cn/full_like_cn.rst b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst index a5445dca343f8a7b047bd6faa18167e0340b513e..f0f26348adf85937abf5ad43d992918a557b2826 100644 --- a/doc/fluid/api_cn/tensor_cn/full_like_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst @@ -5,24 +5,20 @@ full_like .. py:function:: paddle.full_like(x, fill_value, dtype=None, name=None) -:alias_main: paddle.full_like -:alias: paddle.full_like,paddle.tensor.full_like,paddle.tensor.creation.full_like -该OP创建一个和x具有相同的形状和数据类型的张量,其中元素值均为 ``fill_value``。 +该OP创建一个和 ``x`` 具有相同的形状并且数据类型为 ``dtype`` 的Tensor,其中元素值均为 ``fill_value`` , 当 ``dtype`` 为None的时候,Tensor数据类型和输入 ``x`` 相同。 参数: - - **x** (Variable) – 输入张量, 输出张量和x具有相同的形状,x的数据类型可以是bool,float16,float32,float64,int32,int64。 + - **x** (Tensor) – 输入Tensor, 输出Tensor和x具有相同的形状,x的数据类型可以是bool,float16,float32,float64,int32,int64。 - **fill_value** (bool|float|int) - 用于初始化输出张量的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。 - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为None,则输出变量的数据类型和输入变量相同,默认值为None。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:返回一个存储结果的Tensor,数据类型和dtype相同。 -返回类型:Variable - 抛出异常: - - ``TypeError``: - 当dtype不是bool、float16、float32、float64、int32、int64其中之一。 - - ``TypeError``: - 如果 ``shape`` 的类型不是list或tuple或Varibable。 + - ``TypeError``: - 当 ``x`` 的数据类型不是bool、float16、float32、float64、int32、int64其中之一。 + - ``TypeError``: - 当 ``dtype`` 不是bool、float16、float32、float64、int32、int64或者None其中之一。 **代码示例**: diff --git a/doc/fluid/api_cn/tensor_cn/greater_equal_cn.rst b/doc/fluid/api_cn/tensor_cn/greater_equal_cn.rst index 21d26726177ae2d0321d0350b65e5ab9b36eb5c0..6eedd6c3bdcfd5fe971dad36fea0452eea45b10b 100644 --- a/doc/fluid/api_cn/tensor_cn/greater_equal_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/greater_equal_cn.rst @@ -2,6 +2,36 @@ greater_equal ------------------------------- -:doc_source: paddle.fluid.layers.greater_equal +.. py:function:: paddle.greater_equal(x, y, name=None) + +:alias_main: paddle.greater_equal +:alias: paddle.greater_equal,paddle.tensor.greater_equal,paddle.tensor.logic.greater_equal + +该OP逐元素地返回 :math:`x >= y` 的逻辑值,相同位置前者输入大于等于后者输入则返回True,否则返回False。使用重载算子 `>=` 可以有相同的计算函数效果。 + +**注:该OP输出的结果不返回梯度。** + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + + +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.greater_equal(x, y) + print(result1.numpy()) # result1 = [True False True] diff --git a/doc/fluid/api_cn/tensor_cn/greater_than_cn.rst b/doc/fluid/api_cn/tensor_cn/greater_than_cn.rst index 40ad68f703d1784dc4361c09c3f7e25def154d6d..33df3e31c019f4b0ce943f40d5f838cd3d22b19a 100644 --- a/doc/fluid/api_cn/tensor_cn/greater_than_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/greater_than_cn.rst @@ -2,6 +2,34 @@ greater_than ------------------------------- -:doc_source: paddle.fluid.layers.greater_than +.. py:function:: paddle.greater_than(x, y, name=None) +:alias_main: paddle.greater_than +:alias: paddle.greater_than,paddle.tensor.greater_than,paddle.tensor.logic.greater_than +该OP返回 :math:`x>y` 逐元素比较x和y是否相等,相同位置前者输入大于等于后者输入则返回True,否则返回False。使用重载算子 `>` 可以有相同的计算函数效果 + +**注:该OP输出的结果不返回梯度。** + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + + +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.greater_than(x, y) + print(result1.numpy()) # result1 = [False False True] diff --git a/doc/fluid/api_cn/tensor_cn/index_select_cn.rst b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst index 9963de68368a7149f80394b6a20a5d38ec35b1ec..077baf49bd0af13faa889992b2d41ce7723ac574 100644 --- a/doc/fluid/api_cn/tensor_cn/index_select_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst @@ -5,25 +5,22 @@ index_select .. py:function:: paddle.index_select(x, index, axis=0, name=None) -:alias_main: paddle.index_select -:alias: paddle.index_select,paddle.tensor.index_select,paddle.tensor.search.index_select - -该OP沿着指定维度 ``axis`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``axis`` 维外,返回的张量其余维度大小同输入 ``input`` , ``axis`` 维大小等于 ``index`` 的大小。 +该OP沿着指定轴 ``axis`` 对输入 ``x`` 进行索引,取 ``index`` 中指定的相应项,创建并返回到一个新的Tensor。这里 ``index`` 是一个 ``1-D`` Tensor。除 ``axis`` 轴外,返回的Tensor其余维度大小和输入 ``x``相等 , ``axis`` 维度的大小等于 ``index`` 的大小。 **参数**: - - **x** (Variable)– 输入张量。x的数据类型可以是float32,float64,int32,int64。 - - **index** (Variable)– 包含索引下标的一维张量。 - - **axis** (int, optional) – 索引轴,若未指定,则默认选取第0维。 + - **x** (Tensor)– 输入Tensor。 ``x`` 的数据类型可以是float32,float64,int32,int64。 + - **index** (Tensor)– 包含索引下标的一维Tensor。 + - **axis** (int, 可选) – 索引轴,若未指定,则默认选取第0维。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 **返回**: - -**Variable**: 数据类型同输入。 + -**Tensor**: 返回一个数据类型同输入的Tensor。 抛出异常: - - ``TypeError`` - 当x或者index的类型不是Variable。 - - ``TypeError`` - 当x的数据类型不是float32、float64、int32、int64其中之一或者index的数据类型不是int32、int64其中之一。 + - ``TypeError`` - 当 ``x`` 或者 ``index`` 的类型不是Tensor。 + - ``TypeError`` - 当 ``x`` 的数据类型不是float32、float64、int32、int64其中之一或者 ``index`` 的数据类型不是int32、int64其中之一。 **代码示例**: diff --git a/doc/fluid/api_cn/tensor_cn/less_equal_cn.rst b/doc/fluid/api_cn/tensor_cn/less_equal_cn.rst index f2b9381cad039bc6b4200d73c5fa604b9ff7f03e..63427b1442ca0cab965045eff3b7bde02fee137e 100644 --- a/doc/fluid/api_cn/tensor_cn/less_equal_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/less_equal_cn.rst @@ -2,6 +2,36 @@ less_equal ------------------------------- -:doc_source: paddle.fluid.layers.less_equal +.. py:function:: paddle.less_equal(x, y, name=None) + +:alias_main: paddle.less_equal +:alias: paddle.less_equal,paddle.tensor.less_equal,paddle.tensor.logic.less_equal + +该OP逐元素地返回 :math:`x <= y` 的逻辑值,相同位置前者输入小于等于后者输入则返回True,否则返回False。使用重载算子 `<=` 可以有相同的计算函数效果。 + +**注:该OP输出的结果不返回梯度。** + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + + +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.less_equal(x, y) + print(result1.numpy()) # result1 = [True True False] diff --git a/doc/fluid/api_cn/tensor_cn/less_than_cn.rst b/doc/fluid/api_cn/tensor_cn/less_than_cn.rst index 8a89d50b15b135173842875a969a3ee14e73a33a..e49b092cc2d5ce062cfac8551026c616d7befca2 100644 --- a/doc/fluid/api_cn/tensor_cn/less_than_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/less_than_cn.rst @@ -2,6 +2,36 @@ less_than ------------------------------- -:doc_source: paddle.fluid.layers.less_than +.. py:function:: paddle.less_than(x, y, name=None) + +:alias_main: paddle.less_than +:alias: paddle.less_than,paddle.tensor.less_than,paddle.tensor.logic.less_than + +该OP逐元素地返回 :math:`x < y` 的逻辑值,相同位置前者输入小于后者输入则返回True,否则返回False。使用重载算子 `<` 可以有相同的计算函数效果。 + +**注:该OP输出的结果不返回梯度。** + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + + +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.less_than(x, y) + print(result1.numpy()) # result1 = [False True False] diff --git a/doc/fluid/api_cn/tensor_cn/linspace_cn.rst b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst index c08a0dc8a245709d99bd8f81bf0398beafdaeea9..7c228c413e9f167ca92fd547a25c8aa3ad233aeb 100644 --- a/doc/fluid/api_cn/tensor_cn/linspace_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst @@ -6,20 +6,19 @@ linspace .. py:function:: paddle.linspace(start, stop, num, dtype=None, name=None) :alias_main: paddle.linspace -:alias: paddle.linspace,paddle.tensor.linspace,paddle.tensor.creation.linspace -:update_api: paddle.fluid.layers.linspace +:alias: paddle.tensor.linspace, paddle.tensor.creation.linspace -该OP在给定区间内返回固定数目的均匀间隔的值。 +该OP返回一个Tensor,Tensor的值为在区间start和stop上均匀间隔的num个值,输出Tensor的长度为num。 **注意:该OP不进行梯度计算** 参数: - - **start** (float|Variable) – start是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **stop** (float|Variable) – end是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 - - **num** (int|Variable) – num是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 - - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) – 输出Tensor的数据类型,可以是‘float32’或者是‘float64’。如果dtype为None,默认类型为float32。 + - **start** (float|Tensor) – ``start`` 是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **stop** (float|Tensor) – ``end`` 是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。 + - **num** (int|Tensor) – ``num`` 是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。 + - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) – 输出Tensor的数据类型,可以是float32或者是float64。如果dtype为None,默认类型为float32。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:输出结果的数据类型是float32或float64,表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。 diff --git a/doc/fluid/api_cn/tensor_cn/log1p_cn.rst b/doc/fluid/api_cn/tensor_cn/log1p_cn.rst index dab3f158a2d20ee31db2d492f647140ec80eea6f..ff96c608014e706910dbfc30fd11df02995717a8 100644 --- a/doc/fluid/api_cn/tensor_cn/log1p_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/log1p_cn.rst @@ -3,7 +3,7 @@ log1p ------------------------------- -.. py:function:: paddle.tensor.log1p(x, out=None, name=None) +.. py:function:: paddle.log1p(x, name=None) :alias_main: paddle.log1p :alias: paddle.log1p,paddle.tensor.log1p,paddle.tensor.math.log1p @@ -18,32 +18,27 @@ log1p 参数: - - **x** (Variable) – 该OP的输入为LodTensor/Tensor。数据类型为float32,float64。 - - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **x** (Tensor) – 指定输入为一个多维的Tensor。数据类型为float32,float64。 - **name** (str,可选) – 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None。 返回:Log1p算子自然对数输出 -返回类型: Variable - 该OP的输出为LodTensor/Tensor,数据类型为输入一致。 +返回类型: Tensor - 该OP的输出为一个多维的Tensor,数据类型为输入一致。 **代码示例** .. code-block:: python - import paddle - import paddle.fluid as fluid - import numpy as np - - x = fluid.data(name="x", shape=[2,1], dtype="float32") - res = paddle.log1p(x) # paddle.log1p等价于 paddle.tensor.log1p - - # 举例选择CPU计算环境 - exe = fluid.Executor(fluid.CPUPlace()) - - # 执行静态图,输出结果 - x_i = np.array([[0], [1]]).astype(np.float32) - res_val, = exe.run(fluid.default_main_program(), feed={'x':x_i}, fetch_list=[res]) - print(res_val) # [[0.], [0.6931472]] - - + import paddle + import numpy as np + + paddle.enable_imperative() + x = np.array([[1, 2], [3, 4]]).astype('float32') + x1 = paddle.imperative.to_variable(x) + + out1 = paddle.log1p(x1) + print(out1.numpy()) + # [[0.6931472 1.0986123] + # [1.3862944 1.609438 ]] + diff --git a/doc/fluid/api_cn/tensor_cn/log_cn.rst b/doc/fluid/api_cn/tensor_cn/log_cn.rst index 960019d43a20943654c6e3481eca1f29346feee9..5cfc4f49472eda096bafea023bc329d6a8934943 100644 --- a/doc/fluid/api_cn/tensor_cn/log_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/log_cn.rst @@ -2,6 +2,43 @@ log ------------------------------- -:doc_source: paddle.fluid.layers.log +.. py:function:: paddle.log(x, name=None) +:alias_main: paddle.log +:alias: paddle.log,paddle.tensor.log,paddle.tensor.math.log +:old_api: paddle.fluid.layers.log + + + + +Log激活函数(计算自然对数) + +.. math:: + \\Out=ln(x)\\ + + +参数: + - **x** (Tensor) – 指定输入为一个多维的Tensor。数据类型为float32,float64。 + - **name** (str,可选) – 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None。 + +返回:Log算子自然对数输出 + +返回类型: Tensor - 该OP的输出为一个多维的Tensor,数据类型为输入一致。 + + +**代码示例** + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + x = np.array([[1, 2], [3, 4]]).astype('float32') + x1 = paddle.imperative.to_variable(x) + + out1 = paddle.log(x1) + print(out1.numpy()) + # [[0. 0.6931472] + # [1.0986123 1.3862944]] diff --git a/doc/fluid/api_cn/tensor_cn/max_cn.rst b/doc/fluid/api_cn/tensor_cn/max_cn.rst index 24eb34761ef45323fa211f954bdf77b4d8c9d020..e3f1620fa1064f0db21f5fc308cd31521da95354 100644 --- a/doc/fluid/api_cn/tensor_cn/max_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/max_cn.rst @@ -1,60 +1,64 @@ - .. _cn_api_paddle_tensor_max: max ------------------------------- -.. py:function:: paddle.tensor.max(input, dim=None, keep_dim=False, out=None, name=None) +.. py:function:: paddle.tensor.max(x, axis=None, keepdim=False, name=None) :alias_main: paddle.max :alias: paddle.max,paddle.tensor.max,paddle.tensor.math.max -:update_api: paddle.fluid.layers.reduce_max - - -该OP是对指定维度上的Tensor元素求最大值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_max` +该OP是对指定维度上的Tensor元素求最大值运算,并输出相应的计算结果。 -参数: - - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 - - **dim** (list | int ,可选)- 求最大值运算的维度。如果为None,则计算所有元素的最大值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 - - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 - - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 +参数 +::::::::: + - **x** (Tensor)- Tensor,支持数据类型为float32,float64,int32,int64。 + - **axis** (list | int ,可选)- 求最大值运算的维度。如果为None,则计算所有元素的最大值并返回包含单个元素的Tensor变量,否则必须在 :math:`[-x.ndim, x.ndim]` 范围内。如果 :math:`axis[i] <0` ,则维度将变为 :math:`x.ndim+axis[i]` ,默认值为None。 + - **keepdim** (bool)- 是否在输出Tensor中保留减小的维度。如果keepdim 为 False,结果张量的维度将比输入张量的小,默认值为False。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回: 在指定dim上进行求最大值运算的Tensor,数据类型和输入数据类型一致。 +返回 +::::::::: + Tensor, 在指定axis上进行求最大值运算的Tensor,数据类型和输入数据类型一致。 -返回类型: 变量(Variable) -**代码示例** +代码示例 +:::::::::: .. code-block:: python + import numpy as np import paddle - import paddle.fluid as fluid - # x是一个Tensor,元素如下: - # [[0.2, 0.3, 0.5, 0.9] - # [0.1, 0.2, 0.6, 0.7]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - x = fluid.data(name='x', shape=[2, 4], dtype='float32') - # paddle.max 等价于 paddle.tensor.max - paddle.max(x) # [0.9] - paddle.max(x, dim=0) # [0.2, 0.3, 0.6, 0.9] - paddle.max(x, dim=-1) # [0.9, 0.7] - paddle.max(x, dim=1, keep_dim=True) # [[0.9], [0.7]] - - # y是一个shape为[2, 2, 2]的Tensor,元素如下: - # [[[1.0, 2.0], [3.0, 4.0]], - # [[5.0, 6.0], [7.0, 8.0]]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') - paddle.max(y, dim=[1, 2]) # [4.0, 8.0] - paddle.max(y, dim=[0, 1]) # [7.0, 8.0] - - - - - - - - + paddle.disable_static() + + # data_x is a variable with shape [2, 4] + # the axis is a int element + data_x = np.array([[0.2, 0.3, 0.5, 0.9], + [0.1, 0.2, 0.6, 0.7]]) + x = paddle.to_variable(data_x) + result1 = paddle.max(x) + print(result1.numpy()) + #[0.9] + result2 = paddle.max(x, axis=0) + print(result2.numpy()) + #[0.2 0.3 0.6 0.9] + result3 = paddle.max(x, axis=-1) + print(result3.numpy()) + #[0.9 0.7] + result4 = paddle.max(x, axis=1, keepdim=True) + print(result4.numpy()) + #[[0.9] + # [0.7]] + + # data_y is a variable with shape [2, 2, 2] + # the axis is list + data_y = np.array([[[1.0, 2.0], [3.0, 4.0]], + [[5.0, 6.0], [7.0, 8.0]]]) + y = paddle.to_variable(data_y) + result5 = paddle.max(y, axis=[1, 2]) + print(result5.numpy()) + #[4. 8.] + result6 = paddle.max(y, axis=[0, 1]) + print(result6.numpy()) + #[7. 8.] diff --git a/doc/fluid/api_cn/tensor_cn/maximum_cn.rst b/doc/fluid/api_cn/tensor_cn/maximum_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3db694f291098d8ed4c8d2bd08bd4a56adb49f81 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/maximum_cn.rst @@ -0,0 +1,96 @@ +.. _cn_api_paddle_tensor_maximum: + +maximum +------------------------------- + +.. py:function:: paddle.tensor.maximum(x, y, axis=-1, name=None) + +:alias_main: paddle.maximum +:alias: paddle.maximum,paddle.tensor.maximum,paddle.tensor.math.maximum + +该OP逐元素对比输入的两个多维Tensor,并且把各个位置更大的元素保存到返回结果中。 + +等式是: + +.. math:: + Out = max(X, Y) + +- :math:`X` :多维Tensor。 +- :math:`Y` :多维Tensor。 + +此运算算子有两种情况: + 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。 + 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。 + +对于情况2: + 1. 用 :math:`Y` 的 ``shape`` 匹配 :math:`X` 的 ``shape``,其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。 + 2. 如果 ``axis`` < 0(默认值为-1),则 :math:`axis = abs(X.ndim - Y.ndim) - axis - 1` 。 + 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 + +例如: + +.. code-block:: text + + shape(X) = (2, 3, 4, 5), shape(Y) = (,) + shape(X) = (2, 3, 4, 5), shape(Y) = (5,) + shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 + shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 + shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 + shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 + +具体的飞桨的广播(broadcasting)机制可以参考 `<> `_ 。 + +参数 +::::::::: + - **x** (Tensor)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。 + - **y** (Tensor)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。 + - **axis** (int32, 可选)- Y的维度对应到X维度上时的索引。默认值为 -1。 + - **name** (string, 可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: + Tensor,维度和数据类型与 ``x`` 相同的多维Tensor。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x_data = np.array([[1, 2], [3, 4]], dtype=np.float32) + y_data = np.array([[5, 6], [7, 8]], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.maximum(x, y) + print(res.numpy()) + #[[5. 6.] + # [7. 8.]] + + x_data = np.array([[[1, 2, 3], [1, 2, 3]]], dtype=np.float32) + y_data = np.array([1, 2], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.maximum(x, y, axis=1) + print(res.numpy()) + #[[[1. 2. 3.] + # [2. 2. 3.]]] + + x_data = np.array([2, 3, 5], dtype=np.float32) + y_data = np.array([1, 4, np.nan], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.maximum(x, y) + print(res.numpy()) + #[ 2. 4. nan] + + x_data = np.array([5, 3, np.inf], dtype=np.float32) + y_data = np.array([1, 4, 5], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.maximum(x, y) + print(res.numpy()) + #[ 5. 4. inf] diff --git a/doc/fluid/api_cn/tensor_cn/mean_cn.rst b/doc/fluid/api_cn/tensor_cn/mean_cn.rst index fe7f53d6f6cd5218b7f6d884bafeb7c7e12000cc..bc838016e17b8d4992aee8802128eb69c983cb71 100644 --- a/doc/fluid/api_cn/tensor_cn/mean_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/mean_cn.rst @@ -2,6 +2,52 @@ mean ------------------------------- -:doc_source: paddle.fluid.layers.mean +.. py:function:: paddle.mean(x, axis=None, keepdim=False, name=None) + + +该OP沿 ``axis`` 计算 ``x`` 的平均值。 + +参数 +:::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:float32、float64、int32.int64 。 + - axis (int|list|tuple, 可选) - 指定对 ``x`` 进行计算的轴。``axis`` 可以是int、list(int)、tuple(int)。如果 ``axis`` 包含多个维度,则沿着 ``axis`` 中的所有轴进行计算。``axis`` 或者其中的元素值应该在范围[-D, D)内,D是 ``x`` 的维度。如果 ``axis`` 或者其中的元素值小于0,则等价于 :math:`axis + D` 。如果 ``axis`` 是None,则对 ``x`` 的全部元素计算平均值。默认值为None。 + - keepdim (bool, 可选) - 是否在输出Tensor中保留减小的维度。如果 ``keep_dim`` 为True,则输出Tensor和 ``x`` 具有相同的维度(减少的维度除外,减少的维度的大小为1)。否则,输出Tensor的形状会在 ``axsi`` 上进行squeeze操作。默认值为False。 + - name (str, 可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + +返回 +:::::::::: + ``Tensor`` ,沿着 ``axis`` 进行平均值计算的结果,数据类型和 ``x`` 相同。 + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + x = np.array([[[1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12]], + [[13, 14, 15, 16], + [17, 18, 19, 20], + [21, 22, 23, 24]]], 'float32') + x = paddle.to_variable(x) + out1 = paddle.mean(x) + # [12.5] + out2 = paddle.mean(x, axis=-1) + # [[ 2.5 6.5 10.5] + # [14.5 18.5 22.5]] + out3 = paddle.mean(x, axis=-1, keepdim=True) + # [[[ 2.5] + # [ 6.5] + # [10.5]] + # [[14.5] + # [18.5] + # [22.5]]] + out4 = paddle.mean(x, axis=[0, 2]) + # [ 8.5 12.5 16.5] diff --git a/doc/fluid/api_cn/tensor_cn/min_cn.rst b/doc/fluid/api_cn/tensor_cn/min_cn.rst index d3417080c79bcc5df682feff99fd29c8d4a1057f..7231c1b20519c2fb807a05d6d35354177763830e 100644 --- a/doc/fluid/api_cn/tensor_cn/min_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/min_cn.rst @@ -3,57 +3,61 @@ min ------------------------------- -.. py:function:: paddle.tensor.min(input, dim=None, keep_dim=False, out=None, name=None) +.. py:function:: paddle.tensor.min(x, axis=None, keepdim=False, name=None) :alias_main: paddle.min :alias: paddle.min,paddle.tensor.min,paddle.tensor.math.min -:update_api: paddle.fluid.layers.reduce_min +该OP是对指定维度上的Tensor元素求最小值运算,并输出相应的计算结果。 +参数 +::::::::: + - **x** (Tensor)- Tensor,支持数据类型为float32,float64,int32,int64。 + - **axis** (list | int ,可选)- 求最小值运算的维度。如果为None,则计算所有元素的最小值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−x.ndim, x.ndim]` 范围内。如果 :math:`axis[i] < 0` ,则维度将变为 :math:`x.ndim+axis[i]` ,默认值为None。 + - **keepdim** (bool)- 是否在输出Tensor中保留减小的维度。如果keepdim 为False,结果张量的维度将比输入张量的小,默认值为False。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -该OP是对指定维度上的Tensor元素求最小值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_min` +返回 +::::::::: + Tensor,在指定axis上进行求最小值运算的Tensor,数据类型和输入数据类型一致。 -参数: - - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 - - **dim** (list | int ,可选)- 求最小值运算的维度。如果为None,则计算所有元素的最小值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 - - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 - - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - -返回: 在指定dim上进行求最小值运算的Tensor,数据类型和输入数据类型一致。 - -返回类型: 变量(Variable) - -**代码示例** +代码示例 +:::::::::: .. code-block:: python + import numpy as np import paddle - import paddle.fluid as fluid - # x是一个Tensor,元素如下: - # [[0.2, 0.3, 0.5, 0.9] - # [0.1, 0.2, 0.6, 0.7]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - x = fluid.data(name='x', shape=[2, 4], dtype='float32') - # paddle.min 等价于 paddle.tensor.min - paddle.min(x) # [0.1] - paddle.min(x, dim=0) # [0.1, 0.2, 0.5, 0.7] - paddle.min(x, dim=-1) # [0.2, 0.1] - paddle.min(x, dim=1, keep_dim=True) # [[0.2], [0.1]] - - # y是一个shape为[2, 2, 2]的Tensor,元素如下: - # [[[1.0, 2.0], [3.0, 4.0]], - # [[5.0, 6.0], [7.0, 8.0]]] - # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 - y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') - paddle.min(y, dim=[1, 2]) # [1.0, 5.0] - paddle.min(y, dim=[0, 1]) # [1.0, 2.0] - - - - - - - - + paddle.disable_static() + + # data_x is a variable with shape [2, 4] + # the axis is a int element + data_x = np.array([[0.2, 0.3, 0.5, 0.9], + [0.1, 0.2, 0.6, 0.7]]) + x = paddle.to_variable(data_x) + result1 = paddle.min(x) + print(result1.numpy()) + #[0.1] + result2 = paddle.min(x, axis=0) + print(result2.numpy()) + #[0.1 0.2 0.5 0.7] + result3 = paddle.min(x, axis=-1) + print(result3.numpy()) + #[0.2 0.1] + result4 = paddle.min(x, axis=1, keepdim=True) + print(result4.numpy()) + #[[0.2] + # [0.1]] + + # data_y is a variable with shape [2, 2, 2] + # the axis is list + data_y = np.array([[[1.0, 2.0], [3.0, 4.0]], + [[5.0, 6.0], [7.0, 8.0]]]) + y = paddle.to_variable(data_y) + result5 = paddle.min(y, axis=[1, 2]) + print(result5.numpy()) + #[1. 5.] + result6 = paddle.min(y, axis=[0, 1]) + print(result6.numpy()) + #[1. 2.] diff --git a/doc/fluid/api_cn/tensor_cn/minimum_cn.rst b/doc/fluid/api_cn/tensor_cn/minimum_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..1d04313385ff36c3104ec9fd173939bcae8e5c6f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/minimum_cn.rst @@ -0,0 +1,96 @@ +.. _cn_api_paddle_tensor_minimum: + +minimum +------------------------------- + +.. py:function:: paddle.tensor.minimum(x, y, axis=-1, name=None) + +:alias_main: paddle.minimum +:alias: paddle.minimum,paddle.tensor.minimum,paddle.tensor.math.minimum + +该OP逐元素对比输入的两个多维Tensor,并且把各个位置更小的元素保存到返回结果中。 + +等式是: + +.. math:: + Out = min(X, Y) + +- :math:`X` :多维Tensor。 +- :math:`Y` :多维Tensor。 + +此运算算子有两种情况: + 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。 + 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。 + +对于情况2: + 1. 用 :math:`Y` 的 ``shape`` 匹配 :math:`X` 的 ``shape``,其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。 + 2. 如果 ``axis`` < 0(默认值为-1),则 :math:`axis = abs(X.ndim - Y.ndim) - axis - 1` 。 + 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 + +例如: + +.. code-block:: text + + shape(X) = (2, 3, 4, 5), shape(Y) = (,) + shape(X) = (2, 3, 4, 5), shape(Y) = (5,) + shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 + shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 + shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 + shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 + +具体的飞桨的广播(broadcasting)机制可以参考 `<> `_ 。 + +参数 +::::::::: + - **x** (Tensor)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。 + - **y** (Tensor)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。 + - **axis** (int32, 可选)- Y的维度对应到X维度上时的索引。默认值为 -1。 + - **name** (string, 可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: + Tensor,维度和数据类型与 ``x`` 相同的多维Tensor。 + + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + paddle.disable_static() + + x_data = np.array([[1, 2], [3, 4]], dtype=np.float32) + y_data = np.array([[5, 6], [7, 8]], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.minimum(x, y) + print(res.numpy()) + #[[1. 2.] + # [3. 4.]] + + x_data = np.array([[[1, 2, 3], [1, 2, 3]]], dtype=np.float32) + y_data = np.array([1, 2], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.minimum(x, y, axis=1) + print(res.numpy()) + #[[[1. 1. 1.] + # [2. 2. 2.]]] + + x_data = np.array([2, 3, 5], dtype=np.float32) + y_data = np.array([1, 4, np.nan], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.minimum(x, y) + print(res.numpy()) + #[ 1. 3. nan] + + x_data = np.array([5, 3, np.inf], dtype=np.float32) + y_data = np.array([1, 4, 5], dtype=np.float32) + x = paddle.to_variable(x_data) + y = paddle.to_variable(y_data) + res = paddle.minimum(x, y) + print(res.numpy()) + #[1. 3. 5.] diff --git a/doc/fluid/api_cn/tensor_cn/norm_cn.rst b/doc/fluid/api_cn/tensor_cn/norm_cn.rst index 5fed454842b9292b2240cd8d3b575143064b0597..ea6ebd82d2aff71ea5164ce22063a5bf5723cdd7 100644 --- a/doc/fluid/api_cn/tensor_cn/norm_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/norm_cn.rst @@ -7,7 +7,6 @@ norm :alias_main: paddle.norm :alias: paddle.norm,paddle.tensor.norm,paddle.tensor.linalg.norm -:update_api: paddle.fluid.layers.l2_normalize diff --git a/doc/fluid/api_cn/tensor_cn/not_equal_cn.rst b/doc/fluid/api_cn/tensor_cn/not_equal_cn.rst index 5cd088f25e1e21587d24bfc6bf84a1139e181f63..8a81f4f08ff2b31d4f434c169be51d3ca3703103 100644 --- a/doc/fluid/api_cn/tensor_cn/not_equal_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/not_equal_cn.rst @@ -1,7 +1,37 @@ -.. _cn_api_tensor_cn_not_equal: +.. _cn_api_tensor_not_equal: not_equal ------------------------------- -:doc_source: paddle.fluid.layers.not_equal +.. py:function:: paddle.not_equal(x, y, name=None) + +:alias_main: paddle.not_equal +:alias: paddle.not_equal,paddle.tensor.not_equal,paddle.tensor.logic.not_equal + +该OP返回 :math:`x!=y` 逐元素比较x和y是否相等,相同位置的元素不相同则返回True,否则返回False。使用重载算子 `!=` 可以有相同的计算函数效果 + +**注:该OP输出的结果不返回梯度。** + +参数: + - **x** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64,int32, int64。 + - **y** (Tensor) - 输入Tensor,支持的数据类型包括 float32, float64, int32, int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + + +返回:输出结果的Tensor,输出Tensor的shape和输入一致,Tensor数据类型为bool。 + +返回类型:变量(Tensor) + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.imperative as imperative + paddle.enable_imperative() + x = imperative.to_variable(np.array([1, 2, 3])) + y = imperative.to_variable(np.array([1, 3, 2])) + result1 = paddle.not_equal(x, y) + print(result1.numpy()) # result1 = [False True True] diff --git a/doc/fluid/api_cn/tensor_cn/ones_cn.rst b/doc/fluid/api_cn/tensor_cn/ones_cn.rst index f830089c723effc8aeeaf6ede608b4264cefa9ab..fa13c3412fd1d741d129987b415e4ac33a956557 100644 --- a/doc/fluid/api_cn/tensor_cn/ones_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/ones_cn.rst @@ -5,27 +5,21 @@ ones .. py:function:: paddle.ones(shape, dtype=None) -:alias_main: paddle.ones -:alias: paddle.ones,paddle.tensor.ones,paddle.tensor.creation.ones -:update_api: paddle.fluid.layers.ones - - 该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor。 参数: - - **shape** (tuple|list|Variable) - 输出Tensor的形状,数据类型为int32或者int64。 - - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。如果dtype为None,默认数据类型为float32。 + - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 输出Tensor的数据类型,数据类型必须为bool、 float16、float32、float64、int32或int64。如果 ``dtype`` 为None,默认数据类型为float32。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。 -返回类型:Variable 抛出异常: - - ``TypeError`` - 当dtype不是float16、float32、float64、int32或int64中的一个的时候 - - ``TypeError`` - 当shape 不是tuple、list、或者Variable的时候。 + - ``TypeError`` - 当 ``dtype`` 不是bool、 float16、float32、float64、int32、int64和None时。 + - ``TypeError`` - 当 ``shape`` 不是tuple、list、或者Tensor的时, 当 ``shape`` 为Tensor时,其数据类型不是int32或者int64。 **代码示例**: diff --git a/doc/fluid/api_cn/tensor_cn/sort_cn.rst b/doc/fluid/api_cn/tensor_cn/sort_cn.rst index f57b1e438b8bf9bcb7eb6544d5efcccb413e7a3b..dc791485e0327e588091e628b3efdb8e3b04fe00 100644 --- a/doc/fluid/api_cn/tensor_cn/sort_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/sort_cn.rst @@ -9,7 +9,7 @@ sort :alias: paddle.sort,paddle.tensor.sort,paddle.tensor.search.sort -对输入变量沿给定轴进行排序,输出排序好的数据和相应的索引,其维度和输入相同。**默认升序排列,如果需要降序排列设置** ``descending=True`` 。 +对输入变量沿给定轴进行排序,输出排序好的数据,其维度和输入相同。默认升序排列,如果需要降序排列设置 ``descending=True`` 。 参数: @@ -18,9 +18,8 @@ sort - **descending** (bool,可选) - 指定算法排序的方向。如果设置为True,算法按照降序排序。如果设置为False或者不设置,按照升序排序。默认值为False。 - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -返回:一组已排序的输出(与 ``x`` 维度相同、数据类型相同)和索引(数据类型为int64)。 +返回:Tensor, 排序后的输出(与 ``x`` 维度相同、数据类型相同)。 -返回类型:tuple[Tensor] **代码示例**: @@ -41,28 +40,21 @@ sort out1 = paddle.sort(x=x, axis=-1) out2 = paddle.sort(x=x, axis=0) out3 = paddle.sort(x=x, axis=1) - print(out1[0].numpy()) + print(out1.numpy()) #[[[5. 5. 8. 9.] # [0. 0. 1. 7.] # [2. 4. 6. 9.]] # [[2. 2. 4. 5.] # [4. 7. 7. 9.] # [0. 1. 6. 7.]]] - print(out1[1].numpy()) - #[[[0 3 1 2] - # [0 1 2 3] - # [2 3 0 1]] - # [[1 3 2 0] - # [0 1 2 3] - # [2 0 3 1]]] - print(out2[0].numpy()) + print(out2.numpy()) #[[[5. 2. 4. 2.] # [0. 0. 1. 7.] # [1. 7. 0. 4.]] # [[5. 8. 9. 5.] # [4. 7. 7. 9.] # [6. 9. 2. 6.]]] - print(out3[0].numpy()) + print(out3.numpy()) #[[[0. 0. 1. 4.] # [5. 8. 2. 5.] # [6. 9. 9. 7.]] diff --git a/doc/fluid/api_cn/tensor_cn/split_cn.rst b/doc/fluid/api_cn/tensor_cn/split_cn.rst index 4f3aca783c3bd2ca5cf105dce727c3475fc7a06b..52f85fcccef62b2dc97d34bb4626b8fbefa1435b 100644 --- a/doc/fluid/api_cn/tensor_cn/split_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/split_cn.rst @@ -2,39 +2,55 @@ split ------------------------------- -.. py:function:: paddle.tensor.split(input, num_or_sections, dim=-1, name=None) - -:alias_main: paddle.split -:alias: paddle.split,paddle.tensor.split,paddle.tensor.manipulation.split -:update_api: paddle.fluid.layers.split +.. py:function:: paddle.tensor.split(x, num_or_sections, axis=0, name=None) 该OP将输入Tensor分割成多个子Tensor。 **参数**: - - **input** (Variable) - 输入变量,数据类型为float32,float64,int32,int64的多维Tensor或者LoDTensor。 - - **num_or_sections** (int|list|tuple) - 如果 num_or_sections 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。如果 num_or_sections 是一个list或tuple,那么它的长度代表子Tensor的数量,它的元素可以是整数或者形状为[1]的Tensor,依次代表子Tensor需要分割成的维度的大小。list或tuple的长度不能超过输入Tensor待分割的维度的大小。在list或tuple中,至多有一个元素值为-1,表示该值是由input的维度和其他num_or_sections中元素推断出来的。例如对一个维度为[4,6,6]Tensor的第三维进行分割时,指定num_or_sections=[2,-1,1],输出的三个Tensor维度分别为:[4,6,2],[4,6,3],[4,6,1]。 - - **dim** (int|Variable,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果dim < 0,则划分的维度为rank(input) + dim。默认值为-1。 - - **name** (str,可选) - 一般无需设置,默认值为None。 + - **x** (Tensor) - 输入变量,数据类型为bool, float16, float32,float64,int32,int64的多维Tensor。 + - **num_or_sections** (int|list|tuple) - 如果 ``num_or_sections`` 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。如果 ``num_or_sections`` 是一个list或tuple,那么它的长度代表子Tensor的数量,它的元素可以是整数或者形状为[1]的Tensor,依次代表子Tensor需要分割成的维度的大小。list或tuple的长度不能超过输入Tensor待分割的维度的大小。在list或tuple中,至多有一个元素值为-1,表示该值是由 ``x`` 的维度和其他 ``num_or_sections`` 中元素推断出来的。例如对一个维度为[4,6,6]Tensor的第三维进行分割时,指定 ``num_or_sections=[2,-1,1]`` ,输出的三个Tensor维度分别为:[4,6,2],[4,6,3],[4,6,1]。 + - **axis** (int|Tensor,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果 ``axis < 0`` ,则划分的维度为 ``rank(x) + axis`` 。默认值为0。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 -**返回**:分割后的Tensor列表。 +返回:分割后的Tensor列表。 -**返回类型**:列表(Variable(Tensor|LoDTensor)),数据类型为int32,int64,float32,float64。 +抛出异常: + - :code:`TypeError`:``x`` 的数据类型不是float16、float32、float64、int32或int64时 。 + - :code:`TypeError`:``num_or_sections`` 不是int、list 或 tuple时。 + - :code:`TypeError`:``axis`` 不是 int 或 Tensor时。当 ``axis`` 为Tensor,其数据类型不是int32或int64时。 **代码示例**: .. code-block:: python - import paddle - import paddle.fluid as fluid import numpy as np - with fluid.dygraph.guard(): - input_1 = np.random.random([4, 6, 6]).astype("int32") - # input is a variable which shape is [4, 6, 6] - input = fluid.dygraph.to_variable(input_1) - - x0, x1, x2 = paddle.split(input, num_or_sections= 3, dim=1) - # x0.shape [4, 2, 6] - # x1.shape [4, 2, 6] - # x2.shape [4, 2, 6] + import paddle + + paddle.enable_imperative() + # x is a Tensor which shape is [3, 9, 5] + x_np = np.random.random([3, 9, 5]).astype("int32") + x = paddle.imperative.to_variable(x_np) + + out0, out1, out22 = paddle.split(x, num_or_sections=3, axis=1) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 3, 5] + + out0, out1, out2 = paddle.split(x, num_or_sections=[2, 3, 4], axis=1) + # out0.shape [3, 2, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 4, 5] + + out0, out1, out2 = paddle.split(x, num_or_sections=[2, 3, -1], axis=1) + # out0.shape [3, 2, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 4, 5] + + # axis is negative, the real axis is (rank(x) + axis) which real + # value is 1. + out0, out1, out2 = paddle.split(x, num_or_sections=3, axis=-2) + # out0.shape [3, 3, 5] + # out1.shape [3, 3, 5] + # out2.shape [3, 3, 5] diff --git a/doc/fluid/api_cn/tensor_cn/zeros_cn.rst b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst index 0734e744979b08b8bed3dd8724242fbb325d9eb3..e84538f784551d1d0becbf6933bfcadcaaa26413 100644 --- a/doc/fluid/api_cn/tensor_cn/zeros_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst @@ -3,31 +3,41 @@ zeros ------------------------------- -.. py:function:: paddle.zeros(shape, dtype, out=None, device=None) - -:alias_main: paddle.zeros -:alias: paddle.zeros,paddle.tensor.zeros,paddle.tensor.creation.zeros -:update_api: paddle.fluid.layers.zeros +.. py:function:: paddle.zeros(shape, dtype=None, name=None) 该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为0的Tensor。 参数: - - **shape** (tuple|list) - 输出Tensor的形状。 - - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。 - - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 - - **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。 + - **shape** (tuple|list|Tensor) - 输出Tensor的形状, ``shape`` 的数据类型为int32或者int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str,可选) - 输出Tensor的数据类型,数据类型必须为bool、float16、float32、float64、int32或int64。若为None,数据类型为float32, 默认为None。 + - **name** (str, 可选) - 输出的名字。一般无需设置,默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 返回:值全为0的Tensor,数据类型和 ``dtype`` 定义的类型一致。 -返回类型:Variable +抛出异常: + - ``TypeError`` - 当 ``dtype`` 不是bool、 float16、float32、float64、int32、int64和None时。 + - ``TypeError`` - 当 ``shape`` 不是tuple、list、或者Tensor时, 当 ``shape`` 为Tensor,其数据类型不是int32或者int64时。 **代码示例**: .. code-block:: python import paddle - data = paddle.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]] - data = paddle.zeros(shape=[2, 2], dtype='float32', device='cpu') # [[0., 0.], [0., 0.]] + paddle.enable_imperative() # Now we are in imperative mode + data = paddle.zeros(shape=[3, 2], dtype='float32') + # [[0. 0.] + # [0. 0.] + # [0. 0.]] + + data = paddle.zeros(shape=[2, 2]) + # [[0. 0.] + # [0. 0.]] + + # shape is a Tensor + shape = paddle.fill_constant(shape=[2], dtype='int32', value=2) + data3 = paddle.zeros(shape=shape, dtype='int32') + # [[0 0] + # [0 0]] diff --git a/doc/fluid/api_guides/X2Paddle/TensorFlow-Fluid.rst b/doc/fluid/api_guides/X2Paddle/TensorFlow-Fluid.rst index 20ee91c8cd7c19c6521b68962647f46620b436aa..e219eb272ed508e70350ed3a0dfa69f416337a1d 100644 --- a/doc/fluid/api_guides/X2Paddle/TensorFlow-Fluid.rst +++ b/doc/fluid/api_guides/X2Paddle/TensorFlow-Fluid.rst @@ -4,151 +4,152 @@ TensorFlow-Fluid常用接口对应表 ############################### -本文档基于TensorFlow v1.13梳理了常用API与PaddlePaddle API对应关系和差异分析。根据文档对应关系,有TensorFlow使用经验的用户,可根据对应关系,快速熟悉PaddlePaddle的接口使用。 +本文档基于TensorFlow v1.15梳理了常用API与PaddlePaddle API对应关系和差异分析。根据文档对应关系,有TensorFlow使用经验的用户,可根据对应关系,快速熟悉PaddlePaddle的接口使用。 .. csv-table:: :header: "序号", "TensorFlow接口", "Fluid接口", "备注" :widths: 1, 8, 8, 3 - "1", "`tf.abs `_", ":ref:`cn_api_fluid_layers_abs`", "功能一致" - "2", "`tf.add `_", ":ref:`cn_api_fluid_layers_elementwise_add`", "功能一致" - "3", "`tf.argmax `_", ":ref:`cn_api_fluid_layers_argmax`", "功能一致" - "4", "`tf.argmin `_", ":ref:`cn_api_fluid_layers_argmin`", "功能一致" - "5", "`tf.assign `_", ":ref:`cn_api_fluid_layers_assign`", "功能一致" - "6", "`tf.assign_add `_", ":ref:`cn_api_fluid_layers_increment`", "功能一致" - "7", "`tf.case `_", ":ref:`cn_api_fluid_layers_Switch`", "`差异对比 `_" - "8", "`tf.cast `_", ":ref:`cn_api_fluid_layers_cast`", "功能一致" - "9", "`tf.clip_by_global_norm `_", ":ref:`cn_api_fluid_clip_GradientClipByGlobalNorm`", "`差异对比 `_" - "10", "`tf.clip_by_norm `_", ":ref:`cn_api_fluid_layers_clip_by_norm`", "`差异对比 `_" - "11", "`tf.clip_by_value `_", ":ref:`cn_api_fluid_layers_clip`", "功能一致" - "12", "`tf.concat `_", ":ref:`cn_api_fluid_layers_concat`", "功能一致" - "13", "`tf.cond `_", ":ref:`cn_api_fluid_layers_ifElse`", "功能一致" - "14", "`tf.constant `_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致" - "15", "`tf.contrib.layers.batch_norm `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" - "16", "`tf.contrib.layers.flatten `_", ":ref:`cn_api_fluid_layers_flatten`", "`差异对比 `_" - "17", "`tf.contrib.layers.fully_connected `_", ":ref:`cn_api_fluid_layers_fc`", "功能一致" - "18", "`tf.contrib.layers.one_hot_encoding `_", ":ref:`cn_api_fluid_layers_one_hot`", "功能一致" - "19", "`tf.contrib.layers.softmax `_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致" - "20", "`tf.contrib.layers.xavier_initializer `_", ":ref:`cn_api_fluid_initializer_Xavier`", "功能一致" - "21", "`tf.nn.rnn.GRUCell `_", ":ref:`cn_api_fluid_layers_gru_unit`", "`差异对比 `_" - "22", "`tf.nn.rnn.MultiRNNCell `_", "无相应接口", "`Fluid实现 `_" - "23", "`tf.nn.rnn.static_rnn `_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "功能一致" - "24", "`tf.convert_to_tensor `_", ":ref:`cn_api_fluid_layers_assign`", "功能一致" - "25", "`tf.cos `_", ":ref:`cn_api_fluid_layers_cos`", "功能一致" - "26", "`tf.div `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" - "27", "`tf.divide `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" - "28", "`tf.dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "`差异对比 `_" - "29", "`tf.equal `_", "`运算符== `_", "功能一致" - "30", "`tf.exp `_", ":ref:`cn_api_fluid_layers_exp`", "功能一致" - "31", "`tf.expand_dims `_", ":ref:`cn_api_fluid_layers_unsqueeze`", "`差异对比 `_" - "32", "`tf.fill `_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致" - "33", "`tf.floor `_", ":ref:`cn_api_fluid_layers_floor`", "功能一致" - "34", "`tf.gather `_", ":ref:`cn_api_fluid_layers_gather`", "功能一致" - "35", "`tf.greater `_", "`运算符> `_", "功能一致" - "36", "`tf.greater_equal `_", "`运算符>= `_", "功能一致" - "37", "`tf.image.non_max_suppression `_", ":ref:`cn_api_fluid_layers_multiclass_nms`", "`差异对比 `_" - "38", "`tf.image.resize_bilinear `_", ":ref:`cn_api_fluid_layers_resize_bilinear`", "功能一致" - "39", "`tf.image.resize_images `_", ":ref:`cn_api_fluid_layers_image_resize`", "`差异对比 `_" - "40", "`tf.image.resize_nearest_neighbor `_", ":ref:`cn_api_fluid_layers_resize_nearest`", "功能一致" - "41", "`tf.is_finite `_", ":ref:`cn_api_fluid_layers_isfinite`", "`差异对比 `_" - "42", "`tf.layers.batch_normalization `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" - "43", "`tf.layers.conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" - "44", "`tf.layers.dense `_", ":ref:`cn_api_fluid_layers_fc`", "`差异对比 `_" - "45", "`tf.layers.dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致" - "46", "`tf.layers.Dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致" - "47", "`tf.layers.flatten `_", ":ref:`cn_api_fluid_layers_flatten`", "功能一致" - "48", "`tf.less `_", "`运算符< `_", "功能一致" - "49", "`tf.less_equal `_", "`运算符<= `_", "功能一致" - "50", "`tf.log `_", ":ref:`cn_api_fluid_layers_log`", "功能一致" - "51", "`tf.logical_and `_", ":ref:`cn_api_fluid_layers_logical_and`", "功能一致" - "52", "`tf.logical_not `_", ":ref:`cn_api_fluid_layers_logical_not`", "功能一致" - "53", "`tf.logical_or `_", ":ref:`cn_api_fluid_layers_logical_or`", "功能一致" - "54", "`tf.losses.mean_squared_error `_", ":ref:`cn_api_fluid_layers_square_error_cost`", "`差异对比 `_" - "55", "`tf.losses.sigmoid_cross_entropy `_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "`差异对比 `_" - "56", "`tf.losses.softmax_cross_entropy `_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "功能一致" - "57", "`tf.matmul `_", ":ref:`cn_api_fluid_layers_matmul`", "`差异对比 `_" - "58", "`tf.maximum `_", ":ref:`cn_api_fluid_layers_elementwise_max`", "功能一致" - "59", "`tf.metrics.accuracy `_", ":ref:`cn_api_fluid_layers_accuracy`", "功能一致" - "60", "`tf.metrics.mean `_", ":ref:`cn_api_fluid_layers_mean`", "功能一致" - "61", "`tf.minimum `_", ":ref:`cn_api_fluid_layers_elementwise_min`", "功能一致" - "62", "`tf.multiply `_", ":ref:`cn_api_fluid_layers_elementwise_mul`", "功能一致" - "63", "`tf.nn.avg_pool `_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 `_" - "64", "`tf.nn.batch_normalization `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" - "65", "`tf.nn.bidirectional_dynamic_rnn `_", "无相应接口", "`Fluid实现 `_" - "66", "`tf.nn.conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" - "67", "`tf.nn.conv2d_transpose `_", ":ref:`cn_api_fluid_layers_conv2d_transpose`", "`差异对比 `_" - "68", "`tf.nn.conv3d_transpose `_", ":ref:`cn_api_fluid_layers_conv3d_transpose`", "`差异对比 `_" - "69", "`tf.nn.depthwise_conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" - "70", "`tf.nn.dynamic_rnn `_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "`差异对比 `_" - "71", "`tf.nn.l2_normalize `_", ":ref:`cn_api_fluid_layers_l2_normalize`", "`差异对比 `_" - "72", "`tf.nn.leaky_relu `_", ":ref:`cn_api_fluid_layers_leaky_relu`", "功能一致" - "73", "`tf.nn.lrn `_", ":ref:`cn_api_fluid_layers_lrn`", "`差异对比 `_" - "74", "`tf.nn.max_pool `_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 `_" - "75", "`tf.nn.relu `_", ":ref:`cn_api_fluid_layers_relu`", "功能一致" - "76", "`tf.nn.relu6 `_", ":ref:`cn_api_fluid_layers_relu6`", "功能一致" - "77", "`tf.nn.rnn_cell.LSTMCell `_", ":ref:`cn_api_fluid_layers_lstm_unit`", "`差异对比 `_" - "78", "`tf.nn.separable_conv2d `_", "无相应接口", "`Fluid实现 `_" - "79", "`tf.nn.sigmoid `_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致" - "80", "`tf.nn.sigmoid_cross_entropy_with_logits `_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "功能一致" - "81", "`tf.nn.softmax `_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致" - "82", "`tf.nn.softmax_cross_entropy_with_logits `_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "`差异对比 `_" - "83", "`tf.nn.softplus `_", ":ref:`cn_api_fluid_layers_softplus`", "功能一致" - "84", "`tf.nn.softsign `_", ":ref:`cn_api_fluid_layers_softsign`", "功能一致" - "85", "`tf.nn.tanh `_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致" - "86", "`tf.one_hot `_", ":ref:`cn_api_fluid_layers_one_hot`", "`差异对比 `_" - "87", "`tf.ones `_", ":ref:`cn_api_fluid_layers_ones`", "功能一致" - "88", "`tf.intializers.ones `_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致" - "89", "`tf.pad `_", ":ref:`cn_api_fluid_layers_pad`", "`差异对比 `_" - "90", "`tf.placeholder `_", ":ref:`cn_api_fluid_layers_data`", "`差异对比 `_" - "91", "`tf.pow `_", ":ref:`cn_api_fluid_layers_pow`", "`差异对比 `_" - "92", "`tf.print `_", ":ref:`cn_api_fluid_layers_print`", "`差异对比 `_" - "93", "`tf.py_func `_", ":ref:`cn_api_fluid_layers_py_func`", "功能一致" - "94", "`tf.random_normal `_", ":ref:`cn_api_fluid_layers_gaussian_random`", "功能一致" - "95", "`tf.random_normal_initializer `_", ":ref:`cn_api_fluid_initializer_Normal`", "功能一致" - "96", "`tf.random_uniform `_", ":ref:`cn_api_fluid_layers_uniform_random`", "功能一致" - "97", "`tf.random_uniform_initializer `_", ":ref:`cn_api_fluid_initializer_UniformInitializer`", "功能一致" - "98", "`tf.reduce_logsumexp `_", "无相应接口", "`Fluid实现 `_" - "99", "`tf.reduce_max `_", ":ref:`cn_api_fluid_layers_reduce_max`", "功能一致" - "100", "`tf.reduce_mean `_", ":ref:`cn_api_fluid_layers_reduce_mean`", "功能一致" - "101", "`tf.reduce_min `_", ":ref:`cn_api_fluid_layers_reduce_min`", "功能一致" - "102", "`tf.reduce_sum `_", ":ref:`cn_api_fluid_layers_reduce_sum`", "功能一致" - "103", "`tf.reshape `_", ":ref:`cn_api_fluid_layers_reshape`", "`差异对比 `_" - "104", "`tf.reverse `_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致" - "105", "`tf.reverse_sequence `_", ":ref:`cn_api_fluid_layers_sequence_reverse`", "`差异对比 `_" - "106", "`tf.reverse_v2 `_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致" - "107", "`tf.round `_", ":ref:`cn_api_fluid_layers_round`", "功能一致" - "108", "`tf.rsqrt `_", ":ref:`cn_api_fluid_layers_rsqrt`", "功能一致" - "109", "`tf.scalar_mul `_", ":ref:`cn_api_fluid_layers_scale`", "功能一致" - "110", "`tf.scatter_update `_", ":ref:`cn_api_fluid_layers_scatter`", "`差异对比 `_" - "111", "`tf.sequence_mask `_", ":ref:`cn_api_fluid_layers_sequence_mask`", "功能一致" - "112", "`tf.shape `_", ":ref:`cn_api_fluid_layers_shape`", "功能一致" - "113", "`tf.sigmoid `_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致" - "114", "`tf.sin `_", ":ref:`cn_api_fluid_layers_sin`", "功能一致" - "115", "`tf.slice `_", ":ref:`cn_api_fluid_layers_slice`", "`差异对比 `_" - "116", "`tf.split `_", ":ref:`cn_api_fluid_layers_split`", "`差异对比 `_" - "117", "`tf.sqrt `_", ":ref:`cn_api_fluid_layers_sqrt`", "功能一致" - "118", "`tf.square `_", ":ref:`cn_api_fluid_layers_square`", "功能一致" - "119", "`tf.squared_difference `_", "无相应接口", "`Fluid实现 `_" - "120", "`tf.squeeze `_", ":ref:`cn_api_fluid_layers_squeeze`", "功能一致" - "121", "`tf.stack `_", ":ref:`cn_api_fluid_layers_stack`", "功能一致" - "122", "`tf.stop_gradient `_", "无相应接口", "`Fluid实现 `_" - "123", "`tf.subtract `_", ":ref:`cn_api_fluid_layers_elementwise_sub`", "功能一致" - "124", "`tf.tanh `_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致" - "125", "`tf.tile `_", ":ref:`cn_api_fluid_layers_expand`", "功能一致" - "126", "`tf.top_k `_", ":ref:`cn_api_fluid_layers_topk`", "`差异对比 `_" - "127", "`tf.train.AdagradOptimizer `_", ":ref:`cn_api_fluid_optimizer_AdagradOptimizer`", "功能一致" - "128", "`tf.train.AdamOptimizer `_", ":ref:`cn_api_fluid_optimizer_Adam`", "功能一致" - "129", "`tf.train.exponential_decay `_", ":ref:`cn_api_fluid_layers_exponential_decay`", "功能一致" - "130", "`tf.train.GradientDescentOptimizer `_", ":ref:`cn_api_fluid_optimizer_SGDOptimizer`", "功能一致" - "131", "`tf.train.MomentumOptimizer `_", ":ref:`cn_api_fluid_optimizer_MomentumOptimizer`", "功能一致" - "132", "`tf.train.polynomial_decay `_", ":ref:`cn_api_fluid_layers_polynomial_decay`", "功能一致" - "133", "`tf.train.RMSPropOptimizer `_", ":ref:`cn_api_fluid_optimizer_RMSPropOptimizer`", "功能一致" - "134", "`tf.transpose `_", ":ref:`cn_api_fluid_layers_transpose`", "功能一致" - "135", "`tf.truediv `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" - "136", "`tf.truncated_normal `_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致" - "137", "`tf.truncated_normal_initializer `_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致" - "138", "`tf.unstack `_", ":ref:`cn_api_fluid_layers_unstack`", "功能一致" - "139", "`tf.Variable `_", ":ref:`cn_api_fluid_layers_create_parameter`", "功能一致" - "140", "`tf.while_loop `_", ":ref:`cn_api_fluid_layers_While`", "`差异对比 `_" - "141", "`tf.zeros `_", ":ref:`cn_api_fluid_layers_zeros`", "功能一致" - "142", "`tf.zeros_initializer `_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致" + "1", "`tf.abs `_", ":ref:`cn_api_fluid_layers_abs`", "功能一致" + "2", "`tf.add `_", ":ref:`cn_api_fluid_layers_elementwise_add`", "功能一致" + "3", "`tf.argmax `_", ":ref:`cn_api_fluid_layers_argmax`", "功能一致" + "4", "`tf.argmin `_", ":ref:`cn_api_fluid_layers_argmin`", "功能一致" + "5", "`tf.assign `_", ":ref:`cn_api_fluid_layers_assign`", "功能一致" + "6", "`tf.assign_add `_", ":ref:`cn_api_fluid_layers_increment`", "功能一致" + "7", "`tf.case `_", ":ref:`cn_api_fluid_layers_Switch`", "`差异对比 `_" + "8", "`tf.cast `_", ":ref:`cn_api_fluid_layers_cast`", "功能一致" + "9", "`tf.clip_by_global_norm `_", ":ref:`cn_api_fluid_clip_GradientClipByGlobalNorm`", "`差异对比 `_" + "10", "`tf.clip_by_norm `_", ":ref:`cn_api_fluid_layers_clip_by_norm`", "`差异对比 `_" + "11", "`tf.clip_by_value `_", ":ref:`cn_api_fluid_layers_clip`", "功能一致" + "12", "`tf.concat `_", ":ref:`cn_api_fluid_layers_concat`", "功能一致" + "13", "`tf.cond `_", ":ref:`cn_api_fluid_layers_ifElse`", "功能一致" + "14", "`tf.constant `_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致" + "15", "`tf.contrib.layers.batch_norm `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" + "16", "`tf.contrib.layers.flatten `_", ":ref:`cn_api_fluid_layers_flatten`", "`差异对比 `_" + "17", "`tf.contrib.layers.fully_connected `_", ":ref:`cn_api_fluid_layers_fc`", "功能一致" + "18", "`tf.contrib.layers.one_hot_encoding `_", ":ref:`cn_api_fluid_layers_one_hot`", "功能一致" + "19", "`tf.contrib.layers.softmax `_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致" + "20", "`tf.contrib.layers.xavier_initializer `_", ":ref:`cn_api_fluid_initializer_Xavier`", "功能一致" + "21", "`tf.nn.rnn.GRUCell `_", ":ref:`cn_api_fluid_layers_gru_unit`", "`差异对比 `_" + "22", "`tf.nn.rnn.MultiRNNCell `_", "无相应接口", "`Fluid实现 `_" + "23", "`tf.nn.rnn.static_rnn `_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "功能一致" + "24", "`tf.convert_to_tensor `_", ":ref:`cn_api_fluid_layers_assign`", "功能一致" + "25", "`tf.cos `_", ":ref:`cn_api_fluid_layers_cos`", "功能一致" + "26", "`tf.div `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" + "27", "`tf.divide `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" + "28", "`tf.dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "`差异对比 `_" + "29", "`tf.equal `_", "`运算符== `_", "功能一致" + "30", "`tf.exp `_", ":ref:`cn_api_fluid_layers_exp`", "功能一致" + "31", "`tf.expand_dims `_", ":ref:`cn_api_fluid_layers_unsqueeze`", "`差异对比 `_" + "32", "`tf.fill `_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致" + "33", "`tf.floor `_", ":ref:`cn_api_fluid_layers_floor`", "功能一致" + "34", "`tf.gather `_", ":ref:`cn_api_fluid_layers_gather`", "功能一致" + "35", "`tf.greater `_", "`运算符> `_", "功能一致" + "36", "`tf.greater_equal `_", "`运算符>= `_", "功能一致" + "37", "`tf.image.non_max_suppression `_", ":ref:`cn_api_fluid_layers_multiclass_nms`", "`差异对比 `_" + "38", "`tf.image.resize_bilinear `_", ":ref:`cn_api_fluid_layers_resize_bilinear`", "功能一致" + "39", "`tf.image.resize_images `_", ":ref:`cn_api_fluid_layers_image_resize`", "`差异对比 `_" + "40", "`tf.image.resize_nearest_neighbor `_", ":ref:`cn_api_fluid_layers_resize_nearest`", "功能一致" + "41", "`tf.is_finite `_", ":ref:`cn_api_fluid_layers_isfinite`", "`差异对比 `_" + "42", "`tf.layers.batch_normalization `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" + "43", "`tf.layers.conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" + "44", "`tf.layers.dense `_", ":ref:`cn_api_fluid_layers_fc`", "`差异对比 `_" + "45", "`tf.layers.dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致" + "46", "`tf.layers.Dropout `_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致" + "47", "`tf.layers.flatten `_", ":ref:`cn_api_fluid_layers_flatten`", "功能一致" + "48", "`tf.less `_", "`运算符< `_", "功能一致" + "49", "`tf.less_equal `_", "`运算符<= `_", "功能一致" + "50", "`tf.log `_", ":ref:`cn_api_fluid_layers_log`", "功能一致" + "51", "`tf.logical_and `_", ":ref:`cn_api_fluid_layers_logical_and`", "功能一致" + "52", "`tf.logical_not `_", ":ref:`cn_api_fluid_layers_logical_not`", "功能一致" + "53", "`tf.logical_or `_", ":ref:`cn_api_fluid_layers_logical_or`", "功能一致" + "54", "`tf.losses.mean_squared_error `_", ":ref:`cn_api_fluid_layers_square_error_cost`", "`差异对比 `_" + "55", "`tf.losses.sigmoid_cross_entropy `_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "`差异对比 `_" + "56", "`tf.losses.softmax_cross_entropy `_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "功能一致" + "57", "`tf.matmul `_", ":ref:`cn_api_fluid_layers_matmul`", "`差异对比 `_" + "58", "`tf.maximum `_", ":ref:`cn_api_fluid_layers_elementwise_max`", "功能一致" + "59", "`tf.metrics.accuracy `_", ":ref:`cn_api_fluid_layers_accuracy`", "功能一致" + "60", "`tf.metrics.mean `_", ":ref:`cn_api_fluid_layers_mean`", "功能一致" + "61", "`tf.minimum `_", ":ref:`cn_api_fluid_layers_elementwise_min`", "功能一致" + "62", "`tf.multiply `_", ":ref:`cn_api_fluid_layers_elementwise_mul`", "功能一致" + "63", "`tf.nn.avg_pool `_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 `_" + "64", "`tf.nn.batch_normalization `_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致" + "65", "`tf.nn.bidirectional_dynamic_rnn `_", "无相应接口", "`Fluid实现 `_" + "66", "`tf.nn.conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" + "67", "`tf.nn.conv2d_transpose `_", ":ref:`cn_api_fluid_layers_conv2d_transpose`", "`差异对比 `_" + "68", "`tf.nn.conv3d_transpose `_", ":ref:`cn_api_fluid_layers_conv3d_transpose`", "`差异对比 `_" + "69", "`tf.nn.depthwise_conv2d `_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 `_" + "70", "`tf.nn.dynamic_rnn `_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "`差异对比 `_" + "71", "`tf.nn.l2_normalize `_", ":ref:`cn_api_fluid_layers_l2_normalize`", "`差异对比 `_" + "72", "`tf.nn.leaky_relu `_", ":ref:`cn_api_fluid_layers_leaky_relu`", "功能一致" + "73", "`tf.nn.lrn `_", ":ref:`cn_api_fluid_layers_lrn`", "`差异对比 `_" + "74", "`tf.nn.max_pool `_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 `_" + "75", "`tf.nn.relu `_", ":ref:`cn_api_fluid_layers_relu`", "功能一致" + "76", "`tf.nn.relu6 `_", ":ref:`cn_api_fluid_layers_relu6`", "功能一致" + "77", "`tf.nn.rnn_cell.LSTMCell `_", ":ref:`cn_api_fluid_layers_lstm_unit`", "`差异对比 `_" + "78", "`tf.nn.separable_conv2d `_", "无相应接口", "`Fluid实现 `_" + "79", "`tf.nn.sigmoid `_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致" + "80", "`tf.nn.sigmoid_cross_entropy_with_logits `_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "功能一致" + "81", "`tf.nn.softmax `_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致" + "82", "`tf.nn.softmax_cross_entropy_with_logits `_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "`差异对比 `_" + "83", "`tf.nn.softplus `_", ":ref:`cn_api_fluid_layers_softplus`", "功能一致" + "84", "`tf.nn.softsign `_", ":ref:`cn_api_fluid_layers_softsign`", "功能一致" + "85", "`tf.nn.tanh `_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致" + "86", "`tf.one_hot `_", ":ref:`cn_api_fluid_layers_one_hot`", "`差异对比 `_" + "87", "`tf.ones `_", ":ref:`cn_api_fluid_layers_ones`", "功能一致" + "88", "`tf.intializers.ones `_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致" + "89", "`tf.pad `_", ":ref:`cn_api_fluid_layers_pad`", "`差异对比 `_" + "90", "`tf.placeholder `_", ":ref:`cn_api_fluid_layers_data`", "`差异对比 `_" + "91", "`tf.pow `_", ":ref:`cn_api_fluid_layers_pow`", "`差异对比 `_" + "92", "`tf.print `_", ":ref:`cn_api_fluid_layers_print`", "`差异对比 `_" + "93", "`tf.py_func `_", ":ref:`cn_api_fluid_layers_py_func`", "功能一致" + "94", "`tf.random_normal `_", ":ref:`cn_api_fluid_layers_gaussian_random`", "功能一致" + "95", "`tf.random_normal_initializer `_", ":ref:`cn_api_fluid_initializer_Normal`", "功能一致" + "96", "`tf.random_uniform `_", ":ref:`cn_api_fluid_layers_uniform_random`", "功能一致" + "97", "`tf.random_uniform_initializer `_", ":ref:`cn_api_fluid_initializer_UniformInitializer`", "功能一致" + "98", "`tf.reduce_logsumexp `_", "无相应接口", "`Fluid实现 `_" + "99", "`tf.reduce_max `_", ":ref:`cn_api_fluid_layers_reduce_max`", "功能一致" + "100", "`tf.reduce_mean `_", ":ref:`cn_api_fluid_layers_reduce_mean`", "功能一致" + "101", "`tf.reduce_min `_", ":ref:`cn_api_fluid_layers_reduce_min`", "功能一致" + "102", "`tf.reduce_sum `_", ":ref:`cn_api_fluid_layers_reduce_sum`", "功能一致" + "103", "`tf.reshape `_", ":ref:`cn_api_fluid_layers_reshape`", "`差异对比 `_" + "104", "`tf.reverse `_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致" + "105", "`tf.reverse_sequence `_", ":ref:`cn_api_fluid_layers_sequence_reverse`", "`差异对比 `_" + "106", "`tf.reverse_v2 `_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致" + "107", "`tf.round `_", ":ref:`cn_api_fluid_layers_round`", "功能一致" + "108", "`tf.rsqrt `_", ":ref:`cn_api_fluid_layers_rsqrt`", "功能一致" + "109", "`tf.scalar_mul `_", ":ref:`cn_api_fluid_layers_scale`", "功能一致" + "110", "`tf.scatter_update `_", ":ref:`cn_api_fluid_layers_scatter`", "`差异对比 `_" + "111", "`tf.sequence_mask `_", ":ref:`cn_api_fluid_layers_sequence_mask`", "功能一致" + "112", "`tf.shape `_", ":ref:`cn_api_fluid_layers_shape`", "功能一致" + "113", "`tf.sigmoid `_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致" + "114", "`tf.sin `_", ":ref:`cn_api_fluid_layers_sin`", "功能一致" + "115", "`tf.slice `_", ":ref:`cn_api_fluid_layers_slice`", "`差异对比 `_" + "116", "`tf.split `_", ":ref:`cn_api_fluid_layers_split`", "`差异对比 `_" + "117", "`tf.sqrt `_", ":ref:`cn_api_fluid_layers_sqrt`", "功能一致" + "118", "`tf.square `_", ":ref:`cn_api_fluid_layers_square`", "功能一致" + "119", "`tf.squared_difference `_", "无相应接口", "`Fluid实现 `_" + "120", "`tf.squeeze `_", ":ref:`cn_api_fluid_layers_squeeze`", "功能一致" + "121", "`tf.stack `_", ":ref:`cn_api_fluid_layers_stack`", "功能一致" + "122", "`tf.stop_gradient `_", "无相应接口", "`Fluid实现 `_" + "123", "`tf.subtract `_", ":ref:`cn_api_fluid_layers_elementwise_sub`", "功能一致" + "124", "`tf.tanh `_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致" + "125", "`tf.tile `_", ":ref:`cn_api_fluid_layers_expand`", "功能一致" + "126", "`tf.top_k `_", ":ref:`cn_api_fluid_layers_topk`", "`差异对比 `_" + "127", "`tf.train.AdagradOptimizer `_", ":ref:`cn_api_fluid_optimizer_AdagradOptimizer`", "功能一致" + "128", "`tf.train.AdamOptimizer `_", ":ref:`cn_api_fluid_optimizer_Adam`", "功能一致" + "129", "`tf.train.exponential_decay `_", ":ref:`cn_api_fluid_layers_exponential_decay`", "功能一致" + "130", "`tf.train.GradientDescentOptimizer `_", ":ref:`cn_api_fluid_optimizer_SGDOptimizer`", "功能一致" + "131", "`tf.train.MomentumOptimizer `_", ":ref:`cn_api_fluid_optimizer_MomentumOptimizer`", "功能一致" + "132", "`tf.train.polynomial_decay `_", ":ref:`cn_api_fluid_layers_polynomial_decay`", "功能一致" + "133", "`tf.train.RMSPropOptimizer `_", ":ref:`cn_api_fluid_optimizer_RMSPropOptimizer`", "功能一致" + "134", "`tf.transpose `_", ":ref:`cn_api_fluid_layers_transpose`", "功能一致" + "135", "`tf.truediv `_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致" + "136", "`tf.truncated_normal `_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致" + "137", "`tf.truncated_normal_initializer `_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致" + "138", "`tf.unstack `_", ":ref:`cn_api_fluid_layers_unstack`", "功能一致" + "139", "`tf.Variable `_", ":ref:`cn_api_fluid_layers_create_parameter`", "功能一致" + "140", "`tf.while_loop `_", ":ref:`cn_api_fluid_layers_While`", "`差异对比 `_" + "141", "`tf.zeros `_", ":ref:`cn_api_fluid_layers_zeros`", "功能一致" + "142", "`tf.zeros_initializer `_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致" + diff --git a/doc/fluid/beginners_guide/basic_concept/broadcasting.rst b/doc/fluid/beginners_guide/basic_concept/broadcasting.rst new file mode 100644 index 0000000000000000000000000000000000000000..9750bebe8d4750a72430148e2b77188ef4daa87d --- /dev/null +++ b/doc/fluid/beginners_guide/basic_concept/broadcasting.rst @@ -0,0 +1,99 @@ +.. _cn_user_guide_broadcasting: + +================== +广播 (broadcasting) +================== + +飞桨(PaddlePaddle,以下简称Paddle)和其他框架一样,提供的一些API支持广播(broadcasting)机制,允许在一些运算时使用不同形状的张量。 +通常来讲,如果有一个形状较小和一个形状较大的张量,我们希望多次使用较小的张量来对较大的张量执行一些操作,看起来像是较小形状的张量的形状首先被扩展到和较大形状的张量一致,然后做运算。 +值得注意的是,这期间并没有对较小形状张量的数据拷贝操作。 + +飞桨的广播机制主要遵循如下规则;如果两个张量的形状遵循一下规则,我们认为这两个张量是可广播的(参考`Numpy 广播机制 `): + +1. 每个张量至少为一维张量 +2. 从后往前比较张量的形状,当前维度的大小要么相等,要么其中一个等于一,要么其中一个不存在 + +例如: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + # 两个张量 形状一致,可以广播 + + x = paddle.imperative.to_variable(np.ones((2,3,1,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,4,1), np.float32)) + # 从后向前依次比较: + # 第一次:y的维度大小是1 + # 第二次:x的维度大小是1 + # 第三次:x和y的维度大小相等 + # 第四次:y的维度不存在 + # 所以 x和y是可以广播的 + + # 相反 + x = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((2,3,6), np.float32)) + # 此时x和y是不可广播的,因为第一次比较 4不等于6 + +现在我们知道什么情况下两个张量是可以广播的,两个张量进行广播语义后的结果张量的形状计算规则如下: + +1. 如果两个张量的形状的长度不一致,那么需要在较小形状长度的矩阵像前添加1,只到两个张量的形状长度相等。 +2. 保证两个张量形状相等之后,每个维度上的结果维度就是当前维度上较大的那个。 + +例如: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,1), np.float32)) + z = x+y + print(z.shape) + # z的形状: [2,3,4] + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,2), np.float32)) + z = x+y + print(z.shape) + # InvalidArgumentError: Broadcast dimension mismatch. + +除此之外,飞桨的elementwise系列API针对广播机制增加了axis参数,当使用较小形状的y来来匹配较大形状的x的时候,且满足y的形状的长度小于x的形状长度, +axis表示y在x上应用广播机制的时候的起始维度的位置,当设置了asis参数后,张量的维度比较顺序变成了从axis开始,从前向后比较。当axis=-1时,axis = rank(x) - rank(y), +同时y的大小为1的尾部维度将被忽略。 + +例如: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,1), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + # z的形状 [2, 3, 4] + + x = paddle.imperative.to_variable(np.ones((2,3,4,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((4,5), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + print(z.shape) + # InvalidArgumentError: Broadcast dimension mismatch. + # 因为指定了axis之后,计算广播的维度从axis开始从前向后比较 + + x = paddle.imperative.to_variable(np.ones((2,3,4,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((3), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + print(z.shape) + # z的形状 [2, 3, 4, 5] + # 因为此时是从axis=1的维度开始,从前向后比较维度进行广播 diff --git a/doc/fluid/beginners_guide/basic_concept/broadcasting_en.rst b/doc/fluid/beginners_guide/basic_concept/broadcasting_en.rst new file mode 100644 index 0000000000000000000000000000000000000000..d5cfc104e6fbad17f6f20b5c494e601390ee7718 --- /dev/null +++ b/doc/fluid/beginners_guide/basic_concept/broadcasting_en.rst @@ -0,0 +1,101 @@ +.. _user_guide_broadcasting + +================== +Broadcasting +================== + +PaddlePaddle provides broadcasting semantics in some APIs like other deep learning frameworks, which allows using tensors with different shapes while operating. +In General, broadcast is the rule how the smaller tensor is “broadcast” across the larger tsnsor so that they have same shapes. +Note that no copies happened while broadcasting. + +In Paddlepaddle, tensors are broadcastable when following rulrs hold(ref: Numpy Broadcasting `): + +1. there should be at least one dimention in each tensor +2. when we compare their shapes element-wise from backward to forward, two dimensions are compatible when +they are equal, or one of them is 1, or one of them does not exist. + +For example: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + # Two tensor have some shpes are broadcastable + + x = paddle.imperative.to_variable(np.ones((2,3,1,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,4,1), np.float32)) + # compare from backward to forward: + # 1st step:y's dimention is 1 + # 2nd step:x's dimention is 1 + # 3rd step:two dimentions are the same + # 4st step:y's dimention does not exist + # So, x and y are broadcastable + + # In Compare + x = paddle.imperative.to_variable(np.ones((2,3,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((2,3,6), np.float32)) + # x and y are not broadcastable because in first step form tail, x's dimention 4 is not equal to y's dimention 6 + +Now we know in what condition two tensors are broadcastable, how to calculate the resulting tensor's size follows the rules: + +1. If the number of dimensions of x and y are not equal, prepend 1 to the dimensions of the tensor with fewer dimensions to make them equal length. +2. Then, for each dimension size, the resulting dimension size is the max of the sizes of x and y along that dimension. + +For example: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,1), np.float32)) + z = x+y + print(z.shape) + # z'shape: [2,3,4] + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,2), np.float32)) + z = x+y + print(z.shape) + # InvalidArgumentError: Broadcast dimension mismatch. + +In addition, axis is introduced to PaddlePaddle's broadcasting semantics. when using smaller shape tensor y to broadcast a larger tensor x, +and y's length of dimentions is smaller than x's, we can specify a aixs to indicate the starting dimention to do broadcasting. +In this case, the comparation on dimentions runs from forward to backward started at axis. when axis=-1, axis = rank(x) - rank(y). +when the last dimention of y is 1, it will be ignored. + +For example: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.enable_imperative() + + x = paddle.imperative.to_variable(np.ones((2,1,4), np.float32)) + y = paddle.imperative.to_variable(np.ones((3,1), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + # z'shape [2, 3, 4] + + x = paddle.imperative.to_variable(np.ones((2,3,4,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((4,5), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + print(z.shape) + # InvalidArgumentError: Broadcast dimension mismatch. + # axis is indicated, comparation between dimentions starts at axis. + + x = paddle.imperative.to_variable(np.ones((2,3,4,5), np.float32)) + y = paddle.imperative.to_variable(np.ones((3), np.float32)) + z = paddle.elementwise_add(x,y,axis=1) + print(z.shape) + # z'shape [2, 3, 4, 5] + # Start comparation at axis=1 from forward to backward. diff --git a/doc/fluid/beginners_guide/basic_concept/index_cn.rst b/doc/fluid/beginners_guide/basic_concept/index_cn.rst index 19a97536d0c363a0488d15be22e1cc03664cfdf0..3f70df0caecfad6314f4d1b91018778d2da80d15 100644 --- a/doc/fluid/beginners_guide/basic_concept/index_cn.rst +++ b/doc/fluid/beginners_guide/basic_concept/index_cn.rst @@ -11,7 +11,7 @@ - `Operator `_ : Operator表示对数据的操作。 - `Program `_ : Program表示对计算过程的描述。 - `Executor `_ : Executor表示执行引擎。 - +- `Broadcasting `_ : Paddle对广播支持的说明。 .. toctree:: :hidden: @@ -22,4 +22,4 @@ operator.rst program.rst executor.rst - + broadcasting.rst diff --git a/doc/fluid/beginners_guide/basic_concept/index_en.rst b/doc/fluid/beginners_guide/basic_concept/index_en.rst index 8f8924576f6d9dec56dc3c78977e2bc024fcc8d4..7dea4c748aeb55fac24efca0b14f75d252288eb3 100644 --- a/doc/fluid/beginners_guide/basic_concept/index_en.rst +++ b/doc/fluid/beginners_guide/basic_concept/index_en.rst @@ -6,13 +6,13 @@ This paper introduces the basic concepts of Paddle: - `Guide to Fluid Programming <./programming_guide/programming_guide_en.html>`_ :introduces the basic concept and usage of Paddle. - `LoD-Tensor User Guide `_ : LoD-Tensor is a high-level feature of Paddle. It adds sequence information on the basis of tensor and supports processing variable length data. - +- `Broadcasting `_ : introduces Paddle provides broadcasting semantics. .. toctree:: :hidden: programming_guide/programming_guide_en.md lod_tensor_en.rst - + broadcasting_en.rst diff --git a/doc/fluid/beginners_guide/basic_concept/operator.rst b/doc/fluid/beginners_guide/basic_concept/operator.rst index 2d7199380429d5fc482ffcd6178a38e0a221d051..cdb567a085ebffd189925fe88921e0c7e7ae041e 100644 --- a/doc/fluid/beginners_guide/basic_concept/operator.rst +++ b/doc/fluid/beginners_guide/basic_concept/operator.rst @@ -1,8 +1,8 @@ .. _cn_user_guide_Operator: -======= +========= Operator -======= +========= 在飞桨(PaddlePaddle,以下简称Paddle)中,所有对数据的操作都由Operator表示 diff --git a/doc/fluid/install/compile/compile_CentOS.md b/doc/fluid/install/compile/compile_CentOS.md index 74b8a05f7ff2232dec6a3879f8e96a58c83b16fa..d9a434e79fd30c2b9ad6677322a14d010d81132c 100644 --- a/doc/fluid/install/compile/compile_CentOS.md +++ b/doc/fluid/install/compile/compile_CentOS.md @@ -25,7 +25,6 @@ wget http://developer.download.nvidia.com/compute/machine-learning/repos/rhel7/x86_64/nvidia-machine-learning-repo-rhel7-1.0.0-1.x86_64.rpm rpm -i nvidia-machine-learning-repo-rhel7-1.0.0-1.x86_64.rpm - sudo apt-get install -y libnccl2=2.3.7-1+cuda9.0 libnccl-dev=2.3.7-1+cuda9.0 yum update -y yum install -y libnccl-2.3.7-2+cuda9.0 libnccl-devel-2.3.7-2+cuda9.0 libnccl-static-2.3.7-2+cuda9.0 @@ -89,7 +88,7 @@ > -it 与宿主机保持交互状态,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` 使用名为`hub.baidubce.com/paddlepaddle/paddle:latest-dev`的镜像创建Docker容器,/bin/bash 进入容器后启动/bin/bash命令。 - > 注意:hub.baidubce.com/paddlepaddle/paddle:latest-dev内部安装CUDA 8.0。 + > 注意:hub.baidubce.com/paddlepaddle/paddle:latest-dev内部安装CUDA 10.0。 4. 进入Docker后进入paddle目录下: @@ -119,7 +118,7 @@ > 安装protobuf。 - `apt install patchelf` + `yum install patchelf` > 安装patchelf,PatchELF 是一个小而实用的程序,用于修改ELF可执行文件的动态链接器和RPATH。 @@ -153,7 +152,7 @@ 恭喜,至此您已完成PaddlePaddle的编译安装。您只需要进入Docker容器后运行PaddlePaddle,即可开始使用。更多Docker使用请参见[Docker官方文档](https://docs.docker.com) -> 注:PaddlePaddle Docker镜像为了减小体积,默认没有安装`vim`,您可以在容器中执行 `apt-get install -y vim` 来安装 +> 注:PaddlePaddle Docker镜像为了减小体积,默认没有安装`vim`,您可以在容器中执行 `yum install -y vim` 来安装 ### **本机编译** @@ -206,7 +205,7 @@ * 这里特别提供`patchELF`的安装方法,其他的依赖可以使用`yum install`或者`pip install`/`pip3 install` 后跟依赖名称和版本安装: `yum install patchelf` - > 不能使用apt安装的用户请参见patchElF github[官方文档](https://gist.github.com/ruario/80fefd174b3395d34c14) + > 不能使用yum安装的用户请参见patchElF github[官方文档](https://gist.github.com/ruario/80fefd174b3395d34c14) 7. 将PaddlePaddle的源码clone在当下目录下的Paddle的文件夹中,并进入Padde目录下: diff --git a/doc/fluid/install/compile/compile_CentOS_en.md b/doc/fluid/install/compile/compile_CentOS_en.md index 81220c6ef342ae09c7ba084b285c8cb1756bf218..1d92dc4a472546728ee1a802c5451193c9ab66fa 100644 --- a/doc/fluid/install/compile/compile_CentOS_en.md +++ b/doc/fluid/install/compile/compile_CentOS_en.md @@ -25,7 +25,6 @@ wget http://developer.download.nvidia.com/compute/machine-learning/repos/rhel7/x86_64/nvidia-machine-learning-repo-rhel7-1.0.0-1.x86_64.rpm rpm -i nvidia-machine-learning-repo-rhel7-1.0.0-1.x86_64.rpm - sudo apt-get install -y libnccl2=2.3.7-1+cuda9.0 libnccl-dev=2.3.7-1+cuda9.0 yum update -y yum install -y libnccl-2.3.7-2+cuda9.0 libnccl-devel-2.3.7-2+cuda9.0 libnccl-static-2.3.7-2+cuda9.0 @@ -90,7 +89,7 @@ Please follow the steps below to install: > -it keeps interaction with the host,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` use the image named `hub.baidubce.com/paddlepaddle/paddle:latest-dev` to create Docker container, /bin/bash start the /bin/bash command after entering the container. - > Note: hub.baidubce.com/paddlepaddle/paddle:latest-dev internally install CUDA 8.0. + > Note: hub.baidubce.com/paddlepaddle/paddle:latest-dev internally install CUDA 10.0. 4. After entering Docker, go to the paddle directory: `cd paddle` @@ -109,7 +108,7 @@ Please follow the steps below to install: `mkdir -p /paddle/build && cd /paddle/build` -7. Use the following command to install the dependencies: +7. Use the following command to install the dependencies: For Python2: pip install protobuf @@ -119,7 +118,7 @@ Please follow the steps below to install: > Install protobuf 3.1.0 - `apt install patchelf` + `yum install patchelf` > Installing patchelf, PatchELF is a small and useful program for modifying the dynamic linker and RPATH of ELF executables. @@ -145,7 +144,7 @@ Please follow the steps below to install: 10. After compiling successfully, go to the `/paddle/build/python/dist` directory and find the generated `.whl` package: `cd /paddle/build/python/dist` -11. Install the compiled `.whl` package on the current machine or target machine: +11. Install the compiled `.whl` package on the current machine or target machine: For Python2: pip install -U (whl package name) For Python3: pip3.5 install -U (whl package name) @@ -154,7 +153,7 @@ Please follow the steps below to install: Congratulations, now that you have successfully installed PaddlePaddle using Docker, you only need to run PaddlePaddle after entering the Docker container. For more Docker usage, please refer to the [official Docker documentation](https://docs.docker.com/). -> Note: In order to reduce the size, `vim` is not installed in PaddlePaddle Docker image by default. You can edit the code in the container after executing `apt-get install -y vim` in the container. +> Note: In order to reduce the size, `vim` is not installed in PaddlePaddle Docker image by default. You can edit the code in the container after executing `yum install -y vim` in the container. ### **Local compilation** @@ -215,7 +214,7 @@ Congratulations, now that you have successfully installed PaddlePaddle using Doc * Here is the installation method for `patchELF`. Other dependencies can be installed using `yum install` or `pip install`/`pip3 install` followed by the name and version: `yum install patchelf` - > Users who can't use apt installation can refer to patchElF github [official documentation](https://gist.github.com/ruario/80fefd174b3395d34c14). + > Users who can't use yum installation can refer to patchElF github [official documentation](https://gist.github.com/ruario/80fefd174b3395d34c14). 7. Put the PaddlePaddle source cloned in the Paddle folder in the current directory and go to the Paddle directory: diff --git a/doc/fluid/install/compile/compile_Ubuntu.md b/doc/fluid/install/compile/compile_Ubuntu.md index 74954df2a1db1f79cc64643aeaa08c8dc64c8f0e..9feea65fd3fdf394ad00eff5436f6a9e65711b60 100644 --- a/doc/fluid/install/compile/compile_Ubuntu.md +++ b/doc/fluid/install/compile/compile_Ubuntu.md @@ -86,7 +86,7 @@ > -it 与宿主机保持交互状态,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` 使用名为`hub.baidubce.com/paddlepaddle/paddle:latest-dev`的镜像创建Docker容器,/bin/bash 进入容器后启动/bin/bash命令。 - > 注意:hub.baidubce.com/paddlepaddle/paddle:latest-dev内部安装CUDA 8.0。 + > 注意:hub.baidubce.com/paddlepaddle/paddle:latest-dev内部安装CUDA 10.0。 4. 进入Docker后进入paddle目录下: diff --git a/doc/fluid/install/compile/compile_Ubuntu_en.md b/doc/fluid/install/compile/compile_Ubuntu_en.md index d8104a3af529e12a47d939462300ae25c891fc09..9a1faf3a577acdbfebb99a69ad4cf4507ff3c9ec 100644 --- a/doc/fluid/install/compile/compile_Ubuntu_en.md +++ b/doc/fluid/install/compile/compile_Ubuntu_en.md @@ -86,7 +86,7 @@ Please follow the steps below to install: > -it keeps interaction with the host,`hub.baidubce.com/paddlepaddle/paddle:latest-dev` use the image named `hub.baidubce.com/paddlepaddle/paddle:latest-dev` to create Docker container, /bin/bash start the /bin/bash command after entering the container. - > Note: hub.baidubce.com/paddlepaddle/paddle:latest-dev internally install CUDA 8.0. + > Note: hub.baidubce.com/paddlepaddle/paddle:latest-dev internally install CUDA 10.0. 4. After entering Docker, enter the Paddle Directory: @@ -169,7 +169,7 @@ Congratulations, now you have completed the compilation and installation of Padd For Python2: apt install python-dev For Python3: apt install python3.5-dev - * b. Install pip: (Please ensure that pip version is 9.0.1 and above ): + * b. Install pip: (Please ensure that pip version is 9.0.1 and above ): For Python2: apt install python-pip For Python3: apt-get udpate && apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && apt install curl && curl https://bootstrap.pypa.io/get-pip. Py -o - | python3.5 && easy_install pip diff --git a/doc/templates/common_docs.py b/doc/templates/common_docs.py new file mode 100644 index 0000000000000000000000000000000000000000..a6476150d69dc1a965575fb4e8fce697644424d3 --- /dev/null +++ b/doc/templates/common_docs.py @@ -0,0 +1,70 @@ +# +# Some common descriptions used in Paddle API docs +# You can copy the wordings here if that is suitable to your scenario. +# + +common_args_en = """ + x (Tensor): The input tensor, it's data type should be float32, float64, int32, int64. + y (Tensor): The input tensor, it's data type should be float32, float64, int32, int64. + name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. + dtype (str, optional): The data type of the output tensor, can be float32, float64, int32, int64. + param_attr (ParamAttr, optional): The parameter attribute for learnable weights(Parameter) of this layer. For more information, please refer to :ref:`api_fluid_ParamAttr`. + bias_attr (ParamAttr, optional): The parameter attribute for learnable bias(Bias) of this layer. For more information, please refer to :ref:`api_fluid_ParamAttr`. + label (Tensor): The label value corresponding to input, it's data type should be int32, int64. + learning_rate (Tensor|float): The learning rate, can be a Tensor or a float value. Default is 1e-03. + axis (int, optional): The axis along which to operate. Default is 0. + epsilon (float, optional): Small float added to denominator to avoid dividing by zero. Default is 1e-05. + is_test (bool, optional): A flag indicating whether execution is in test phase. Default is False, means not in test phase. + shape (Tensor|tuple|list): Shape of the Tensor. If shape is a list or tuple, the elements of it should be integers or Tensors with shape [1]. If shape is Tensor, it should be an 1-D Tensor . + keep_dim (bool): Whether to reserve the reduced dimension in the output Tensor. The result tensor will have one fewer dimension than the input unless keep_dim is true. Default is False. + filter_size (tuple|list|int): The size of convolving kernel. It can be a single integer or a tuple/list containing two integers, representing the height and width of the convolution window respectively. If it is a single integer, the height and width are equal to the integer. + padding (tuple|int): The padding size. It can be a single integer or a tuple containing two integers, representing the size of padding added to the height and width of the input. If it is a single integer, the both sides of padding are equal to the integer. Default is 0. + include_sublayers (bool, optional): Whether include the sublayers. If True, return list includes the sublayers weights. Default is True. + stride (tuple|int): The stride size. It can be a single integer or a tuple containing two integers, representing the strides of the convolution along the height and width. If it is a single integer, the height and width are equal to the integer. Default is 1. + groups (int, optional): The group number of convolution layer. When group=n, the input and convolution kernels are divided into n groups equally, the first group of convolution kernels and the first group of inputs are subjected to convolution calculation, the second group of convolution kernels and the second group of inputs are subjected to convolution calculation, ……, the nth group of convolution kernels and the nth group of inputs perform convolution calculations. Default is 1. + regularization (WeightDecayRegularizer, optional): The strategy of regularization. There are two method: :ref:`api_fluid_regularizer_L1Decay` 、 :ref:`api_fluid_regularizer_L2Decay` . If a parameter has set regularizer using :ref:`api_fluid_ParamAttr` already, the regularization setting here in optimizer will be ignored for this parameter. Otherwise, the regularization setting here in optimizer will take effect. Default None, meaning there is no regularization. + grad_clip (GradientClipBase, optional): Gradient cliping strategy, it's an instance of some derived class of ``GradientClipBase`` . There are three cliping strategies ( :ref:`api_fluid_clip_GradientClipByGlobalNorm` , :ref:`api_fluid_clip_GradientClipByNorm` , :ref:`api_fluid_clip_GradientClipByValue` ). Default None, meaning there is no gradient clipping. + dilation (tuple|int): The dilation size. It can be a single integer or a tuple containing two integers, representing the height and width of dilation of the convolution kernel elements. If it is a single integer,the height and width of dilation are equal to the integer. Default is 1. + stop_gradient (bool, optional): A boolean that mentions whether gradient should flow. Default is True, means stop calculate gradients. + force_cpu (bool, optional): Whether force to store the output tensor in CPU memory. If force_cpu is False, the output tensor will be stored in running device memory, otherwise it will be stored to the CPU memory. Default is False. + data_format (str, optional): Specify the input data format, the output data format will be consistent with the input, which can be "NCHW" or "NHWC". N is batch size, C is channels, H is height, and W is width. Default is "NCHW". + grad_clip (GradientClipBase, optional): Gradient cliping strategy, it's an instance of some derived class of ``GradientClipBase`` . There are three cliping strategies ( :ref:`api_fluid_clip_GradientClipByGlobalNorm` , :ref:`api_fluid_clip_GradientClipByNorm` , :ref:`api_fluid_clip_GradientClipByValue` ). Default is None, meaning there is no gradient clipping. + num_filters (int): The number of filter. It is as same as the output channals numbers. + dim (int, optional): A dimension along which to operate. Default is 0. + is_sparse (bool, optional): Whether use sparse updating. For more information, please refer to :ref:`api_guide_sparse_update_en` . If it’s True, it will ues sparse updating. + place (fluid.CPUPlace()|fluid.CUDAPlace(N)|None): This parameter represents which device the executor runs on, and N means the GPU's id. When this parameter is None, PaddlePaddle will set the default device according to its installation version. If Paddle is CPU version, the default device would be set to CPUPlace(). If Paddle is GPU version, the default device would be set to CUDAPlace(0). Default is None. + num_filters (int): the number of convolution kernels, is also the number of output channels. +""" + +common_args_cn = """ + x (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64、int32、int64。 + y (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64、int32、int64。 + name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 + dtype (str,可选) - 输出 `Tensor` 的数据类型,支持int32、int64、float32、float64。 + param_attr (ParamAttr,可选) – 该Layer的可学习的权重(Parameter)的参数属性。更多信息请参见 :ref:`cn_api_fluid_ParamAttr`。 + bias_attr (ParamAttr,可选) - 该Layer的可学习的偏置(Bias)的参数属性。更多信息请参见 :ref:`cn_api_fluid_ParamAttr`。 + label (Tensor) - 训练数据的标签,数据类型为:int32, int64。 + learning_rate (Tensor|float) - 学习率,可以是一个 `Tensor` 或者是一个浮点数。默认值为1e-03. + axis (int,可选) - 指定对输入 `Tensor` 进行运算的轴。默认值为0。 + epsilon (float,可选) - 添加到分母上的值以防止分母除0。默认值为1e-05。 + is_test (bool,可选) - 用于表明是否在测试阶段执行。默认值为False,表示非测试阶段。 + shape (Tensor|tuple|list) - `Tensor` 的形状。如果 `shape` 是一个列表或元组,则其元素应该是形状为[1]的整数或 `Tensor` 。 如果 `shape` 是 `Tensor` ,则它应该是1-D `Tensor`。 + keep_dim (bool) - 是否在输出 `Tensor` 中保留减小的维度。如 `keep_dim` 为True,否则结果张量的维度将比输入张量小,默认值为False。 + filter_size (tuple|list|int) - 卷积核大小。可以为单个整数或包含两个整数的元组或列表,分别表示卷积核的高和宽。如果为单个整数,表示卷积核的高和宽都等于该整数。 + padding (tuple|int) – 填充大小。可以为单个整数或包含两个整数的元组,分别表示对输入高和宽两侧填充的大小。如果为单个整数,表示高和宽的填充都等于该整数。默认值为0。 + include_sublayers (bool,可选) - 是否返回子层的参数。如果为True,返回的列表中包含子层的参数。默认值为True。 + stride (tuple|int) - 步长大小。可以为单个整数或包含两个整数的元组,分别表示卷积沿着高和宽的步长。如果为单个整数,表示沿着高和宽的步长都等于该整数。默认值为1。 + groups (int,可选) - 卷积的组数。当group=n,输入和卷积核分别平均分为n组,第一组卷积核和第一组输入进行卷积计算,第二组卷积核和第二组输入进行卷积计算,……,第n组卷积核和第n组输入进行卷积计算。默认值为11。 + regularization (WeightDecayRegularizer,可选) - 正则化方法。支持两种正则化策略: :ref:`cn_api_fluid_regularizer_L1Decay` 、 :ref:`cn_api_fluid_regularizer_L2Decay` 。如果一个参数已经在 :ref:`cn_api_fluid_ParamAttr` 中设置了正则化,这里的正则化设置将被忽略;如果没有在 :ref:`cn_api_fluid_ParamAttr` 中设置正则化,这里的设置才会生效。默认值为None,表示没有正则化。 + grad_clip (GradientClipBase,可选) – 梯度裁剪的策略,支持三种裁剪策略: :ref:`cn_api_fluid_clip_GradientClipByGlobalNorm` 、 :ref:`cn_api_fluid_clip_GradientClipByNorm` 、 :ref:`cn_api_fluid_clip_GradientClipByValue` 。 + dilation (tuple|int,可选) - 空洞大小。可以为单个整数或包含两个整数的元组,分别表示卷积核中的元素沿着高和宽的空洞。如果为单个整数,表示高和宽的空洞都等于该整数。默认值为1。 + stop_gradient (bool,可选) - 提示是否应该停止计算梯度,默认值为True,表示停止计算梯度。 + force_cpu (bool,可选) - 是否强制将输出Tensor写入CPU内存。如果为False,则将输出Tensor写入当前所在运算设备的内存,否则写入CPU内存中。默认为False。 + data_format (str,可选) - 指定输入的数据格式,输出的数据格式将与输入保持一致,可以是"NCHW"和"NHWC"。N是批大小,C是通道数,H是高度,W是宽度。默认值为"NCHW"。 + grad_clip (GradientClipBase,可选) – 梯度裁剪的策略,支持三种裁剪策略: :ref:`cn_api_fluid_clip_GradientClipByGlobalNorm` 、 :ref:`cn_api_fluid_clip_GradientClipByNorm` 、 :ref:`cn_api_fluid_clip_GradientClipByValue` 。默认值为None,表示不使用梯度裁剪。 + num_filters (int) - 卷积核的个数,与输出的通道数相同。 + dim (int,可选) - 指定对输入Tensor进行运算的维度。默认值为0。 + is_sparse (bool,可选) - 是否使用稀疏更新的方式,更多信息请参见 :ref:`api_guide_sparse_update` 。默认值为True,表示使用稀疏更新的方式。 + place (fluid.CPUPlace()|fluid.CUDAPlace(N)|None) – 该参数表示Executor执行所在的设备,这里的N为GPU对应的ID。当该参数为None时,PaddlePaddle会根据其安装版本来设置默认设备。当PaddlePaddle是CPU版时,默认运行设备将会设置为 `fluid.CPUPlace()` ;当PaddlePaddle是GPU版本时,默认执行设备将会设置为 `fluid.CUDAPlace(0)` 。默认值为None。 + num_filters (int) - 卷积核个数,同时也是输出的通道数。 +""" diff --git a/gen_index.py b/gen_index.py new file mode 100644 index 0000000000000000000000000000000000000000..e2817e3ab06c62700676813fd15effa086ceda40 --- /dev/null +++ b/gen_index.py @@ -0,0 +1,72 @@ +import argparse +import sys +import types +import os +import contextlib + + +def parse_arg(): + parser = argparse.ArgumentParser() + parser.add_argument( + '--api_path', + type=str, + default='paddle.nn.functional.l1_loss', + help='the function/class path') + parser.add_argument( + '--is_class', + type=str, + default='False', + help='whether function or class, False means function') + return parser.parse_args() + + +def add_index(en_doc_review_dir, api_name): + + stream = open(en_doc_review_dir + '.rst', 'a') + stream.write(' review_tmp/' + api_name + '.rst\n') + stream.close() + print('add index to ' + en_doc_review_dir + '.rst success') + + +def add_file(en_doc_review_dir, api_path, is_class=False): + + api_path_list = api_path.split('.') + api_name = api_path_list[-1] + api_title = '_'.join(api_path_list[1:]) + + stream = open(en_doc_review_dir + '/' + api_name + '.rst', 'w') + stream.write('.. _api_' + api_title + ':\n') + stream.write('\n') + stream.write(api_name + '\n') + for i in range(max(9, len(api_name))): + stream.write('-') + stream.write('\n') + stream.write('\n') + + if is_class == 'True': + stream.write('.. autoclass:: ' + api_path + '\n') + stream.write(' :members:\n') + stream.write(' :inherited-members:\n') + else: + stream.write('.. autofunction:: ' + api_path + '\n') + + stream.write(' :noindex:\n') + stream.close() + print('add' + en_doc_review_dir + '/' + api_name + '.rst success') + + +def main(): + args = parse_arg() + api_path = args.api_path + is_class = args.is_class + api_name = api_path.split('.')[-1] + + fluid_doc_path = os.getcwd() + en_doc_review_dir = fluid_doc_path + '/doc/fluid/api/review_tmp' + + add_index(en_doc_review_dir, api_name) + add_file(en_doc_review_dir, api_path, is_class) + + +if __name__ == '__main__': + main() diff --git a/scripts/check_api_cn.sh b/scripts/check_api_cn.sh index a986d39469024293436395fa681e239a680c79b1..5d7dfe193edfea07864e78e5ba8c089d5c8a5591 100644 --- a/scripts/check_api_cn.sh +++ b/scripts/check_api_cn.sh @@ -13,7 +13,9 @@ else pip install -U python/dist/paddlepaddle_gpu-0.0.0-cp27-cp27mu-linux_x86_64.whl fi + for files in `echo $git_files`;do + cd /FluidDoc grep "code-block" $files if [ $? -eq 0 ] ;then echo $files|grep 'doc/fluid/api_cn/.*/.*.rst'