Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
fc2c7799
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看板
提交
fc2c7799
编写于
9月 15, 2020
作者:
M
michaelowenliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use new api
上级
ea9c7cfd
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
70 addition
and
147 deletion
+70
-147
dygraph/paddleseg/models/ann.py
dygraph/paddleseg/models/ann.py
+9
-8
dygraph/paddleseg/models/backbones/mobilenetv3.py
dygraph/paddleseg/models/backbones/mobilenetv3.py
+1
-1
dygraph/paddleseg/models/backbones/resnet_vd.py
dygraph/paddleseg/models/backbones/resnet_vd.py
+3
-3
dygraph/paddleseg/models/backbones/xception_deeplab.py
dygraph/paddleseg/models/backbones/xception_deeplab.py
+1
-1
dygraph/paddleseg/models/deeplab.py
dygraph/paddleseg/models/deeplab.py
+30
-111
dygraph/paddleseg/models/fast_scnn.py
dygraph/paddleseg/models/fast_scnn.py
+9
-9
dygraph/paddleseg/models/gcnet.py
dygraph/paddleseg/models/gcnet.py
+8
-8
dygraph/paddleseg/models/ocrnet.py
dygraph/paddleseg/models/ocrnet.py
+1
-1
dygraph/paddleseg/models/pspnet.py
dygraph/paddleseg/models/pspnet.py
+8
-5
未找到文件。
dygraph/paddleseg/models/ann.py
浏览文件 @
fc2c7799
...
...
@@ -17,8 +17,9 @@ import os
import
paddle
import
paddle.nn.functional
as
F
from
paddle
import
nn
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common
import
layer_
utils
,
model_util
s
from
paddleseg.models.common
import
layer_
lib
s
from
paddleseg.utils
import
utils
...
...
@@ -88,7 +89,7 @@ class ANN(nn.Layer):
psp_size
=
psp_size
)
self
.
context
=
nn
.
Sequential
(
layer_
util
s
.
ConvBnRelu
(
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
high_in_channels
,
out_channels
=
inter_channels
,
kernel_size
=
3
,
...
...
@@ -106,7 +107,7 @@ class ANN(nn.Layer):
in_channels
=
inter_channels
,
out_channels
=
num_classes
,
kernel_size
=
1
)
self
.
auxlayer
=
model_util
s
.
AuxLayer
(
self
.
auxlayer
=
layer_lib
s
.
AuxLayer
(
in_channels
=
low_in_channels
,
inter_channels
=
low_in_channels
//
2
,
out_channels
=
num_classes
,
...
...
@@ -189,7 +190,7 @@ class AFNB(nn.Layer):
key_channels
,
value_channels
,
out_channels
,
size
)
for
size
in
sizes
])
self
.
conv_bn
=
layer_
util
s
.
ConvBn
(
self
.
conv_bn
=
layer_
lib
s
.
ConvBn
(
in_channels
=
out_channels
+
high_in_channels
,
out_channels
=
out_channels
,
kernel_size
=
1
)
...
...
@@ -243,7 +244,7 @@ class APNB(nn.Layer):
SelfAttentionBlock_APNB
(
in_channels
,
out_channels
,
key_channels
,
value_channels
,
size
)
for
size
in
sizes
])
self
.
conv_bn
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
in_channels
*
2
,
out_channels
=
out_channels
,
kernel_size
=
1
)
...
...
@@ -310,11 +311,11 @@ class SelfAttentionBlock_AFNB(nn.Layer):
if
out_channels
==
None
:
self
.
out_channels
=
high_in_channels
self
.
pool
=
nn
.
Pool2D
(
pool_size
=
(
scale
,
scale
),
pool_type
=
"max"
)
self
.
f_key
=
layer_
util
s
.
ConvBnRelu
(
self
.
f_key
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
low_in_channels
,
out_channels
=
key_channels
,
kernel_size
=
1
)
self
.
f_query
=
layer_
util
s
.
ConvBnRelu
(
self
.
f_query
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
high_in_channels
,
out_channels
=
key_channels
,
kernel_size
=
1
)
...
...
@@ -393,7 +394,7 @@ class SelfAttentionBlock_APNB(nn.Layer):
self
.
value_channels
=
value_channels
self
.
pool
=
nn
.
Pool2D
(
pool_size
=
(
scale
,
scale
),
pool_type
=
"max"
)
self
.
f_key
=
layer_
util
s
.
ConvBnRelu
(
self
.
f_key
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
self
.
in_channels
,
out_channels
=
self
.
key_channels
,
kernel_size
=
1
)
...
...
dygraph/paddleseg/models/backbones/mobilenetv3.py
浏览文件 @
fc2c7799
...
...
@@ -27,7 +27,7 @@ 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
paddleseg.models.common
import
layer_
util
s
from
paddleseg.models.common
import
layer_
lib
s
from
paddleseg.cvlibs
import
manager
from
paddleseg.utils
import
utils
...
...
dygraph/paddleseg/models/backbones/resnet_vd.py
浏览文件 @
fc2c7799
...
...
@@ -28,7 +28,7 @@ from paddle.fluid.dygraph.nn import Conv2D, Pool2D, Linear, Dropout
from
paddle.nn
import
SyncBatchNorm
as
BatchNorm
from
paddleseg.utils
import
utils
from
paddleseg.models.common
import
layer_
utils
from
paddleseg.models.common
import
layer_
libs
,
activation
from
paddleseg.cvlibs
import
manager
__all__
=
[
...
...
@@ -77,7 +77,7 @@ class ConvBNLayer(fluid.dygraph.Layer):
num_filters
,
weight_attr
=
ParamAttr
(
name
=
bn_name
+
'_scale'
),
bias_attr
=
ParamAttr
(
bn_name
+
'_offset'
))
self
.
_act_op
=
layer_utils
.
Activation
(
act
=
act
)
self
.
_act_op
=
activation
.
Activation
(
act
=
act
)
def
forward
(
self
,
inputs
):
if
self
.
is_vd_mode
:
...
...
@@ -213,7 +213,7 @@ class ResNet_vd(fluid.dygraph.Layer):
layers
=
50
,
class_dim
=
1000
,
output_stride
=
None
,
multi_grid
=
(
1
,
2
,
4
)):
multi_grid
=
(
1
,
1
,
1
)):
super
(
ResNet_vd
,
self
).
__init__
()
self
.
layers
=
layers
...
...
dygraph/paddleseg/models/backbones/xception_deeplab.py
浏览文件 @
fc2c7799
...
...
@@ -21,7 +21,7 @@ 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
paddleseg.models.common
import
layer_
util
s
from
paddleseg.models.common
import
layer_
lib
s
from
paddleseg.cvlibs
import
manager
from
paddleseg.utils
import
utils
...
...
dygraph/paddleseg/models/deeplab.py
浏览文件 @
fc2c7799
...
...
@@ -18,7 +18,7 @@ import paddle
import
paddle.nn.functional
as
F
from
paddle
import
nn
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common
import
layer_util
s
from
paddleseg.models.common
import
pyramid_pool
,
layer_lib
s
from
paddleseg.utils
import
utils
__all__
=
[
'DeepLabV3P'
,
'DeepLabV3'
]
...
...
@@ -43,8 +43,9 @@ class DeepLabV3P(nn.Layer):
model_pretrained (str): the path of pretrained model.
output_stride (int): the ratio of input size and final feature size.
Support 16 or 8. Default to 16.
aspp_ratios (tuple): the dilation rate using in ASSP module.
if output_stride=16, aspp_ratios should be set as (1, 6, 12, 18).
if output_stride=8, aspp_ratios is (1, 12, 24, 36).
backbone_indices (tuple): two values in the tuple indicte the indices of output of backbone.
the first index will be taken as a low-level feature in Deconder component;
...
...
@@ -61,18 +62,24 @@ class DeepLabV3P(nn.Layer):
def
__init__
(
self
,
num_classes
,
backbone
,
backbone_pretrained
=
None
,
model_pretrained
=
None
,
backbone_indices
=
(
0
,
3
),
backbone_channels
=
(
256
,
2048
),
output_stride
=
16
):
aspp_ratios
=
(
1
,
6
,
12
,
18
),
aspp_out_channels
=
256
):
super
(
DeepLabV3P
,
self
).
__init__
()
self
.
backbone
=
backbone
self
.
aspp
=
ASPP
(
output_stride
,
backbone_channels
[
1
])
self
.
backbone_pretrained
=
backbone_pretrained
self
.
model_pretrained
=
model_pretrained
self
.
aspp
=
pyramid_pool
.
ASPPModule
(
aspp_ratios
,
backbone_channels
[
1
],
aspp_out_channels
,
sep_conv
=
True
,
image_pooling
=
True
)
self
.
decoder
=
Decoder
(
num_classes
,
backbone_channels
[
0
])
self
.
backbone_indices
=
backbone_indices
self
.
init_weight
(
model_pretrained
)
self
.
init_weight
()
def
forward
(
self
,
input
,
label
=
None
):
...
...
@@ -87,19 +94,17 @@ class DeepLabV3P(nn.Layer):
return
logit_list
def
init_weight
(
self
,
pretrained_model
=
None
):
def
init_weight
(
self
):
"""
Initialize the parameters of model parts.
Args:
pretrained_model ([str], optional): the path of pretrained model. Defaults to None.
"""
if
pretrained_model
is
not
None
:
if
os
.
path
.
exists
(
pretrained_model
):
utils
.
load_pretrained_model
(
self
,
pretrained_model
)
else
:
raise
Exception
(
'Pretrained model is not found: {}'
.
format
(
pretrained_model
))
if
self
.
model_pretrained
is
not
None
:
utils
.
load_pretrained_model
(
self
,
self
.
model_pretrained
)
elif
self
.
backbone_pretrained
is
not
None
:
utils
.
load_pretrained_model
(
self
.
backbone
,
self
.
backbone_pretrained
)
@
manager
.
MODELS
.
add_component
class
DeepLabV3
(
nn
.
Layer
):
...
...
@@ -119,15 +124,21 @@ class DeepLabV3(nn.Layer):
def
__init__
(
self
,
num_classes
,
backbone
,
backbone_pretrained
=
None
,
model_pretrained
=
None
,
backbone_indices
=
(
3
,),
backbone_channels
=
(
2048
,),
output_stride
=
16
):
aspp_ratios
=
(
1
,
6
,
12
,
18
),
aspp_out_channels
=
256
):
super
(
DeepLabV3
,
self
).
__init__
()
self
.
backbone
=
backbone
self
.
aspp
=
ASPP
(
output_stride
,
backbone_channels
[
0
])
self
.
aspp
=
pyramid_pool
.
ASPPModule
(
aspp_ratios
,
backbone_channels
[
0
],
aspp_out_channels
,
sep_conv
=
False
,
image_pooling
=
True
)
self
.
cls
=
nn
.
Conv2d
(
in_channels
=
backbone_channels
[
0
],
out_channels
=
num_classes
,
...
...
@@ -161,98 +172,6 @@ class DeepLabV3(nn.Layer):
pretrained_model
))
class
ImageAverage
(
nn
.
Layer
):
"""
Global average pooling
Args:
in_channels (int): the number of input channels.
"""
def
__init__
(
self
,
in_channels
):
super
(
ImageAverage
,
self
).
__init__
()
self
.
conv_bn_relu
=
layer_utils
.
ConvBnRelu
(
in_channels
,
out_channels
=
256
,
kernel_size
=
1
)
def
forward
(
self
,
input
):
x
=
paddle
.
reduce_mean
(
input
,
dim
=
[
2
,
3
],
keep_dim
=
True
)
x
=
self
.
conv_bn_relu
(
x
)
x
=
F
.
resize_bilinear
(
x
,
out_shape
=
input
.
shape
[
2
:])
return
x
class
ASPP
(
nn
.
Layer
):
"""
Decoder module of DeepLabV3P model
Args:
output_stride (int): the ratio of input size and final feature size. Support 16 or 8.
in_channels (int): the number of input channels in decoder module.
"""
def
__init__
(
self
,
output_stride
,
in_channels
):
super
(
ASPP
,
self
).
__init__
()
if
output_stride
==
16
:
aspp_ratios
=
(
6
,
12
,
18
)
elif
output_stride
==
8
:
aspp_ratios
=
(
12
,
24
,
36
)
else
:
raise
NotImplementedError
(
"Only support output_stride is 8 or 16, but received{}"
.
format
(
output_stride
))
self
.
image_average
=
ImageAverage
(
in_channels
=
in_channels
)
# The first aspp using 1*1 conv
self
.
aspp1
=
layer_utils
.
DepthwiseConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
256
,
kernel_size
=
1
)
# The second aspp using 3*3 (separable) conv at dilated rate aspp_ratios[0]
self
.
aspp2
=
layer_utils
.
DepthwiseConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
256
,
kernel_size
=
3
,
dilation
=
aspp_ratios
[
0
],
padding
=
aspp_ratios
[
0
])
# The Third aspp using 3*3 (separable) conv at dilated rate aspp_ratios[1]
self
.
aspp3
=
layer_utils
.
DepthwiseConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
256
,
kernel_size
=
3
,
dilation
=
aspp_ratios
[
1
],
padding
=
aspp_ratios
[
1
])
# The Third aspp using 3*3 (separable) conv at dilated rate aspp_ratios[2]
self
.
aspp4
=
layer_utils
.
DepthwiseConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
256
,
kernel_size
=
3
,
dilation
=
aspp_ratios
[
2
],
padding
=
aspp_ratios
[
2
])
# After concat op, using 1*1 conv
self
.
conv_bn_relu
=
layer_utils
.
ConvBnRelu
(
in_channels
=
1280
,
out_channels
=
256
,
kernel_size
=
1
)
def
forward
(
self
,
x
):
x1
=
self
.
image_average
(
x
)
x2
=
self
.
aspp1
(
x
)
x3
=
self
.
aspp2
(
x
)
x4
=
self
.
aspp3
(
x
)
x5
=
self
.
aspp4
(
x
)
x
=
paddle
.
concat
([
x1
,
x2
,
x3
,
x4
,
x5
],
axis
=
1
)
x
=
self
.
conv_bn_relu
(
x
)
x
=
F
.
dropout
(
x
,
p
=
0.1
)
# dropout_prob
return
x
class
Decoder
(
nn
.
Layer
):
"""
Decoder module of DeepLabV3P model
...
...
@@ -267,12 +186,12 @@ class Decoder(nn.Layer):
def
__init__
(
self
,
num_classes
,
in_channels
):
super
(
Decoder
,
self
).
__init__
()
self
.
conv_bn_relu1
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn_relu1
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
48
,
kernel_size
=
1
)
self
.
conv_bn_relu2
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
conv_bn_relu2
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
304
,
out_channels
=
256
,
kernel_size
=
3
,
padding
=
1
)
self
.
conv_bn_relu3
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
conv_bn_relu3
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
256
,
out_channels
=
256
,
kernel_size
=
3
,
padding
=
1
)
self
.
conv
=
nn
.
Conv2d
(
in_channels
=
256
,
out_channels
=
num_classes
,
kernel_size
=
1
)
...
...
dygraph/paddleseg/models/fast_scnn.py
浏览文件 @
fc2c7799
...
...
@@ -15,7 +15,7 @@
import
paddle.nn.functional
as
F
from
paddle
import
nn
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common
import
layer_
utils
,
model_util
s
from
paddleseg.models.common
import
layer_
lib
s
@
manager
.
MODELS
.
add_component
...
...
@@ -110,15 +110,15 @@ class LearningToDownsample(nn.Layer):
def
__init__
(
self
,
dw_channels1
=
32
,
dw_channels2
=
48
,
out_channels
=
64
):
super
(
LearningToDownsample
,
self
).
__init__
()
self
.
conv_bn_relu
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn_relu
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
3
,
out_channels
=
dw_channels1
,
kernel_size
=
3
,
stride
=
2
)
self
.
dsconv_bn_relu1
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
dsconv_bn_relu1
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
dw_channels1
,
out_channels
=
dw_channels2
,
kernel_size
=
3
,
stride
=
2
,
padding
=
1
)
self
.
dsconv_bn_relu2
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
dsconv_bn_relu2
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
dw_channels2
,
out_channels
=
out_channels
,
kernel_size
=
3
,
...
...
@@ -220,13 +220,13 @@ class LinearBottleneck(nn.Layer):
expand_channels
=
in_channels
*
expansion
self
.
block
=
nn
.
Sequential
(
# pw
layer_
util
s
.
ConvBnRelu
(
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
expand_channels
,
kernel_size
=
1
,
bias_attr
=
False
),
# dw
layer_
util
s
.
ConvBnRelu
(
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
expand_channels
,
out_channels
=
expand_channels
,
kernel_size
=
3
,
...
...
@@ -267,7 +267,7 @@ class FeatureFusionModule(nn.Layer):
super
(
FeatureFusionModule
,
self
).
__init__
()
# There only depth-wise conv is used WITHOUT point-wise conv
self
.
dwconv
=
layer_
util
s
.
ConvBnRelu
(
self
.
dwconv
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
low_in_channels
,
out_channels
=
out_channels
,
kernel_size
=
3
,
...
...
@@ -317,13 +317,13 @@ class Classifier(nn.Layer):
def
__init__
(
self
,
input_channels
,
num_classes
):
super
(
Classifier
,
self
).
__init__
()
self
.
dsconv1
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
dsconv1
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
input_channels
,
out_channels
=
input_channels
,
kernel_size
=
3
,
padding
=
1
)
self
.
dsconv2
=
layer_
util
s
.
DepthwiseConvBnRelu
(
self
.
dsconv2
=
layer_
lib
s
.
DepthwiseConvBnRelu
(
in_channels
=
input_channels
,
out_channels
=
input_channels
,
kernel_size
=
3
,
...
...
dygraph/paddleseg/models/gcnet.py
浏览文件 @
fc2c7799
...
...
@@ -18,7 +18,7 @@ import paddle
import
paddle.nn.functional
as
F
from
paddle
import
nn
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common
import
layer_
utils
,
model_util
s
from
paddleseg.models.common
import
layer_
lib
s
from
paddleseg.utils
import
utils
...
...
@@ -72,7 +72,7 @@ class GCNet(nn.Layer):
self
.
backbone
=
backbone
in_channels
=
backbone_channels
[
1
]
self
.
conv_bn_relu1
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn_relu1
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
in_channels
,
out_channels
=
gc_channels
,
kernel_size
=
3
,
...
...
@@ -80,13 +80,13 @@ class GCNet(nn.Layer):
self
.
gc_block
=
GlobalContextBlock
(
in_channels
=
gc_channels
,
ratio
=
ratio
)
self
.
conv_bn_relu2
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn_relu2
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
gc_channels
,
out_channels
=
gc_channels
,
kernel_size
=
3
,
padding
=
1
)
self
.
conv_bn_relu3
=
layer_
util
s
.
ConvBnRelu
(
self
.
conv_bn_relu3
=
layer_
lib
s
.
ConvBnRelu
(
in_channels
=
in_channels
+
gc_channels
,
out_channels
=
gc_channels
,
kernel_size
=
3
,
...
...
@@ -96,7 +96,7 @@ class GCNet(nn.Layer):
in_channels
=
gc_channels
,
out_channels
=
num_classes
,
kernel_size
=
1
)
if
enable_auxiliary_loss
:
self
.
auxlayer
=
model_util
s
.
AuxLayer
(
self
.
auxlayer
=
layer_lib
s
.
AuxLayer
(
in_channels
=
backbone_channels
[
0
],
inter_channels
=
backbone_channels
[
0
]
//
4
,
out_channels
=
num_classes
)
...
...
@@ -161,9 +161,9 @@ class GlobalContextBlock(nn.Layer):
self
.
conv_mask
=
nn
.
Conv2d
(
in_channels
=
in_channels
,
out_channels
=
1
,
kernel_size
=
1
)
# current paddle version does not support Softmax class
# self.softmax = layer_utils.Activation("softmax", dim=2)
self
.
softmax
=
nn
.
Softmax
(
axis
=
2
)
inter_channels
=
int
(
in_channels
*
ratio
)
self
.
channel_add_conv
=
nn
.
Sequential
(
nn
.
Conv2d
(
...
...
@@ -188,7 +188,7 @@ class GlobalContextBlock(nn.Layer):
# [N, 1, H * W]
context_mask
=
paddle
.
reshape
(
context_mask
,
shape
=
[
batch
,
1
,
height
*
width
])
context_mask
=
F
.
softmax
(
context_mask
)
context_mask
=
self
.
softmax
(
context_mask
)
# [N, 1, H * W, 1]
context_mask
=
paddle
.
unsqueeze
(
context_mask
,
axis
=-
1
)
# [N, 1, C, 1]
...
...
dygraph/paddleseg/models/ocrnet.py
浏览文件 @
fc2c7799
...
...
@@ -18,7 +18,7 @@ import paddle.fluid as fluid
from
paddle.fluid.dygraph
import
Sequential
,
Conv2D
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common.layer_
util
s
import
ConvBnRelu
from
paddleseg.models.common.layer_
lib
s
import
ConvBnRelu
from
paddleseg
import
utils
...
...
dygraph/paddleseg/models/pspnet.py
浏览文件 @
fc2c7799
...
...
@@ -17,7 +17,7 @@ import os
import
paddle.nn.functional
as
F
from
paddle
import
nn
from
paddleseg.cvlibs
import
manager
from
paddleseg.models.common
import
model_utils
from
paddleseg.models.common
import
layer_libs
,
pyramid_pool
from
paddleseg.utils
import
utils
...
...
@@ -70,7 +70,7 @@ class PSPNet(nn.Layer):
self
.
backbone
=
backbone
self
.
backbone_indices
=
backbone_indices
self
.
psp_module
=
model_utils
.
PPModule
(
self
.
psp_module
=
pyramid_pool
.
PPModule
(
in_channels
=
backbone_channels
[
1
],
out_channels
=
pp_out_channels
,
bin_sizes
=
bin_sizes
)
...
...
@@ -81,8 +81,11 @@ class PSPNet(nn.Layer):
kernel_size
=
1
)
if
enable_auxiliary_loss
:
self
.
fcn_head
=
model_utils
.
FCNHead
(
in_channels
=
backbone_channels
[
0
],
out_channels
=
num_classes
)
self
.
auxlayer
=
layer_libs
.
AuxLayer
(
in_channels
=
backbone_channels
[
0
],
inter_channels
=
backbone_channels
[
0
]
//
4
,
out_channels
=
num_classes
)
self
.
enable_auxiliary_loss
=
enable_auxiliary_loss
...
...
@@ -102,7 +105,7 @@ class PSPNet(nn.Layer):
if
self
.
enable_auxiliary_loss
:
auxiliary_feat
=
feat_list
[
self
.
backbone_indices
[
0
]]
auxiliary_logit
=
self
.
fcn_head
(
auxiliary_feat
)
auxiliary_logit
=
self
.
auxlayer
(
auxiliary_feat
)
auxiliary_logit
=
F
.
resize_bilinear
(
auxiliary_logit
,
input
.
shape
[
2
:])
logit_list
.
append
(
auxiliary_logit
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录