Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
de443726
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
de443726
编写于
11月 29, 2022
作者:
G
GGBond8488
提交者:
GitHub
11月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove paddle.nn.Sequential to fix dygraph to static error (#48477)
上级
d926b30b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
1 addition
and
74 deletion
+1
-74
python/paddle/nn/__init__.py
python/paddle/nn/__init__.py
+1
-1
python/paddle/nn/layer/container.py
python/paddle/nn/layer/container.py
+0
-73
未找到文件。
python/paddle/nn/__init__.py
浏览文件 @
de443726
...
...
@@ -17,7 +17,7 @@
from
..fluid.dygraph.layers
import
Layer
# noqa: F401
from
.layer.container
import
LayerList
# noqa: F401
from
.layer.container
import
ParameterList
# noqa: F401
from
.
layer
.container
import
Sequential
# noqa: F401
from
.
.fluid.dygraph
.container
import
Sequential
# noqa: F401
from
.clip
import
ClipGradByGlobalNorm
# noqa: F401
from
.clip
import
ClipGradByNorm
# noqa: F401
...
...
python/paddle/nn/layer/container.py
浏览文件 @
de443726
...
...
@@ -299,79 +299,6 @@ class LayerDict(Layer):
self
.
add_sublayer
(
kv
[
0
],
kv
[
1
])
class
Sequential
(
Layer
):
"""Sequential container.
Sub layers will be added to this container in the order of argument in the constructor.
The argument passed to the constructor can be iterable Layers or iterable name Layer pairs.
Parameters:
layers(Layer|list|tuple): Layer or list/tuple of iterable name Layer pair.
Examples:
.. code-block:: python
import paddle
data = paddle.uniform(shape=[30, 10], dtype='float32')
# create Sequential with iterable Layers
model1 = paddle.nn.Sequential(
paddle.nn.Linear(10, 1), paddle.nn.Linear(1, 2)
)
model1[0] # access the first layer
res1 = model1(data) # sequential execution
# create Sequential with name Layer pairs
model2 = paddle.nn.Sequential(
('l1', paddle.nn.Linear(10, 2)),
('l2', paddle.nn.Linear(2, 3))
)
model2['l1'] # access l1 layer
model2.add_sublayer('l3', paddle.nn.Linear(3, 3)) # add sublayer
res2 = model2(data) # sequential execution
"""
def
__init__
(
self
,
*
layers
):
super
().
__init__
()
if
len
(
layers
)
>
0
and
isinstance
(
layers
[
0
],
(
list
,
tuple
)):
for
name
,
layer
in
layers
:
self
.
add_sublayer
(
name
,
layer
)
else
:
for
idx
,
layer
in
enumerate
(
layers
):
self
.
add_sublayer
(
str
(
idx
),
layer
)
def
__getitem__
(
self
,
name
):
if
isinstance
(
name
,
slice
):
return
self
.
__class__
(
*
(
list
(
self
.
_sub_layers
.
values
())[
name
]))
elif
isinstance
(
name
,
str
):
return
self
.
_sub_layers
[
name
]
else
:
if
name
>=
len
(
self
.
_sub_layers
):
raise
IndexError
(
'index {} is out of range'
.
format
(
name
))
elif
name
<
0
and
name
>=
-
len
(
self
.
_sub_layers
):
name
+=
len
(
self
.
_sub_layers
)
elif
name
<
-
len
(
self
.
_sub_layers
):
raise
IndexError
(
'index {} is out of range'
.
format
(
name
))
return
list
(
self
.
_sub_layers
.
values
())[
name
]
def
__setitem__
(
self
,
name
,
layer
):
assert
isinstance
(
layer
,
Layer
)
setattr
(
self
,
str
(
name
),
layer
)
def
__delitem__
(
self
,
name
):
name
=
str
(
name
)
assert
name
in
self
.
_sub_layers
del
self
.
_sub_layers
[
name
]
def
__len__
(
self
):
return
len
(
self
.
_sub_layers
)
def
forward
(
self
,
input
):
for
layer
in
self
.
_sub_layers
.
values
():
input
=
layer
(
input
)
return
input
class
ParameterList
(
Layer
):
"""ParameterList Container.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录