Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
07e1e5dc
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看板
提交
07e1e5dc
编写于
5月 14, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cspnet
上级
9123f5da
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
74 deletion
+68
-74
ppcls/modeling/architectures/__init__.py
ppcls/modeling/architectures/__init__.py
+1
-1
ppcls/modeling/architectures/csp_resnet.py
ppcls/modeling/architectures/csp_resnet.py
+67
-73
未找到文件。
ppcls/modeling/architectures/__init__.py
浏览文件 @
07e1e5dc
...
...
@@ -46,4 +46,4 @@ from .resnet_acnet import ResNet18_ACNet, ResNet34_ACNet, ResNet50_ACNet, ResNet
# distillation model
from
.distillation_models
import
ResNet50_vd_distill_MobileNetV3_large_x1_0
,
ResNeXt101_32x16d_wsl_distill_ResNet50_vd
from
.csp_resnet
import
CSPResNet50
from
.csp_resnet
import
*
ppcls/modeling/architectures/csp_resnet.py
浏览文件 @
07e1e5dc
...
...
@@ -18,11 +18,10 @@ from __future__ import print_function
import
math
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
__all__
=
[
"CSPResNet50"
,
]
__all__
=
[
"CSPResNet50"
,
"CSPResNet101"
]
class
CSPResNet
():
...
...
@@ -31,19 +30,16 @@ class CSPResNet():
def
net
(
self
,
input
,
class_dim
=
1000
,
data_format
=
"NCHW"
):
layers
=
self
.
layers
supported_layers
=
[
18
,
34
,
50
,
101
,
152
]
supported_layers
=
[
50
,
101
]
assert
layers
in
supported_layers
,
\
"supported layers are {} but input layer is {}"
.
format
(
supported_layers
,
layers
)
if
layers
==
18
:
depth
=
[
2
,
2
,
2
,
2
]
elif
layers
==
34
or
layers
==
50
:
if
layers
==
50
:
depth
=
[
3
,
3
,
5
,
2
]
elif
layers
==
101
:
depth
=
[
3
,
4
,
23
,
3
]
elif
layers
==
152
:
depth
=
[
3
,
8
,
36
,
3
]
depth
=
[
3
,
3
,
22
,
2
]
num_filters
=
[
64
,
128
,
256
,
512
]
conv
=
self
.
conv_bn_layer
(
...
...
@@ -62,75 +58,68 @@ class CSPResNet():
pool_type
=
'max'
,
data_format
=
data_format
)
if
layers
>=
50
:
for
block
in
range
(
len
(
depth
)):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
)
if
block
!=
0
:
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
num_filters
=
num_filters
[
block
],
filter_size
=
3
,
stride
=
2
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_downsample"
,
data_format
=
data_format
)
# layer warp
# left, right = fluid.layers.split(
# conv,
# num_or_sections=[conv.shape[1]//2, conv.shape[1]//2],
# dim=1)
left
=
conv
right
=
conv
if
block
==
0
:
ch
=
num_filters
[
block
]
else
:
ch
=
num_filters
[
block
]
*
2
right
=
self
.
conv_bn_layer
(
input
=
right
,
num_filters
=
ch
,
filter_size
=
1
,
for
block
in
range
(
len
(
depth
)):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
)
if
block
!=
0
:
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
num_filters
=
num_filters
[
block
],
filter_size
=
3
,
stride
=
2
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_
right_first_rout
e"
,
name
=
conv_name
+
"_
downsampl
e"
,
data_format
=
data_format
)
for
i
in
range
(
depth
[
block
]):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
+
i
)
right
=
self
.
bottleneck_block
(
input
=
right
,
num_filters
=
num_filters
[
block
],
stride
=
1
,
name
=
conv_name
,
data_format
=
data_format
)
# route
left
=
self
.
conv_bn_layer
(
input
=
left
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_left_route"
,
data_format
=
data_format
)
right
=
self
.
conv_bn_layer
(
# split
left
=
conv
right
=
conv
if
block
==
0
:
ch
=
num_filters
[
block
]
else
:
ch
=
num_filters
[
block
]
*
2
right
=
self
.
conv_bn_layer
(
input
=
right
,
num_filters
=
ch
,
filter_size
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_right_first_route"
,
data_format
=
data_format
)
for
i
in
range
(
depth
[
block
]):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
+
i
)
right
=
self
.
bottleneck_block
(
input
=
right
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_right_route"
,
data_format
=
data_format
)
conv
=
fluid
.
layers
.
concat
([
left
,
right
],
axis
=
1
)
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
num_filters
=
num_filters
[
block
],
stride
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_merged_transition"
,
name
=
conv_name
,
data_format
=
data_format
)
else
:
assert
False
,
"not implemented now!!!"
# route
left
=
self
.
conv_bn_layer
(
input
=
left
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_left_route"
,
data_format
=
data_format
)
right
=
self
.
conv_bn_layer
(
input
=
right
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_right_route"
,
data_format
=
data_format
)
conv
=
fluid
.
layers
.
concat
([
left
,
right
],
axis
=
1
)
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
num_filters
=
num_filters
[
block
]
*
2
,
filter_size
=
1
,
stride
=
1
,
act
=
"leaky_relu"
,
name
=
conv_name
+
"_merged_transition"
,
data_format
=
data_format
)
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
...
...
@@ -193,7 +182,7 @@ class CSPResNet():
ch_in
=
input
.
shape
[
1
]
else
:
ch_in
=
input
.
shape
[
-
1
]
if
ch_in
!=
ch_out
or
stride
!=
1
or
is_first
==
True
:
if
ch_in
!=
ch_out
or
stride
!=
1
or
is_first
is
True
:
return
self
.
conv_bn_layer
(
input
,
ch_out
,
1
,
stride
,
name
=
name
,
data_format
=
data_format
)
else
:
...
...
@@ -239,3 +228,8 @@ class CSPResNet():
def
CSPResNet50
():
model
=
CSPResNet
(
layers
=
50
)
return
model
def
CSPResNet101
():
model
=
CSPResNet
(
layers
=
101
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录