Skip to content

Commit 34f027d

Browse files
author
Shibo Tao
authored
add doc for api paddle.static.normalize_program. test=develop (#3577) (#3578)
1 parent abec0cb commit 34f027d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. _cn_api_fluid_io_normalize_program:
2+
3+
normalize_program
4+
-------------------------------
5+
6+
7+
.. py:function:: paddle.static.normalize_program(program, feed_vars, fetch_vars)
8+
9+
10+
11+
12+
根据指定的 feed_vars 和 fetch_vars,优化 program。
13+
14+
参数:
15+
- **program** - 指定想要优化的 program。
16+
- **feed_vars** (Variable | list[Variable]) – 模型的输入变量。
17+
- **fetch_vars** (Variable | list[Variable]) – 模型的输出变量。
18+
19+
返回:优化之后的 program。
20+
21+
抛出异常:
22+
- ``TypeError`` – 如果 ``program`` 类型不是 ``Program``, 或 ``feed_vars``, ``fetch_vars`` 类型不是 Variable 或 list[Variable],则抛出异常。
23+
24+
**代码示例**
25+
26+
.. code-block:: python
27+
28+
import paddle
29+
30+
paddle.enable_static()
31+
32+
path_prefix = "./infer_model"
33+
34+
# User defined network, here a softmax regession example
35+
image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32')
36+
label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
37+
predict = paddle.static.nn.fc(image, 10, activation='softmax')
38+
39+
loss = paddle.nn.functional.cross_entropy(predict, label)
40+
41+
exe = paddle.static.Executor(paddle.CPUPlace())
42+
exe.run(paddle.static.default_startup_program())
43+
44+
# normalize main program.
45+
program = paddle.static.default_main_program()
46+
normalized_program = paddle.static.normalize_program(program, [image], [predict])
47+

0 commit comments

Comments
 (0)