提交 fc7da52f 编写于 作者: S sandyhouse

Merge branch 'develop' of https://github.com/PaddlePaddle/FluidDoc into develop

# 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 <dir_1, dir_2, ... , dir_n> --host <host> --port <port>
visualdl --logdir <dir_1, dir_2, ... , dir_n> --host <host> --port <port> --cache-timeout <cache_timeout> --language <language> --public-path <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://&lt;host&gt;:&lt;port&gt;/app' |
| --api-only | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/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://<host>:<port>/app' |
| api_only | boolean | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://<host>:<port>/<public_path>/api';若没有设置public_path参数,则默认为http://<host>:<port>/api' |
| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板,若设置api_only,则忽略此参数 |
针对上一步生成的日志,我们的启动脚本为:
......@@ -155,7 +186,7 @@ app.run(logdir="./log")
在使用任意一种方式启动VisualDL面板后,打开浏览器访问VisualDL面板,即可查看日志的可视化结果,如图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/3points_demo.png" width="60%"/>
<img src="https://user-images.githubusercontent.com/48054808/82786044-67ae9880-9e96-11ea-8a2b-3a0951a6ec19.png" width="60%"/>
</p>
......@@ -163,27 +194,31 @@ app.run(logdir="./log")
## 可视化功能概览
### Scalar
以图表形式实时展示训练过程参数,如loss、accuracy。让用户通过观察单组或多组训练参数变化,了解训练过程,加速模型调优。具有两大特点:
#### 动态展示
在启动VisualDL Board后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图:
在启动VisualDL后,LogReader将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/dynamic_display.gif" width="60%"/>
</p>
#### 多实验对比
只需在启动VisualDL Board的时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图:
只需在启动VisualDL时将每个实验日志所在路径同时传入即可,每个实验中相同tag的指标将绘制在一张图中同步呈现,如下图:
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/multi_experiments.gif" width="100%"/>
</p>
### Image
实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。
<p align="center">
......@@ -191,6 +226,56 @@ app.run(logdir="./log")
</p>
### Audio
实时查看训练过程中的音频数据,监控语音识别与合成等任务的训练过程。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/89017647-38605000-d34d-11ea-9d75-7d10b9854c36.gif" width="100%"/>
</p>
### Graph
一键可视化模型的网络结构。可查看模型属性、节点信息、节点输入输出等,并支持节点搜索,辅助用户快速分析模型结构与了解数据流向。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84483052-5acdd980-accb-11ea-8519-1608da7ee698.png" width="100%"/>
</p>
### Histogram
以直方图形式展示Tensor(weight、bias、gradient等)数据在训练过程中的变化趋势。深入了解模型各层效果,帮助开发者精准调整模型结构。
- Offset模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86551031-86647c80-bf76-11ea-8ec2-8c86826c8137.png" width="100%"/>
</p>
- Overlay模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86551033-882e4000-bf76-11ea-8e6a-af954c662ced.png" width="100%"/>
</p>
### PR Curve
精度-召回率曲线,帮助开发者权衡模型精度和召回率之间的平衡,设定最佳阈值。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86738774-ee46c000-c067-11ea-90d2-a98aac445cca.png" width="100%"/>
</p>
### 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进行讨论与交流。
# VisualDL 使用指南
### 概述
VisualDL 是一个面向深度学习任务设计的可视化工具。VisualDL 利用了丰富的图表来展示数据,用户可以更直观、清晰地查看数据的特征与变化趋势,有助于分析数据、及时发现错误,进而改进神经网络模型的设计。
目前,VisualDL 支持 scalar, image, high dimensional 三个组件,项目正处于高速迭代中,敬请期待新组件的加入。
| 组件名称 | 展示图表 | 作用 |
| :----------------------------------------------------------: | :--------: | :----------------------------------------------------------- |
| <a href="#1">[ Scalar](#Scalar -- 折线图组件)</a> | 折线图 | 动态展示损失函数值、准确率等标量数据 |
| <a href="#3">[Image](#Image -- 图片可视化组件)</a> | 图片可视化 | 显示图片,可显示输入图片和处理后的结果,便于查看中间过程的变化 |
| <a href="#6">[High Dimensional](#High Dimensional -- 数据降维组件)</a> | 数据降维 | 将高维数据映射到 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`,即可查看以下折线图。
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/scalar-globalstatic.png" width="100%"/>
<img src="https://user-images.githubusercontent.com/48054808/82397559-478c6d00-9a83-11ea-80db-a0844dcaca35.png" width="100%"/>
</p>
- 多组实验对比
下面展示了使用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。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84644158-5efb3080-af31-11ea-8e64-bbe4078425f4.png" width="100%"/>
</p>
*多组实验对比的应用案例可参考AI Studio项目:[VisualDL 2.0--眼疾识别训练可视化](https://aistudio.baidu.com/aistudio/projectdetail/502834)
### 功能操作说明
* 支持数据卡片「最大化」、「还原」、「坐标系转化」(y轴对数坐标)、「下载」折线图
......@@ -75,6 +130,8 @@ visualdl --logdir ./log --port 8080
* 数据点Hover展示详细信息
<p align="center">
......@@ -83,6 +140,8 @@ visualdl --logdir ./log --port 8080
* 可搜索卡片标签,展示目标图像
<p align="center">
......@@ -91,6 +150,8 @@ visualdl --logdir ./log --port 8080
* 可搜索打点数据标签,展示特定数据
<p align="center">
......@@ -98,6 +159,8 @@ visualdl --logdir ./log --port 8080
</p>
* X轴有三种衡量尺度
1. Step:迭代次数
......@@ -107,6 +170,8 @@ visualdl --logdir ./log --port 8080
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/x-axis.png" width="40%"/>
</p>
* 可调整曲线平滑度,以便更好的展现参数整体的变化趋势
<p align="center">
......@@ -114,6 +179,8 @@ visualdl --logdir ./log --port 8080
</p>
## 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`,即可查看图片数据。
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/image-static.png" width="90%"/>
<img src="http://visualdl.bj.bcebos.com/images/image-static.png" width="100%"/>
</p>
### 功能操作说明
可搜索图片标签显示对应图片数据
......@@ -184,6 +259,8 @@ visualdl --logdir ./log --port 8080
</p>
支持滑动Step/迭代次数查看不同迭代次数下的图片数据
<p align="center">
......@@ -191,6 +268,442 @@ visualdl --logdir ./log --port 8080
</p>
## 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`,即可查看音频数据。
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87659138-b4746880-c78f-11ea-965b-c33804e7c296.png" width="100%"/>
</p>
### 功能操作说明
- 可搜索音频标签显示对应音频数据
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87661431-29956d00-c793-11ea-833b-172d8fc1b221.png" width="100%"/>
</p>
- 支持滑动Step/迭代次数试听不同迭代次数下的音频数据
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87661089-a07e3600-c792-11ea-8740-cbe99a64d830.png" width="60%"/>
</p>
- 支持播放/暂停音频数据
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87661130-b3910600-c792-11ea-9f9f-2ae66132e9de.png" width="60%"/>
</p>
- 支持音量调节
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87661497-49c52c00-c793-11ea-9eeb-471543cd2a0b.png" width="60%"/>
</p>
- 支持音频下载
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/87661166-c277b880-c792-11ea-8ad7-5c60bb08379b.png" width="60%"/>
</p>
## Graph--网络结构组件
### 介绍
Graph组件一键可视化模型的网络结构。用于查看模型属性、节点信息、节点输入输出等,并进行节点搜索,协助开发者们快速分析模型结构与了解数据流向。
### Demo
共有两种启动方式:
- 前端模型文件拖拽上传:
- 如只需使用Graph组件,则无需添加任何参数,在命令行执行`visualdl`后即可启动面板进行上传。
- 如果同时需使用其他功能,在命令行指定日志文件路径(以`./log`为例)即可启动面板进行上传:
```shell
visualdl --logdir ./log --port 8080
```
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487396-44c31780-acd1-11ea-831a-1632e636613d.png" width="80%"/>
</p>
- 后端启动Graph:
- 在命令行加入参数`--model`并指定**模型文件**路径(非文件夹路径),即可启动并查看网络结构可视化:
```shell
visualdl --model ./log/model --port 8080
```
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84490149-51e20580-acd5-11ea-9663-1f156892c0e0.png" width="100%"/>
</p>
### 功能操作说明
- 一键上传模型
- 支持模型格式: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
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487396-44c31780-acd1-11ea-831a-1632e636613d.png" width="80%"/>
</p>
- 支持上下左右任意拖拽模型、放大和缩小模型
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/89163601-6ab9b980-d5a8-11ea-9c6d-2dc5eaed0d41.gif" width="100%"/>
</p>
- 搜索定位到对应节点
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487694-b9965180-acd1-11ea-8214-34f3febc1828.png" width="30%"/>
</p>
- 点击查看模型属性
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487751-cadf5e00-acd1-11ea-9ce2-4fdfeeea9c5a.png" width="30%"/>
</p>
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487759-d03ca880-acd1-11ea-9294-520ef7f9e0b1.png" width="30%"/>
</p>
- 支持选择模型展示的信息
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487829-ee0a0d80-acd1-11ea-8563-6682a15483d9.png" width="23%"/>
</p>
- 支持以PNG、SVG格式导出模型结构图
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487884-ff531a00-acd1-11ea-8b12-5221db78683e.png" width="30%"/>
</p>
- 点击节点即可展示对应属性信息
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487941-13971700-acd2-11ea-937d-42fb524b9ee1.png" width="30%"/>
</p>
- 支持一键更换模型
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/84487998-27db1400-acd2-11ea-83d7-5d75832ef41d.png" width="25%"/>
</p>
## 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`,即可查看训练参数直方图。
### 功能操作说明
- 支持数据卡片「最大化」、直方图「下载」
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86535351-42d82700-bf12-11ea-89f0-171280e7c526.png" width="60%"/>
</p>
- 可选择Offset或Overlay模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86535413-c134c900-bf12-11ea-9ad6-f0ad8eafa76f.png" width="30%"/>
</p>
- Offset模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86536435-2b9d3780-bf1a-11ea-9981-92f837d22ae5.png" width="60%"/>
</p>
- Overlay模式
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86536458-5ab3a900-bf1a-11ea-985e-05f06c1b762b.png" width="60%"/>
</p>
- 数据点Hover展示参数值、训练步数、频次
- 在第240次训练步数时,权重为-0.0031,且出现的频次是2734次
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86536482-80d94900-bf1a-11ea-9e12-5bea9f382b34.png" width="60%"/>
</p>
- 可搜索卡片标签,展示目标直方图
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86536503-baaa4f80-bf1a-11ea-80ab-cd988617d018.png" width="30%"/>
</p>
- 可搜索打点数据标签,展示特定数据流
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86536639-b894c080-bf1b-11ea-9ee5-cf815dd4bbd7.png" width="30%"/>
</p>
## 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
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86738774-ee46c000-c067-11ea-90d2-a98aac445cca.png" width="100%"/>
</p>
### 功能操作说明
- 支持数据卡片「最大化」,「还原」、「下载」PR曲线
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86740067-f18e7b80-c068-11ea-96bf-52cb7da1f799.png" width="60%"/>
</p>
- 数据点Hover展示详细信息:阈值对应的TP、TN、FP、FN
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86740477-43370600-c069-11ea-93f0-f4d05445fbab.png" width="70%"/>
</p>
- 可搜索卡片标签,展示目标图表
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86740670-66fa4c00-c069-11ea-9ee3-0a22e2d0dbec.png" width="50%"/>
</p>
- 可搜索打点数据标签,展示特定数据
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86740817-809b9380-c069-11ea-9453-6531e3ff5f43.png" width="50%"/>
</p>
- 支持查看不同训练步数下的PR曲线
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86741057-b04a9b80-c069-11ea-9fef-2dcc16f9cd46.png" width="50%"/>
</p>
- X轴-时间显示类型有三种衡量尺度
- Step:迭代次数
- Walltime:训练绝对时间
- Relative:训练时长
<p align="center">
<img src="https://user-images.githubusercontent.com/48054808/86741304-db34ef80-c069-11ea-86eb-787b49ed3705.png" width="50%"/>
</p>
## 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`,即可查看降维后的可视化数据。
<p align="center">
<img src="http://visualdl.bj.bcebos.com/images/dynamic_high_dimensional.gif" width="80%"/>
<img src="http://visualdl.bj.bcebos.com/images/dynamic_high_dimensional.gif" width="100%"/>
</p>
#
......@@ -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
......
......@@ -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).
......
......@@ -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}
......
......@@ -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")
......@@ -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
......@@ -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
==========
functional
==========
.. toctree::
:maxdepth: 1
functional/l1_loss.rst
functional/nll_loss.rst
.. _api_nn_functional_l1_loss:
l1_loss
------
.. autoclass:: paddle.nn.functional.l1_loss
:members:
:inherited-members:
:noindex:
.. 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:
.. _api_nn_functional_nll_loss:
nll_loss
-------------------------------
.. autoclass:: paddle.nn.functional.nll_loss
:members:
:inherited-members:
:noindex:
.. 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:
.. 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:
.. _api_nn_margin_rank_loss:
margin_rank_loss
-------------------------------
:doc_source: paddle.fluid.layers.margin_rank_loss
.. 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:
......@@ -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
......
......@@ -2,6 +2,6 @@
cumsum
-------------------------------
:doc_source: paddle.fluid.layers.cumsum
:doc_source: paddle.tensor.cumsum
.. _api_paddle_elementwise_equal:
elementwise_equal
-------------------------------
:doc_source: paddle.fluid.layers.equal
.. _api_paddle_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _api_paddle_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _api_paddle_equal_all
equal_all
-------------------------------
:doc_source: paddle.tensor.equal_all
......@@ -2,6 +2,6 @@
greater_equal
-------------------------------
:doc_source: paddle.fluid.layers.greater_equal
:doc_source: paddle.tensor.greater_equal
......@@ -2,6 +2,6 @@
greater_than
-------------------------------
:doc_source: paddle.fluid.layers.greater_than
:doc_source: paddle.tensor.greater_than
......@@ -2,6 +2,6 @@
less_equal
-------------------------------
:doc_source: paddle.fluid.layers.less_equal
:doc_source: paddle.tensor.less_equal
......@@ -2,6 +2,6 @@
less_than
-------------------------------
:doc_source: paddle.fluid.layers.less_than
:doc_source: paddle.tensor.less_than
......@@ -2,6 +2,6 @@
max
-------------------------------
:doc_source: paddle.fluid.layers.reduce_max
:doc_source: paddle.tensor.max
.. _api_paddle_maximum:
maximum
-------------------------------
:doc_source: paddle.tensor.maximum
......@@ -2,6 +2,6 @@
min
-------------------------------
:doc_source: paddle.fluid.layers.reduce_min
:doc_source: paddle.tensor.min
.. _api_paddle_minimum:
minimum
-------------------------------
:doc_source: paddle.tensor.minimum
......@@ -2,6 +2,6 @@
not_equal
-------------------------------
:doc_source: paddle.fluid.layers.not_equal
:doc_source: paddle.tensor.not_equal
=================
paddle.review_tmp
=================
.. toctree::
:maxdepth: 1
review_tmp/MarginRankingLoss.rst
review_tmp/margin_ranking_loss.rst
.. _api_nn_loss_MarginRankingLoss_tmp:
MarginRankingLoss
-----------------
.. autoclass:: paddle.nn.loss.MarginRankingLoss
:members:
:inherited-members:
:noindex:
.. _api_nn_functional_margin_ranking_loss_tmp:
margin_ranking_loss
-------------------
.. autofunction:: paddle.nn.functional.margin_ranking_loss
:noindex:
......@@ -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
......
......@@ -2,6 +2,6 @@
cumsum
-------------------------------
:doc_source: paddle.fluid.layers.cumsum
:doc_source: paddle.tensor.cumsum
.. _api_tensor_cn_elementwise_equal:
elementwise_equal
-------------------------------
:doc_source: paddle.fluid.layers.equal
.. _api_tensor_cn_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _api_tensor_cn_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _api_tensor_cn_equal_all:
equal_all
-------------------------------
:doc_source: paddle.tensor.equal_all
......@@ -2,6 +2,6 @@
greater_equal
-------------------------------
:doc_source: paddle.fluid.layers.greater_equal
:doc_source: paddle.tensor.greater_equal
......@@ -2,6 +2,6 @@
greater_than
-------------------------------
:doc_source: paddle.fluid.layers.greater_than
:doc_source: paddle.tensor.greater_than
......@@ -2,6 +2,6 @@
less_equal
-------------------------------
:doc_source: paddle.fluid.layers.less_equal
:doc_source: paddle.tensor.less_equal
......@@ -2,6 +2,6 @@
less_than
-------------------------------
:doc_source: paddle.fluid.layers.less_than
:doc_source: paddle.tensor.less_than
......@@ -2,6 +2,6 @@
max
-------------------------------
:doc_source: paddle.fluid.layers.reduce_max
:doc_source: paddle.tensor.max
.. _api_tensor_cn_maximum:
maximum
-------------------------------
:doc_source: paddle.tensor.maximum
.. _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:
......@@ -2,6 +2,6 @@
min
-------------------------------
:doc_source: paddle.fluid.layers.reduce_min
:doc_source: paddle.tensor.min
.. _api_tensor_cn_minimum:
minimum
-------------------------------
:doc_source: paddle.tensor.minimum
......@@ -2,6 +2,6 @@
not_equal
-------------------------------
:doc_source: paddle.fluid.layers.not_equal
:doc_source: paddle.tensor.not_equal
......@@ -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。
......
......@@ -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()
......@@ -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)
......@@ -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
......@@ -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 <https://arxiv.org/abs/1502.01852>`_ 。这是一个鲁棒性特别强的初始化方法,并且适应了非线性激活函数(rectifier nonlinearities)。
可以选择使用均匀分布或者正分布初始化权重;
可以选择使用均匀分布或者正分布初始化权重;
在均匀分布中,范围为[-x,x],其中:
.. math::
......
......@@ -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]]
......
......@@ -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。
......
......@@ -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。
......
......@@ -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其中之一。
......
......@@ -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]]
......@@ -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一致。
......
......@@ -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一致。
......
......@@ -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一致。
......
......@@ -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一致。
......
......@@ -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。
**代码示例**:
......
......@@ -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类型。
......
......@@ -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时。
**代码示例**:
......
......@@ -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`` 维会被置换到最后一维;
......
......@@ -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]
......
......@@ -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
......
......@@ -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时。
**代码示例**:
......
......@@ -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
.. _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.]
......@@ -8,4 +8,5 @@ activation
.. toctree::
:maxdepth: 1
activation_cn/LeakyReLU_cn.rst
activation_cn/Sigmoid_cn.rst
.. _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]
=======================
functional
=======================
.. toctree::
:maxdepth: 1
functional_cn/l1_loss_cn.rst
functional_cn/nll_loss_cn.rst
functional_cn/margin_ranking_loss_cn.rst
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]
.. _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]
.. _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]
......@@ -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
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]]
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]
.. _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]
.. _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]
.. _cn_api_nn_cn_margin_rank_loss:
margin_rank_loss
-------------------------------
:doc_source: paddle.fluid.layers.margin_rank_loss
......@@ -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]]]
......@@ -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
......
......@@ -2,6 +2,6 @@
cumsum
-------------------------------
:doc_source: paddle.fluid.layers.cumsum
:doc_source: paddle.tensor.cumsum
.. _cn_api_paddle_cn_elementwise_equal:
elementwise_equal
-------------------------------
:doc_source: paddle.fluid.layers.equal
.. _cn_api_paddle_cn_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _cn_api_paddle_cn_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _cn_api_paddle_cn_equal_all:
equal_all
-------------------------------
:doc_source: paddle.tensor.equal_all
......@@ -2,6 +2,6 @@
greater_equal
-------------------------------
:doc_source: paddle.fluid.layers.greater_equal
:doc_source: paddle.tensor.greater_equal
......@@ -2,6 +2,6 @@
greater_than
-------------------------------
:doc_source: paddle.fluid.layers.greater_than
:doc_source: paddle.tensor.greater_than
......@@ -2,6 +2,6 @@
less_equal
-------------------------------
:doc_source: paddle.fluid.layers.less_equal
:doc_source: paddle.tensor.less_equal
......@@ -2,6 +2,6 @@
less_than
-------------------------------
:doc_source: paddle.fluid.layers.less_than
:doc_source: paddle.tensor.less_than
.. _cn_api_paddle_cn_name_scope:
name_scope
-------------------------------
:doc_source: paddle.fluid.dygraph.no_grad
......@@ -2,6 +2,6 @@
not_equal
-------------------------------
:doc_source: paddle.fluid.layers.not_equal
:doc_source: paddle.tensor.not_equal
......@@ -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
......
......@@ -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
**代码示例**:
......
.. _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]]
......@@ -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
.. _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]
.. _cn_api_tensor_cn_elementwise_max:
elementwise_max
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_max
.. _cn_api_tensor_cn_elementwise_min:
elementwise_min
-------------------------------
:doc_source: paddle.fluid.layers.elementwise_min
.. _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 ]
......@@ -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]
......@@ -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]]
......
......@@ -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]
......
......@@ -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其中之一
**代码示例**:
......
......@@ -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]
......@@ -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]
......@@ -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其中之一。
**代码示例**:
......
......@@ -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]
......@@ -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]
......@@ -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。
......
......@@ -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 ]]
......@@ -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]]
.. _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.]
.. _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)机制可以参考 `<<PaddlePaddle广播机制文档>> <https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/beginners_guide/basic_concept/broadcasting.rst>`_ 。
参数
:::::::::
- **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]
......@@ -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]
......@@ -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.]
.. _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)机制可以参考 `<<PaddlePaddle广播机制文档>> <https://github.com/PaddlePaddle/FluidDoc/blob/develop/doc/fluid/beginners_guide/basic_concept/broadcasting.rst>`_ 。
参数
:::::::::
- **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.]
......@@ -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
......
.. _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]
......@@ -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
**代码示例**:
......
......@@ -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.]]
......
......@@ -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]
......@@ -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]]
......@@ -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 <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/abs>`_", ":ref:`cn_api_fluid_layers_abs`", "功能一致"
"2", "`tf.add <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/add>`_", ":ref:`cn_api_fluid_layers_elementwise_add`", "功能一致"
"3", "`tf.argmax <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/argmax>`_", ":ref:`cn_api_fluid_layers_argmax`", "功能一致"
"4", "`tf.argmin <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/argmin>`_", ":ref:`cn_api_fluid_layers_argmin`", "功能一致"
"5", "`tf.assign <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/assign>`_", ":ref:`cn_api_fluid_layers_assign`", "功能一致"
"6", "`tf.assign_add <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/assign_add>`_", ":ref:`cn_api_fluid_layers_increment`", "功能一致"
"7", "`tf.case <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/case>`_", ":ref:`cn_api_fluid_layers_Switch`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.case.md>`_"
"8", "`tf.cast <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/dtypes/cast>`_", ":ref:`cn_api_fluid_layers_cast`", "功能一致"
"9", "`tf.clip_by_global_norm <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/clip_by_global_norm>`_", ":ref:`cn_api_fluid_clip_GradientClipByGlobalNorm`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.clip_by_global_norm.md>`_"
"10", "`tf.clip_by_norm <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/clip_by_norm>`_", ":ref:`cn_api_fluid_layers_clip_by_norm`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.clip_by_norm.md>`_"
"11", "`tf.clip_by_value <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/clip_by_value>`_", ":ref:`cn_api_fluid_layers_clip`", "功能一致"
"12", "`tf.concat <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/concat>`_", ":ref:`cn_api_fluid_layers_concat`", "功能一致"
"13", "`tf.cond <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/cond>`_", ":ref:`cn_api_fluid_layers_ifElse`", "功能一致"
"14", "`tf.constant <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/constant>`_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致"
"15", "`tf.contrib.layers.batch_norm <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/batch_norm>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"16", "`tf.contrib.layers.flatten <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/flatten>`_", ":ref:`cn_api_fluid_layers_flatten`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.contrib.layers.flatten.md>`_"
"17", "`tf.contrib.layers.fully_connected <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/fully_connected>`_", ":ref:`cn_api_fluid_layers_fc`", "功能一致"
"18", "`tf.contrib.layers.one_hot_encoding <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/one_hot_encoding>`_", ":ref:`cn_api_fluid_layers_one_hot`", "功能一致"
"19", "`tf.contrib.layers.softmax <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/softmax>`_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致"
"20", "`tf.contrib.layers.xavier_initializer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/xavier_initializer>`_", ":ref:`cn_api_fluid_initializer_Xavier`", "功能一致"
"21", "`tf.nn.rnn.GRUCell <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/GRUCell>`_", ":ref:`cn_api_fluid_layers_gru_unit`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn.GRUCell.md>`_"
"22", "`tf.nn.rnn.MultiRNNCell <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/MultiRNNCell>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn_cell.MultiRNNCell.md>`_"
"23", "`tf.nn.rnn.static_rnn <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/static_rnn>`_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "功能一致"
"24", "`tf.convert_to_tensor <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/convert_to_tensor>`_", ":ref:`cn_api_fluid_layers_assign`", "功能一致"
"25", "`tf.cos <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/cos>`_", ":ref:`cn_api_fluid_layers_cos`", "功能一致"
"26", "`tf.div <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/div>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"27", "`tf.divide <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/divide>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"28", "`tf.dropout <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.dropout.md>`_"
"29", "`tf.equal <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/equal>`_", "`运算符== <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"30", "`tf.exp <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/exp>`_", ":ref:`cn_api_fluid_layers_exp`", "功能一致"
"31", "`tf.expand_dims <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/expand_dims>`_", ":ref:`cn_api_fluid_layers_unsqueeze`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.expand_dims.md>`_"
"32", "`tf.fill <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/fill>`_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致"
"33", "`tf.floor <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/floor>`_", ":ref:`cn_api_fluid_layers_floor`", "功能一致"
"34", "`tf.gather <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/gather>`_", ":ref:`cn_api_fluid_layers_gather`", "功能一致"
"35", "`tf.greater <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/greater>`_", "`运算符> <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"36", "`tf.greater_equal <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/greater_equal>`_", "`运算符>= <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"37", "`tf.image.non_max_suppression <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/non_max_suppression>`_", ":ref:`cn_api_fluid_layers_multiclass_nms`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.image.non_max_suppression.md>`_"
"38", "`tf.image.resize_bilinear <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/resize_bilinear>`_", ":ref:`cn_api_fluid_layers_resize_bilinear`", "功能一致"
"39", "`tf.image.resize_images <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/resize_images>`_", ":ref:`cn_api_fluid_layers_image_resize`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.image.resize_images.md>`_"
"40", "`tf.image.resize_nearest_neighbor <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/resize_nearest_neighbor>`_", ":ref:`cn_api_fluid_layers_resize_nearest`", "功能一致"
"41", "`tf.is_finite <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/is_finite>`_", ":ref:`cn_api_fluid_layers_isfinite`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.math.is_finite.md>`_"
"42", "`tf.layers.batch_normalization <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/batch_normalization>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"43", "`tf.layers.conv2d <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.layers.conv2d.md>`_"
"44", "`tf.layers.dense <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/dense>`_", ":ref:`cn_api_fluid_layers_fc`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.layers.dense.md>`_"
"45", "`tf.layers.dropout <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致"
"46", "`tf.layers.Dropout <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/Dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致"
"47", "`tf.layers.flatten <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/flatten>`_", ":ref:`cn_api_fluid_layers_flatten`", "功能一致"
"48", "`tf.less <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/less>`_", "`运算符< <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"49", "`tf.less_equal <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/less_equal>`_", "`运算符<= <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"50", "`tf.log <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/log>`_", ":ref:`cn_api_fluid_layers_log`", "功能一致"
"51", "`tf.logical_and <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/logical_and>`_", ":ref:`cn_api_fluid_layers_logical_and`", "功能一致"
"52", "`tf.logical_not <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/logical_not>`_", ":ref:`cn_api_fluid_layers_logical_not`", "功能一致"
"53", "`tf.logical_or <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/logical_or>`_", ":ref:`cn_api_fluid_layers_logical_or`", "功能一致"
"54", "`tf.losses.mean_squared_error <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/losses/mean_squared_error>`_", ":ref:`cn_api_fluid_layers_square_error_cost`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.losses.mean_and_squared_error.md>`_"
"55", "`tf.losses.sigmoid_cross_entropy <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/losses/sigmoid_cross_entropy>`_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.losses.sigmoid_cross_entropy.md>`_"
"56", "`tf.losses.softmax_cross_entropy <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/losses/softmax_cross_entropy>`_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "功能一致"
"57", "`tf.matmul <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/linalg/matmul>`_", ":ref:`cn_api_fluid_layers_matmul`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.matmul.md>`_"
"58", "`tf.maximum <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/maximum>`_", ":ref:`cn_api_fluid_layers_elementwise_max`", "功能一致"
"59", "`tf.metrics.accuracy <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/metrics/accuracy>`_", ":ref:`cn_api_fluid_layers_accuracy`", "功能一致"
"60", "`tf.metrics.mean <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/metrics/mean>`_", ":ref:`cn_api_fluid_layers_mean`", "功能一致"
"61", "`tf.minimum <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/minimum>`_", ":ref:`cn_api_fluid_layers_elementwise_min`", "功能一致"
"62", "`tf.multiply <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/multiply>`_", ":ref:`cn_api_fluid_layers_elementwise_mul`", "功能一致"
"63", "`tf.nn.avg_pool <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/avg_pool>`_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.avg_pool.md>`_"
"64", "`tf.nn.batch_normalization <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/batch_normalization>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"65", "`tf.nn.bidirectional_dynamic_rnn <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/bidirectional_dynamic_rnn>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.bidirectional_dynamic_rnn.md>`_"
"66", "`tf.nn.conv2d <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv2d.md>`_"
"67", "`tf.nn.conv2d_transpose <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv2d_transpose>`_", ":ref:`cn_api_fluid_layers_conv2d_transpose`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv2d_transpose.md>`_"
"68", "`tf.nn.conv3d_transpose <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv3d_transpose>`_", ":ref:`cn_api_fluid_layers_conv3d_transpose`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv3d_transpose.md>`_"
"69", "`tf.nn.depthwise_conv2d <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/depthwise_conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.depthwise_conv2d.md>`_"
"70", "`tf.nn.dynamic_rnn <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/dynamic_rnn>`_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.dynamic_rnn.md>`_"
"71", "`tf.nn.l2_normalize <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/l2_normalize>`_", ":ref:`cn_api_fluid_layers_l2_normalize`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.l2_normalize.md>`_"
"72", "`tf.nn.leaky_relu <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/leaky_relu>`_", ":ref:`cn_api_fluid_layers_leaky_relu`", "功能一致"
"73", "`tf.nn.lrn <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/local_response_normalization>`_", ":ref:`cn_api_fluid_layers_lrn`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.lrn.md>`_"
"74", "`tf.nn.max_pool <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/max_pool>`_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.max_pool.md>`_"
"75", "`tf.nn.relu <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/relu>`_", ":ref:`cn_api_fluid_layers_relu`", "功能一致"
"76", "`tf.nn.relu6 <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/relu6>`_", ":ref:`cn_api_fluid_layers_relu6`", "功能一致"
"77", "`tf.nn.rnn_cell.LSTMCell <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/LSTMCell>`_", ":ref:`cn_api_fluid_layers_lstm_unit`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn_cell.LSTMCell.md>`_"
"78", "`tf.nn.separable_conv2d <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/separable_conv2d>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.separable_conv2d.md>`_"
"79", "`tf.nn.sigmoid <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/sigmoid>`_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致"
"80", "`tf.nn.sigmoid_cross_entropy_with_logits <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits>`_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "功能一致"
"81", "`tf.nn.softmax <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/softmax>`_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致"
"82", "`tf.nn.softmax_cross_entropy_with_logits <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/softmax_cross_entropy_with_logits>`_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.softmax_cross_entropy_with_logits.md>`_"
"83", "`tf.nn.softplus <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/softplus>`_", ":ref:`cn_api_fluid_layers_softplus`", "功能一致"
"84", "`tf.nn.softsign <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/softsign>`_", ":ref:`cn_api_fluid_layers_softsign`", "功能一致"
"85", "`tf.nn.tanh <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/tanh>`_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致"
"86", "`tf.one_hot <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/one_hot>`_", ":ref:`cn_api_fluid_layers_one_hot`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.one_hot.md>`_"
"87", "`tf.ones <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/ones>`_", ":ref:`cn_api_fluid_layers_ones`", "功能一致"
"88", "`tf.intializers.ones <https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/initializers/ones>`_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致"
"89", "`tf.pad <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/pad>`_", ":ref:`cn_api_fluid_layers_pad`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.pad.md>`_"
"90", "`tf.placeholder <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/placeholder>`_", ":ref:`cn_api_fluid_layers_data`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.placeholder.md>`_"
"91", "`tf.pow <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/pow>`_", ":ref:`cn_api_fluid_layers_pow`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.pow.md>`_"
"92", "`tf.print <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/print>`_", ":ref:`cn_api_fluid_layers_print`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.print.md>`_"
"93", "`tf.py_func <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/py_func>`_", ":ref:`cn_api_fluid_layers_py_func`", "功能一致"
"94", "`tf.random_normal <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/random/normal>`_", ":ref:`cn_api_fluid_layers_gaussian_random`", "功能一致"
"95", "`tf.random_normal_initializer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/initializers/random_normal>`_", ":ref:`cn_api_fluid_initializer_Normal`", "功能一致"
"96", "`tf.random_uniform <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/random/uniform>`_", ":ref:`cn_api_fluid_layers_uniform_random`", "功能一致"
"97", "`tf.random_uniform_initializer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/initializers/random_uniform>`_", ":ref:`cn_api_fluid_initializer_UniformInitializer`", "功能一致"
"98", "`tf.reduce_logsumexp <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_logsumexp>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.reduce_logsumexp.md>`_"
"99", "`tf.reduce_max <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_max>`_", ":ref:`cn_api_fluid_layers_reduce_max`", "功能一致"
"100", "`tf.reduce_mean <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_mean>`_", ":ref:`cn_api_fluid_layers_reduce_mean`", "功能一致"
"101", "`tf.reduce_min <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_min>`_", ":ref:`cn_api_fluid_layers_reduce_min`", "功能一致"
"102", "`tf.reduce_sum <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_sum>`_", ":ref:`cn_api_fluid_layers_reduce_sum`", "功能一致"
"103", "`tf.reshape <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reshape>`_", ":ref:`cn_api_fluid_layers_reshape`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.reshape.md>`_"
"104", "`tf.reverse <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reverse>`_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致"
"105", "`tf.reverse_sequence <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reverse_sequence>`_", ":ref:`cn_api_fluid_layers_sequence_reverse`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.reverse_sequence.md>`_"
"106", "`tf.reverse_v2 <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reverse>`_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致"
"107", "`tf.round <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/round>`_", ":ref:`cn_api_fluid_layers_round`", "功能一致"
"108", "`tf.rsqrt <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/rsqrt>`_", ":ref:`cn_api_fluid_layers_rsqrt`", "功能一致"
"109", "`tf.scalar_mul <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/scalar_mul>`_", ":ref:`cn_api_fluid_layers_scale`", "功能一致"
"110", "`tf.scatter_update <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/scatter_update>`_", ":ref:`cn_api_fluid_layers_scatter`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.scatter_update.md>`_"
"111", "`tf.sequence_mask <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/sequence_mask>`_", ":ref:`cn_api_fluid_layers_sequence_mask`", "功能一致"
"112", "`tf.shape <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/shape>`_", ":ref:`cn_api_fluid_layers_shape`", "功能一致"
"113", "`tf.sigmoid <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/sigmoid>`_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致"
"114", "`tf.sin <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/sin>`_", ":ref:`cn_api_fluid_layers_sin`", "功能一致"
"115", "`tf.slice <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/slice>`_", ":ref:`cn_api_fluid_layers_slice`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.slice.md>`_"
"116", "`tf.split <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/split>`_", ":ref:`cn_api_fluid_layers_split`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.split.md>`_"
"117", "`tf.sqrt <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/sqrt>`_", ":ref:`cn_api_fluid_layers_sqrt`", "功能一致"
"118", "`tf.square <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/square>`_", ":ref:`cn_api_fluid_layers_square`", "功能一致"
"119", "`tf.squared_difference <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/squared_difference>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.squared_difference.md>`_"
"120", "`tf.squeeze <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/squeeze>`_", ":ref:`cn_api_fluid_layers_squeeze`", "功能一致"
"121", "`tf.stack <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/stack>`_", ":ref:`cn_api_fluid_layers_stack`", "功能一致"
"122", "`tf.stop_gradient <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/stop_gradient>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.stop_gradient.md>`_"
"123", "`tf.subtract <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/subtract>`_", ":ref:`cn_api_fluid_layers_elementwise_sub`", "功能一致"
"124", "`tf.tanh <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/tanh>`_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致"
"125", "`tf.tile <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/tile>`_", ":ref:`cn_api_fluid_layers_expand`", "功能一致"
"126", "`tf.top_k <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/top_k>`_", ":ref:`cn_api_fluid_layers_topk`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.top_k.md>`_"
"127", "`tf.train.AdagradOptimizer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/AdagradOptimizer>`_", ":ref:`cn_api_fluid_optimizer_AdagradOptimizer`", "功能一致"
"128", "`tf.train.AdamOptimizer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/AdamOptimizer>`_", ":ref:`cn_api_fluid_optimizer_Adam`", "功能一致"
"129", "`tf.train.exponential_decay <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/exponential_decay>`_", ":ref:`cn_api_fluid_layers_exponential_decay`", "功能一致"
"130", "`tf.train.GradientDescentOptimizer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/GradientDescentOptimizer>`_", ":ref:`cn_api_fluid_optimizer_SGDOptimizer`", "功能一致"
"131", "`tf.train.MomentumOptimizer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/MomentumOptimizer>`_", ":ref:`cn_api_fluid_optimizer_MomentumOptimizer`", "功能一致"
"132", "`tf.train.polynomial_decay <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/polynomial_decay>`_", ":ref:`cn_api_fluid_layers_polynomial_decay`", "功能一致"
"133", "`tf.train.RMSPropOptimizer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/train/RMSPropOptimizer>`_", ":ref:`cn_api_fluid_optimizer_RMSPropOptimizer`", "功能一致"
"134", "`tf.transpose <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/transpose>`_", ":ref:`cn_api_fluid_layers_transpose`", "功能一致"
"135", "`tf.truediv <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/truediv>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"136", "`tf.truncated_normal <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/random/truncated_normal>`_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致"
"137", "`tf.truncated_normal_initializer <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/initializers/truncated_normal>`_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致"
"138", "`tf.unstack <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/unstack>`_", ":ref:`cn_api_fluid_layers_unstack`", "功能一致"
"139", "`tf.Variable <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/Variable>`_", ":ref:`cn_api_fluid_layers_create_parameter`", "功能一致"
"140", "`tf.while_loop <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/while_loop>`_", ":ref:`cn_api_fluid_layers_While`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.while_loop.md>`_"
"141", "`tf.zeros <https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/zeros>`_", ":ref:`cn_api_fluid_layers_zeros`", "功能一致"
"142", "`tf.zeros_initializer <https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/zeros_initializer>`_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致"
"1", "`tf.abs <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/abs>`_", ":ref:`cn_api_fluid_layers_abs`", "功能一致"
"2", "`tf.add <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/add>`_", ":ref:`cn_api_fluid_layers_elementwise_add`", "功能一致"
"3", "`tf.argmax <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/argmax>`_", ":ref:`cn_api_fluid_layers_argmax`", "功能一致"
"4", "`tf.argmin <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/argmin>`_", ":ref:`cn_api_fluid_layers_argmin`", "功能一致"
"5", "`tf.assign <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/assign>`_", ":ref:`cn_api_fluid_layers_assign`", "功能一致"
"6", "`tf.assign_add <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/assign_add>`_", ":ref:`cn_api_fluid_layers_increment`", "功能一致"
"7", "`tf.case <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/case>`_", ":ref:`cn_api_fluid_layers_Switch`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.case.md>`_"
"8", "`tf.cast <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/dtypes/cast>`_", ":ref:`cn_api_fluid_layers_cast`", "功能一致"
"9", "`tf.clip_by_global_norm <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/clip_by_global_norm>`_", ":ref:`cn_api_fluid_clip_GradientClipByGlobalNorm`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.clip_by_global_norm.md>`_"
"10", "`tf.clip_by_norm <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/clip_by_norm>`_", ":ref:`cn_api_fluid_layers_clip_by_norm`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.clip_by_norm.md>`_"
"11", "`tf.clip_by_value <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/clip_by_value>`_", ":ref:`cn_api_fluid_layers_clip`", "功能一致"
"12", "`tf.concat <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/concat>`_", ":ref:`cn_api_fluid_layers_concat`", "功能一致"
"13", "`tf.cond <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/cond>`_", ":ref:`cn_api_fluid_layers_ifElse`", "功能一致"
"14", "`tf.constant <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/constant>`_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致"
"15", "`tf.contrib.layers.batch_norm <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/batch_norm>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"16", "`tf.contrib.layers.flatten <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/flatten>`_", ":ref:`cn_api_fluid_layers_flatten`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.contrib.layers.flatten.md>`_"
"17", "`tf.contrib.layers.fully_connected <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/fully_connected>`_", ":ref:`cn_api_fluid_layers_fc`", "功能一致"
"18", "`tf.contrib.layers.one_hot_encoding <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/one_hot_encoding>`_", ":ref:`cn_api_fluid_layers_one_hot`", "功能一致"
"19", "`tf.contrib.layers.softmax <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/softmax>`_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致"
"20", "`tf.contrib.layers.xavier_initializer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/layers/xavier_initializer>`_", ":ref:`cn_api_fluid_initializer_Xavier`", "功能一致"
"21", "`tf.nn.rnn.GRUCell <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/rnn_cell/GRUCell>`_", ":ref:`cn_api_fluid_layers_gru_unit`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn.GRUCell.md>`_"
"22", "`tf.nn.rnn.MultiRNNCell <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/rnn_cell/MultiRNNCell>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn_cell.MultiRNNCell.md>`_"
"23", "`tf.nn.rnn.static_rnn <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/static_rnn>`_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "功能一致"
"24", "`tf.convert_to_tensor <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/convert_to_tensor>`_", ":ref:`cn_api_fluid_layers_assign`", "功能一致"
"25", "`tf.cos <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/cos>`_", ":ref:`cn_api_fluid_layers_cos`", "功能一致"
"26", "`tf.div <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/div>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"27", "`tf.divide <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/divide>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"28", "`tf.dropout <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.dropout.md>`_"
"29", "`tf.equal <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/equal>`_", "`运算符== <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"30", "`tf.exp <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/exp>`_", ":ref:`cn_api_fluid_layers_exp`", "功能一致"
"31", "`tf.expand_dims <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/expand_dims>`_", ":ref:`cn_api_fluid_layers_unsqueeze`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.expand_dims.md>`_"
"32", "`tf.fill <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/fill>`_", ":ref:`cn_api_fluid_layers_fill_constant`", "功能一致"
"33", "`tf.floor <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/floor>`_", ":ref:`cn_api_fluid_layers_floor`", "功能一致"
"34", "`tf.gather <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/gather>`_", ":ref:`cn_api_fluid_layers_gather`", "功能一致"
"35", "`tf.greater <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/greater>`_", "`运算符> <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"36", "`tf.greater_equal <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/greater_equal>`_", "`运算符>= <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"37", "`tf.image.non_max_suppression <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/image/non_max_suppression>`_", ":ref:`cn_api_fluid_layers_multiclass_nms`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.image.non_max_suppression.md>`_"
"38", "`tf.image.resize_bilinear <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/image/resize_bilinear>`_", ":ref:`cn_api_fluid_layers_resize_bilinear`", "功能一致"
"39", "`tf.image.resize_images <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/image/resize_images>`_", ":ref:`cn_api_fluid_layers_image_resize`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.image.resize_images.md>`_"
"40", "`tf.image.resize_nearest_neighbor <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/image/resize_nearest_neighbor>`_", ":ref:`cn_api_fluid_layers_resize_nearest`", "功能一致"
"41", "`tf.is_finite <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/is_finite>`_", ":ref:`cn_api_fluid_layers_isfinite`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.math.is_finite.md>`_"
"42", "`tf.layers.batch_normalization <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/batch_normalization>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"43", "`tf.layers.conv2d <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.layers.conv2d.md>`_"
"44", "`tf.layers.dense <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/dense>`_", ":ref:`cn_api_fluid_layers_fc`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.layers.dense.md>`_"
"45", "`tf.layers.dropout <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致"
"46", "`tf.layers.Dropout <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/Dropout>`_", ":ref:`cn_api_fluid_layers_dropout`", "功能一致"
"47", "`tf.layers.flatten <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/layers/flatten>`_", ":ref:`cn_api_fluid_layers_flatten`", "功能一致"
"48", "`tf.less <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/less>`_", "`运算符< <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"49", "`tf.less_equal <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/less_equal>`_", "`运算符<= <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/compare_op.md>`_", "功能一致"
"50", "`tf.log <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/log>`_", ":ref:`cn_api_fluid_layers_log`", "功能一致"
"51", "`tf.logical_and <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/logical_and>`_", ":ref:`cn_api_fluid_layers_logical_and`", "功能一致"
"52", "`tf.logical_not <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/logical_not>`_", ":ref:`cn_api_fluid_layers_logical_not`", "功能一致"
"53", "`tf.logical_or <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/logical_or>`_", ":ref:`cn_api_fluid_layers_logical_or`", "功能一致"
"54", "`tf.losses.mean_squared_error <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/losses/mean_squared_error>`_", ":ref:`cn_api_fluid_layers_square_error_cost`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.losses.mean_and_squared_error.md>`_"
"55", "`tf.losses.sigmoid_cross_entropy <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/losses/sigmoid_cross_entropy>`_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.losses.sigmoid_cross_entropy.md>`_"
"56", "`tf.losses.softmax_cross_entropy <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/losses/softmax_cross_entropy>`_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "功能一致"
"57", "`tf.matmul <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/linalg/matmul>`_", ":ref:`cn_api_fluid_layers_matmul`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.matmul.md>`_"
"58", "`tf.maximum <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/maximum>`_", ":ref:`cn_api_fluid_layers_elementwise_max`", "功能一致"
"59", "`tf.metrics.accuracy <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/metrics/accuracy>`_", ":ref:`cn_api_fluid_layers_accuracy`", "功能一致"
"60", "`tf.metrics.mean <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/metrics/mean>`_", ":ref:`cn_api_fluid_layers_mean`", "功能一致"
"61", "`tf.minimum <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/minimum>`_", ":ref:`cn_api_fluid_layers_elementwise_min`", "功能一致"
"62", "`tf.multiply <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/multiply>`_", ":ref:`cn_api_fluid_layers_elementwise_mul`", "功能一致"
"63", "`tf.nn.avg_pool <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/avg_pool>`_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.avg_pool.md>`_"
"64", "`tf.nn.batch_normalization <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/batch_normalization>`_", ":ref:`cn_api_fluid_layers_batch_norm`", "功能一致"
"65", "`tf.nn.bidirectional_dynamic_rnn <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/bidirectional_dynamic_rnn>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.bidirectional_dynamic_rnn.md>`_"
"66", "`tf.nn.conv2d <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv2d.md>`_"
"67", "`tf.nn.conv2d_transpose <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/conv2d_transpose>`_", ":ref:`cn_api_fluid_layers_conv2d_transpose`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv2d_transpose.md>`_"
"68", "`tf.nn.conv3d_transpose <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/conv3d_transpose>`_", ":ref:`cn_api_fluid_layers_conv3d_transpose`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.conv3d_transpose.md>`_"
"69", "`tf.nn.depthwise_conv2d <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/depthwise_conv2d>`_", ":ref:`cn_api_fluid_layers_conv2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.depthwise_conv2d.md>`_"
"70", "`tf.nn.dynamic_rnn <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/dynamic_rnn>`_", ":ref:`cn_api_fluid_layers_DynamicRNN`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.dynamic_rnn.md>`_"
"71", "`tf.nn.l2_normalize <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/l2_normalize>`_", ":ref:`cn_api_fluid_layers_l2_normalize`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.l2_normalize.md>`_"
"72", "`tf.nn.leaky_relu <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/leaky_relu>`_", ":ref:`cn_api_fluid_layers_leaky_relu`", "功能一致"
"73", "`tf.nn.lrn <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/local_response_normalization>`_", ":ref:`cn_api_fluid_layers_lrn`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.lrn.md>`_"
"74", "`tf.nn.max_pool <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/max_pool>`_", ":ref:`cn_api_fluid_layers_pool2d`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.max_pool.md>`_"
"75", "`tf.nn.relu <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/relu>`_", ":ref:`cn_api_fluid_layers_relu`", "功能一致"
"76", "`tf.nn.relu6 <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/relu6>`_", ":ref:`cn_api_fluid_layers_relu6`", "功能一致"
"77", "`tf.nn.rnn_cell.LSTMCell <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/rnn_cell/LSTMCell>`_", ":ref:`cn_api_fluid_layers_lstm_unit`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.rnn_cell.LSTMCell.md>`_"
"78", "`tf.nn.separable_conv2d <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/separable_conv2d>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.separable_conv2d.md>`_"
"79", "`tf.nn.sigmoid <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/sigmoid>`_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致"
"80", "`tf.nn.sigmoid_cross_entropy_with_logits <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits>`_", ":ref:`cn_api_fluid_layers_sigmoid_cross_entropy_with_logits`", "功能一致"
"81", "`tf.nn.softmax <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/softmax>`_", ":ref:`cn_api_fluid_layers_softmax`", "功能一致"
"82", "`tf.nn.softmax_cross_entropy_with_logits <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/softmax_cross_entropy_with_logits>`_", ":ref:`cn_api_fluid_layers_softmax_with_cross_entropy`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.softmax_cross_entropy_with_logits.md>`_"
"83", "`tf.nn.softplus <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/softplus>`_", ":ref:`cn_api_fluid_layers_softplus`", "功能一致"
"84", "`tf.nn.softsign <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/softsign>`_", ":ref:`cn_api_fluid_layers_softsign`", "功能一致"
"85", "`tf.nn.tanh <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/tanh>`_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致"
"86", "`tf.one_hot <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/one_hot>`_", ":ref:`cn_api_fluid_layers_one_hot`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.one_hot.md>`_"
"87", "`tf.ones <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/ones>`_", ":ref:`cn_api_fluid_layers_ones`", "功能一致"
"88", "`tf.intializers.ones <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/initializers/ones>`_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致"
"89", "`tf.pad <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/pad>`_", ":ref:`cn_api_fluid_layers_pad`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.pad.md>`_"
"90", "`tf.placeholder <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/placeholder>`_", ":ref:`cn_api_fluid_layers_data`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.placeholder.md>`_"
"91", "`tf.pow <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/pow>`_", ":ref:`cn_api_fluid_layers_pow`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.pow.md>`_"
"92", "`tf.print <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/print>`_", ":ref:`cn_api_fluid_layers_print`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.print.md>`_"
"93", "`tf.py_func <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/py_func>`_", ":ref:`cn_api_fluid_layers_py_func`", "功能一致"
"94", "`tf.random_normal <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/random/normal>`_", ":ref:`cn_api_fluid_layers_gaussian_random`", "功能一致"
"95", "`tf.random_normal_initializer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/initializers/random_normal>`_", ":ref:`cn_api_fluid_initializer_Normal`", "功能一致"
"96", "`tf.random_uniform <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/random/uniform>`_", ":ref:`cn_api_fluid_layers_uniform_random`", "功能一致"
"97", "`tf.random_uniform_initializer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/initializers/random_uniform>`_", ":ref:`cn_api_fluid_initializer_UniformInitializer`", "功能一致"
"98", "`tf.reduce_logsumexp <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_logsumexp>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.reduce_logsumexp.md>`_"
"99", "`tf.reduce_max <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_max>`_", ":ref:`cn_api_fluid_layers_reduce_max`", "功能一致"
"100", "`tf.reduce_mean <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_mean>`_", ":ref:`cn_api_fluid_layers_reduce_mean`", "功能一致"
"101", "`tf.reduce_min <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_min>`_", ":ref:`cn_api_fluid_layers_reduce_min`", "功能一致"
"102", "`tf.reduce_sum <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_sum>`_", ":ref:`cn_api_fluid_layers_reduce_sum`", "功能一致"
"103", "`tf.reshape <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/reshape>`_", ":ref:`cn_api_fluid_layers_reshape`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.reshape.md>`_"
"104", "`tf.reverse <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/reverse>`_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致"
"105", "`tf.reverse_sequence <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/reverse_sequence>`_", ":ref:`cn_api_fluid_layers_sequence_reverse`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.reverse_sequence.md>`_"
"106", "`tf.reverse_v2 <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/reverse>`_", ":ref:`cn_api_fluid_layers_reverse`", "功能一致"
"107", "`tf.round <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/round>`_", ":ref:`cn_api_fluid_layers_round`", "功能一致"
"108", "`tf.rsqrt <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/rsqrt>`_", ":ref:`cn_api_fluid_layers_rsqrt`", "功能一致"
"109", "`tf.scalar_mul <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/scalar_mul>`_", ":ref:`cn_api_fluid_layers_scale`", "功能一致"
"110", "`tf.scatter_update <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/scatter_update>`_", ":ref:`cn_api_fluid_layers_scatter`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.scatter_update.md>`_"
"111", "`tf.sequence_mask <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/sequence_mask>`_", ":ref:`cn_api_fluid_layers_sequence_mask`", "功能一致"
"112", "`tf.shape <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/shape>`_", ":ref:`cn_api_fluid_layers_shape`", "功能一致"
"113", "`tf.sigmoid <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/sigmoid>`_", ":ref:`cn_api_fluid_layers_sigmoid`", "功能一致"
"114", "`tf.sin <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/sin>`_", ":ref:`cn_api_fluid_layers_sin`", "功能一致"
"115", "`tf.slice <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/slice>`_", ":ref:`cn_api_fluid_layers_slice`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.slice.md>`_"
"116", "`tf.split <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/split>`_", ":ref:`cn_api_fluid_layers_split`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.split.md>`_"
"117", "`tf.sqrt <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/sqrt>`_", ":ref:`cn_api_fluid_layers_sqrt`", "功能一致"
"118", "`tf.square <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/square>`_", ":ref:`cn_api_fluid_layers_square`", "功能一致"
"119", "`tf.squared_difference <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/squared_difference>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.squared_difference.md>`_"
"120", "`tf.squeeze <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/squeeze>`_", ":ref:`cn_api_fluid_layers_squeeze`", "功能一致"
"121", "`tf.stack <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/stack>`_", ":ref:`cn_api_fluid_layers_stack`", "功能一致"
"122", "`tf.stop_gradient <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/stop_gradient>`_", "无相应接口", "`Fluid实现 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.stop_gradient.md>`_"
"123", "`tf.subtract <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/subtract>`_", ":ref:`cn_api_fluid_layers_elementwise_sub`", "功能一致"
"124", "`tf.tanh <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/tanh>`_", ":ref:`cn_api_fluid_layers_tanh`", "功能一致"
"125", "`tf.tile <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/tile>`_", ":ref:`cn_api_fluid_layers_expand`", "功能一致"
"126", "`tf.top_k <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/top_k>`_", ":ref:`cn_api_fluid_layers_topk`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.top_k.md>`_"
"127", "`tf.train.AdagradOptimizer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/AdagradOptimizer>`_", ":ref:`cn_api_fluid_optimizer_AdagradOptimizer`", "功能一致"
"128", "`tf.train.AdamOptimizer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/AdamOptimizer>`_", ":ref:`cn_api_fluid_optimizer_Adam`", "功能一致"
"129", "`tf.train.exponential_decay <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/exponential_decay>`_", ":ref:`cn_api_fluid_layers_exponential_decay`", "功能一致"
"130", "`tf.train.GradientDescentOptimizer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/GradientDescentOptimizer>`_", ":ref:`cn_api_fluid_optimizer_SGDOptimizer`", "功能一致"
"131", "`tf.train.MomentumOptimizer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/MomentumOptimizer>`_", ":ref:`cn_api_fluid_optimizer_MomentumOptimizer`", "功能一致"
"132", "`tf.train.polynomial_decay <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/polynomial_decay>`_", ":ref:`cn_api_fluid_layers_polynomial_decay`", "功能一致"
"133", "`tf.train.RMSPropOptimizer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/RMSPropOptimizer>`_", ":ref:`cn_api_fluid_optimizer_RMSPropOptimizer`", "功能一致"
"134", "`tf.transpose <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/transpose>`_", ":ref:`cn_api_fluid_layers_transpose`", "功能一致"
"135", "`tf.truediv <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/truediv>`_", ":ref:`cn_api_fluid_layers_elementwise_div`", "功能一致"
"136", "`tf.truncated_normal <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/random/truncated_normal>`_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致"
"137", "`tf.truncated_normal_initializer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/initializers/truncated_normal>`_", ":ref:`cn_api_fluid_initializer_TruncatedNormal`", "功能一致"
"138", "`tf.unstack <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/unstack>`_", ":ref:`cn_api_fluid_layers_unstack`", "功能一致"
"139", "`tf.Variable <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Variable>`_", ":ref:`cn_api_fluid_layers_create_parameter`", "功能一致"
"140", "`tf.while_loop <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/while_loop>`_", ":ref:`cn_api_fluid_layers_While`", "`差异对比 <https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.while_loop.md>`_"
"141", "`tf.zeros <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/zeros>`_", ":ref:`cn_api_fluid_layers_zeros`", "功能一致"
"142", "`tf.zeros_initializer <https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/zeros_initializer>`_", ":ref:`cn_api_fluid_initializer_Constant`", "功能一致"
.. _cn_user_guide_broadcasting:
==================
广播 (broadcasting)
==================
飞桨(PaddlePaddle,以下简称Paddle)和其他框架一样,提供的一些API支持广播(broadcasting)机制,允许在一些运算时使用不同形状的张量。
通常来讲,如果有一个形状较小和一个形状较大的张量,我们希望多次使用较小的张量来对较大的张量执行一些操作,看起来像是较小形状的张量的形状首先被扩展到和较大形状的张量一致,然后做运算。
值得注意的是,这期间并没有对较小形状张量的数据拷贝操作。
飞桨的广播机制主要遵循如下规则;如果两个张量的形状遵循一下规则,我们认为这两个张量是可广播的(参考`Numpy 广播机制 <https://numpy.org/doc/stable/user/basics.broadcasting.html#module-numpy.doc.broadcasting>`):
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的维度开始,从前向后比较维度进行广播
.. _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 <https://numpy.org/doc/stable/user/basics.broadcasting.html#module-numpy.doc.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.
......@@ -11,7 +11,7 @@
- `Operator <operator.html>`_ : Operator表示对数据的操作。
- `Program <program.html>`_ : Program表示对计算过程的描述。
- `Executor <executor.html>`_ : Executor表示执行引擎。
- `Broadcasting <broadcasting.html>`_ : Paddle对广播支持的说明。
.. toctree::
:hidden:
......@@ -22,4 +22,4 @@
operator.rst
program.rst
executor.rst
broadcasting.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_en.html>`_ : 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 <broadcasting_en.html>`_ : introduces Paddle provides broadcasting semantics.
.. toctree::
:hidden:
programming_guide/programming_guide_en.md
lod_tensor_en.rst
broadcasting_en.rst
.. _cn_user_guide_Operator:
=======
=========
Operator
=======
=========
在飞桨(PaddlePaddle,以下简称Paddle)中,所有对数据的操作都由Operator表示
......
......@@ -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` 来安装
<a name="ct_source"></a>
### **本机编译**
......@@ -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目录下:
......
......@@ -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.
<a name="ct_source"></a>
### **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:
......
......@@ -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目录下:
......
......@@ -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
......
#
# 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) - 卷积核个数,同时也是输出的通道数。
"""
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()
......@@ -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'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册