提交 3209aeb9 编写于 作者: L liym27 提交者: hong

Add Print in programming_guide, test=develop (#1040)

Committer: liym27 <liym0923@126.com>
上级 bd3642aa
......@@ -43,7 +43,6 @@ import paddle.fluid as fluid
y = fluid.layers.fc(input=x, size=128, bias_attr=True)
```
**2. 输入输出Tensor**
整个神经网络的输入数据也是一个特殊的 Tensor,在这个 Tensor 中,一些维度的大小在定义模型时无法确定(通常包括:batch size,如果 mini-batch 之间数据可变,也会包括图片的宽度和高度等),在定义模型时需要占位。
......@@ -97,7 +96,30 @@ type {
persistable: false
```
具体输出数值将在Executor运行时得到,详细过程会在后文展开描述。
具体输出数值将在Executor运行时得到。获取运行时的Variable数值有两种方式:方式一是利用 `paddle.fluid.layers.Print` 创建一个打印操作,打印正在访问的张量。方式二是将Variable添加在fetch_list中。
方式一的代码实现如下所示:
```python
import paddle.fluid as fluid
data = fluid.layers.fill_constant(shape=[1], value=0, dtype='int64')
data = fluid.layers.Print(data, message="Print data:")
```
运行时的输出结果:
```
1563874307 Print data: The place is:CPUPlace
Tensor[fill_constant_0.tmp_0]
shape: [1,]
dtype: x
data: 0,
```
更多 Print API 的使用方式请查看:[Print操作命令](https://www.paddlepaddle.org.cn/documentation/docs/zh/1.5/api_cn/layers_cn/control_flow_cn.html#print)
方式二Fetch_list的详细过程会在后文展开描述。
## 数据传入
......
......@@ -101,7 +101,29 @@ type {
persistable: false
```
Specific output value will be shown at the runtime of Executor. Detailed process will be explained later.
Specific output value will be shown at the runtime of Executor. There are two ways to get runtime Variable value. The first way is to use `paddle.fluid.layers.Print` to create a print op that will print the tensor being accessed. The second way is to add Variable to Fetch_list.
Code of the first way is as follows:
```python
import paddle.fluid as fluid
data = fluid.layers.fill_constant(shape=[1], value=0, dtype='int64')
data = fluid.layers.Print(data, message="Print data: ")
```
Output at the runtime of Executor:
```
1563874307 Print data: The place is:CPUPlace
Tensor[fill_constant_0.tmp_0]
shape: [1,]
dtype: x
data: 0,
```
For more information on how to use the Print API, please refer to [Print operator](https://www.paddlepaddle.org.cn/documentation/docs/en/1.5/api/layers/control_flow.html#print).
Detailed process of the second way Fetch_list will be explained later.
## Feed data
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册