Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
5131956d
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5131956d
编写于
9月 06, 2021
作者:
W
weishengyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbg theseus
上级
ce39aea9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
15 deletion
+21
-15
ppcls/arch/backbone/base/theseus_layer.py
ppcls/arch/backbone/base/theseus_layer.py
+16
-13
ppcls/arch/backbone/legendary_models/mobilenet_v1.py
ppcls/arch/backbone/legendary_models/mobilenet_v1.py
+4
-1
ppcls/arch/backbone/legendary_models/vgg.py
ppcls/arch/backbone/legendary_models/vgg.py
+1
-1
未找到文件。
ppcls/arch/backbone/base/theseus_layer.py
浏览文件 @
5131956d
...
...
@@ -38,20 +38,21 @@ class TheseusLayer(nn.Layer):
for
layer_i
in
self
.
_sub_layers
:
layer_name
=
self
.
_sub_layers
[
layer_i
].
full_name
()
if
isinstance
(
self
.
_sub_layers
[
layer_i
],
(
nn
.
Sequential
,
nn
.
LayerList
)):
self
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
_sub_layers
[
layer_i
])
self
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
_sub_layers
[
layer_i
],
self
.
res_dict
)
self
.
_sub_layers
[
layer_i
].
update_res
(
return_patterns
)
else
:
for
return_pattern
in
return_patterns
:
if
re
.
match
(
return_pattern
,
layer_name
):
if
not
isinstance
(
self
.
_sub_layers
[
layer_i
],
TheseusLayer
):
self
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
_sub_layers
[
layer_i
])
self
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
_sub_layers
[
layer_i
],
self
.
res_dict
)
else
:
self
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
_sub_layers
[
layer_i
].
register_forward_post_hook
(
self
.
_sub_layers
[
layer_i
].
_save_sub_res_hook
)
self
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
if
isinstance
(
self
.
_sub_layers
[
layer_i
],
TheseusLayer
):
self
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
_sub_layers
[
layer_i
].
update_res
(
return_patterns
)
if
isinstance
(
self
.
_sub_layers
[
layer_i
],
TheseusLayer
):
self
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
_sub_layers
[
layer_i
].
update_res
(
return_patterns
)
def
_save_sub_res_hook
(
self
,
layer
,
input
,
output
):
self
.
res_dict
[
layer
.
full_name
()]
=
output
...
...
@@ -85,10 +86,12 @@ class TheseusLayer(nn.Layer):
class
WrapLayer
(
TheseusLayer
):
def
__init__
(
self
,
sub_layer
):
def
__init__
(
self
,
sub_layer
,
res_dict
=
None
):
super
(
WrapLayer
,
self
).
__init__
()
self
.
sub_layer
=
sub_layer
self
.
name
=
sub_layer
.
full_name
()
if
res_dict
is
not
None
:
self
.
res_dict
=
res_dict
def
full_name
(
self
):
return
self
.
name
...
...
@@ -101,14 +104,14 @@ class WrapLayer(TheseusLayer):
return
for
layer_i
in
self
.
sub_layer
.
_sub_layers
:
if
isinstance
(
self
.
sub_layer
.
_sub_layers
[
layer_i
],
(
nn
.
Sequential
,
nn
.
LayerList
)):
self
.
sub_layer
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
sub_layer
.
_sub_layers
[
layer_i
])
self
.
sub_layer
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
sub_layer
.
_sub_layers
[
layer_i
]
=
wrap_theseus
(
self
.
sub_layer
.
_sub_layers
[
layer_i
],
self
.
res_dict
)
self
.
sub_layer
.
_sub_layers
[
layer_i
].
update_res
(
return_patterns
)
elif
isinstance
(
self
.
sub_layer
.
_sub_layers
[
layer_i
],
TheseusLayer
):
self
.
sub_layer
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
layer_name
=
self
.
sub_layer
.
_sub_layers
[
layer_i
].
full_name
()
for
return_pattern
in
return_patterns
:
if
re
.
match
(
return_pattern
,
layer_name
):
self
.
sub_layer
.
_sub_layers
[
layer_i
].
res_dict
=
self
.
res_dict
self
.
sub_layer
.
_sub_layers
[
layer_i
].
register_forward_post_hook
(
self
.
_sub_layers
[
layer_i
].
_save_sub_res_hook
)
...
...
@@ -116,6 +119,6 @@ class WrapLayer(TheseusLayer):
self
.
sub_layer
.
_sub_layers
[
layer_i
].
update_res
(
return_patterns
)
def
wrap_theseus
(
sub_layer
):
wrapped_layer
=
WrapLayer
(
sub_layer
)
def
wrap_theseus
(
sub_layer
,
res_dict
=
None
):
wrapped_layer
=
WrapLayer
(
sub_layer
,
res_dict
)
return
wrapped_layer
ppcls/arch/backbone/legendary_models/mobilenet_v1.py
浏览文件 @
5131956d
...
...
@@ -146,12 +146,15 @@ class MobileNet(TheseusLayer):
class_num
,
weight_attr
=
ParamAttr
(
initializer
=
KaimingNormal
()))
def
forward
(
self
,
x
):
def
forward
(
self
,
x
,
res_dict
=
None
):
x
=
self
.
conv
(
x
)
x
=
self
.
blocks
(
x
)
x
=
self
.
avg_pool
(
x
)
x
=
self
.
flatten
(
x
)
x
=
self
.
fc
(
x
)
if
self
.
res_dict
and
res_dict
is
not
None
:
for
res_key
in
list
(
self
.
res_dict
):
res_dict
[
res_key
]
=
self
.
res_dict
.
pop
(
res_key
)
return
x
...
...
ppcls/arch/backbone/legendary_models/vgg.py
浏览文件 @
5131956d
...
...
@@ -111,7 +111,7 @@ class VGGNet(TheseusLayer):
model: nn.Layer. Specific VGG model depends on args.
"""
def
__init__
(
self
,
config
,
stop_grad_layers
=
0
,
class_num
=
1000
,
return_patterns
=
None
):
def
__init__
(
self
,
config
,
stop_grad_layers
=
0
,
class_num
=
1000
):
super
().
__init__
()
self
.
stop_grad_layers
=
stop_grad_layers
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录