Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
04fa1750
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看板
提交
04fa1750
编写于
9月 16, 2020
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update conv
上级
df15bf4d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
74 addition
and
71 deletion
+74
-71
dygraph/paddleseg/models/backbones/resnet_vd.py
dygraph/paddleseg/models/backbones/resnet_vd.py
+52
-51
dygraph/paddleseg/models/fcn.py
dygraph/paddleseg/models/fcn.py
+22
-20
未找到文件。
dygraph/paddleseg/models/backbones/resnet_vd.py
浏览文件 @
04fa1750
...
@@ -21,11 +21,13 @@ import math
...
@@ -21,11 +21,13 @@ import math
import
numpy
as
np
import
numpy
as
np
import
paddle
import
paddle
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddle.nn
import
Conv2d
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
Linear
,
Dropout
from
paddle.fluid.dygraph.nn
import
Pool2D
,
Linear
,
Dropout
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddleseg.utils
import
utils
from
paddleseg.utils
import
utils
from
paddleseg.models.common
import
layer_utils
from
paddleseg.models.common
import
layer_utils
...
@@ -39,9 +41,9 @@ __all__ = [
...
@@ -39,9 +41,9 @@ __all__ = [
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
def
__init__
(
self
,
self
,
num
_channels
,
in
_channels
,
num_filter
s
,
out_channel
s
,
filter
_size
,
kernel
_size
,
stride
=
1
,
stride
=
1
,
dilation
=
1
,
dilation
=
1
,
groups
=
1
,
groups
=
1
,
...
@@ -58,23 +60,22 @@ class ConvBNLayer(fluid.dygraph.Layer):
...
@@ -58,23 +60,22 @@ class ConvBNLayer(fluid.dygraph.Layer):
pool_padding
=
0
,
pool_padding
=
0
,
pool_type
=
'avg'
,
pool_type
=
'avg'
,
ceil_mode
=
True
)
ceil_mode
=
True
)
self
.
_conv
=
Conv2
D
(
self
.
_conv
=
Conv2
d
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter_size
=
filter
_size
,
kernel_size
=
kernel
_size
,
stride
=
stride
,
stride
=
stride
,
padding
=
(
filter
_size
-
1
)
//
2
if
dilation
==
1
else
0
,
padding
=
(
kernel
_size
-
1
)
//
2
if
dilation
==
1
else
0
,
dilation
=
dilation
,
dilation
=
dilation
,
groups
=
groups
,
groups
=
groups
,
act
=
None
,
weight_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
False
)
bias_attr
=
False
)
if
name
==
"conv1"
:
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
bn_name
=
"bn_"
+
name
else
:
else
:
bn_name
=
"bn"
+
name
[
3
:]
bn_name
=
"bn"
+
name
[
3
:]
self
.
_batch_norm
=
BatchNorm
(
self
.
_batch_norm
=
BatchNorm
(
num_filter
s
,
out_channel
s
,
weight_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
weight_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
))
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
))
self
.
_act_op
=
layer_utils
.
Activation
(
act
=
act
)
self
.
_act_op
=
layer_utils
.
Activation
(
act
=
act
)
...
@@ -91,8 +92,8 @@ class ConvBNLayer(fluid.dygraph.Layer):
...
@@ -91,8 +92,8 @@ class ConvBNLayer(fluid.dygraph.Layer):
class
BottleneckBlock
(
fluid
.
dygraph
.
Layer
):
class
BottleneckBlock
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
def
__init__
(
self
,
num
_channels
,
in
_channels
,
num_filter
s
,
out_channel
s
,
stride
,
stride
,
shortcut
=
True
,
shortcut
=
True
,
if_first
=
False
,
if_first
=
False
,
...
@@ -101,34 +102,34 @@ class BottleneckBlock(fluid.dygraph.Layer):
...
@@ -101,34 +102,34 @@ class BottleneckBlock(fluid.dygraph.Layer):
super
(
BottleneckBlock
,
self
).
__init__
()
super
(
BottleneckBlock
,
self
).
__init__
()
self
.
conv0
=
ConvBNLayer
(
self
.
conv0
=
ConvBNLayer
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter
_size
=
1
,
kernel
_size
=
1
,
act
=
'relu'
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
name
=
name
+
"_branch2a"
)
self
.
dilation
=
dilation
self
.
dilation
=
dilation
self
.
conv1
=
ConvBNLayer
(
self
.
conv1
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
in_channels
=
out_channel
s
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter
_size
=
3
,
kernel
_size
=
3
,
stride
=
stride
,
stride
=
stride
,
act
=
'relu'
,
act
=
'relu'
,
dilation
=
dilation
,
dilation
=
dilation
,
name
=
name
+
"_branch2b"
)
name
=
name
+
"_branch2b"
)
self
.
conv2
=
ConvBNLayer
(
self
.
conv2
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
in_channels
=
out_channel
s
,
num_filters
=
num_filter
s
*
4
,
out_channels
=
out_channel
s
*
4
,
filter
_size
=
1
,
kernel
_size
=
1
,
act
=
None
,
act
=
None
,
name
=
name
+
"_branch2c"
)
name
=
name
+
"_branch2c"
)
if
not
shortcut
:
if
not
shortcut
:
self
.
short
=
ConvBNLayer
(
self
.
short
=
ConvBNLayer
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
*
4
,
out_channels
=
out_channel
s
*
4
,
filter
_size
=
1
,
kernel
_size
=
1
,
stride
=
1
,
stride
=
1
,
is_vd_mode
=
False
if
if_first
or
stride
==
1
else
True
,
is_vd_mode
=
False
if
if_first
or
stride
==
1
else
True
,
name
=
name
+
"_branch1"
)
name
=
name
+
"_branch1"
)
...
@@ -160,8 +161,8 @@ class BottleneckBlock(fluid.dygraph.Layer):
...
@@ -160,8 +161,8 @@ class BottleneckBlock(fluid.dygraph.Layer):
class
BasicBlock
(
fluid
.
dygraph
.
Layer
):
class
BasicBlock
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
def
__init__
(
self
,
num
_channels
,
in
_channels
,
num_filter
s
,
out_channel
s
,
stride
,
stride
,
shortcut
=
True
,
shortcut
=
True
,
if_first
=
False
,
if_first
=
False
,
...
@@ -169,24 +170,24 @@ class BasicBlock(fluid.dygraph.Layer):
...
@@ -169,24 +170,24 @@ class BasicBlock(fluid.dygraph.Layer):
super
(
BasicBlock
,
self
).
__init__
()
super
(
BasicBlock
,
self
).
__init__
()
self
.
stride
=
stride
self
.
stride
=
stride
self
.
conv0
=
ConvBNLayer
(
self
.
conv0
=
ConvBNLayer
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter
_size
=
3
,
kernel
_size
=
3
,
stride
=
stride
,
stride
=
stride
,
act
=
'relu'
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
name
=
name
+
"_branch2a"
)
self
.
conv1
=
ConvBNLayer
(
self
.
conv1
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
in_channels
=
out_channel
s
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter
_size
=
3
,
kernel
_size
=
3
,
act
=
None
,
act
=
None
,
name
=
name
+
"_branch2b"
)
name
=
name
+
"_branch2b"
)
if
not
shortcut
:
if
not
shortcut
:
self
.
short
=
ConvBNLayer
(
self
.
short
=
ConvBNLayer
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter
_size
=
1
,
kernel
_size
=
1
,
stride
=
1
,
stride
=
1
,
is_vd_mode
=
False
if
if_first
else
True
,
is_vd_mode
=
False
if
if_first
else
True
,
name
=
name
+
"_branch1"
)
name
=
name
+
"_branch1"
)
...
@@ -243,23 +244,23 @@ class ResNet_vd(fluid.dygraph.Layer):
...
@@ -243,23 +244,23 @@ class ResNet_vd(fluid.dygraph.Layer):
dilation_dict
=
{
3
:
2
}
dilation_dict
=
{
3
:
2
}
self
.
conv1_1
=
ConvBNLayer
(
self
.
conv1_1
=
ConvBNLayer
(
num
_channels
=
3
,
in
_channels
=
3
,
num_filter
s
=
32
,
out_channel
s
=
32
,
filter
_size
=
3
,
kernel
_size
=
3
,
stride
=
2
,
stride
=
2
,
act
=
'relu'
,
act
=
'relu'
,
name
=
"conv1_1"
)
name
=
"conv1_1"
)
self
.
conv1_2
=
ConvBNLayer
(
self
.
conv1_2
=
ConvBNLayer
(
num
_channels
=
32
,
in
_channels
=
32
,
num_filter
s
=
32
,
out_channel
s
=
32
,
filter
_size
=
3
,
kernel
_size
=
3
,
stride
=
1
,
stride
=
1
,
act
=
'relu'
,
act
=
'relu'
,
name
=
"conv1_2"
)
name
=
"conv1_2"
)
self
.
conv1_3
=
ConvBNLayer
(
self
.
conv1_3
=
ConvBNLayer
(
num
_channels
=
32
,
in
_channels
=
32
,
num_filter
s
=
64
,
out_channel
s
=
64
,
filter
_size
=
3
,
kernel
_size
=
3
,
stride
=
1
,
stride
=
1
,
act
=
'relu'
,
act
=
'relu'
,
name
=
"conv1_3"
)
name
=
"conv1_3"
)
...
@@ -296,9 +297,9 @@ class ResNet_vd(fluid.dygraph.Layer):
...
@@ -296,9 +297,9 @@ class ResNet_vd(fluid.dygraph.Layer):
bottleneck_block
=
self
.
add_sublayer
(
bottleneck_block
=
self
.
add_sublayer
(
'bb_%d_%d'
%
(
block
,
i
),
'bb_%d_%d'
%
(
block
,
i
),
BottleneckBlock
(
BottleneckBlock
(
num
_channels
=
num_channels
[
block
]
in
_channels
=
num_channels
[
block
]
if
i
==
0
else
num_filters
[
block
]
*
4
,
if
i
==
0
else
num_filters
[
block
]
*
4
,
num_filter
s
=
num_filters
[
block
],
out_channel
s
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
stride
=
2
if
i
==
0
and
block
!=
0
and
dilation_rate
==
1
else
1
,
and
dilation_rate
==
1
else
1
,
shortcut
=
shortcut
,
shortcut
=
shortcut
,
...
@@ -318,9 +319,9 @@ class ResNet_vd(fluid.dygraph.Layer):
...
@@ -318,9 +319,9 @@ class ResNet_vd(fluid.dygraph.Layer):
basic_block
=
self
.
add_sublayer
(
basic_block
=
self
.
add_sublayer
(
'bb_%d_%d'
%
(
block
,
i
),
'bb_%d_%d'
%
(
block
,
i
),
BasicBlock
(
BasicBlock
(
num
_channels
=
num_channels
[
block
]
in
_channels
=
num_channels
[
block
]
if
i
==
0
else
num_filters
[
block
],
if
i
==
0
else
num_filters
[
block
],
num_filter
s
=
num_filters
[
block
],
out_channel
s
=
num_filters
[
block
],
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
stride
=
2
if
i
==
0
and
block
!=
0
else
1
,
shortcut
=
shortcut
,
shortcut
=
shortcut
,
if_first
=
block
==
i
==
0
,
if_first
=
block
==
i
==
0
,
...
...
dygraph/paddleseg/models/fcn.py
浏览文件 @
04fa1750
...
@@ -16,10 +16,12 @@ import math
...
@@ -16,10 +16,12 @@ import math
import
os
import
os
import
paddle
import
paddle
from
paddle.nn
import
Conv2d
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
Linear
from
paddle.fluid.dygraph.nn
import
Pool2D
,
Linear
from
paddle.fluid.initializer
import
Normal
from
paddle.fluid.initializer
import
Normal
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
...
@@ -27,6 +29,7 @@ from paddleseg.cvlibs import manager
...
@@ -27,6 +29,7 @@ from paddleseg.cvlibs import manager
from
paddleseg
import
utils
from
paddleseg
import
utils
from
paddleseg.cvlibs
import
param_init
from
paddleseg.cvlibs
import
param_init
from
paddleseg.utils
import
logger
from
paddleseg.utils
import
logger
from
paddleseg.models.common
import
layer_utils
__all__
=
[
__all__
=
[
"fcn_hrnet_w18_small_v1"
,
"fcn_hrnet_w18_small_v2"
,
"fcn_hrnet_w18"
,
"fcn_hrnet_w18_small_v1"
,
"fcn_hrnet_w18_small_v2"
,
"fcn_hrnet_w18"
,
...
@@ -74,14 +77,14 @@ class FCN(fluid.dygraph.Layer):
...
@@ -74,14 +77,14 @@ class FCN(fluid.dygraph.Layer):
self
.
backbone
=
backbone
self
.
backbone
=
backbone
self
.
conv_last_2
=
ConvBNLayer
(
self
.
conv_last_2
=
ConvBNLayer
(
num
_channels
=
backbone_channels
[
0
],
in
_channels
=
backbone_channels
[
0
],
num_filter
s
=
channels
,
out_channel
s
=
channels
,
filter
_size
=
1
,
kernel
_size
=
1
,
stride
=
1
)
stride
=
1
)
self
.
conv_last_1
=
Conv2
D
(
self
.
conv_last_1
=
Conv2
d
(
num
_channels
=
channels
,
in
_channels
=
channels
,
num_filter
s
=
self
.
num_classes
,
out_channel
s
=
self
.
num_classes
,
filter
_size
=
1
,
kernel
_size
=
1
,
stride
=
1
,
stride
=
1
,
padding
=
0
)
padding
=
0
)
if
self
.
training
:
if
self
.
training
:
...
@@ -127,30 +130,29 @@ class FCN(fluid.dygraph.Layer):
...
@@ -127,30 +130,29 @@ class FCN(fluid.dygraph.Layer):
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
def
__init__
(
self
,
num
_channels
,
in
_channels
,
num_filter
s
,
out_channel
s
,
filter
_size
,
kernel
_size
,
stride
=
1
,
stride
=
1
,
groups
=
1
,
groups
=
1
,
act
=
"relu"
):
act
=
"relu"
):
super
(
ConvBNLayer
,
self
).
__init__
()
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
_conv
=
Conv2
D
(
self
.
_conv
=
Conv2
d
(
num_channels
=
num
_channels
,
in_channels
=
in
_channels
,
num_filters
=
num_filter
s
,
out_channels
=
out_channel
s
,
filter_size
=
filter
_size
,
kernel_size
=
kernel
_size
,
stride
=
stride
,
stride
=
stride
,
padding
=
(
filter
_size
-
1
)
//
2
,
padding
=
(
kernel
_size
-
1
)
//
2
,
groups
=
groups
,
groups
=
groups
,
bias_attr
=
False
)
bias_attr
=
False
)
self
.
_batch_norm
=
BatchNorm
(
num_filter
s
)
self
.
_batch_norm
=
BatchNorm
(
out_channel
s
)
self
.
act
=
act
self
.
act
=
layer_utils
.
Activation
(
act
=
act
)
def
forward
(
self
,
input
):
def
forward
(
self
,
input
):
y
=
self
.
_conv
(
input
)
y
=
self
.
_conv
(
input
)
y
=
self
.
_batch_norm
(
y
)
y
=
self
.
_batch_norm
(
y
)
if
self
.
act
==
'relu'
:
y
=
self
.
act
(
y
)
y
=
fluid
.
layers
.
relu
(
y
)
return
y
return
y
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录