Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f8b759a3
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f8b759a3
编写于
9月 27, 2020
作者:
Z
zhangting2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify docs of program API, test=document_fix
上级
f2c97b6d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
43 deletion
+44
-43
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+44
-43
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
f8b759a3
...
...
@@ -5264,32 +5264,32 @@ def default_startup_program():
"""
Get default/global startup program.
The layer function in :ref:`api_fluid_layers` will create parameters, :ref:`api_paddle_data_reader_reader` ,
`NCCL <https://developer.nvidia.com/nccl>`_ handles as global variables. The :code:`startup_program` will
initialize them by the OPs in startup :ref:`api_fluid_Program` . The :ref:`api_fluid_layers` function will
append these initialization operators into startup program.
The :code:`paddle.nn` function will append the initialization operators into startup program.
The :code:`startup_program` will initialize the parameters by the OPs.
This method will return the default or the current startup program. Users can use
:ref:`api_paddle_fluid_framework_program_guard` to switch :ref:`api_paddle_fluid_framework_Program` .
This method will return the :code:`default` or the :code:`current` startup
program. Users can use :ref:`api_fluid_program_guard` to switch :ref:`api_fluid_Program` .
Returns: current default startup :ref:`api_fluid_Program`
Returns:
Program: current default startup program.
Returns type:
:ref:`api_fluid_Program`
Returns type:
Examples:
.. code-block:: python
import paddle
.fluid as fluid
import paddle
main_program = fluid.Program()
startup_program = fluid.Program()
with fluid.program_guard(main_program=main_program, startup_program=startup_program):
x = fluid.layers.data(name="x", shape=[-1, 784], dtype='float32')
y = fluid.layers.data(name="y", shape=[-1, 1], dtype='int32')
z = fluid.layers.fc(name="fc", input=x, size=10, act="relu")
paddle.enable_static()
main_program = paddle.static.Program()
startup_program = paddle.static.Program()
with paddle.static.program_guard(main_program=main_program, startup_program=startup_program):
x = paddle.data(name="x", shape=[-1, 784], dtype='float32')
y = paddle.data(name="y", shape=[-1, 1], dtype='int32')
z = paddle.static.nn.fc(name="fc", input=x, size=10, act="relu")
print("main program is: {}".format(
fluid
.default_main_program()))
print("start up program is: {}".format(
fluid
.default_startup_program()))
print("main program is: {}".format(
paddle.static
.default_main_program()))
print("start up program is: {}".format(
paddle.static
.default_startup_program()))
"""
return
_startup_program_
...
...
@@ -5297,52 +5297,53 @@ def default_startup_program():
def
default_main_program
():
"""
This API can be used to get ``default main program`` which store the
descriptions of
``op`` and ``variable``
.
descriptions of
Ops and tensors
.
For example ``z =
fluid.layers
.elementwise_add(x, y)`` will create a new ``elementwise_add``
``op`` and a new ``z`` ``variable``, and they will be recorded in ``default main program``
For example ``z =
paddle
.elementwise_add(x, y)`` will create a new ``elementwise_add``
Op and a new ``z`` tensor, and they will be recorded in ``default main program`` .
The ``default
_main_
program`` is the default value for ``Program`` parameter in
a lot of
``fluid``
APIs. For example, the :code:`Executor.run()` will execute the
The ``default
main
program`` is the default value for ``Program`` parameter in
a lot of APIs. For example, the :code:`Executor.run()` will execute the
:code:`default_main_program` when the program is not specified.
If you want to
replace the ``default main program``, you can use :ref:`api_fluid_program_guard`
If you want to
switch the ``default main program``, you can use :ref:`api_paddle_fluid_framework_program_guard` .
Returns:
:ref:`api_fluid_Program`: a ``Program`` which holding the descriptions of ops and variable
s in the network.
Program: A ``Program`` which holding the descriptions of OPs and tensor
s in the network.
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
paddle.enable_static()
# Sample Network:
data =
fluid
.data(name='image', shape=[None, 3, 224, 224], dtype='float32')
label =
fluid
.data(name='label', shape=[None, 1], dtype='int64')
data =
paddle
.data(name='image', shape=[None, 3, 224, 224], dtype='float32')
label =
paddle
.data(name='label', shape=[None, 1], dtype='int64')
conv1 =
fluid.layers
.conv2d(data, 4, 5, 1, act=None)
bn1 =
fluid.layers
.batch_norm(conv1, act='relu')
pool1 =
fluid.layers
.pool2d(bn1, 2, 'max', 2)
conv2 =
fluid.layers
.conv2d(pool1, 16, 5, 1, act=None)
bn2 =
fluid.layers
.batch_norm(conv2, act='relu')
pool2 =
fluid.layers
.pool2d(bn2, 2, 'max', 2)
conv1 =
paddle.static.nn
.conv2d(data, 4, 5, 1, act=None)
bn1 =
paddle.static.nn
.batch_norm(conv1, act='relu')
pool1 =
paddle.nn.functional
.pool2d(bn1, 2, 'max', 2)
conv2 =
paddle.static.nn
.conv2d(pool1, 16, 5, 1, act=None)
bn2 =
paddle.static.nn
.batch_norm(conv2, act='relu')
pool2 =
paddle.nn.functional
.pool2d(bn2, 2, 'max', 2)
fc1 =
fluid.layers
.fc(pool2, size=50, act='relu')
fc2 =
fluid.layers
.fc(fc1, size=102, act='softmax')
fc1 =
paddle.static.nn
.fc(pool2, size=50, act='relu')
fc2 =
paddle.static.nn
.fc(fc1, size=102, act='softmax')
loss =
fluid.layer
s.cross_entropy(input=fc2, label=label)
loss =
fluid.layers
.mean(loss)
opt =
fluid
.optimizer.Momentum(
loss =
paddle.nn.functional.los
s.cross_entropy(input=fc2, label=label)
loss =
paddle
.mean(loss)
opt =
paddle
.optimizer.Momentum(
learning_rate=0.1,
momentum=0.9,
regularization=fluid
.regularizer.L2Decay(1e-4))
weight_decay=paddle
.regularizer.L2Decay(1e-4))
opt.minimize(loss)
#print the number of blocks in the program, 1 in this case
print(
fluid.default_main_program().num_blocks)
print(
paddle.static.default_main_program().num_blocks) #[1]
#print the description of variable 'image'
print(
fluid.default_main_program().blocks[0].var('image'
))
print(
paddle.static.default_main_program(
))
"""
return
_main_program_
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录