Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
FluidDoc
提交
f369cef6
F
FluidDoc
项目概览
PaddlePaddle
/
FluidDoc
通知
10
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
23
列表
看板
标记
里程碑
合并请求
111
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FluidDoc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
23
Issue
23
列表
看板
标记
里程碑
合并请求
111
合并请求
111
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f369cef6
编写于
6月 29, 2020
作者:
A
Aurelius84
提交者:
GitHub
6月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add register_buffer zh doc in dygraph Layer (#2229)
* add register buffer zh doc * refine zh doc
上级
c3e0fc3b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
91 addition
and
10 deletion
+91
-10
doc/fluid/api_cn/dygraph_cn/Layer_cn.rst
doc/fluid/api_cn/dygraph_cn/Layer_cn.rst
+91
-10
未找到文件。
doc/fluid/api_cn/dygraph_cn/Layer_cn.rst
浏览文件 @
f369cef6
...
...
@@ -256,6 +256,87 @@ hook(Layer, input, output) -> None or modified output
for
prefix
,
layer
in
model
.
named_sublayers
():
print
(
prefix
,
layer
)
..
py
:
method
::
register_buffer
(
name
,
variable
,
persistable
=
True
)
将一个
Variable
注册为
buffer
。
buffer
是一个非参数类型的变量,不会被优化器更新,但在评估或预测阶段可能是必要的状态变量。比如
``
BatchNorm
``
中的均值和方差。
注册的
buffer
默认是可持久性的,会被保存到
``
state_dict
``
中。如果指定
``
persistable
``
参数为
False
,则会注册一个非持久性的
buffer
,即不会同步和保存到
``
state_dict
``
中。
参数:
-
**
name
**
(
str
)
-
注册
buffer
的名字。可以通过此名字来访问已注册的
buffer
。
-
**
variable
**
(
Variable
)
-
将被注册为
buffer
的变量。
-
**
persistable
**
(
bool
,
可选
)
-
注册的
buffer
是否需要可持久性地保存到
``
state_dict
``
中。
返回:
None
返回类型:
None
**
代码示例
**
..
code
-
block
::
python
import
numpy
as
np
import
paddle
.
fluid
as
fluid
with
fluid
.
dygraph
.
guard
():
linear
=
fluid
.
Linear
(
10
,
3
)
value
=
np
.
array
([
0
]).
astype
(
"float32"
)
buffer
=
fluid
.
dygraph
.
to_variable
(
value
)
linear
.
register_buffer
(
"buf_name"
,
buffer
,
persistable
=
True
)
#
get
the
buffer
by
attribute
.
print
(
linear
.
buf_name
)
..
py
:
method
::
buffers
(
include_sublayers
=
True
)
返回一个由当前层及其子层的所有
buffers
组成的列表。
参数:
-
**
include_sublayers
**
(
bool
,
可选
)
-
是否返回子层的
buffers
。如果为
True
,返回的列表中包含子层的
buffers
。默认值:
True
。
返回:一个由当前层及其子层的所有
buffers
组成的列表,列表中的元素类型为
Variable
。
返回类型:
list
..
py
:
method
::
named_buffers
(
prefix
=
''
,
include_sublayers
=
True
)
返回层中所有
buffers
的迭代器,生成名称和
buffer
的元组。
参数:
-
**
prefix
**
(
str
,
可选
)
-
在所有
buffer
名称前加的前缀。默认值:
''
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
是否返回子层的
buffers
。如果为
True
,返回的列表中包含子层的
buffers
。默认值:
True
。
返回:产出名称和
buffer
的元组的迭代器。
返回类型:
iterator
**
代码示例
**
..
code
-
block
::
python
import
numpy
as
np
import
paddle
.
fluid
as
fluid
with
fluid
.
dygraph
.
guard
():
fc1
=
fluid
.
Linear
(
10
,
3
)
buffer1
=
fluid
.
dygraph
.
to_variable
(
np
.
array
([
0
]).
astype
(
"float32"
))
#
register
a
variable
as
buffer
by
specific
`
persistable
`
fc1
.
register_buffer
(
"buf_name_1"
,
buffer1
,
persistable
=
True
)
fc2
=
fluid
.
Linear
(
3
,
10
)
buffer2
=
fluid
.
dygraph
.
to_variable
(
np
.
array
([
1
]).
astype
(
"float32"
))
#
register
a
buffer
by
assigning
an
attribute
with
Variable
.
#
The
`
persistable
`
can
only
be
False
by
this
way
.
fc2
.
buf_name_2
=
buffer2
model
=
fluid
.
dygraph
.
Sequential
(
fc1
,
fc2
)
#
get
all
named
buffers
for
name
,
buffer
in
model
.
named_buffers
():
print
(
name
,
buffer
)
..
py
:
method
::
forward
(*
inputs
,
**
kwargs
)
定义每次调用时执行的计算。应该被所有子类覆盖。
...
...
@@ -290,13 +371,13 @@ hook(Layer, input, output) -> None or modified output
..
py
:
method
::
state_dict
(
destination
=
None
,
include_sublayers
=
True
)
获取当前层及其子层的所有参数
。并将所有参数
存放在
dict
结构中。
获取当前层及其子层的所有参数
和可持久性
buffers
。并将所有参数和
buffers
存放在
dict
结构中。
参数:
-
**
destination
**
(
dict
,
可选
)
-
如果提供
``
destination
``
,则所有参数都将存放在
``
destination
``
中。
默认值:
None
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则包括子层的参数。默认值:
True
。
-
**
destination
**
(
dict
,
可选
)
-
如果提供
``
destination
``
,则所有参数
和可持久性
buffers
都将存放在
``
destination
``
中。
默认值:
None
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则包括子层的参数
和
buffers
。默认值:
True
。
返回:包含所有参数的
dict
返回:包含所有参数
和可持久行
buffers
的
dict
返回类型:
dict
...
...
@@ -312,11 +393,11 @@ hook(Layer, input, output) -> None or modified output
..
py
:
method
::
set_dict
(
stat_dict
,
include_sublayers
=
True
)
根据传入的
``
stat_dict
``
设置参数
。
所有参数
将由
``
stat_dict
``
中的
``
Tensor
``
设置。
根据传入的
``
stat_dict
``
设置参数
和可持久性
buffers
。
所有参数和
buffers
将由
``
stat_dict
``
中的
``
Tensor
``
设置。
参数:
-
**
state_dict
**
(
dict
)
-
包含所有参数的
dict
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则还包括子层的参数。
默认值:
True
。
-
**
state_dict
**
(
dict
)
-
包含所有参数
和可持久性
buffers
的
dict
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则还包括子层的参数
和
buffers
。
默认值:
True
。
返回:
None
...
...
@@ -337,11 +418,11 @@ hook(Layer, input, output) -> None or modified output
..
warning
::
该函数将被弃用。请使用
set_dict
函数。
根据传入的
``
stat_dict
``
设置参数
。
所有参数
将由
``
stat_dict
``
中的
``
Tensor
``
设置。
根据传入的
``
stat_dict
``
设置参数
和可持久性
buffers
。
所有参数和
buffers
将由
``
stat_dict
``
中的
``
Tensor
``
设置。
参数:
-
**
state_dict
**
(
dict
)
-
包含所有参数的
dict
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则还包括子层的参数。
默认值:
True
。
-
**
state_dict
**
(
dict
)
-
包含所有参数
和可持久性
buffers
的
dict
。
-
**
include_sublayers
**
(
bool
,
可选
)
-
如果设置为
True
,则还包括子层的参数
和
buffers
。
默认值:
True
。
返回:
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录