Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
fbce7ca3
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看板
提交
fbce7ca3
编写于
9月 23, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update unet fcn hrnet
上级
b5a12185
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
87 addition
and
69 deletion
+87
-69
dygraph/configs/_base_/cityscapes.yml
dygraph/configs/_base_/cityscapes.yml
+1
-0
dygraph/configs/_base_/optic_disc_seg.yml
dygraph/configs/_base_/optic_disc_seg.yml
+1
-0
dygraph/configs/fcn_hrnet/fcn_hrnetw18_cityscapes_1024x512_100k.yml
...nfigs/fcn_hrnet/fcn_hrnetw18_cityscapes_1024x512_100k.yml
+3
-2
dygraph/configs/fcn_hrnet/fcn_hrnetw18_optic_disc_512x512_10k.yml
...configs/fcn_hrnet/fcn_hrnetw18_optic_disc_512x512_10k.yml
+4
-3
dygraph/configs/fcn_hrnet/fcn_hrnetw48_cityscapes_1024x512_100k.yml
...nfigs/fcn_hrnet/fcn_hrnetw48_cityscapes_1024x512_100k.yml
+6
-2
dygraph/configs/unet/unet_cityscapes_1024x512_40k.yml
dygraph/configs/unet/unet_cityscapes_1024x512_40k.yml
+9
-0
dygraph/paddleseg/models/backbones/hrnet.py
dygraph/paddleseg/models/backbones/hrnet.py
+18
-1
dygraph/paddleseg/models/fcn.py
dygraph/paddleseg/models/fcn.py
+39
-42
dygraph/paddleseg/models/unet.py
dygraph/paddleseg/models/unet.py
+6
-19
未找到文件。
dygraph/configs/_base_/cityscapes.yml
浏览文件 @
fbce7ca3
...
...
@@ -32,6 +32,7 @@ learning_rate:
decay
:
type
:
poly
power
:
0.9
end_lr
:
0.0
loss
:
types
:
...
...
dygraph/configs/_base_/optic_disc_seg.yml
浏览文件 @
fbce7ca3
...
...
@@ -30,6 +30,7 @@ learning_rate:
decay
:
type
:
poly
power
:
0.9
end_lr
:
0
loss
:
types
:
...
...
dygraph/configs/fcn_hrnet/fcn_hrnetw18_cityscapes_1024x512_100k.yml
浏览文件 @
fbce7ca3
...
...
@@ -4,9 +4,10 @@ model:
type
:
FCN
backbone
:
type
:
HRNet_W18
pretrained
:
pretrained_model/hrnet_w18_imagenet
num_classes
:
19
backbone_channels
:
[
270
]
backbone_
pretrained
:
pretrained_model/hrnet_w18_imagenet
pretrained
:
Null
backbone_
indices
:
[
-1
]
optimizer
:
weight_decay
:
0.0005
dygraph/configs/fcn_hrnet/fcn_hrnetw18_optic_disc_512x512_10k.yml
浏览文件 @
fbce7ca3
...
...
@@ -4,6 +4,7 @@ model:
type
:
FCN
backbone
:
type
:
HRNet_W18
num_classes
:
2
backbone_channels
:
[
270
]
backbone_pretrained
:
pretrained_model/hrnet_w18_imagenet
pretrained
:
pretrained_model/hrnet_w18_imagenet
num_classes
:
19
pretrained
:
Null
backbone_indices
:
[
-1
]
dygraph/configs/fcn_hrnet/fcn_hrnetw48_cityscapes_1024x512_100k.yml
浏览文件 @
fbce7ca3
...
...
@@ -4,6 +4,10 @@ model:
type
:
FCN
backbone
:
type
:
HRNet_W48
pretrained
:
pretrained_model/hrnet_w48_imagenet
num_classes
:
19
backbone_channels
:
[
720
]
backbone_pretrained
:
pretrained_model/hrnet_w48_imagenet
pretrained
:
Null
backbone_indices
:
[
-1
]
optimizer
:
weight_decay
:
0.0005
dygraph/configs/unet/unet_cityscapes_1024x512_40k.yml
0 → 100644
浏览文件 @
fbce7ca3
_base_
:
'
../_base_/cityscapes.yml'
batch_size
:
2
iters
:
40000
model
:
type
:
UNet
num_classes
:
19
pretrained
:
Null
dygraph/paddleseg/models/backbones/hrnet.py
浏览文件 @
fbce7ca3
...
...
@@ -57,6 +57,7 @@ class HRNet(nn.Layer):
"""
def
__init__
(
self
,
pretrained
=
None
,
stage1_num_modules
=
1
,
stage1_num_blocks
=
[
4
],
stage1_num_channels
=
[
64
],
...
...
@@ -71,7 +72,7 @@ class HRNet(nn.Layer):
stage4_num_channels
=
[
18
,
36
,
72
,
144
],
has_se
=
False
):
super
(
HRNet
,
self
).
__init__
()
self
.
pretrained
=
pretrained
self
.
stage1_num_modules
=
stage1_num_modules
self
.
stage1_num_blocks
=
stage1_num_blocks
self
.
stage1_num_channels
=
stage1_num_channels
...
...
@@ -85,6 +86,7 @@ class HRNet(nn.Layer):
self
.
stage4_num_blocks
=
stage4_num_blocks
self
.
stage4_num_channels
=
stage4_num_channels
self
.
has_se
=
has_se
self
.
feat_channels
=
[
sum
(
stage4_num_channels
)]
self
.
conv_layer1_1
=
layer_libs
.
ConvBNReLU
(
in_channels
=
3
,
...
...
@@ -145,6 +147,7 @@ class HRNet(nn.Layer):
num_filters
=
self
.
stage4_num_channels
,
has_se
=
self
.
has_se
,
name
=
"st4"
)
self
.
init_weight
()
def
forward
(
self
,
x
,
label
=
None
,
mode
=
'train'
):
input_shape
=
x
.
shape
[
2
:]
...
...
@@ -170,6 +173,20 @@ class HRNet(nn.Layer):
return
[
x
]
def
init_weight
(
self
):
params
=
self
.
parameters
()
for
param
in
params
:
param_name
=
param
.
name
if
'batch_norm'
in
param_name
:
if
'w_0'
in
param_name
:
param_init
.
constant_init
(
param
,
value
=
1.0
)
elif
'b_0'
in
param_name
:
param_init
.
constant_init
(
param
,
value
=
0.0
)
if
'conv'
in
param_name
and
'w_0'
in
param_name
:
param_init
.
normal_init
(
param
,
scale
=
0.001
)
if
self
.
pretrained
is
not
None
:
utils
.
load_pretrained_model
(
self
,
self
.
pretrained
)
class
Layer1
(
nn
.
Layer
):
def
__init__
(
self
,
...
...
dygraph/paddleseg/models/fcn.py
浏览文件 @
fbce7ca3
...
...
@@ -36,65 +36,78 @@ __all__ = [
@
manager
.
MODELS
.
add_component
class
FCN
(
nn
.
Layer
):
def
__init__
(
self
,
num_classes
,
backbone
,
pretrained
=
None
,
backbone_indices
=
(
-
1
,
),
channels
=
None
):
super
(
FCN
,
self
).
__init__
()
self
.
backbone
=
backbone
backbone_channels
=
[
backbone
.
feat_channels
[
i
]
for
i
in
backbone_indices
]
self
.
head
=
FCNHead
(
num_classes
,
backbone_indices
,
backbone_channels
,
channels
)
utils
.
load_entire_model
(
self
,
pretrained
)
def
forward
(
self
,
input
):
feat_list
=
self
.
backbone
(
input
)
logit_list
=
self
.
head
(
feat_list
)
return
[
F
.
resize_bilinear
(
logit
,
input
.
shape
[
2
:])
for
logit
in
logit_list
]
class
FCNHead
(
nn
.
Layer
):
"""
Fully Convolutional Networks for Semantic Segmentation.
A simple implementation for
Fully Convolutional Networks for Semantic Segmentation.
https://arxiv.org/abs/1411.4038
Args:
num_classes (int): the unique number of target classes.
backbone (paddle.nn.Layer): backbone networks.
model_pretrained (str): the path of pretrained model.
backbone_indices (tuple): one values in the tuple indicte the indices of output of backbone.Default -1.
backbone_channels (tuple): the same length with "backbone_indices". It indicates the channels of corresponding index.
channels (int): channels after conv layer before the last one.
"""
def
__init__
(
self
,
num_classes
,
backbone
,
backbone_pretrained
=
None
,
model_pretrained
=
None
,
backbone_indices
=
(
-
1
,
),
backbone_channels
=
(
270
,
),
channels
=
None
):
super
(
FCN
,
self
).
__init__
()
super
(
FCN
Head
,
self
).
__init__
()
self
.
num_classes
=
num_classes
self
.
backbone_pretrained
=
backbone_pretrained
self
.
model_pretrained
=
model_pretrained
self
.
backbone_indices
=
backbone_indices
if
channels
is
None
:
channels
=
backbone_channels
[
0
]
self
.
backbone
=
backbone
self
.
conv_last_2
=
layer_libs
.
ConvBNReLU
(
self
.
conv_1
=
layer_libs
.
ConvBNReLU
(
in_channels
=
backbone_channels
[
0
],
out_channels
=
channels
,
kernel_size
=
1
,
padding
=
'same'
,
stride
=
1
)
self
.
c
onv_last_1
=
Conv2d
(
self
.
c
ls
=
Conv2d
(
in_channels
=
channels
,
out_channels
=
self
.
num_classes
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
)
if
self
.
training
:
self
.
init_weight
()
def
forward
(
self
,
x
):
input_shape
=
x
.
shape
[
2
:]
fea_list
=
self
.
backbone
(
x
)
x
=
fea_list
[
self
.
backbone_indices
[
0
]]
x
=
self
.
conv_last_2
(
x
)
logit
=
self
.
conv_last_1
(
x
)
logit
=
F
.
resize_bilinear
(
logit
,
input_shape
)
return
[
logit
]
self
.
init_weight
()
def
forward
(
self
,
feat_list
):
logit_list
=
[]
x
=
feat_list
[
self
.
backbone_indices
[
0
]]
x
=
self
.
conv_1
(
x
)
logit
=
self
.
cls
(
x
)
logit_list
.
append
(
logit
)
return
logit_list
def
init_weight
(
self
):
params
=
self
.
parameters
()
...
...
@@ -108,22 +121,6 @@ class FCN(nn.Layer):
if
'conv'
in
param_name
and
'w_0'
in
param_name
:
param_init
.
normal_init
(
param
,
scale
=
0.001
)
if
self
.
model_pretrained
is
not
None
:
if
os
.
path
.
exists
(
self
.
model_pretrained
):
utils
.
load_pretrained_model
(
self
,
self
.
model_pretrained
)
else
:
raise
Exception
(
'Pretrained model is not found: {}'
.
format
(
self
.
model_pretrained
))
elif
self
.
backbone_pretrained
is
not
None
:
if
os
.
path
.
exists
(
self
.
backbone_pretrained
):
utils
.
load_pretrained_model
(
self
.
backbone
,
self
.
backbone_pretrained
)
else
:
raise
Exception
(
'Pretrained model is not found: {}'
.
format
(
self
.
backbone_pretrained
))
else
:
logger
.
warning
(
'No pretrained model to load, train from scratch'
)
@
manager
.
MODELS
.
add_component
def
fcn_hrnet_w18_small_v1
(
*
args
,
**
kwargs
):
...
...
dygraph/paddleseg/models/unet.py
浏览文件 @
fbce7ca3
...
...
@@ -33,38 +33,25 @@ class UNet(nn.Layer):
Args:
num_classes (int): the unique number of target classes.
pretrained_model (str): the path of pretrained model.
ignore_index (int): the value of ground-truth mask would be ignored while computing loss or doing evaluation. Default 255.
pretrained (str): the path of pretrained model for fine tuning.
"""
def
__init__
(
self
,
num_classes
,
model_pretrained
=
None
,
ignore_index
=
255
):
def
__init__
(
self
,
num_classes
,
pretrained
=
None
):
super
(
UNet
,
self
).
__init__
()
self
.
model_pretrained
=
model_pretrained
self
.
ignore_index
=
ignore_index
self
.
encode
=
UnetEncoder
()
self
.
decode
=
UnetDecode
()
self
.
get_logit
=
GetLogit
(
64
,
num_classes
)
self
.
EPS
=
1e-5
self
.
init_weight
(
)
utils
.
load_entire_model
(
self
,
pretrained
)
def
forward
(
self
,
x
,
label
=
None
):
logit_list
=
[]
encode_data
,
short_cuts
=
self
.
encode
(
x
)
decode_data
=
self
.
decode
(
encode_data
,
short_cuts
)
logit
=
self
.
get_logit
(
decode_data
)
return
[
logit
]
def
init_weight
(
self
):
"""
Initialize the parameters of model parts.
"""
if
self
.
model_pretrained
is
not
None
:
if
os
.
path
.
exists
(
self
.
model_pretrained
):
utils
.
load_pretrained_model
(
self
,
self
.
model_pretrained
)
else
:
raise
Exception
(
'Pretrained model is not found: {}'
.
format
(
self
.
model_pretrained
))
logit_list
.
append
(
logit
)
return
logit_list
class
UnetEncoder
(
nn
.
Layer
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录