Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
97cd5540
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看板
未验证
提交
97cd5540
编写于
6月 04, 2021
作者:
W
Walter
提交者:
GitHub
6月 04, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #780 from RainFrost1/develop_reg
add variant models
上级
ff232a58
76fcde59
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
10 deletion
+48
-10
ppcls/arch/backbone/__init__.py
ppcls/arch/backbone/__init__.py
+1
-0
ppcls/arch/backbone/base/theseus_layer.py
ppcls/arch/backbone/base/theseus_layer.py
+24
-10
ppcls/arch/backbone/variant_models/__init__.py
ppcls/arch/backbone/variant_models/__init__.py
+1
-0
ppcls/arch/backbone/variant_models/resnet_variant.py
ppcls/arch/backbone/variant_models/resnet_variant.py
+22
-0
未找到文件。
ppcls/arch/backbone/__init__.py
浏览文件 @
97cd5540
...
...
@@ -47,3 +47,4 @@ from ppcls.arch.backbone.model_zoo.distillation_models import ResNet50_vd_distil
from
ppcls.arch.backbone.model_zoo.swin_transformer
import
SwinTransformer_tiny_patch4_window7_224
,
SwinTransformer_small_patch4_window7_224
,
SwinTransformer_base_patch4_window7_224
,
SwinTransformer_base_patch4_window12_384
,
SwinTransformer_large_patch4_window7_224
,
SwinTransformer_large_patch4_window12_384
from
ppcls.arch.backbone.model_zoo.mixnet
import
MixNet_S
,
MixNet_M
,
MixNet_L
from
ppcls.arch.backbone.model_zoo.rexnet
import
ReXNet_1_0
,
ReXNet_1_3
,
ReXNet_1_5
,
ReXNet_2_0
,
ReXNet_3_0
from
ppcls.arch.backbone.variant_models.resnet_variant
import
ResNet50_last_stage_stride1
ppcls/arch/backbone/base/theseus_layer.py
浏览文件 @
97cd5540
...
...
@@ -35,15 +35,18 @@ class TheseusLayer(nn.Layer):
after_stop
=
True
continue
if
isinstance
(
self
.
_sub_layers
[
layer_i
],
TheseusLayer
):
after_stop
=
self
.
_sub_layers
[
layer_i
].
stop_after
(
stop_layer_name
)
after_stop
=
self
.
_sub_layers
[
layer_i
].
stop_after
(
stop_layer_name
)
return
after_stop
def
_update_res
(
self
,
return_layers
):
for
layer_i
in
self
.
_sub_layers
:
layer_name
=
self
.
_sub_layers
[
layer_i
].
full_name
()
for
return_pattern
in
return_layers
:
if
return_layers
is
not
None
and
re
.
match
(
return_pattern
,
layer_name
):
self
.
_sub_layers
[
layer_i
].
register_forward_post_hook
(
self
.
_save_sub_res_hook
)
if
return_layers
is
not
None
and
re
.
match
(
return_pattern
,
layer_name
):
self
.
_sub_layers
[
layer_i
].
register_forward_post_hook
(
self
.
_save_sub_res_hook
)
# def _save_sub_res_hook(self, layer, input, output):
# self.res_dict[layer.full_name()] = output
...
...
@@ -51,13 +54,24 @@ class TheseusLayer(nn.Layer):
# def _disconnect_res_dict_hook(self, input, output):
# self.res_dict = None
def
replace_sub
(
self
,
layer_name_pattern
,
replace_function
,
recursive
=
True
):
for
layer_i
in
self
.
_sub_layers
:
layer_name
=
self
.
_sub_layers
[
layer_i
].
full_name
()
def
replace_sub
(
self
,
layer_name_pattern
,
replace_function
,
recursive
=
True
):
for
k
in
self
.
_sub_layers
.
keys
():
layer_name
=
self
.
_sub_layers
[
k
].
full_name
()
if
re
.
match
(
layer_name_pattern
,
layer_name
):
self
.
_sub_layers
[
layer_i
]
=
replace_function
(
self
.
_sub_layers
[
layer_i
])
if
recursive
and
isinstance
(
self
.
_sub_layers
[
layer_i
],
TheseusLayer
):
self
.
_sub_layers
[
layer_i
].
replace_sub
(
layer_name_pattern
,
replace_function
,
recursive
)
self
.
_sub_layers
[
k
]
=
replace_function
(
self
.
_sub_layers
[
k
])
if
recursive
:
if
isinstance
(
self
.
_sub_layers
[
k
],
TheseusLayer
):
self
.
_sub_layers
[
k
].
replace_sub
(
layer_name_pattern
,
replace_function
,
recursive
)
elif
isinstance
(
self
.
_sub_layers
[
k
],
nn
.
Sequential
)
or
isinstance
(
self
.
_sub_layers
[
k
],
nn
.
LayerList
):
for
kk
in
self
.
_sub_layers
[
k
].
_sub_layers
.
keys
():
self
.
_sub_layers
[
k
].
_sub_layers
[
kk
].
replace_sub
(
layer_name_pattern
,
replace_function
,
recursive
)
else
:
pass
'''
example of replace function:
...
...
@@ -70,4 +84,4 @@ class TheseusLayer(nn.Layer):
)
return new_conv
'''
\ No newline at end of file
'''
ppcls/arch/backbone/variant_models/__init__.py
0 → 100644
浏览文件 @
97cd5540
from
.resnet_variant
import
ResNet50_last_stage_stride1
ppcls/arch/backbone/variant_models/resnet_variant.py
0 → 100644
浏览文件 @
97cd5540
from
paddle.nn
import
Conv2D
from
ppcls.arch.backbone.legendary_models.resnet
import
ResNet50
__all__
=
[
"ResNet50_last_stage_stride1"
]
def
ResNet50_last_stage_stride1
(
pretrained
=
False
,
use_ssld
=
False
,
**
kwargs
):
def
replace_function
(
conv
):
new_conv
=
Conv2D
(
in_channels
=
conv
.
_in_channels
,
out_channels
=
conv
.
_out_channels
,
kernel_size
=
conv
.
_kernel_size
,
stride
=
1
,
padding
=
conv
.
_padding
,
groups
=
conv
.
_groups
,
bias_attr
=
conv
.
_bias_attr
)
return
new_conv
match_re
=
"conv2d_4[4|6]"
model
=
ResNet50
(
pretrained
=
pretrained
,
use_ssld
=
use_ssld
,
**
kwargs
)
model
.
replace_sub
(
match_re
,
replace_function
,
True
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录