YOLOv11v10v8使用教程: YOLOv11入门到入土使用教程
YOLOv11改进汇总贴:YOLOv11及自研模型更新汇总
《FFCA-YOLO for Small Object Detection in Remote Sensing Images》
一、 模块介绍
论文链接:https://ieeexplore.ieee.org/document/10423050
代码链接:yemu1138178251/FFCA-YOLO (github.com)
论文速览:
特征表示不足、背景混淆等问题使得遥感中小目标的探测任务变得艰巨。特别是当算法将部署在机上进行实时处理时,这需要在有限的计算资源下对准确性和速度进行广泛的优化。为了解决这些问题,本文提出了一种称为特征增强、融合和上下文感知 YOLO (FFCA-YOLO) 的高效检测器。FFCA-YOLO 包括三个创新的轻量级和即插即用模块:功能增强模块 (FEM)、功能融合模块 (FFM) 和空间上下文感知模块 (SCAM)。这三个模块分别提高了局域网感知、多尺度特征融合和全局关联跨信道和空间的网络能力,同时尽可能避免增加复杂性。因此,小物体的弱特征表示得到了增强,并且抑制了可能混淆的背景。此外,为了在保证效率的同时进一步减少计算资源消耗,通过基于部分卷积 (PConv) 重建 FFCA-YOLO 的主干和颈部,优化了 FFCA-YOLO (L-FFCA-YOLO) 的精简版。
总结:文章提出几个针对小目标的特征提取模块,有一定效果。
二、 加入到YOLO中
2.1 创建脚本文件
首先在ultralytics->nn路径下创建blocks.py脚本,用于存放模块代码。
2.2 复制代码
复制代码粘到刚刚创建的blocks.py脚本中,如下图所示:
import torch
import torch.nn as nn
from ultralytics.nn.modules.conv import Conv
class BasicConv_FFCA(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, dilation=1, groups=1, relu=True,
bn=True, bias=False):
super(BasicConv_FFCA, self).__init__()
self.out_channels = out_planes
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=stride, padding=padding,
dilation=dilation, groups=groups, bias=bias)
self.bn = nn.BatchNorm2d(out_planes, eps=1e-5, momentum=0.01, affine=True) if bn else None
self.relu = nn.ReLU(inplace=True) if relu else None
def forward(self, x):
x = self.conv(x)
if self.bn is not None:
x = self.bn(x)
if self.relu is not None:
x = self.relu(x)
return x
class FEM(nn.Module):
def __init__(self, in_planes, out_planes, stride=1, scale=0.1, map_reduce=8):
super(FEM, self).__init__()
self.scale = scale
self.out_channels = out_planes
inter_planes = in_planes // map_reduce
self.branch0 = nn.Sequential(
BasicConv_FFCA(in_planes, 2 * inter_planes, kernel_size=1, stride=stride),
BasicConv_FFCA(2 * inter_planes, 2 * inter_planes, kernel_size=3, stride=1, padding=1, relu=False)
)
self.branch1 = nn.Sequential(
BasicConv_FFCA(in_planes, inter_planes, kernel_size=1, stride=1),
BasicConv_FFCA(inter_planes, (inter_planes // 2) * 3, kernel_size=(1, 3), stride=stride, padding=(0, 1)),
BasicConv_FFCA((inter_planes // 2) * 3, 2 * inter_planes, kernel_size=(3, 1), stride=stride, padding=(1, 0)),
BasicConv_FFCA(2 * inter_planes, 2 * inter_planes, kernel_size=3, stride=1, padding=5, dilation=5, relu=False)
)
self.branch2 = nn.Sequential(
BasicConv_FFCA(in_planes, inter_planes, kernel_size=1, stride=1),
BasicConv_FFCA(inter_planes, (inter_planes // 2) * 3, kernel_size=(3, 1), stride=stride, padding=(1, 0)),
BasicConv_FFCA((inter_planes // 2) * 3, 2 * inter_planes, kernel_size=(1, 3), stride=stride, padding=(0, 1)),
BasicConv_FFCA(2 * inter_planes, 2 * inter_planes, kernel_size=3, stride=1, padding=5, dilation=5, relu=False)
)
self.ConvLinear = BasicConv_FFCA(6 * inter_planes, out_planes, kernel_size=1, stride=1, relu=False)
self.shortcut = BasicConv_FFCA(in_planes, out_planes, kernel_size=1, stride=stride, relu=False)
self.relu = nn.ReLU(inplace=False)
def forward(self, x):
x0 = self.branch0(x)
x1 = self.branch1(x)
x2 = self.branch2(x)
out = torch.cat((x0, x1, x2), 1)
out = self.ConvLinear(out)
short = self.shortcut(x)
out = out * self.scale + short
out = self.relu(out)
return out
2.3 更改task.py文件
打开ultralytics->nn->modules->task.py,在脚本空白处导入函数。
from ultralytics.nn.blocks import *
之后找到模型解析函数parse_model(约在tasks.py脚本中940行左右位置,可能因代码版本不同变动),在该函数的最后一个else分支上面增加相关解析代码。
elif m is FEM:
c2 = args[0]
args = [ch[f], *args]
2.4 更改yaml文件
打开更改ultralytics/cfg/models/11路径下的YOLOv11.yaml文件,替换原有模块。(放在该位置仅能插入该模块,具体效果未知。博主精力有限,仅完成与其他模块二次创新融合的测试,结构图见文末,代码见群文件更新。)
# Ultralytics YOLO
标签:YOPLO,self,FEM,stride,YOLOv11,planes,FFCA,inter,out
From: https://blog.csdn.net/StopAndGoyyy/article/details/143866491