当前位置: 首页 > AI > 文章内容页

【第五期论文复现赛-语义分割】ENCNet

时间:2025-07-17    作者:游乐小编    

本文作者引入了上下文编码模块(Context Encoding Module),在语义分割任务中利用全局上下文信息来提升语义分割的效果。本次复现赛要求是在Cityscapes验证集上miou为78.55%,本次复现的miou为79.42%,该算法已被PaddleSeg收录。

【第五期论文复现赛-语义分割】encnet - 游乐网

【论文复现赛】ENCNet:Context Encoding for Semantic Segmentation

本文作者引入了上下文编码模块(Context Encoding Module),在语义分割任务中利用全局上下文信息来提升语义分割的效果。本次复现赛要求是在Cityscapes验证集上miou为78.55%,本次复现的miou为79.42%,该算法已被PaddleSeg收录。

一、引言

PSPNet通过SPP(Spatial Pyramid polling)模块得到不同尺寸的特征图,然后将不同尺寸的特征图结合扩大感受野;DeepLab利用ASPP(Atrous Spatial Pyramid Pooling)来扩大感受野。但是ENCNet提出了一个问题:“Is capturing contextual information the same as increasing the receptive field size?”(增加感受野等于捕获上下文信息吗?)。作者提出一个想法:利用图片的上下文信息来减少图片中像素种类的搜索空间。比如一张卧室的图片,那么该图片中有床、椅子等物体的可能性就会比汽车、湖面等其他物体的概率大很多。本文提出了Context Encoding Module和Semantic Encoding Loss(SE-loss)来学习上下文信息。

二、网络结构

【第五期论文复现赛-语义分割】ENCNet - 游乐网 上图为ENCNet的网络结构,主要包括Context Encoding Module, Featuremap Attention和Semantic Encoding Loss。
Context Encoding Module:该模块对输入的特征图进行编码得到编码后的语义向量(原文中叫做encoded semantics),得到的语义向量有2个用处,第一个是送入Featuremap Attention用作注意力机制的权重,另一个用处是用于计算Semantic Encoding Loss。
Featuremap Attention:该模块使得模型更注重于信息量大的channel特征,抑制不重要的channel特征。例如在一张背景为天空的图片中,存在飞机的可能性就会比汽车的可能性大。
Semantic Encoding Loss:像素级的交叉熵损失函数无法考虑到全局信息,可能会导致小目标无法正常识别,而SELoss可以平等的考虑不同大小的目标。SELoss损失的target是一个(N, NUM_CLASSES)的矩阵,它的构造也很简单,如果图片中存在某种物体,则对应的target的标签就为1。

三、实验结果

【第五期论文复现赛-语义分割】ENCNet - 游乐网
上图为ENCNet在ADE20K数据集的预测结果,与FCN对比,可以看出ENCNet利用全局语义信息的显著优点:
1、第一行图片中,FCN将sand分类成了earth,ENCNet利用了全局信息(海边大概率存在沙)正确分类;
2、第二、四行图片中,FCN很难区分building,house和skyscraper这3类;
3、第三行,FCN将 windowpane分类成door。

四、核心代码

class Encoding(nn.Layer):    def __init__(self, channels, num_codes):        super().__init__()        self.channels, self.num_codes = channels, num_codes        std = 1 / ((channels * num_codes) ** 0.5)        self.codewords = self.create_parameter(            shape=(num_codes, channels),            default_initializer=nn.initializer.Uniform(-std, std),        )     # 编码        self.scale = self.create_parameter(            shape=(num_codes,),            default_initializer=nn.initializer.Uniform(-1, 0),        )        # 缩放因子        self.channels = channels    def scaled_l2(self, x, codewords, scale):        num_codes, channels = paddle.shape(codewords)        reshaped_scale = scale.reshape([1, 1, num_codes])        expanded_x = paddle.tile(x.unsqueeze(2), [1, 1, num_codes, 1])        reshaped_codewords = codewords.reshape([1, 1, num_codes, channels])        scaled_l2_norm = paddle.multiply(reshaped_scale, (expanded_x - reshaped_codewords).pow(2).sum(axis=3))        return scaled_l2_norm    def aggregate(self, assignment_weights, x, codewords):        num_codes, channels = paddle.shape(codewords)        reshaped_codewords = codewords.reshape([1, 1, num_codes, channels])        expanded_x = paddle.tile(x.unsqueeze(2), [1, 1, num_codes, 1])                encoded_feat = paddle.multiply(assignment_weights.unsqueeze(3), (expanded_x - reshaped_codewords)).sum(axis=1)        encoded_feat = paddle.reshape(encoded_feat, [-1, self.num_codes, self.channels])        return encoded_feat        def forward(self, x):        x_dims = x.ndim        assert x_dims == 4, "The dimension of input tensor must equal 4, but got {}.".format(x_dims)        assert paddle.shape(x)[1] == self.channels, "Encoding channels error, excepted {} but got {}.".format(self.channels, paddle.shape(x)[1])        batch_size = paddle.shape(x)[0]        x = x.reshape([batch_size, self.channels, -1]).transpose([0, 2, 1])        assignment_weights = F.softmax(self.scaled_l2(x, self.codewords, self.scale), axis=2)        encoded_feat = self.aggregate(assignment_weights, x, self.codewords)        return encoded_feat
登录后复制

五、ENCNet快速体验

1、解压cityscapes数据集;
2、训练ENCNet,本论文的复现环境是Tesla V100 * 4,想要完整的复现结果请移步脚本任务;
3、验证训练结果,如果想要验证复现的结果,需要下载权重,并放入output/best_model文件夹内(权重超出150MB限制,可以分卷压缩上传)。

In [ ]
# step 1: unzip data%cd ~/data/data64550!tar -xf cityscapes.tar%cd ~/
登录后复制In [ ]
# step 2: training%cd ~/ENCNet_paddle/!python train.py --config configs/encnet/encnet_cityscapes_1024x512_80k.yml --num_workers 16 --do_eval --use_vdl --log_iter 20 --save_interval 5000
登录后复制In [ ]
# step 3: val%cd ~/ENCNet_paddle/!python val.py --config configs/encnet/encnet_cityscapes_1024x512_80k.yml --model_path output/best_model/model.pdparams
登录后复制

六、复现结果

本次复现的目标是Cityscapes 验证集miou 78.55%,复现的为miou 79.42%。
环境:
Tesla V100 *4
PaddlePaddle==2.2.0


热门推荐

更多

热门文章

更多

首页  返回顶部

本站所有软件都由网友上传,如有侵犯您的版权,请发邮件youleyoucom@outlook.com