学习资源站

【YOLOv8单模态融合改进】普通数据集的双模型融合改进,涉及中期,中后期,后期融合方式的完整配置步骤以及二次改进方案_yolov8可以一次性读两个模型结构吗-

【YOLOv8单模态融合改进】普通数据集的双模型融合改进,涉及中期、中后期、后期融合方式的完整配置步骤以及二次改进方案

前言

主题: YOLOv8的单模态融合改进,普通数据集的双模型融合改进(双模型同步提升)

方式: 中期融合、中-后期融合、后期融合。

内容: 包含融合方式详解和完整配置步骤以及二次改进建议,通过融合多个模型的优势实现精度提升。


一、融合方式

输入的是一个模态的数据,所以没有早期的融合。

1.1 中期融合方法及结构图

定义: 在网络中间层(骨干网络与颈部网络之间)对多模态特征进行融合。

实现方式: 每个模态通过独立的骨干网络提取特征,融合时采用Concat操作合并特征图,送入颈部网络。

结构示意图:

1.2 中-后期融合方法及结构图

定义: 在颈部网络的上采样之后对多模态特征进行融合。

实现方式: 每个模态通过独立的骨干网络和颈部的FPN网络提取特征,融合时采用Concat操作合并特征图,送入检测头。

结构示意图:

1.3 后期融合方法及结构图

定义: 在网络输出阶段(如检测头或分类器前)对多模态特征进行融合。

实现方式: 每个模态通过独立的骨干网络和颈部网络提取特征,融合时采用Concat操作合并特征图,送入检测头。

结构示意图:

二、完整配置步骤

相关的配置只涉及单模态,只需在原本的项目包中配置运行即可,不需要使用我提供的多模态项目包。

①:在 ultralytics/nn/modules/block.py 中添加如下代码,并在 __all__ 中添加 “IN”

class IN(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return x

在这里插入图片描述
②:在 ultralytics/nn/modules/__init__.py 中的 from .block import (...) 添加 IN
在这里插入图片描述
③:在 ultralytics/nn/tasks.py 中的 from ultralytics.nn.modules import (...) 中添加 IN

在这里插入图片描述
至此,添加完成。

三、YAML模型结构

此处以 ultralytics/cfg/models/v8/yolov8.yaml 为例,在同目录下创建一个用于自己数据集训练的双模型融合文件,并粘贴下方的模型训练即可。

3.1 中期融合

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Ultralytics YOLOv8 object detection model with P3/8 - P5/32 outputs
# Model docs: https://docs.ultralytics.com/models/yolov8
# Task docs: https://docs.ultralytics.com/tasks/detect

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers,  3157200 parameters,  3157184 gradients,   8.9 GFLOPs
  s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients,  28.8 GFLOPs
  m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients,  79.3 GFLOPs
  l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
  x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs

# YOLOv8.0n backbone
backbone:
  # [from, repeats, module, args]
  - [-1, 1, IN, []] # 0

  - [0, 1, Conv, [64, 3, 2]] # 1-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 2-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 4-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 6-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 8-P5/32
  - [-1, 3, C2f, [1024, True]]

  - [0, 1, Conv, [64, 3, 2]] # 10-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 11-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 13-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 15-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 17-P5/32
  - [-1, 3, C2f, [1024, True]]

  - [[5, 14], 1, Concat, [1]]  # 19 cat backbone P3
  - [[7, 16], 1, Concat, [1]]  # 20 cat backbone P4
  - [[9, 18], 1, Concat, [1]]  # 21 cat backbone P5

  - [-1, 1, SPPF, [1024, 5]] # 22

# YOLOv8.0n head
head:
  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 20], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 25

  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 19], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 28 (P3/8-small)

  - [-1, 1, Conv, [256, 3, 2]]
  - [[-1, 25], 1, Concat, [1]] # cat head P4
  - [-1, 3, C2f, [512]] # 31 (P4/16-medium)

  - [-1, 1, Conv, [512, 3, 2]]
  - [[-1, 22], 1, Concat, [1]] # cat head P5
  - [-1, 3, C2f, [1024]] # 34 (P5/32-large)

  - [[28, 31, 34], 1, Detect, [nc]] # Detect(P3, P4, P5)

3.2 中-后期融合

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Ultralytics YOLOv8 object detection model with P3/8 - P5/32 outputs
# Model docs: https://docs.ultralytics.com/models/yolov8
# Task docs: https://docs.ultralytics.com/tasks/detect

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers,  3157200 parameters,  3157184 gradients,   8.9 GFLOPs
  s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients,  28.8 GFLOPs
  m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients,  79.3 GFLOPs
  l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
  x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs

# YOLOv8.0n backbone
backbone:
  # [from, repeats, module, args]
  - [-1, 1, IN, []] # 0

  - [0, 1, Conv, [64, 3, 2]] # 1-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 2-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 4-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 6-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 8-P5/32
  - [-1, 3, C2f, [1024, True]]
  - [-1, 1, SPPF, [1024, 5]] # 10

  - [0, 1, Conv, [64, 3, 2]] # 11-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 12-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 14-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 16-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 18-P5/32
  - [-1, 3, C2f, [1024, True]]
  - [-1, 1, SPPF, [1024, 5]] # 20

# YOLOv8.0n head
head:
  - [10, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 7], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 23

  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 5], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 26 (P3/8-small)

  - [20, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 17], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 29

  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 15], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 32 (P3/8-small)

  - [[10, 20], 1, Concat, [1]]  # 33 cat backbone P3
  - [[23, 29], 1, Concat, [1]]  # 34 cat backbone P4
  - [[26, 32], 1, Concat, [1]]  # 35 cat backbone P5

  - [-1, 1, Conv, [256, 3, 2]]
  - [[-1, 34], 1, Concat, [1]] # cat head P4
  - [-1, 3, C2f, [512]] # 38 (P4/16-medium)

  - [-1, 1, Conv, [512, 3, 2]]
  - [[-1, 33], 1, Concat, [1]] # cat head P5
  - [-1, 3, C2f, [1024]] # 41 (P5/32-large)

  - [[35, 38, 41], 1, Detect, [nc]] # Detect(P3, P4, P5)

3.3 后期融合

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Ultralytics YOLOv8 object detection model with P3/8 - P5/32 outputs
# Model docs: https://docs.ultralytics.com/models/yolov8
# Task docs: https://docs.ultralytics.com/tasks/detect

# Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers,  3157200 parameters,  3157184 gradients,   8.9 GFLOPs
  s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients,  28.8 GFLOPs
  m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients,  79.3 GFLOPs
  l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
  x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs

# YOLOv8.0n backbone
backbone:
  # [from, repeats, module, args]
  - [-1, 1, IN, []] # 0

  - [0, 1, Conv, [64, 3, 2]] # 1-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 2-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 4-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 6-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 8-P5/32
  - [-1, 3, C2f, [1024, True]]
  - [-1, 1, SPPF, [1024, 5]] # 10

  - [0, 1, Conv, [64, 3, 2]] # 11-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 12-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 14-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 16-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 18-P5/32
  - [-1, 3, C2f, [1024, True]]
  - [-1, 1, SPPF, [1024, 5]] # 20

# YOLOv8.0n head
head:
  - [10, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 7], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 23

  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 5], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 26 (P3/8-small)

  - [-1, 1, Conv, [256, 3, 2]]
  - [[-1, 23], 1, Concat, [1]] # cat head P4
  - [-1, 3, C2f, [512]] # 29 (P4/16-medium)

  - [-1, 1, Conv, [512, 3, 2]]
  - [[-1, 10], 1, Concat, [1]] # cat head P5
  - [-1, 3, C2f, [1024]] # 32 (P5/32-large)

  - [20, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 17], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 35

  - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  - [[-1, 15], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 38 (P3/8-small)

  - [-1, 1, Conv, [256, 3, 2]]
  - [[-1, 35], 1, Concat, [1]] # cat head P4
  - [-1, 3, C2f, [512]] # 41 (P4/16-medium)

  - [-1, 1, Conv, [512, 3, 2]]
  - [[-1, 20], 1, Concat, [1]] # cat head P5
  - [-1, 3, C2f, [1024]] # 44 (P5/32-large)

  - [[10, 20], 1, Concat, [1]]  # 45 cat backbone P3
  - [[29, 41], 1, Concat, [1]]  # 46 cat backbone P4
  - [[32, 44], 1, Concat, [1]]  # 47 cat backbone P5

  - [[45, 46, 47], 1, Detect, [nc]] # Detect(P3, P4, P5)

四、成功运行结果

中期融合结果:

YOLOv8-BiModel summary: 318 layers, 4,369,203 parameters, 4,369,187 gradients, 11.6 GFLOPs

                   from  n    params  module                                       arguments
  0                  -1  1         0  ultralytics.nn.modules.block.IN              []
  1                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
  2                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
  3                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
  4                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  5                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
  6                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  7                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
  8                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  9                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 10                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
 11                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
 12                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
 13                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
 14                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
 15                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
 16                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
 17                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
 18                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 19             [5, 14]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 20             [7, 16]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 21             [9, 18]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 22                  -1  1    394240  ultralytics.nn.modules.block.SPPF            [512, 256, 5]
 23                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 24            [-1, 20]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 25                  -1  1    164608  ultralytics.nn.modules.block.C2f             [512, 128, 1]
 26                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 27            [-1, 19]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 28                  -1  1     41344  ultralytics.nn.modules.block.C2f             [256, 64, 1]
 29                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]
 30            [-1, 25]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 31                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]
 32                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 33            [-1, 22]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 34                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]
 35        [28, 31, 34]  1    751507  ultralytics.nn.modules.head.Detect           [1, [64, 128, 256]]
YOLOv8-BiModel summary: 318 layers, 4,369,203 parameters, 4,369,187 gradients, 11.6 GFLOPs

中-后期融合结果:

YOLOv8-BiModel summary: 360 layers, 5,289,331 parameters, 5,289,315 gradients, 16.7 GFLOPs

                   from  n    params  module                                       arguments
  0                  -1  1         0  ultralytics.nn.modules.block.IN              []
  1                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
  2                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
  3                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
  4                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  5                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
  6                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  7                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
  8                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  9                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 10                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 11                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
 12                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
 13                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
 14                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
 15                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
 16                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
 17                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
 18                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
 19                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 20                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 21                  10  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 22             [-1, 7]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 23                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 24                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 25             [-1, 5]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 26                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 27                  20  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 28            [-1, 17]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 29                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 30                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 31            [-1, 15]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 32                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 33            [10, 20]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 34            [23, 29]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 35            [26, 32]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 36                  -1  1     73856  ultralytics.nn.modules.conv.Conv             [128, 64, 3, 2]
 37            [-1, 34]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 38                  -1  1    140032  ultralytics.nn.modules.block.C2f             [320, 128, 1]
 39                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 40            [-1, 33]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 41                  -1  1    558592  ultralytics.nn.modules.block.C2f             [640, 256, 1]
 42        [35, 38, 41]  1   1452883  ultralytics.nn.modules.head.Detect           [1, [128, 128, 256]]
YOLOv8-BiModel summary: 360 layers, 5,289,331 parameters, 5,289,315 gradients, 16.7 GFLOPs

后期融合结果:

YOLOv8-BiModel summary: 398 layers, 19,446,131 parameters, 19,446,115 gradients, 32.0 GFLOPs

                   from  n    params  module                                       arguments
  0                  -1  1         0  ultralytics.nn.modules.block.IN              []
  1                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
  2                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
  3                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
  4                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
  5                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
  6                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
  7                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
  8                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
  9                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 10                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 11                   0  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]
 12                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]
 13                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]
 14                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]
 15                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]
 16                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]
 17                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]
 18                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]
 19                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]
 20                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]
 21                  10  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 22             [-1, 7]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 23                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 24                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 25             [-1, 5]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 26                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 27                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]
 28            [-1, 23]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 29                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]
 30                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 31            [-1, 10]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 32                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]
 33                  20  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 34            [-1, 17]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 35                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]
 36                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 37            [-1, 15]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 38                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]
 39                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]
 40            [-1, 35]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 41                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]
 42                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]
 43            [-1, 20]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 44                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]
 45            [10, 20]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 46            [29, 41]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 47            [32, 44]  1         0  ultralytics.nn.modules.conv.Concat           [1]
 48        [45, 46, 47]  1  14927059  ultralytics.nn.modules.head.Detect           [1, [512, 256, 512]]
YOLOv8-BiModel summary: 398 layers, 19,446,131 parameters, 19,446,115 gradients, 32.0 GFLOPs

五、二次改进方案

  1. 双模型的二次改进和普通模型的改进一致,主要涉及到C2f、颈部结构、上采样、下采样等,可以增加或替换成其它模块,可以换成其它的颈部结构在进行融合。

  2. 两个骨干中均可以再次添加其它模块,需要注意的是融合的时候特征图大小要一致。