
💡💡💡问题点:航空和卫星图像固有存在低空间分辨率、传感器噪声、目标模糊、低光照退化和部分遮挡等限制
💡💡💡解决方案:一种轻量级网络,其创新性地整合了专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块。

《YOLO11魔术师专栏》将从以下各个方向进行创新:
💡💡💡为本专栏订阅者提供创新点改进代码,改进网络结构图,方便paper写作!!!
💡💡💡适用场景:红外、小目标检测、工业缺陷检测、医学影像、遥感目标检测、低对比度场景
💡💡💡适用任务:所有改进点适用【检测】、【分割】、【pose】、【分类】等
💡💡💡全网独家首发创新,【自研多个自研模块】,【多创新点组合适合paper 】!!!
☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️ ☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️
包含注意力机制魔改、卷积魔改、检测头创新、损失&IOU优化、block优化&多层特征融合、 轻量级网络设计、24年最新顶会改进思路、原创自研paper级创新等
🚀🚀🚀 本项目持续更新 | 更新完结保底≥50+ ,冲刺100+ 🚀🚀🚀
💡💡💡 2025年计算机视觉顶会创新点适用于Yolov5、Yolov7、Yolov8、Yolov9、Yolov10等各个Yolo系列,专栏文章提供每一步步骤和源码,轻松带你上手魔改网络 !!!
💡💡💡重点:通过本专栏的阅读,后续你也可以设计魔改网络,在网络不同位置(Backbone、head、detect、loss等)进行魔改,实现创新!!!
☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️ ☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️☁️
Ultralytics YOLO11是一款尖端的、最先进的模型,它在之前YOLO版本成功的基础上进行了构建,并引入了新功能和改进,以进一步提升性能和灵活性。YOLO11设计快速、准确且易于使用,使其成为各种物体检测和跟踪、实例分割、图像分类以及姿态估计任务的绝佳选择。


目标检测性能

语义分割性能

Pose关键点检测性能

结构图如下:

C3k2,结构图如下

C3k2,继承自类C2f,其中通过c3k设置False或者Ture来决定选择使用C3k还是Bottleneck

实现代码ultralytics/nn/modules/block.py
class C3k2(C2f):
"""Faster Implementation of CSP Bottleneck with 2 convolutions."""
def __init__(self, c1, c2, n=1, c3k=False, e=0.5, g=1, shortcut=True):
"""Initializes the C3k2 module, a faster CSP Bottleneck with 2 convolutions and optional C3k blocks."""
super().__init__(c1, c2, n, shortcut, g, e)
self.m = nn.ModuleList(
C3k(self.c, self.c, 2, shortcut, g) if c3k else Bottleneck(self.c, self.c, shortcut, g) for _ in range(n)
)
class C3k(C3):
"""C3k is a CSP bottleneck module with customizable kernel sizes for feature extraction in neural networks."""
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5, k=3):
"""Initializes the C3k module with specified channels, number of layers, and configurations."""
super().__init__(c1, c2, n, shortcut, g, e)
c_ = int(c2 * e) # hidden channels
# self.m = nn.Sequential(*(RepBottleneck(c_, c_, shortcut, g, k=(k, k), e=1.0) for _ in range(n)))
self.m = nn.Sequential(*(Bottleneck(c_, c_, shortcut, g, k=(k, k), e=1.0) for _ in range(n)))借鉴V10 PSA结构,实现了C2PSA和C2fPSA,最终选择了基于C2的C2PSA(可能涨点更好?)

实现代码ultralytics/nn/modules/block.py
class PSABlock(nn.Module):
"""
PSABlock class implementing a Position-Sensitive Attention block for neural networks.
This class encapsulates the functionality for applying multi-head attention and feed-forward neural network layers
with optional shortcut connections.
Attributes:
attn (Attention): Multi-head attention module.
ffn (nn.Sequential): Feed-forward neural network module.
add (bool): Flag indicating whether to add shortcut connections.
Methods:
forward: Performs a forward pass through the PSABlock, applying attention and feed-forward layers.
Examples:
Create a PSABlock and perform a forward pass
>>> psablock = PSABlock(c=128, attn_ratio=0.5, num_heads=4, shortcut=True)
>>> input_tensor = torch.randn(1, 128, 32, 32)
>>> output_tensor = psablock(input_tensor)
"""
def __init__(self, c, attn_ratio=0.5, num_heads=4, shortcut=True) -> None:
"""Initializes the PSABlock with attention and feed-forward layers for enhanced feature extraction."""
super().__init__()
self.attn = Attention(c, attn_ratio=attn_ratio, num_heads=num_heads)
self.ffn = nn.Sequential(Conv(c, c * 2, 1), Conv(c * 2, c, 1, act=False))
self.add = shortcut
def forward(self, x):
"""Executes a forward pass through PSABlock, applying attention and feed-forward layers to the input tensor."""
x = x + self.attn(x) if self.add else self.attn(x)
x = x + self.ffn(x) if self.add else self.ffn(x)
return x
class C2PSA(nn.Module):
"""
C2PSA module with attention mechanism for enhanced feature extraction and processing.
This module implements a convolutional block with attention mechanisms to enhance feature extraction and processing
capabilities. It includes a series of PSABlock modules for self-attention and feed-forward operations.
Attributes:
c (int): Number of hidden channels.
cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c.
m (nn.Sequential): Sequential container of PSABlock modules for attention and feed-forward operations.
Methods:
forward: Performs a forward pass through the C2PSA module, applying attention and feed-forward operations.
Notes:
This module essentially is the same as PSA module, but refactored to allow stacking more PSABlock modules.
Examples:
>>> c2psa = C2PSA(c1=256, c2=256, n=3, e=0.5)
>>> input_tensor = torch.randn(1, 256, 64, 64)
>>> output_tensor = c2psa(input_tensor)
"""
def __init__(self, c1, c2, n=1, e=0.5):
"""Initializes the C2PSA module with specified input/output channels, number of layers, and expansion ratio."""
super().__init__()
assert c1 == c2
self.c = int(c1 * e)
self.cv1 = Conv(c1, 2 * self.c, 1, 1)
self.cv2 = Conv(2 * self.c, c1, 1)
self.m = nn.Sequential(*(PSABlock(self.c, attn_ratio=0.5, num_heads=self.c // 64) for _ in range(n)))
def forward(self, x):
"""Processes the input tensor 'x' through a series of PSA blocks and returns the transformed tensor."""
a, b = self.cv1(x).split((self.c, self.c), dim=1)
b = self.m(b)
return self.cv2(torch.cat((a, b), 1))
class C2fPSA(C2f):
"""
C2fPSA module with enhanced feature extraction using PSA blocks.
This class extends the C2f module by incorporating PSA blocks for improved attention mechanisms and feature extraction.
Attributes:
c (int): Number of hidden channels.
cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c.
m (nn.ModuleList): List of PSA blocks for feature extraction.
Methods:
forward: Performs a forward pass through the C2fPSA module.
forward_split: Performs a forward pass using split() instead of chunk().
Examples:
>>> import torch
>>> from ultralytics.models.common import C2fPSA
>>> model = C2fPSA(c1=64, c2=64, n=3, e=0.5)
>>> x = torch.randn(1, 64, 128, 128)
>>> output = model(x)
>>> print(output.shape)
"""
def __init__(self, c1, c2, n=1, e=0.5):
"""Initializes the C2fPSA module, a variant of C2f with PSA blocks for enhanced feature extraction."""
assert c1 == c2
super().__init__(c1, c2, n=n, e=e)
self.m = nn.ModuleList(PSABlock(self.c, attn_ratio=0.5, num_heads=self.c // 64) for _ in range(n))分类检测头引入了DWConv(更加轻量级,为后续二次创新提供了改进点),结构图如下(和V8的区别):

实现代码ultralytics/nn/modules/head.py
self.cv2 = nn.ModuleList(
nn.Sequential(Conv(x, c2, 3), Conv(c2, c2, 3), nn.Conv2d(c2, 4 * self.reg_max, 1)) for x in ch
)
self.cv3 = nn.ModuleList(
nn.Sequential(
nn.Sequential(DWConv(x, x, 3), Conv(x, c3, 1)),
nn.Sequential(DWConv(c3, c3, 3), Conv(c3, c3, 1)),
nn.Conv2d(c3, self.nc, 1),
)
for x in ch
)
论文: https://arxiv.org/pdf/2503.14012
摘要:遥感目标检测(RSOD)在复杂视觉环境中面临巨大挑战。航空和卫星图像固有存在低空间分辨率、传感器噪声、目标模糊、低光照退化和部分遮挡等限制。这些退化因素共同损害检测模型的特征可区分性,导致三个关键问题:(1)降低对比度,阻碍前景 - 背景分离;(2)边缘表示出现结构不连续性;(3)由于光照变化导致特征响应模糊。这些问题共同削弱了模型的鲁棒性和部署可行性。为应对这些挑战,我们提出 LEGNet,一种轻量级网络,其创新性地整合了专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块。我们的关键创新在于将基于 Scharr 算子的边缘先验与不确定性感知的高斯建模协同整合:(a)具有方向感知的 Scharr 滤波器以旋转不变性保留高频边缘细节;(b)不确定性感知的高斯层通过方差估计对低置信度特征进行概率性细化。这种设计在保持架构简洁的同时提升了精度。在四个 RSOD 基准数据集(DOTA-v1.0、v1.5、DIOR-R、FAIR1M-v1.0)和一个无人机视角数据集(VisDrone2019)上的全面评估表明,LEGNet 取得了显著改进,其在五个基准数据集上实现最先进的性能,同时确保计算效率,使其适合在实际遥感应用中部署于资源受限的边缘设备上。

图 1:在 DOTA-v1.0 测试集上的可视化结果。所有模型均基于 Oriented R-CNN 构建。我们的 LEGNet 在遮挡和低光照条件下展现出强大的检测能力,例如能够检测被树木和建筑物遮挡的目标,其准确性和鲁棒性超过了以往的最佳水平。
本文主要贡献总结如下:
如图 2 所示,LEGNet 是一种多阶段架构,可分别在第 1 - 4 阶段以 1/4、1/8、1/16 和 1/32 的下采样率逐步提取多尺度特征。它由三个主要组件构成:LoG-stem 层、采用深度鲁棒特征下采样(DRFD)方法的下采样模块以及轻量级边缘高斯(LEG)模块。

每个阶段的 LEG 模块利用边缘信息或高斯建模来增强特征表示,使该网络特别适合处理低质量图像。

######################################## LEGNet by AI Little monster start #######################################
import torch
import torch.nn as nn
from ultralytics.nn.modules import Conv,C2f
from ultralytics.nn.modules.block import Bottleneck, C2f,C3k,C3k2
from timm.models.layers import DropPath
import math
class Conv_Extra(nn.Module):
def __init__(self, channel):
super(Conv_Extra, self).__init__()
self.block = nn.Sequential(Conv(channel, 64, 1),
Conv(64, 64, 3),
Conv(64, channel, 1, act=False))
def forward(self, x):
out = self.block(x)
return out
class Scharr(nn.Module):
def __init__(self, channel):
super(Scharr, self).__init__()
# 定义Scharr滤波器
scharr_x = torch.tensor([[-3., 0., 3.], [-10., 0., 10.], [-3., 0., 3.]], dtype=torch.float32).unsqueeze(
0).unsqueeze(0)
scharr_y = torch.tensor([[-3., -10., -3.], [0., 0., 0.], [3., 10., 3.]], dtype=torch.float32).unsqueeze(
0).unsqueeze(0)
self.conv_x = nn.Conv2d(channel, channel, kernel_size=3, padding=1, groups=channel, bias=False)
self.conv_y = nn.Conv2d(channel, channel, kernel_size=3, padding=1, groups=channel, bias=False)
# 将Sobel滤波器分配给卷积层
self.conv_x.weight.data = scharr_x.repeat(channel, 1, 1, 1)
self.conv_y.weight.data = scharr_y.repeat(channel, 1, 1, 1)
self.norm = nn.BatchNorm2d(channel)
self.conv_extra = Conv_Extra(channel)
def forward(self, x):
# show_feature(x)
# 应用卷积操作
edges_x = self.conv_x(x)
edges_y = self.conv_y(x)
# 计算边缘和高斯分布强度(可以选择不同的方式进行融合,这里使用平方和开根号)
scharr_edge = torch.sqrt(edges_x ** 2 + edges_y ** 2)
scharr_edge = self.act(self.norm(scharr_edge))
out = self.conv_extra(x + scharr_edge)
# show_feature(out)
return out
class Gaussian(nn.Module):
def __init__(self, dim, size, sigma, feature_extra=True):
super().__init__()
self.feature_extra = feature_extra
gaussian = self.gaussian_kernel(size, sigma)
gaussian = nn.Parameter(data=gaussian, requires_grad=False).clone()
self.gaussian = nn.Conv2d(dim, dim, kernel_size=size, stride=1, padding=int(size // 2), groups=dim, bias=False)
self.gaussian.weight.data = gaussian.repeat(dim, 1, 1, 1)
self.norm = nn.BatchNorm2d(dim)
self.act = nn.SiLU()
if feature_extra == True:
self.conv_extra = Conv_Extra(dim)
def forward(self, x):
edges_o = self.gaussian(x)
gaussian = self.act(self.norm(edges_o))
if self.feature_extra == True:
out = self.conv_extra(x + gaussian)
else:
out = gaussian
return out
def gaussian_kernel(self, size: int, sigma: float):
kernel = torch.FloatTensor([
[(1 / (2 * math.pi * sigma ** 2)) * math.exp(-(x ** 2 + y ** 2) / (2 * sigma ** 2))
for x in range(-size // 2 + 1, size // 2 + 1)]
for y in range(-size // 2 + 1, size // 2 + 1)
]).unsqueeze(0).unsqueeze(0)
return kernel / kernel.sum()
class LFEA(nn.Module):
def __init__(self, channel):
super(LFEA, self).__init__()
self.channel = channel
t = int(abs((math.log(channel, 2) + 1) / 2))
k = t if t % 2 else t + 1
self.conv2d = self.block = Conv(channel, channel, 3)
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.conv1d = nn.Conv1d(1, 1, kernel_size=k, padding=(k - 1) // 2, bias=False)
self.sigmoid = nn.Sigmoid()
self.norm = nn.BatchNorm2d(channel)
def forward(self, c, att):
att = c * att + c
att = self.conv2d(att)
wei = self.avg_pool(att)
wei = self.conv1d(wei.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)
wei = self.sigmoid(wei)
x = self.norm(c + att * wei)
return x
class LFE_Module(nn.Module):
def __init__(self,
dim,
stage=1,
mlp_ratio=2,
drop_path=0.1,
):
super().__init__()
self.stage = stage
self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
mlp_hidden_dim = int(dim * mlp_ratio)
mlp_layer: List[nn.Module] = [
Conv(dim, mlp_hidden_dim, 1),
nn.Conv2d(mlp_hidden_dim, dim, 1, bias=False)]
self.mlp = nn.Sequential(*mlp_layer)
self.LFEA = LFEA(dim)
if stage == 0:
self.Scharr_edge = Scharr(dim)
else:
self.gaussian = Gaussian(dim, 5, 1.0)
self.norm = nn.BatchNorm2d(dim)
def forward(self, x: Tensor) -> Tensor:
# show_feature(x)
if self.stage == 0:
att = self.Scharr_edge(x)
else:
att = self.gaussian(x)
x_att = self.LFEA(x, att)
x = x + self.norm(self.drop_path(self.mlp(x_att)))
return x
1)首先进行引用定义
from ultralytics.nn.block.LEGNet import C3k2_LFE:


# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
# 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: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPs
s: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPs
m: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPs
l: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPs
x: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs
# 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, C3k2_LFEM, [256, False, 0.25]]
- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
- [-1, 2, C3k2_LFEM, [512, False, 0.25]]
- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
- [-1, 2, C3k2_LFEM, [512, True]]
- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
- [-1, 2, C3k2_LFEM, [1024, True]]
- [-1, 1, SPPF, [1024, 5]] # 9
- [-1, 2, C2PSA, [1024]] # 10
# YOLO11n head
head:
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 6], 1, Concat, [1]] # cat backbone P4
- [-1, 2, C3k2, [512, False]] # 13
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 4], 1, Concat, [1]] # cat backbone P3
- [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)
- [-1, 1, Conv, [256, 3, 2]]
- [[-1, 13], 1, Concat, [1]] # cat head P4
- [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)
- [-1, 1, Conv, [512, 3, 2]]
- [[-1, 10], 1, Concat, [1]] # cat head P5
- [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)
- [[16, 19, 22], 1, Detect, [nc]] # Detect(P3, P4, P5)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。