【第五期论文复现赛-语义分割】ENCNet
发布时间:2025-07-17 编辑:游乐网
本文作者引入了上下文编码模块(Context Encoding Module),在语义分割任务中利用全局上下文信息来提升语义分割的效果。本次复现赛要求是在Cityscapes验证集上miou为78.55%,本次复现的miou为79.42%,该算法已被PaddleSeg收录。
【论文复现赛】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的网络结构,主要包括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在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限制,可以分卷压缩上传)。
# 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
相关阅读
MORE
+- 【第五期论文复现赛-语义分割】ENCNet 07-17 百度网盘AI大赛:手写文字擦除(赛题二)Baseline 07-17
- 如何让豆包AI生成Python机器学习模型 07-17 ftp扫描工具免安装 ftp扫描工具绿色版推荐 07-17
- DeepSeek运行时老是报错怎么办 常见报错类型及修复建议 07-17 AI Overviews如何导出项目配置 AI Overviews设置备份与迁移方法 07-17
- 用AI语言实现语音转视频输出,打造多平台内容通用格式 07-17 豆包AI编程功能教学 豆包AI自动编程说明 07-17
- mobi怎么提取文本_mobi如何提取文本 07-17 deepseek华为手机使用 deepseek怎么优化搜索体验 07-17
- 百度网盘AI大赛:文档图像阴影消除参赛方案 AB榜第二名 07-17 【飞桨打比赛】同花顺-文档图片表格结构识别算法官方baseline迁移版 07-17
- 怎么在Excel中制作对比柱状图_双柱图绘制教程 07-17 Excel怎么导入外部数据 Excel外部数据导入的教程 07-17
- mac系统内存怎么清理详细步骤 07-17 豆包AI代码生成指南 豆包AI编程应用方法 07-16
- Deepseek 满血版联合 Scribble Diffusion,实现草图快速上色 07-16 苹果用户DeepSeek轻松上手操作指南 07-16