YOLO融合SMFANet中的SFMA模块


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

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


《A Lightweight Self-Modulation Feature Aggregation Network for Efficient Image Super-Resolution》

一、 模块介绍

        论文链接:https://link.springer.com/chapter/10.1007/978-3-031-72973-7_21

        代码链接:https://github.com/Zheng-MJ/SMFANet

论文速览:

        基于 Transformer 的修复方法取得了显着的性能,因为 Transformer 的自注意力 (SA) 可以探索非局部信息以获得更好的高分辨率图像重建。然而,关键的点积 SA 需要大量的计算资源,这限制了它在低功耗器件中的应用。此外,SA 机制的低通特性限制了其捕获局部细节的能力,从而导致平滑的重建结果。为了解决这些问题,我们提出了一个自调制特征聚合 (SMFA) 模块,以协同利用局部和非局部特征交互来实现更准确的重建。具体来说,SMFA 模块采用高效的自我注意近似 (EASA) 分支来对非局部信息进行建模,并使用局部细节估计 (LDE) 分支来捕获局部细节。此外,我们进一步引入了基于部分卷积的前馈网络 (PCFN) 来优化从 SMFA 派生的代表性特征。大量实验表明,所提出的 SMFANet 系列在公共基准数据集上实现了更好的重建性能和计算效率之间的权衡。

总结:本文更新其中的SMFA模块代码及使用方法


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

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

二、二创融合模块

2.1 相关代码

# https://blog.youkuaiyun.com/StopAndGoyyy?spm=1011.2124.3001.5343\
# SMFANet: A Lightweight Self-Modulation Feature Aggregation Network for Efficient Image Super-Resolution
# https://www.ecva.net/papers/eccv_2024/papers_ECCV/papers/06713.pdf
# https://github.com/Zheng-MJ/SMFANet
class DMlp_SMFA(nn.Module):
    def __init__(self, dim, growth_rate=2.0):
        super().__init__()
        hidden_dim = int(dim * growth_rate)
        self.conv_0 = nn.Sequential(
            nn.Conv2d(dim, hidden_dim, 3, 1, 1, groups=dim),
            nn.Conv2d(hidden_dim, hidden_dim, 1, 1, 0)
        )
        self.act = nn.GELU()
        self.conv_1 = nn.Conv2d(hidden_dim, dim, 1, 1, 0)

    def forward(self, x):
        x = self.conv_0(x)
        x = self.act(x)
        x = self.conv_1(x)
        return x

class SMFA(nn.Module):
    def __init__(self, dim):
        super(SMFA, self).__init__()
        self.linear_0 = nn.Conv2d(dim, dim * 2, 1, 1, 0)
        self.linear_1 = nn.Conv2d(dim, dim, 1, 1, 0)
        self.linear_2 = nn.Conv2d(dim, dim, 1, 1, 0)
        self.lde = DMlp_SMFA(dim, 2)
        self.dw_conv = nn.Conv2d(dim, dim, 3, 1, 1, groups=dim)
        self.gelu = nn.GELU()
        self.down_scale = 8
        self.alpha = nn.Parameter(torch.ones((1, dim, 1, 1)))  # 乘法因子
        self.belt = nn.Parameter(torch.zeros((1, dim, 1, 1)))  # 加法因子

    def forward(self, f):
        _, _, h, w = f.shape
        y, x = self.linear_0(f).chunk(2, dim=1)
        x_s = self.dw_conv(F.adaptive_max_pool2d(x, (h // self.down_scale, w // self.down_scale)))
        x_v = torch.var(x, dim=(-2, -1), keepdim=True)
        x_l = x * F.interpolate(self.gelu(self.linear_1(x_s * self.alpha + x_v * self.belt)), size=(h, w), mode='nearest')
        y_d = self.lde(y)
        return self.linear_2(x_l + y_d)

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

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

       打开更改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.youkuaiyun.com/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 GFLOPs
  s: [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 GFLOPs
  m: [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 GFLOPs
  l: [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 GFLOPs
  x: [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, SMFA, []] # 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, Concat, [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.youkuaiyun.com/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使用教程-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值