Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
71cb728b
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
接近 2 年 前同步成功
通知
116
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看板
提交
71cb728b
编写于
12月 27, 2021
作者:
G
gaotingquan
提交者:
Tingquan Gao
12月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: rename to upgrade_sublayer()
上级
1e696ac2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
26 deletion
+26
-26
ppcls/arch/backbone/base/theseus_layer.py
ppcls/arch/backbone/base/theseus_layer.py
+12
-12
ppcls/arch/backbone/variant_models/resnet_variant.py
ppcls/arch/backbone/variant_models/resnet_variant.py
+3
-3
ppcls/arch/backbone/variant_models/vgg_variant.py
ppcls/arch/backbone/variant_models/vgg_variant.py
+11
-11
未找到文件。
ppcls/arch/backbone/base/theseus_layer.py
浏览文件 @
71cb728b
...
...
@@ -45,15 +45,14 @@ class TheseusLayer(nn.Layer):
self
.
res_dict
[
self
.
res_name
]
=
output
def
replace_sub
(
self
,
*
args
,
**
kwargs
)
->
None
:
msg
=
"The function 'replace_sub()' is deprecated, please use '
layer_wrench
()' instead."
msg
=
"The function 'replace_sub()' is deprecated, please use '
upgrade_sublayer
()' instead."
logger
.
error
(
DeprecationWarning
(
msg
))
raise
DeprecationWarning
(
msg
)
# TODO(gaotingquan): what is a good name?
def
layer_wrench
(
self
,
layer_name_pattern
:
Union
[
str
,
List
[
str
]],
handle_func
:
Callable
[[
nn
.
Layer
,
str
],
nn
.
Layer
])
->
Dict
[
str
,
nn
.
Layer
]:
def
upgrade_sublayer
(
self
,
layer_name_pattern
:
Union
[
str
,
List
[
str
]],
handle_func
:
Callable
[[
nn
.
Layer
,
str
],
nn
.
Layer
]
)
->
Dict
[
str
,
nn
.
Layer
]:
"""use 'handle_func' to modify the sub-layer(s) specified by 'layer_name_pattern'.
Args:
...
...
@@ -88,7 +87,7 @@ class TheseusLayer(nn.Layer):
handle_res_dict
=
{}
for
pattern
in
layer_name_pattern
:
# parse pattern to find target layer and its parent
# parse pattern to find target layer and its parent
layer_list
=
parse_pattern_str
(
pattern
=
pattern
,
parent_layer
=
self
)
if
not
layer_list
:
continue
...
...
@@ -166,7 +165,8 @@ class TheseusLayer(nn.Layer):
handle_func
=
Handler
(
self
.
res_dict
)
res_dict
=
self
.
layer_wrench
(
return_patterns
,
handle_func
=
handle_func
)
res_dict
=
self
.
upgrade_sublayer
(
return_patterns
,
handle_func
=
handle_func
)
if
hasattr
(
self
,
"hook_remove_helper"
):
self
.
hook_remove_helper
.
remove
()
...
...
@@ -221,10 +221,10 @@ def parse_pattern_str(pattern: str, parent_layer: nn.Layer) -> Union[
parent_layer (nn.Layer): The root layer relative to the pattern.
Returns:
Union[None, List[Dict[str, Union[nn.Layer, str, None]]]]: None if failed. If successfully, the members are layers parsed in order:
[
{"layer": first layer, "name": first layer's name parsed, "index": first layer's index parsed if exist},
{"layer": second layer, "name": second layer's name parsed, "index": second layer's index parsed if exist},
Union[None, List[Dict[str, Union[nn.Layer, str, None]]]]: None if failed. If successfully, the members are layers parsed in order:
[
{"layer": first layer, "name": first layer's name parsed, "index": first layer's index parsed if exist},
{"layer": second layer, "name": second layer's name parsed, "index": second layer's index parsed if exist},
...
]
"""
...
...
ppcls/arch/backbone/variant_models/resnet_variant.py
浏览文件 @
71cb728b
...
...
@@ -5,7 +5,7 @@ __all__ = ["ResNet50_last_stage_stride1"]
def
ResNet50_last_stage_stride1
(
pretrained
=
False
,
use_ssld
=
False
,
**
kwargs
):
def
replace_function
(
conv
):
def
replace_function
(
conv
,
pattern
):
new_conv
=
Conv2D
(
in_channels
=
conv
.
_in_channels
,
out_channels
=
conv
.
_out_channels
,
...
...
@@ -16,8 +16,8 @@ def ResNet50_last_stage_stride1(pretrained=False, use_ssld=False, **kwargs):
bias_attr
=
conv
.
_bias_attr
)
return
new_conv
match_re
=
"conv2d_4[4|6]"
pattern
=
[
"blocks[13].conv1.conv"
,
"blocks[13].short.conv"
]
model
=
ResNet50
(
pretrained
=
False
,
use_ssld
=
use_ssld
,
**
kwargs
)
model
.
replace_sub
(
match_re
,
replace_function
,
True
)
model
.
upgrade_sublayer
(
pattern
,
replace_function
)
_load_pretrained
(
pretrained
,
model
,
MODEL_URLS
[
"ResNet50"
],
use_ssld
)
return
model
ppcls/arch/backbone/variant_models/vgg_variant.py
浏览文件 @
71cb728b
import
paddle
from
paddle.nn
import
Sigmoid
from
ppcls.arch.backbone.legendary_models.vgg
import
VGG19
__all__
=
[
"VGG19Sigmoid"
]
class
SigmoidSuffix
(
paddle
.
nn
.
Layer
):
def
__init__
(
self
,
origin_layer
):
super
(
SigmoidSuffix
,
self
).
__init__
()
super
().
__init__
()
self
.
origin_layer
=
origin_layer
self
.
sigmoid
=
Sigmoid
()
def
forward
(
self
,
input
,
res_dict
=
None
,
**
kwargs
):
x
=
self
.
origin_layer
(
input
)
x
=
self
.
sigmoid
(
x
)
return
x
def
VGG19Sigmoid
(
pretrained
=
False
,
use_ssld
=
False
,
**
kwargs
):
def
replace_function
(
origin_layer
):
def
replace_function
(
origin_layer
,
pattern
):
new_layer
=
SigmoidSuffix
(
origin_layer
)
return
new_layer
match_re
=
"linear_
2"
pattern
=
"fc
2"
model
=
VGG19
(
pretrained
=
pretrained
,
use_ssld
=
use_ssld
,
**
kwargs
)
model
.
replace_sub
(
match_re
,
replace_function
,
True
)
model
.
upgrade_sublayer
(
pattern
,
replace_function
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录