Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
78791df2
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
78791df2
编写于
6月 16, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add lr_mult_list
上级
5d19dfa6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
140 addition
and
123 deletion
+140
-123
pdseg/models/backbone/resnet_vd.py
pdseg/models/backbone/resnet_vd.py
+140
-123
未找到文件。
pdseg/models/backbone/resnet_vd.py
浏览文件 @
78791df2
...
@@ -40,11 +40,21 @@ train_parameters = {
...
@@ -40,11 +40,21 @@ train_parameters = {
class
ResNet
():
class
ResNet
():
def
__init__
(
self
,
layers
=
50
,
scale
=
1.0
,
stem
=
None
):
def
__init__
(
self
,
layers
=
50
,
scale
=
1.0
,
stem
=
None
,
lr_mult_list
=
[
1.0
,
1.0
,
1.0
,
1.0
,
1.0
]):
self
.
params
=
train_parameters
self
.
params
=
train_parameters
self
.
layers
=
layers
self
.
layers
=
layers
self
.
scale
=
scale
self
.
scale
=
scale
self
.
stem
=
stem
self
.
stem
=
stem
self
.
lr_mult_list
=
lr_mult_list
assert
len
(
self
.
lr_mult_list
)
==
5
,
"lr_mult_list length in ResNet must be 5 but got {}!!"
.
format
(
len
(
self
.
lr_mult_list
))
self
.
curr_stage
=
0
def
net
(
self
,
def
net
(
self
,
input
,
input
,
...
@@ -86,42 +96,37 @@ class ResNet():
...
@@ -86,42 +96,37 @@ class ResNet():
num_filters
=
[
64
,
128
,
256
,
512
]
num_filters
=
[
64
,
128
,
256
,
512
]
if
self
.
stem
==
'icnet'
or
self
.
stem
==
'pspnet'
or
self
.
stem
==
'deeplab'
:
if
self
.
stem
==
'icnet'
or
self
.
stem
==
'pspnet'
or
self
.
stem
==
'deeplab'
:
conv
=
self
.
conv_bn_layer
(
conv
=
self
.
conv_bn_layer
(
input
=
input
,
input
=
input
,
num_filters
=
int
(
32
*
self
.
scale
),
num_filters
=
int
(
32
*
self
.
scale
),
filter_size
=
3
,
filter_size
=
3
,
stride
=
2
,
stride
=
2
,
act
=
'relu'
,
act
=
'relu'
,
name
=
"conv1_1"
)
name
=
"conv1_1"
)
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
conv
=
self
.
conv_bn_layer
(
num_filters
=
int
(
32
*
self
.
scale
),
input
=
conv
,
filter_size
=
3
,
num_filters
=
int
(
32
*
self
.
scale
),
stride
=
1
,
filter_size
=
3
,
act
=
'relu'
,
stride
=
1
,
name
=
"conv1_2"
)
act
=
'relu'
,
conv
=
self
.
conv_bn_layer
(
input
=
conv
,
name
=
"conv1_2"
)
num_filters
=
int
(
64
*
self
.
scale
),
conv
=
self
.
conv_bn_layer
(
filter_size
=
3
,
input
=
conv
,
stride
=
1
,
num_filters
=
int
(
64
*
self
.
scale
),
act
=
'relu'
,
filter_size
=
3
,
name
=
"conv1_3"
)
stride
=
1
,
act
=
'relu'
,
name
=
"conv1_3"
)
else
:
else
:
conv
=
self
.
conv_bn_layer
(
conv
=
self
.
conv_bn_layer
(
input
=
input
,
input
=
input
,
num_filters
=
int
(
64
*
self
.
scale
),
num_filters
=
int
(
64
*
self
.
scale
),
filter_size
=
7
,
filter_size
=
7
,
stride
=
2
,
stride
=
2
,
act
=
'relu'
,
act
=
'relu'
,
name
=
"conv1"
)
name
=
"conv1"
)
conv
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
conv
=
fluid
.
layers
.
pool2d
(
pool_size
=
3
,
input
=
conv
,
pool_stride
=
2
,
pool_size
=
3
,
pool_padding
=
1
,
pool_stride
=
2
,
pool_type
=
'max'
)
pool_padding
=
1
,
pool_type
=
'max'
)
layer_count
=
1
layer_count
=
1
if
check_points
(
layer_count
,
decode_points
):
if
check_points
(
layer_count
,
decode_points
):
...
@@ -132,6 +137,7 @@ class ResNet():
...
@@ -132,6 +137,7 @@ class ResNet():
if
layers
>=
50
:
if
layers
>=
50
:
for
block
in
range
(
len
(
depth
)):
for
block
in
range
(
len
(
depth
)):
self
.
curr_stage
+=
1
for
i
in
range
(
depth
[
block
]):
for
i
in
range
(
depth
[
block
]):
if
layers
in
[
101
,
152
]
and
block
==
2
:
if
layers
in
[
101
,
152
]
and
block
==
2
:
if
i
==
0
:
if
i
==
0
:
...
@@ -164,8 +170,10 @@ class ResNet():
...
@@ -164,8 +170,10 @@ class ResNet():
np
.
ceil
(
np
.
ceil
(
np
.
array
(
conv
.
shape
[
2
:]).
astype
(
'int32'
)
/
2
))
np
.
array
(
conv
.
shape
[
2
:]).
astype
(
'int32'
)
/
2
))
pool
=
fluid
.
layers
.
pool2d
(
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
out
=
fluid
.
layers
.
fc
(
out
=
fluid
.
layers
.
fc
(
input
=
pool
,
input
=
pool
,
...
@@ -174,6 +182,7 @@ class ResNet():
...
@@ -174,6 +182,7 @@ class ResNet():
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
)))
initializer
=
fluid
.
initializer
.
Uniform
(
-
stdv
,
stdv
)))
else
:
else
:
for
block
in
range
(
len
(
depth
)):
for
block
in
range
(
len
(
depth
)):
self
.
curr_stage
+=
1
for
i
in
range
(
depth
[
block
]):
for
i
in
range
(
depth
[
block
]):
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
+
i
)
conv_name
=
"res"
+
str
(
block
+
2
)
+
chr
(
97
+
i
)
conv
=
self
.
basic_block
(
conv
=
self
.
basic_block
(
...
@@ -189,8 +198,10 @@ class ResNet():
...
@@ -189,8 +198,10 @@ class ResNet():
if
check_points
(
layer_count
,
end_points
):
if
check_points
(
layer_count
,
end_points
):
return
conv
,
decode_ends
return
conv
,
decode_ends
pool
=
fluid
.
layers
.
pool2d
(
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
out
=
fluid
.
layers
.
fc
(
out
=
fluid
.
layers
.
fc
(
input
=
pool
,
input
=
pool
,
...
@@ -217,23 +228,25 @@ class ResNet():
...
@@ -217,23 +228,25 @@ class ResNet():
act
=
None
,
act
=
None
,
name
=
None
):
name
=
None
):
lr_mult
=
self
.
lr_mult_list
[
self
.
curr_stage
]
if
self
.
stem
==
'pspnet'
:
if
self
.
stem
==
'pspnet'
:
bias_attr
=
ParamAttr
(
name
=
name
+
"_biases"
)
bias_attr
=
ParamAttr
(
name
=
name
+
"_biases"
)
else
:
else
:
bias_attr
=
False
bias_attr
=
False
conv
=
fluid
.
layers
.
conv2d
(
conv
=
fluid
.
layers
.
conv2d
(
input
=
input
,
input
=
input
,
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
filter_size
,
filter_size
=
filter_size
,
stride
=
stride
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
//
padding
=
(
filter_size
-
1
)
//
2
if
dilation
==
1
else
0
,
2
if
dilation
==
1
else
0
,
dilation
=
dilation
,
dilation
=
dilation
,
groups
=
groups
,
groups
=
groups
,
act
=
None
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
,
bias_attr
=
bias_attr
,
learning_rate
=
lr_mult
),
name
=
name
+
'.conv2d.output.1'
)
bias_attr
=
bias_attr
,
name
=
name
+
'.conv2d.output.1'
)
if
name
==
"conv1"
:
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
bn_name
=
"bn_"
+
name
...
@@ -243,8 +256,9 @@ class ResNet():
...
@@ -243,8 +256,9 @@ class ResNet():
input
=
conv
,
input
=
conv
,
act
=
act
,
act
=
act
,
name
=
bn_name
+
'.output.1'
,
name
=
bn_name
+
'.output.1'
,
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
,
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
),
learning_rate
=
lr_mult
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
,
learning_rate
=
lr_mult
),
moving_mean_name
=
bn_name
+
'_mean'
,
moving_mean_name
=
bn_name
+
'_mean'
,
moving_variance_name
=
bn_name
+
'_variance'
,
moving_variance_name
=
bn_name
+
'_variance'
,
)
)
...
@@ -257,24 +271,24 @@ class ResNet():
...
@@ -257,24 +271,24 @@ class ResNet():
groups
=
1
,
groups
=
1
,
act
=
None
,
act
=
None
,
name
=
None
):
name
=
None
):
pool
=
fluid
.
layers
.
pool2d
(
lr_mult
=
self
.
lr_mult_list
[
self
.
curr_stage
]
input
=
input
,
pool
=
fluid
.
layers
.
pool2d
(
input
=
input
,
pool_size
=
2
,
pool_size
=
2
,
pool_stride
=
2
,
pool_stride
=
2
,
pool_padding
=
0
,
pool_padding
=
0
,
pool_type
=
'avg'
,
pool_type
=
'avg'
,
ceil_mode
=
True
)
ceil_mode
=
True
)
conv
=
fluid
.
layers
.
conv2d
(
conv
=
fluid
.
layers
.
conv2d
(
input
=
pool
,
input
=
pool
,
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
filter_size
,
filter_size
=
filter_size
,
stride
=
1
,
stride
=
1
,
padding
=
(
filter_size
-
1
)
//
2
,
padding
=
(
filter_size
-
1
)
//
2
,
groups
=
groups
,
groups
=
groups
,
act
=
None
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
learning_rate
=
lr_mult
),
bias_attr
=
False
)
bias_attr
=
False
)
if
name
==
"conv1"
:
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
bn_name
=
"bn_"
+
name
else
:
else
:
...
@@ -282,8 +296,9 @@ class ResNet():
...
@@ -282,8 +296,9 @@ class ResNet():
return
fluid
.
layers
.
batch_norm
(
return
fluid
.
layers
.
batch_norm
(
input
=
conv
,
input
=
conv
,
act
=
act
,
act
=
act
,
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
param_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
,
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
),
learning_rate
=
lr_mult
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
,
learning_rate
=
lr_mult
),
moving_mean_name
=
bn_name
+
'_mean'
,
moving_mean_name
=
bn_name
+
'_mean'
,
moving_variance_name
=
bn_name
+
'_variance'
)
moving_variance_name
=
bn_name
+
'_variance'
)
...
@@ -294,8 +309,11 @@ class ResNet():
...
@@ -294,8 +309,11 @@ class ResNet():
if
is_first
or
stride
==
1
:
if
is_first
or
stride
==
1
:
return
self
.
conv_bn_layer
(
input
,
ch_out
,
1
,
stride
,
name
=
name
)
return
self
.
conv_bn_layer
(
input
,
ch_out
,
1
,
stride
,
name
=
name
)
else
:
else
:
return
self
.
conv_bn_layer_new
(
return
self
.
conv_bn_layer_new
(
input
,
input
,
ch_out
,
1
,
stride
,
name
=
name
)
ch_out
,
1
,
stride
,
name
=
name
)
elif
is_first
:
elif
is_first
:
return
self
.
conv_bn_layer
(
input
,
ch_out
,
1
,
stride
,
name
=
name
)
return
self
.
conv_bn_layer
(
input
,
ch_out
,
1
,
stride
,
name
=
name
)
else
:
else
:
...
@@ -308,60 +326,59 @@ class ResNet():
...
@@ -308,60 +326,59 @@ class ResNet():
name
,
name
,
is_first
=
False
,
is_first
=
False
,
dilation
=
1
):
dilation
=
1
):
conv0
=
self
.
conv_bn_layer
(
conv0
=
self
.
conv_bn_layer
(
input
=
input
,
input
=
input
,
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
1
,
filter_size
=
1
,
dilation
=
1
,
dilation
=
1
,
stride
=
1
,
stride
=
1
,
act
=
'relu'
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
name
=
name
+
"_branch2a"
)
if
dilation
>
1
:
if
dilation
>
1
:
conv0
=
self
.
zero_padding
(
conv0
,
dilation
)
conv0
=
self
.
zero_padding
(
conv0
,
dilation
)
conv1
=
self
.
conv_bn_layer
(
conv1
=
self
.
conv_bn_layer
(
input
=
conv0
,
input
=
conv0
,
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
3
,
filter_size
=
3
,
dilation
=
dilation
,
dilation
=
dilation
,
stride
=
stride
,
stride
=
stride
,
act
=
'relu'
,
act
=
'relu'
,
name
=
name
+
"_branch2b"
)
name
=
name
+
"_branch2b"
)
conv2
=
self
.
conv_bn_layer
(
input
=
conv1
,
conv2
=
self
.
conv_bn_layer
(
num_filters
=
num_filters
*
4
,
input
=
conv1
,
dilation
=
1
,
num_filters
=
num_filters
*
4
,
filter_size
=
1
,
dilation
=
1
,
act
=
None
,
filter_size
=
1
,
name
=
name
+
"_branch2c"
)
act
=
None
,
name
=
name
+
"_branch2c"
)
short
=
self
.
shortcut
(
input
,
num_filters
*
4
,
short
=
self
.
shortcut
(
stride
,
input
,
is_first
=
is_first
,
num_filters
*
4
,
name
=
name
+
"_branch1"
)
stride
,
is_first
=
is_first
,
name
=
name
+
"_branch1"
)
print
(
input
.
shape
,
short
.
shape
,
conv2
.
shape
)
print
(
input
.
shape
,
short
.
shape
,
conv2
.
shape
)
print
(
stride
)
print
(
stride
)
return
fluid
.
layers
.
elementwise_add
(
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
x
=
short
,
y
=
conv2
,
act
=
'relu'
,
name
=
name
+
".add.output.5"
)
y
=
conv2
,
act
=
'relu'
,
name
=
name
+
".add.output.5"
)
def
basic_block
(
self
,
input
,
num_filters
,
stride
,
is_first
,
name
):
def
basic_block
(
self
,
input
,
num_filters
,
stride
,
is_first
,
name
):
conv0
=
self
.
conv_bn_layer
(
conv0
=
self
.
conv_bn_layer
(
input
=
input
,
input
=
input
,
num_filters
=
num_filters
,
num_filters
=
num_filters
,
filter_size
=
3
,
filter_size
=
3
,
act
=
'relu'
,
act
=
'relu'
,
stride
=
stride
,
stride
=
stride
,
name
=
name
+
"_branch2a"
)
name
=
name
+
"_branch2a"
)
conv1
=
self
.
conv_bn_layer
(
input
=
conv0
,
conv1
=
self
.
conv_bn_layer
(
num_filters
=
num_filters
,
input
=
conv0
,
filter_size
=
3
,
num_filters
=
num_filters
,
act
=
None
,
filter_size
=
3
,
name
=
name
+
"_branch2b"
)
act
=
None
,
short
=
self
.
shortcut
(
input
,
name
=
name
+
"_branch2b"
)
num_filters
,
short
=
self
.
shortcut
(
stride
,
input
,
num_filters
,
stride
,
is_first
,
name
=
name
+
"_branch1"
)
is_first
,
name
=
name
+
"_branch1"
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv1
,
act
=
'relu'
)
return
fluid
.
layers
.
elementwise_add
(
x
=
short
,
y
=
conv1
,
act
=
'relu'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录