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
import
numpy
as
np
import
paddle
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddle.nn
import
Conv2d
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Pool2D
,
Linear
,
Dropout
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddle.fluid.dygraph.nn
import
Pool2D
,
Linear
,
Dropout
from
paddleseg.utils
import
utils
from
paddleseg.models.common
import
layer_utils
...
...
@@ -39,9 +41,9 @@ __all__ = [
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num
_channels
,
num_filter
s
,
filter
_size
,
in
_channels
,
out_channel
s
,
kernel
_size
,
stride
=
1
,
dilation
=
1
,
groups
=
1
,
...
...
@@ -58,23 +60,22 @@ class ConvBNLayer(fluid.dygraph.Layer):
pool_padding
=
0
,
pool_type
=
'avg'
,
ceil_mode
=
True
)
self
.
_conv
=
Conv2
D
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
,
filter_size
=
filter
_size
,
self
.
_conv
=
Conv2
d
(
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
,
kernel_size
=
kernel
_size
,
stride
=
stride
,
padding
=
(
filter
_size
-
1
)
//
2
if
dilation
==
1
else
0
,
padding
=
(
kernel
_size
-
1
)
//
2
if
dilation
==
1
else
0
,
dilation
=
dilation
,
groups
=
groups
,
act
=
None
,
param_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
weight_attr
=
ParamAttr
(
name
=
name
+
"_weights"
),
bias_attr
=
False
)
if
name
==
"conv1"
:
bn_name
=
"bn_"
+
name
else
:
bn_name
=
"bn"
+
name
[
3
:]
self
.
_batch_norm
=
BatchNorm
(
num_filter
s
,
out_channel
s
,
weight_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
))
self
.
_act_op
=
layer_utils
.
Activation
(
act
=
act
)
...
...
@@ -91,8 +92,8 @@ class ConvBNLayer(fluid.dygraph.Layer):
class
BottleneckBlock
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num
_channels
,
num_filter
s
,
in
_channels
,
out_channel
s
,
stride
,
shortcut
=
True
,
if_first
=
False
,
...
...
@@ -101,34 +102,34 @@ class BottleneckBlock(fluid.dygraph.Layer):
super
(
BottleneckBlock
,
self
).
__init__
()
self
.
conv0
=
ConvBNLayer
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
,
filter
_size
=
1
,
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
,
kernel
_size
=
1
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
self
.
dilation
=
dilation
self
.
conv1
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
num_filters
=
num_filter
s
,
filter
_size
=
3
,
in_channels
=
out_channel
s
,
out_channels
=
out_channel
s
,
kernel
_size
=
3
,
stride
=
stride
,
act
=
'relu'
,
dilation
=
dilation
,
name
=
name
+
"_branch2b"
)
self
.
conv2
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
num_filters
=
num_filter
s
*
4
,
filter
_size
=
1
,
in_channels
=
out_channel
s
,
out_channels
=
out_channel
s
*
4
,
kernel
_size
=
1
,
act
=
None
,
name
=
name
+
"_branch2c"
)
if
not
shortcut
:
self
.
short
=
ConvBNLayer
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
*
4
,
filter
_size
=
1
,
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
*
4
,
kernel
_size
=
1
,
stride
=
1
,
is_vd_mode
=
False
if
if_first
or
stride
==
1
else
True
,
name
=
name
+
"_branch1"
)
...
...
@@ -160,8 +161,8 @@ class BottleneckBlock(fluid.dygraph.Layer):
class
BasicBlock
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num
_channels
,
num_filter
s
,
in
_channels
,
out_channel
s
,
stride
,
shortcut
=
True
,
if_first
=
False
,
...
...
@@ -169,24 +170,24 @@ class BasicBlock(fluid.dygraph.Layer):
super
(
BasicBlock
,
self
).
__init__
()
self
.
stride
=
stride
self
.
conv0
=
ConvBNLayer
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
,
filter
_size
=
3
,
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
,
kernel
_size
=
3
,
stride
=
stride
,
act
=
'relu'
,
name
=
name
+
"_branch2a"
)
self
.
conv1
=
ConvBNLayer
(
num_channels
=
num_filter
s
,
num_filters
=
num_filter
s
,
filter
_size
=
3
,
in_channels
=
out_channel
s
,
out_channels
=
out_channel
s
,
kernel
_size
=
3
,
act
=
None
,
name
=
name
+
"_branch2b"
)
if
not
shortcut
:
self
.
short
=
ConvBNLayer
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
,
filter
_size
=
1
,
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
,
kernel
_size
=
1
,
stride
=
1
,
is_vd_mode
=
False
if
if_first
else
True
,
name
=
name
+
"_branch1"
)
...
...
@@ -243,23 +244,23 @@ class ResNet_vd(fluid.dygraph.Layer):
dilation_dict
=
{
3
:
2
}
self
.
conv1_1
=
ConvBNLayer
(
num
_channels
=
3
,
num_filter
s
=
32
,
filter
_size
=
3
,
in
_channels
=
3
,
out_channel
s
=
32
,
kernel
_size
=
3
,
stride
=
2
,
act
=
'relu'
,
name
=
"conv1_1"
)
self
.
conv1_2
=
ConvBNLayer
(
num
_channels
=
32
,
num_filter
s
=
32
,
filter
_size
=
3
,
in
_channels
=
32
,
out_channel
s
=
32
,
kernel
_size
=
3
,
stride
=
1
,
act
=
'relu'
,
name
=
"conv1_2"
)
self
.
conv1_3
=
ConvBNLayer
(
num
_channels
=
32
,
num_filter
s
=
64
,
filter
_size
=
3
,
in
_channels
=
32
,
out_channel
s
=
64
,
kernel
_size
=
3
,
stride
=
1
,
act
=
'relu'
,
name
=
"conv1_3"
)
...
...
@@ -296,9 +297,9 @@ class ResNet_vd(fluid.dygraph.Layer):
bottleneck_block
=
self
.
add_sublayer
(
'bb_%d_%d'
%
(
block
,
i
),
BottleneckBlock
(
num
_channels
=
num_channels
[
block
]
in
_channels
=
num_channels
[
block
]
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
and
dilation_rate
==
1
else
1
,
shortcut
=
shortcut
,
...
...
@@ -318,9 +319,9 @@ class ResNet_vd(fluid.dygraph.Layer):
basic_block
=
self
.
add_sublayer
(
'bb_%d_%d'
%
(
block
,
i
),
BasicBlock
(
num
_channels
=
num_channels
[
block
]
in
_channels
=
num_channels
[
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
,
shortcut
=
shortcut
,
if_first
=
block
==
i
==
0
,
...
...
dygraph/paddleseg/models/fcn.py
浏览文件 @
04fa1750
...
...
@@ -16,10 +16,12 @@ import math
import
os
import
paddle
from
paddle.nn
import
Conv2d
import
paddle.fluid
as
fluid
from
paddle.fluid.param_attr
import
ParamAttr
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.nn
import
SyncBatchNorm
as
BatchNorm
...
...
@@ -27,6 +29,7 @@ from paddleseg.cvlibs import manager
from
paddleseg
import
utils
from
paddleseg.cvlibs
import
param_init
from
paddleseg.utils
import
logger
from
paddleseg.models.common
import
layer_utils
__all__
=
[
"fcn_hrnet_w18_small_v1"
,
"fcn_hrnet_w18_small_v2"
,
"fcn_hrnet_w18"
,
...
...
@@ -74,14 +77,14 @@ class FCN(fluid.dygraph.Layer):
self
.
backbone
=
backbone
self
.
conv_last_2
=
ConvBNLayer
(
num
_channels
=
backbone_channels
[
0
],
num_filter
s
=
channels
,
filter
_size
=
1
,
in
_channels
=
backbone_channels
[
0
],
out_channel
s
=
channels
,
kernel
_size
=
1
,
stride
=
1
)
self
.
conv_last_1
=
Conv2
D
(
num
_channels
=
channels
,
num_filter
s
=
self
.
num_classes
,
filter
_size
=
1
,
self
.
conv_last_1
=
Conv2
d
(
in
_channels
=
channels
,
out_channel
s
=
self
.
num_classes
,
kernel
_size
=
1
,
stride
=
1
,
padding
=
0
)
if
self
.
training
:
...
...
@@ -127,30 +130,29 @@ class FCN(fluid.dygraph.Layer):
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
num
_channels
,
num_filter
s
,
filter
_size
,
in
_channels
,
out_channel
s
,
kernel
_size
,
stride
=
1
,
groups
=
1
,
act
=
"relu"
):
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
_conv
=
Conv2
D
(
num_channels
=
num
_channels
,
num_filters
=
num_filter
s
,
filter_size
=
filter
_size
,
self
.
_conv
=
Conv2
d
(
in_channels
=
in
_channels
,
out_channels
=
out_channel
s
,
kernel_size
=
kernel
_size
,
stride
=
stride
,
padding
=
(
filter
_size
-
1
)
//
2
,
padding
=
(
kernel
_size
-
1
)
//
2
,
groups
=
groups
,
bias_attr
=
False
)
self
.
_batch_norm
=
BatchNorm
(
num_filter
s
)
self
.
act
=
act
self
.
_batch_norm
=
BatchNorm
(
out_channel
s
)
self
.
act
=
layer_utils
.
Activation
(
act
=
act
)
def
forward
(
self
,
input
):
y
=
self
.
_conv
(
input
)
y
=
self
.
_batch_norm
(
y
)
if
self
.
act
==
'relu'
:
y
=
fluid
.
layers
.
relu
(
y
)
y
=
self
.
act
(
y
)
return
y
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录