YOLOv11改进 | 注意力篇 | YOLOv11引入GAM注意力机制

1.GAM介绍

摘要:为了提高各种计算机视觉任务的性能,人们研究了各种注意机制。然而,现有的方法忽略了保留通道和空间信息以增强跨维交互的重要性。因此,我们提出了一种通过减少信息减少和放大全球交互表示来提高深度神经网络性能的全球驻留机制。我们引入了具有多层单个Ceptron的3D置换用于信道注意,同时还引入了卷积空间注意子模块。对 CIFAR-100和lmageNet-1K上图像分类任务的拟议机制的评估表明我们的方法稳定地优于ResNet和轻量级的 MobileNet的几个最近的注意机制。

官方论文地址:https://ar5iv.labs.arxiv.org/html/2112.05561

官方代码地址:

### YOLOv11中的注意力机制实现及其在目标检测中的应用 #### 注意力机制的重要性 为了增强YOLOv11目标检测性能,引入了多种类型的注意力机制来改善特征图的质量。这些方法有助于更好地捕捉多尺度信息以及处理小目标和遮挡等问题[^1]。 #### MSDA多尺度空洞注意力 一种具体的改进方式是在YOLOv11中加入MSDA(Multi-Scale Dilated Attention),这是一种基于自注意力机制的方法,可以有效地获取不同尺度下的语义信息。通过调整不同的膨胀率参数,使得网络能够在更广泛的范围内感知上下文关系,从而提高对于各种尺寸物体的识别准确性[^4]。 ```python class MSDABlock(nn.Module): def __init__(self, channels): super(MSDABlock, self).__init__() # 定义多个带有不同扩张系数的一维卷积层模拟多尺度感受野 self.branches = nn.ModuleList([ nn.Conv2d(channels, channels//3, kernel_size=3, dilation=dil, padding=dil) for dil in [1, 2, 5] ]) def forward(self, x): out = torch.cat([branch(x) for branch in self.branches], dim=1) return F.relu(out) ``` #### LSKA大核可分离卷积注意力模块 除了上述提到的MSDA外,另一种有效的技术是采用LSKA(Large Separable Kernel Attention)。该组件融合了较大卷积核带来的广泛视野优势与轻量级的深度方向上的分解操作,既减少了运算负担又提升了模型的表现力。特别是当应用于小型物品或是密集分布的对象群组时效果显著[^3]。 ```python import math from functools import partial def lsk_block(in_channels, out_channels, stride=1, groups=1, norm_layer=None): layers = [] if norm_layer is None: norm_layer = nn.BatchNorm2d # 使用较大的7x7卷积代替标准的小型滤波器 conv_func = partial(nn.Conv2d, kernel_size=(7, 7), bias=False) layers.append(conv_func(in_channels=in_channels, out_channels=out_channels, stride=stride)) layers.append(norm_layer(out_channels)) layers.append(nn.ReLU(inplace=True)) return nn.Sequential(*layers) class LSkaBlock(nn.Module): expansion = 4 def __init__( self, inplanes: int, planes: int, stride: int = 1, downsample=None, groups: int = 1, base_width: int = 64, dilation: int = 1, norm_layer=None ) -> None: super(LSkaBlock, self).__init__() width = int(planes * (base_width / 64.)) * groups # Both self.conv2 and self.downsample layers downsample the input when stride != 1 self.conv1 = lsk_block( inplanes, width, stride, groups, norm_layer) self.conv2 = lsk_block(width, width, groups=groups, norm_layer=norm_layer) self.conv3 = lsk_block(width, planes * self.expansion, groups=groups, norm_layer=norm_layer) self.shortcut = nn.Identity() if downsample is not None or inplanes != planes * self.expansion: self.shortcut = nn.Sequential( nn.Conv2d(inplanes, planes*self.expansion, kernel_size=1, stride=stride, bias=False), norm_layer(planes * self.expansion) ) self.act_fn = nn.ReLU(inplace=True) def forward(self, x): identity = self.shortcut(x) out = self.conv1(x) out = self.conv2(out) out = self.conv3(out) out += identity out = self.act_fn(out) return out ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值