YOLO融合synergisticNet中的模块

YOLO融合synergisticNet中的模块_第1张图片


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

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


《HyperSINet: A Synergetic Interaction Network Combined With Convolution and Transformer for Hyperspectral Image Classification》

一、 模块介绍

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

        代码链接:https://github.com/chenpeng052/synergisticNet/tree/main

论文速览:

        在高光谱影像 (HSI) 中,局部和非局部特征在分类任务中起着至关重要的作用。视觉转换器 (VIT) 可以通过注意力机制提取非局部特征,而卷积神经网络 (CNN) 擅长处理局部组件。然而,在基于 VIT 和 CNN 的传统双分支模型中,特征处理过程中缺乏交互,导致两类特征合并时可能存在兼容性问题。在本文中,我们提出了 HyperSINet,这是一种结合 VIT 和 CNN 的协同交互网络,用于建立两个分支之间的交互,在训练过程中实现局部和非局部特征之间的相互补偿,并最终增强分类任务的性能。具体来说,我们设计了一对交互器,即 Conv2Trans 和 Trans2Conv,它们充当两个分支之间的中介,使 VIT 分支能够细化其局部细节,同时允许 CNN 分支处理更大的感受野非局部特征。实现典型的特征图是为了可视化交互器的功能。此外,在 VIT 分支中,开发了具有局部掩码的 VIT 编码器,以在强调非局部特征和保留局部细节之间取得平衡,同时设计了一个轻量级 CNN 块来处理 CNN 分支中的光谱和空间特征。在四个真实数据集上进行的广泛实验表明,在合理的参数数量下,HyperSINet 超越了当前几种最先进的方法。

总结:本文更新其中TBFE模块的使用方法。


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

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

二、二创融合模块

2.1 相关代码

   class TBFE(nn.Module):
    def __init__(self, input_channels, reduction_N=32):
        super(TBFE, self).__init__()
        self.point_wise = nn.Conv2d(input_channels, reduction_N, kernel_size=1, padding=0, bias=False)
        self.depth_wise = nn.Sequential(nn.Conv2d(reduction_N, reduction_N, kernel_size=(3, 3), padding=1),
                                        nn.BatchNorm2d(reduction_N), nn.ReLU(), )

        self.conv3D = nn.Conv3d(in_channels=1, out_channels=1, kernel_size=(1, 1, 3), padding=(0, 0, 1),
                                stride=(1, 1, 1), bias=False)
        self.bn = nn.BatchNorm2d(reduction_N)
        self.relu = nn.ReLU()

    def forward(self, x):
        x_1 = self.point_wise(x)
        x_2 = self.depth_wise(x_1)
        x_2 = x_1 + x_2

        # DSC
        x_3 = x_1.unsqueeze(1)
        x_3 = self.conv3D(x_3)
        x_3 = x_3.squeeze(1)
        x = torch.cat((x_2, x_3), dim=1)

        return x

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

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

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

YOLO融合synergisticNet中的模块_第2张图片

# 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 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, 1, TBFE, []]
  - [-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, 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.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',)

YOLO融合synergisticNet中的模块_第3张图片

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

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

YOLO融合synergisticNet中的模块_第4张图片


你可能感兴趣的:(YOLOv11与自研模型专栏,YOLO)