当前位置: 首页 > news >正文

YOLO融合CFFormer中的FeatureCorrection_s2c模块


YOLOv11v10v8使用教程:  YOLOv11入门到入土使用教程

YOLOv11改进汇总贴:YOLOv11及自研模型更新汇总 


《CFFormer: A Cross-Fusion Transformer Framework for the Semantic Segmentation of Multisource Remote Sensing Images》

一、 模块介绍

        论文链接:https://ieeexplore.ieee.org/document/10786275

        代码链接:https://github.com/masurq/CFFormer/tree/master

论文速览:

        多源遥感图像(RSIs)能够捕捉地面物体的互补信息,用于语义分割。然而,来自不同传感器的多模态数据之间可能存在不一致性和干扰噪声。因此,如何有效减少不同模态之间的差异和噪声,并充分利用其互补特征,是一个挑战。在本文中,我们提出了一种用于多源遥感图像语义分割的通用跨融合变压器框架(CFFormer),采用并行双流结构分别从不同模态中提取特征。我们引入了一个特征校正模块(FCM),通过结合其他模态的特征,在空间和通道维度上校正当前模态的特征。在特征融合模块(FFM)中,我们采用多头交叉注意力机制进行全局交互和融合不同模态的特征,从而能够全面利用多源遥感图像中的互补信息。最后,对比实验表明,所提出的 CFFormer 框架不仅达到了最先进的(SOTA)精度,而且与当前用于多源遥感图像语义分割的先进网络相比,还表现出出色的鲁棒性。

总结:本文更新其中的FeatureCorrection_s2c模块。


⭐⭐本文二创模块仅更新于付费群中,往期免费教程可看下方链接⭐⭐

YOLOv11及自研模型更新汇总(含免费教程)文章浏览阅读366次,点赞3次,收藏4次。群文件2024/11/08日更新。,群文件2024/11/08日更新。_yolo11部署自己的数据集https://xy2668825911.blog.csdn.net/article/details/143633356

二、二创融合模块

2.1 相关代码

# https://blog.csdn.net/StopAndGoyyy?spm=1011.2124.3001.5343
# https://ieeexplore.ieee.org/document/10786275
class ChannelWeights(nn.Module):def __init__(self, dim, reduction=1):super(ChannelWeights, self).__init__()self.dim = dimself.avg_pool = nn.AdaptiveAvgPool2d(1)self.max_pool = nn.AdaptiveMaxPool2d(1)self.mlp = nn.Sequential(nn.Linear(self.dim * 6, self.dim * 6 // reduction),nn.ReLU(inplace=True),nn.Linear(self.dim * 6 // reduction, self.dim * 2),nn.Sigmoid())def forward(self, x1, x2):B, _, H, W = x1.shapex = torch.cat((x1, x2), dim=1)avg = self.avg_pool(x).view(B, self.dim * 2)std = torch.std(x, dim=(2, 3), keepdim=True).view(B, self.dim * 2)max = self.max_pool(x).view(B, self.dim * 2)y = torch.cat((avg, std, max), dim=1)  # B 6Cy = self.mlp(y).view(B, self.dim * 2, 1)channel_weights = y.reshape(B, 2, self.dim, 1, 1).permute(1, 0, 2, 3, 4)  # 2 B C 1 1return channel_weightsclass SpatialWeights(nn.Module):def __init__(self, dim, reduction=1):super(SpatialWeights, self).__init__()self.dim = dimself.mlp = nn.Sequential(nn.Conv2d(self.dim * 2, self.dim // reduction, kernel_size=1),nn.ReLU(inplace=True),nn.Conv2d(self.dim // reduction, 2, kernel_size=1),nn.Sigmoid())def forward(self, x1, x2):B, _, H, W = x1.shapex = torch.cat((x1, x2), dim=1)  # B 2C H Wspatial_weights = self.mlp(x).reshape(B, 2, 1, H, W).permute(1, 0, 2, 3, 4)  # 2 B 1 H Wreturn spatial_weights# 先空间校正再通道校正
class FeatureCorrection_s2c(nn.Module):def __init__(self, dim, reduction=1, eps=1e-8):super(FeatureCorrection_s2c, self).__init__()# 自定义可训练权重参数self.weights = nn.Parameter(torch.ones(2, dtype=torch.float32), requires_grad=True)self.eps = epsself.spatial_weights = SpatialWeights(dim=dim, reduction=reduction)self.channel_weights = ChannelWeights(dim=dim, reduction=reduction)self.apply(self._init_weights)@classmethoddef _init_weights(cls, m):if isinstance(m, nn.Linear):trunc_normal_(m.weight, std=.02)if isinstance(m, nn.Linear) and m.bias is not None:nn.init.constant_(m.bias, 0)elif isinstance(m, nn.LayerNorm):nn.init.constant_(m.bias, 0)nn.init.constant_(m.weight, 1.0)elif isinstance(m, nn.Conv2d):fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channelsfan_out //= m.groupsm.weight.data.normal_(0, math.sqrt(2.0 / fan_out))if m.bias is not None:m.bias.data.zero_()def forward(self, x):x1, x2 = xweights = nn.ReLU()(self.weights)fuse_weights = weights / (torch.sum(weights, dim=0) + self.eps)spatial_weights = self.spatial_weights(x1, x2)x1_1 = x1 + fuse_weights[0] * spatial_weights[1] * x2x2_1 = x2 + fuse_weights[0] * spatial_weights[0] * x1channel_weights = self.channel_weights(x1_1, x2_1)main_out = x1_1 + fuse_weights[1] * channel_weights[1] * x2_1aux_out = x2_1 + fuse_weights[1] * channel_weights[0] * x1_1return torch.cat([main_out, aux_out], dim=1)

2.2更改yaml文件 (以自研模型为例)

yam文件解读:YOLO系列 “.yaml“文件解读_yolo yaml文件-CSDN博客

       打开更改ultralytics/cfg/models/11路径下的YOLOv11.yaml文件,替换原有模块。

# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# ⭐⭐Powered by https://blog.csdn.net/StopAndGoyyy,  技术指导QQ:2668825911⭐⭐# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'# [depth, width, max_channels]n: [0.50, 0.25, 1024] # summary: 377 layers, 2,249,525 parameters, 2,249,509 gradients, 8.7 GFLOPs/258 layers, 2,219,405 parameters, 0 gradients, 8.5 GFLOPss: [0.50, 0.50, 1024] # summary: 377 layers, 8,082,389 parameters, 8,082,373 gradients, 29.8 GFLOPs/258 layers, 7,972,885 parameters, 0 gradients, 29.2 GFLOPsm: [0.50, 1.00, 512] # summary:  377 layers, 20,370,221 parameters, 20,370,205 gradients, 103.0 GFLOPs/258 layers, 20,153,773 parameters, 0 gradients, 101.2 GFLOPsl: [1.00, 1.00, 512] # summary: 521 layers, 23,648,717 parameters, 23,648,701 gradients, 124.5 GFLOPs/330 layers, 23,226,989 parameters, 0 gradients, 121.2 GFLOPsx: [1.00, 1.50, 512] # summary: 521 layers, 53,125,237 parameters, 53,125,221 gradients, 278.9 GFLOPs/330 layers, 52,191,589 parameters, 0 gradients, 272.1 GFLOPs#  n: [0.33, 0.25, 1024]
#  s: [0.50, 0.50, 1024]
#  m: [0.67, 0.75, 768]
#  l: [1.00, 1.00, 512]
#  x: [1.00, 1.25, 512]
# YOLO11n backbone
backbone:# [from, repeats, module, args]- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4- [-1, 2, RCRep2A, [128, False, 0.25]]- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8- [-1, 4, RCRep2A, [256, False, 0.25]]- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16- [-1, 4, RCRep2A, [512, True]]- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32- [-1, 2, RCRep2A, [1024, True]]- [-1, 1, SPPF_WD, [1024, 7]] # 9# YOLO11n head
head:- [[3, 5, 7], 1, align_3In, [256, 1]] # 10- [[4, 6, 9], 1, align_3In, [256, 1]] # 11- [[-1, -2], 1, FeatureCorrection_s2c, [1]] #12  cat- [-1, 1, RepVGGBlocks, []] #13- [-1, 1, nn.Upsample, [None, 2, "nearest"]] #14- [[-1, 4], 1, Concat, [1]] #15 cat- [-1, 1, Conv, [256, 3]] # 16- [13, 1, Conv, [512, 3]] #17- [13, 1, Conv, [1024, 3, 2]] #18- [[16, 17, 18], 1, Detect, [nc]] # Detect(P3, P4, P5)# ⭐⭐Powered by https://blog.csdn.net/StopAndGoyyy,  技术指导QQ:2668825911⭐⭐

 2.3 修改train.py文件

       创建Train脚本用于训练。

from ultralytics.models import YOLO
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'if __name__ == '__main__':model = YOLO(model='ultralytics/cfg/models/xy_YOLO/xy_yolov1.yaml')# model = YOLO(model='ultralytics/cfg/models/11/yolo11l.yaml')model.train(data='./datasets/data.yaml', epochs=1, batch=1, device='0', imgsz=320, workers=1, cache=False,amp=True, mosaic=False, project='run/train', name='exp',)

         在train.py脚本中填入修改好的yaml路径,运行即可训练,数据集创建教程见下方链接。

YOLOv11入门到入土使用教程(含结构图)_yolov11使用教程-CSDN博客


http://www.lryc.cn/news/588962.html

相关文章:

  • 多租户SaaS系统中设计安全便捷的跨租户流程共享
  • 遥感数据与作物生长模型同化及在作物长势监测与估产中的应用
  • 弗兰肯斯坦式的人工智能与GTM策略的崩溃
  • 运维效率提升利器:grep、sed、awk详解与实战练习指南
  • (LeetCode 面试经典 150 题) 383. 赎金信 (哈希表)
  • AR眼镜:重塑医学教育,开启智能教学新时代
  • 配置使用SSH与VScode进行连接
  • dockerfile 最佳实践
  • 如何解决服务器频繁重启的问题?
  • 流媒体直播分发服务器
  • 基于深度学习的LSTM、GRU对大数据交通流量分析与预测的研究
  • Python初学者笔记第十二期 -- (集合与字典编程练习题)
  • 信息学奥赛一本通 1552:【例 1】点的距离
  • 短剧小程序的「技术革命」:从「粗放生长」到「精准运营」
  • MySQL中的“引擎“是什么意思
  • 【算法-BFS 解决最短路问题】探索BFS在图论中的应用:最短路径问题的高效解法
  • UnitTest测试框架的基本使用方法(详细介绍)
  • Ubuntu24 辅助系统-屏幕键盘的back按键在网页文本框删除不正常的问题解决方法
  • 博客项目 laravel vue mysql 第六章 文章功能
  • WPF中的ListBox详解
  • QTableView鼠标双击先触发单击信号
  • 3. ArrayList与LinkedList的区别
  • Redis的下载安装+基础操作+redis客户端的安装
  • Java :List,LinkedList,ArrayList
  • 23种设计模式--#1工厂模式
  • CodeRush AI 助手进驻 Visual Studio:AiGen/AiFind 亮相(一)
  • AI Agent 开发
  • 【Qt】 设计模式
  • SQLite技术架构解析,适用场景有哪些?
  • 设计模式之对象池模式