Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
4c5ed46b
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看板
未验证
提交
4c5ed46b
编写于
5月 12, 2022
作者:
G
gaotingquan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
0b036064
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
79 deletion
+35
-79
ppcls/arch/backbone/legendary_models/pp_lcnet_v2.py
ppcls/arch/backbone/legendary_models/pp_lcnet_v2.py
+35
-79
未找到文件。
ppcls/arch/backbone/legendary_models/pp_lcnet_v2.py
浏览文件 @
4c5ed46b
...
@@ -24,7 +24,6 @@ from paddle.nn.initializer import KaimingNormal
...
@@ -24,7 +24,6 @@ from paddle.nn.initializer import KaimingNormal
from
ppcls.arch.backbone.base.theseus_layer
import
TheseusLayer
from
ppcls.arch.backbone.base.theseus_layer
import
TheseusLayer
from
ppcls.utils.save_load
import
load_dygraph_pretrain
,
load_dygraph_pretrain_from_url
from
ppcls.utils.save_load
import
load_dygraph_pretrain
,
load_dygraph_pretrain_from_url
#TODO(gaotingquan): upload pretrained to bos
MODEL_URLS
=
{
MODEL_URLS
=
{
"PPLCNetV2_base"
:
"PPLCNetV2_base"
:
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_pretrained.pdparams"
,
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNetV2_base_pretrained.pdparams"
,
...
@@ -252,14 +251,16 @@ class RepDepthwiseSeparable(TheseusLayer):
...
@@ -252,14 +251,16 @@ class RepDepthwiseSeparable(TheseusLayer):
class
PPLCNetV2
(
TheseusLayer
):
class
PPLCNetV2
(
TheseusLayer
):
def
__init__
(
self
,
def
__init__
(
self
,
scale
=
1.0
,
scale
,
depths
=
[
2
,
2
,
6
,
2
]
,
depths
,
class_num
=
1000
,
class_num
=
1000
,
dropout_prob
=
0.2
,
dropout_prob
=
0
,
expand
=
1280
):
use_last_conv
=
True
,
class_expand
=
1280
):
super
().
__init__
()
super
().
__init__
()
self
.
scale
=
scale
self
.
scale
=
scale
self
.
expand
=
expand
self
.
use_last_conv
=
use_last_conv
self
.
class_expand
=
class_expand
self
.
stem
=
nn
.
Sequential
(
*
[
self
.
stem
=
nn
.
Sequential
(
*
[
ConvBNLayer
(
ConvBNLayer
(
...
@@ -273,77 +274,33 @@ class PPLCNetV2(TheseusLayer):
...
@@ -273,77 +274,33 @@ class PPLCNetV2(TheseusLayer):
dw_size
=
3
)
dw_size
=
3
)
])
])
# stage1
# stages
in_channels
,
kernel_size
,
split_pw
,
use_rep
,
use_se
,
use_shortcut
=
NET_CONFIG
[
self
.
stages
=
nn
.
LayerList
()
"stage1"
]
for
depth_idx
,
k
in
enumerate
(
NET_CONFIG
):
self
.
stage1
=
nn
.
Sequential
(
*
[
in_channels
,
kernel_size
,
split_pw
,
use_rep
,
use_se
,
use_shortcut
=
NET_CONFIG
[
RepDepthwiseSeparable
(
k
]
in_channels
=
make_divisible
((
in_channels
if
i
==
0
else
self
.
stages
.
append
(
in_channels
*
2
)
*
scale
),
nn
.
Sequential
(
*
[
out_channels
=
make_divisible
(
in_channels
*
2
*
scale
),
RepDepthwiseSeparable
(
stride
=
2
if
i
==
0
else
1
,
in_channels
=
make_divisible
((
in_channels
if
i
==
0
else
dw_size
=
kernel_size
,
in_channels
*
2
)
*
scale
),
split_pw
=
split_pw
,
out_channels
=
make_divisible
(
in_channels
*
2
*
scale
),
use_rep
=
use_rep
,
stride
=
2
if
i
==
0
else
1
,
use_se
=
use_se
,
dw_size
=
kernel_size
,
use_shortcut
=
use_shortcut
,
)
for
i
in
range
(
depths
[
0
])
split_pw
=
split_pw
,
])
use_rep
=
use_rep
,
use_se
=
use_se
,
# stage2
use_shortcut
=
use_shortcut
)
in_channels
,
kernel_size
,
split_pw
,
use_rep
,
use_se
,
use_shortcut
=
NET_CONFIG
[
for
i
in
range
(
depths
[
depth_idx
])
"stage2"
]
]))
self
.
stage2
=
nn
.
Sequential
(
*
[
RepDepthwiseSeparable
(
in_channels
=
make_divisible
((
in_channels
if
i
==
0
else
in_channels
*
2
)
*
scale
),
out_channels
=
make_divisible
(
in_channels
*
2
*
scale
),
stride
=
2
if
i
==
0
else
1
,
dw_size
=
kernel_size
,
split_pw
=
split_pw
,
use_rep
=
use_rep
,
use_se
=
use_se
,
use_shortcut
=
use_shortcut
,
)
for
i
in
range
(
depths
[
1
])
])
# stage3
in_channels
,
kernel_size
,
split_pw
,
use_rep
,
use_se
,
use_shortcut
=
NET_CONFIG
[
"stage3"
]
self
.
stage3
=
nn
.
Sequential
(
*
[
RepDepthwiseSeparable
(
in_channels
=
make_divisible
((
in_channels
if
i
==
0
else
in_channels
*
2
)
*
scale
),
out_channels
=
make_divisible
(
in_channels
*
2
*
scale
),
stride
=
2
if
i
==
0
else
1
,
dw_size
=
kernel_size
,
split_pw
=
split_pw
,
use_rep
=
use_rep
,
use_se
=
use_se
,
use_shortcut
=
use_shortcut
,
)
for
i
in
range
(
depths
[
2
])
])
# stage4
in_channels
,
kernel_size
,
split_pw
,
use_rep
,
use_se
,
use_shortcut
=
NET_CONFIG
[
"stage4"
]
self
.
stage4
=
nn
.
Sequential
(
*
[
RepDepthwiseSeparable
(
in_channels
=
make_divisible
((
in_channels
if
i
==
0
else
in_channels
*
2
)
*
scale
),
out_channels
=
make_divisible
(
in_channels
*
2
*
scale
),
stride
=
2
if
i
==
0
else
1
,
dw_size
=
kernel_size
,
split_pw
=
split_pw
,
use_rep
=
use_rep
,
use_se
=
use_se
,
use_shortcut
=
use_shortcut
,
)
for
i
in
range
(
depths
[
3
])
])
self
.
avg_pool
=
AdaptiveAvgPool2D
(
1
)
self
.
avg_pool
=
AdaptiveAvgPool2D
(
1
)
if
self
.
expand
:
if
self
.
use_last_conv
:
self
.
last_conv
=
Conv2D
(
self
.
last_conv
=
Conv2D
(
in_channels
=
make_divisible
(
NET_CONFIG
[
"stage4"
][
0
]
*
2
*
in_channels
=
make_divisible
(
NET_CONFIG
[
"stage4"
][
0
]
*
2
*
scale
),
scale
),
out_channels
=
self
.
expand
,
out_channels
=
self
.
class_
expand
,
kernel_size
=
1
,
kernel_size
=
1
,
stride
=
1
,
stride
=
1
,
padding
=
0
,
padding
=
0
,
...
@@ -352,18 +309,16 @@ class PPLCNetV2(TheseusLayer):
...
@@ -352,18 +309,16 @@ class PPLCNetV2(TheseusLayer):
self
.
dropout
=
Dropout
(
p
=
dropout_prob
,
mode
=
"downscale_in_infer"
)
self
.
dropout
=
Dropout
(
p
=
dropout_prob
,
mode
=
"downscale_in_infer"
)
self
.
flatten
=
nn
.
Flatten
(
start_axis
=
1
,
stop_axis
=-
1
)
self
.
flatten
=
nn
.
Flatten
(
start_axis
=
1
,
stop_axis
=-
1
)
in_features
=
self
.
expand
if
self
.
expand
else
NET_CONFIG
[
"stage4"
]
[
in_features
=
self
.
class_expand
if
self
.
use_last_conv
else
NET_CONFIG
[
0
]
*
2
*
scale
"stage4"
][
0
]
*
2
*
scale
self
.
fc
=
Linear
(
in_features
,
class_num
)
self
.
fc
=
Linear
(
in_features
,
class_num
)
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
x
=
self
.
stem
(
x
)
x
=
self
.
stem
(
x
)
x
=
self
.
stage1
(
x
)
for
stage
in
self
.
stages
:
x
=
self
.
stage2
(
x
)
x
=
stage
(
x
)
x
=
self
.
stage3
(
x
)
x
=
self
.
stage4
(
x
)
x
=
self
.
avg_pool
(
x
)
x
=
self
.
avg_pool
(
x
)
if
self
.
expand
:
if
self
.
use_last_conv
:
x
=
self
.
last_conv
(
x
)
x
=
self
.
last_conv
(
x
)
x
=
self
.
act
(
x
)
x
=
self
.
act
(
x
)
x
=
self
.
dropout
(
x
)
x
=
self
.
dropout
(
x
)
...
@@ -395,6 +350,7 @@ def PPLCNetV2_base(pretrained=False, use_ssld=False, **kwargs):
...
@@ -395,6 +350,7 @@ def PPLCNetV2_base(pretrained=False, use_ssld=False, **kwargs):
Returns:
Returns:
model: nn.Layer. Specific `PPLCNetV2_base` model depends on args.
model: nn.Layer. Specific `PPLCNetV2_base` model depends on args.
"""
"""
model
=
PPLCNetV2
(
scale
=
1.0
,
depths
=
[
2
,
2
,
6
,
2
],
**
kwargs
)
model
=
PPLCNetV2
(
scale
=
1.0
,
depths
=
[
2
,
2
,
6
,
2
],
dropout_prob
=
0.2
,
**
kwargs
)
_load_pretrained
(
pretrained
,
model
,
MODEL_URLS
[
"PPLCNetV2_base"
],
use_ssld
)
_load_pretrained
(
pretrained
,
model
,
MODEL_URLS
[
"PPLCNetV2_base"
],
use_ssld
)
return
model
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录