未验证 提交 871f6162 编写于 作者: R Rosun 提交者: GitHub

delete bak files for SemSegPaddle (#4244)

delete bak files for SemSegPaddle
上级 0990636b
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from src.models.libs.model_libs import scope, name_scope
from src.models.libs.model_libs import avg_pool, conv, bn, conv1d, FCNHead
from src.models.backbone.resnet import ResNet as resnet_backbone
from src.utils.config import cfg
def get_logit_interp(input, num_classes, out_shape, name="logit"):
# 根据类别数决定最后一层卷积输出, 并插值回原始尺寸
param_attr = fluid.ParamAttr(
name= name + 'weights',
regularizer= fluid.regularizer.L2DecayRegularizer(regularization_coeff=0.0),
initializer= fluid.initializer.TruncatedNormal(loc=0.0, scale=0.01))
with scope(name):
logit = conv(input, num_classes, filter_size=1, param_attr=param_attr, bias_attr=True, name=name+'_conv')
logit_interp = fluid.layers.resize_bilinear( logit, out_shape=out_shape, name=name+'_interp')
return logit_interp
def gcn_module(name_scope, x, num_node, num_state):
'''
input: any tensor of 3D, B,C,N
'''
h = fluid.layers.transpose(x, perm=[0, 2, 1]) #B,C,N-->B,N,C
h = conv1d(h, num_node, name_scope+'_conv1d1')
h = fluid.layers.transpose(h, perm=[0, 2, 1]) #B,C,N
h = fluid.layers.elementwise_add(h, x, act='relu')
h = conv1d(h, num_state, name_scope+'_conv1d2')
return h
def gru_module(x, num_state, num_node):
'''
Global Reasoning Unit: projection --> graph reasoning --> reverse projection
params:
x: B x C x H x W
num_state: the dimension of each vertex feature
num_node: the number of vertet
output: B x C x H x W
feature trans:
B, C, H, W --> B, N, H, W --> B, N, H*W -->B, N, C1 -->B, C1, N-->B, C1, N-->B, C1, H*W-->B, C, H, W
--> B, C1,H, W -->B, C1,H*W -->B, H*W, C1
'''
num_batch, C, H, W = x.shape
with scope('projection'):
B = conv(x, num_node,
filter_size=1,
bias_attr=True,
name='projection'+'_conv') #num_batch, node, H, W
B = fluid.layers.reshape(B, shape=[num_batch, num_node, H*W]) #num_batch, node, L=H*W
with scope('reduce_channel'):
x_reduce = conv(x, num_state,
filter_size=1,
bias_attr=True,
name='reduce_channel'+'_conv') #num_batch, num_state, H, W
x_reduce = fluid.layers.reshape(x_reduce, shape=[num_batch, num_state, H*W]) #num_batch, num_state, L
x_reduce = fluid.layers.transpose(x_reduce, perm=[0, 2, 1]) #num_batch, L, num_state
V = fluid.layers.transpose(fluid.layers.matmul(B, x_reduce), perm=[0,2,1]) #num_batch, num_state, num_node
new_V = gcn_module('gru'+'_gcn', V, num_node, num_state)
D = fluid.layers.transpose(B, perm=[0, 2, 1])
Y = fluid.layers.matmul(D, fluid.layers.transpose(new_V, perm=[0, 2, 1]))
Y = fluid.layers.transpose(Y, perm=[0, 2, 1])
Y = fluid.layers.reshape(Y, shape=[num_batch, num_state, H, W])
with scope('extand_dim'):
Y = conv(Y, C, filter_size=1, bias_attr=True, name='extend_dim'+'_conv')
Y = bn(Y)
out = fluid.layers.elementwise_add(Y, x)
return out
def resnet(input):
# PSPNET backbone: resnet, 默认resnet50
# end_points: resnet终止层数
# dilation_dict: resnet block数及对应的膨胀卷积尺度
scale = cfg.MODEL.GLORE.DEPTH_MULTIPLIER
layers = cfg.MODEL.BACKBONE_LAYERS
end_points = layers - 1
dilation_dict = {2:2, 3:4}
decode_points= [91, 100]
model = resnet_backbone(layers, scale)
res5, feat_dict = model.net(input,
end_points=end_points,
dilation_dict=dilation_dict,
decode_points= decode_points)
return res5, feat_dict
def glore(input, num_classes):
"""
Reference:
Chen, Yunpeng, et al. "Graph-Based Global Reasoning Networks", In CVPR 2019
"""
# Backbone: ResNet
res5, feat_dict = resnet(input)
res4= feat_dict[91]
# Conv_1x1 for reduce dimension
with scope('feature'):
feature = conv(res5, 512, filter_size=1, bias_attr=True, name='feature_conv')
feature = bn(feature, act='relu')
# GRU Module
gru_output = gru_module(feature, 128, 64)
dropout = fluid.layers.dropout(gru_output, dropout_prob=0.1, name="dropout")
# 根据类别数决定最后一层卷积输出, 并插值回原始尺寸
logit = get_logit_interp(dropout, num_classes, input.shape[2:])
if cfg.MODEL.GLORE.AuxHead:
aux_logit = FCNHead(res4, 256, num_classes, input.shape[2:])
return logit, aux_logit
return logit
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import paddle.fluid as fluid
from paddle.fluid.param_attr import ParamAttr
from src.models.libs.model_libs import scope, name_scope
from src.models.libs.model_libs import avg_pool, conv, bn, bn_zero, conv1d, FCNHead
from src.models.backbone.resnet import ResNet as resnet_backbone
from src.utils.config import cfg
def get_logit_interp(input, num_classes, out_shape, name="logit"):
# 1x1_Conv
param_attr = fluid.ParamAttr(
name= name + 'weights',
regularizer= fluid.regularizer.L2DecayRegularizer(regularization_coeff=0.0),
initializer= fluid.initializer.TruncatedNormal(loc=0.0, scale=0.01))
with scope(name):
logit = conv(input, num_classes, filter_size=1, param_attr=param_attr, bias_attr=True, name=name+'_conv')
logit_interp = fluid.layers.resize_bilinear( logit, out_shape=out_shape, name=name+'_interp')
return logit_interp
def gcn_module(name_scope, x, num_node, num_state):
'''
input: any tensor of 3D, B,C,N
'''
print(x.shape)
h = fluid.layers.transpose(x, perm=[0, 2, 1]) #B,C,N-->B,N,C
h = conv1d(h, num_node, name_scope+'_conv1d1')
h = fluid.layers.transpose(h, perm=[0, 2, 1]) #B,C,N
h = fluid.layers.elementwise_add(h, x, act='relu')
h = conv1d(h, num_state, name_scope+'_conv1d2')
return h
def gru_module(x, num_state, num_node):
'''
Global Reasoning Unit: projection --> graph reasoning --> reverse projection
params:
x: B x C x H x W
num_state: the dimension of each vertex feature
num_node: the number of vertet
output: B x C x H x W
feature trans:
B, C, H, W --> B, N, H, W --> B, N, H*W -->B, N, C1 -->B, C1, N-->B, C1, N-->B, C1, H*W-->B, C, H, W
--> B, C1,H, W -->B, C1,H*W -->B, H*W, C1
'''
num_batch, C, H, W = x.shape
with scope('projection'):
B = conv(x, num_node,
filter_size=1,
bias_attr=True,
name='projection'+'_conv') #num_batch, node, H, W
B = fluid.layers.reshape(B, shape=[num_batch, num_node, H*W]) #num_batch, node, L=H*W
with scope('reduce_channel'):
x_reduce = conv(x, num_state,
filter_size=1,
bias_attr=True,
name='reduce_channel'+'_conv') #num_batch, num_state, H, W
x_reduce = fluid.layers.reshape(x_reduce, shape=[num_batch, num_state, H*W]) #num_batch, num_state, L
x_reduce = fluid.layers.transpose(x_reduce, perm=[0, 2, 1]) #num_batch, L, num_state
V = fluid.layers.transpose(fluid.layers.matmul(B, x_reduce), perm=[0,2,1]) #num_batch, num_state, num_node
L = fluid.layers.fill_constant(shape=[1], value=H*W, dtype='float32')
V = fluid.layers.elementwise_div(V, L)
new_V = gcn_module('gru'+'_gcn', V, num_node, num_state)
D = fluid.layers.transpose(B, perm=[0, 2, 1])
Y = fluid.layers.matmul(D, fluid.layers.transpose(new_V, perm=[0, 2, 1]))
Y = fluid.layers.transpose(Y, perm=[0, 2, 1])
Y = fluid.layers.reshape(Y, shape=[num_batch, num_state, H, W])
with scope('extend_dim'):
Y = conv(Y, C, filter_size=1, bias_attr=True, name='extend_dim'+'_conv')
#Y = bn_zero(Y)
Y = bn(Y)
out = fluid.layers.elementwise_add(Y, x)
return out
def resnet(input):
# end_points: end_layer of resnet backbone
# dilation_dict: dilation factor for stages_key
scale = cfg.MODEL.GLORE.DEPTH_MULTIPLIER
layers = cfg.MODEL.BACKBONE_LAYERS
end_points = layers - 1
dilation_dict = {2:2, 3:4}
decode_points= [91, 100]
model = resnet_backbone(layers, scale)
res5, feat_dict = model.net(input,
end_points=end_points,
dilation_dict=dilation_dict,
decode_points= decode_points)
return res5, feat_dict
def glore(input, num_classes):
"""
Reference:
Chen, Yunpeng, et al. "Graph-Based Global Reasoning Networks", In CVPR 2019
"""
# Backbone: ResNet
res5, feat_dict = resnet(input)
res4= feat_dict[91]
# Conv_1x1 for reduce dimension
with scope('feature'):
feature = conv(res5, 512, filter_size=3, bias_attr=True, name='feature_conv')
feature = bn(feature, act='relu')
# GRU Module
gru_output = gru_module(feature, 128, 64)
dropout = fluid.layers.dropout(gru_output, dropout_prob=0.1, name="dropout")
logit = get_logit_interp(dropout, num_classes, input.shape[2:])
if cfg.MODEL.GLORE.AuxHead:
aux_logit = FCNHead(res4, 256, num_classes, input.shape[2:])
return logit, aux_logit
return logit
此差异已折叠。
......@@ -75,9 +75,9 @@ PaddlePaddle 提供了丰富的计算单元,使得用户可以采用模块化
| 模型名称 | 模型简介 | 数据集 | 评估指标 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | --------- | --------------- |
| [ICNet](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/icnet) | 主要用于图像实时语义分割,能够兼顾速度和准确性,易于线上部署 | Cityscape | Mean IoU=67.0% |
| [DeepLab V3+](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/deeplabv3%2B) | 通过 encoder-decoder 进行多尺度信息的融合,同时保留了原来的空洞卷积和 ASSP 层, 其骨干网络使用了 Xception 模型,提高了语义分割的健壮性和运行速率 | Cityscape | Mean IoU=78.81% |
| [PSPNet (res101)](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/Research/SemSegPaddle) | 通过利用不同子区域和全局的上下文信息来增强语义分割质量,同时提出deeply supervised 的辅助loss去改善模型的优化 | Cityscape | Mean IoU = 78.1 |
| [ICNet](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/icnet) | 主要用于图像实时语义分割,能够兼顾速度和准确性,易于线上部署 | Cityscapes | Mean IoU=67.0% |
| [DeepLab V3+](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/deeplabv3%2B) | 通过 encoder-decoder 进行多尺度信息的融合,同时保留了原来的空洞卷积和 ASSP 层, 其骨干网络使用了 Xception 模型,提高了语义分割的健壮性和运行速率 | Cityscapes | Mean IoU=78.81% |
| [PSPNet (res101)](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/Research/SemSegPaddle) | 通过利用不同子区域和全局的上下文信息来增强语义分割质量,同时提出deeply supervised 的辅助loss去改善模型的优化 | Cityscapes | Mean IoU = 78.1 |
| [GloRe (res101)](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/Research/SemSegPaddle)| 提出一个轻量级的、可端到端训练的全局推理单元GloRe来高效推理image regions之间的关系,增强了模型上下文建模能力| Cityscapes | Mean IoU = 78.4 |
| [PSPNet (res101)](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/Research/SemSegPaddle) | -| PASCAL Context | Mean IoU = 48.9 |
| [GloRe (res101)](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/Research/SemSegPaddle)| -| PASCAL Context | Mean IoU = 48.4 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册