学习资源站

YOLOv11改进-添加注意力机制篇-2024最新空间和通道协同注意力SCSA改进yolov11有效涨点(含二次创新C2PSA机制)

一、本文介绍

本文给大家带来的改进机制是 2024最新 的空间和通道协同 注意力模块 (Spatial and Channel Synergistic Attention)SCSA,其通过结合空间注意力(Spatial Attention)和通道注意力(Channel Attention),提出了 一种新的协同注意力模块SCSA 。SCSA的设计由两个主要部分组成:共享多语义 空间注意力 (SMSA)和渐进通道自注意力(PCSA)| 个人感觉类似于CBAM,SCSA机制旨在有效地结合通道和空间注意力的优势,充分利用多语义信息,从而提高视觉任务的表现, 在本文中我提供其二次创新C2PSA机制。

欢迎大家订阅我的专栏一起学习YOLO!



二、基本原理

论文地址: 官方论文地址

代码地址: 官方代码地址


该论文探讨了空间注意力(Spatial Attention)和 通道注意力 (Channel Attention)之间的协同效应,提出了 一种新的协同注意力模块(SCSA) 。SCSA的设计由两个主要部分组成:共享多语义空间注意力(SMSA)和渐进通道自注意力(PCSA)。

SCSA机制的主要原理

SCSA(Spatial and Channel Synergistic Attention)机制旨在有效地结合通道和空间注意力的优势,充分利用多语义信息,从而提高视觉任务的表现。其主要原理分为以下几个方面:

1. 多语义信息集成

  • SCSA设计的一个关键特点是多语义信息的集成。通过共享多语义空间注意力(SMSA),它可以从多尺度的空间信息中提取丰富的语义特征。
  • SMSA通过多尺度深度共享的1D卷积,提取多层次的空间信息,为通道自注意力提供了多语义空间先验,有助于增强不同语义信息的表达。​

2. 渐进式压缩策略

  • 在SCSA中,SMSA模块使用渐进压缩策略,将辨别性空间信息注入到PCSA(Progressive Channel-wise Self-Attention)中,以便有效地引导通道重新校准。
  • 这种压缩策略能够在降低计算复杂度的同时,保留空间结构的关键信息,使得通道注意力在进行计算时能够利用到更多的空间先验。

3. 通道自注意力的渐进式通道相似性计算

  • PCSA模块采用了输入感知的自注意力机制,能够有效地计算通道之间的相似性,从而缓解SMSA内部不同子特征间的语义差异。
  • PCSA结合SMSA提供的空间知识,对通道特征进行更精细的自注意力调整,增强了通道注意力在语义一致性和区分性上的表现。

4. 模块化设计与协同效应

  • SCSA的设计是模块化的,即SMSA和PCSA串联使用,从而在维度解耦、轻量化多语义指导和语义差异缓解的基础上实现空间和通道的协同效应。
  • 这种协同机制通过空间注意力引导通道学习,使得通道能够更好地关注重要的空间区域,同时通道自注意力可以进一步增强空间结构中的细节表现。

总结

SCSA通过结合SMSA和PCSA两个模块,实现了空间和通道注意力的协同作用。在SMSA中,多语义空间信息的集成和渐进压缩策略有效地为通道注意力提供了空间先验,而PCSA则利用这些空间信息,通过自注意力机制进一步优化通道特征,缓解了不同语义层次的差异。实验结果表明,SCSA在图像分类、目标检测和语义分割等多种视觉任务上具有出色的表现和 泛化能力 ,显著超越了当前的主流注意力机制。这种设计思路为未来多维度协同注意力机制的研究提供了新的方向。

下图是文章中提供的几种思路添加方法.


三、核心代码

核心代码的使用方式看章节四!

  1. import typing as t
  2. import torch
  3. import torch.nn as nn
  4. from einops import rearrange
  5. from mmengine.model import BaseModule
  6. __all__ = ['SCSA', 'C2PSASCSA']
  7. class SCSA(BaseModule):
  8. def __init__(
  9. self,
  10. dim: int,
  11. head_num: int = 4,
  12. window_size: int = 7,
  13. group_kernel_sizes: t.List[int] = [3, 5, 7, 9],
  14. qkv_bias: bool = False,
  15. fuse_bn: bool = False,
  16. norm_cfg: t.Dict = dict(type='BN'),
  17. act_cfg: t.Dict = dict(type='ReLU'),
  18. down_sample_mode: str = 'avg_pool',
  19. attn_drop_ratio: float = 0.,
  20. gate_layer: str = 'sigmoid',
  21. ):
  22. super(SCSA, self).__init__()
  23. self.dim = dim
  24. head_num = dim // 64
  25. if head_num == 0:
  26. head_num = 1
  27. self.head_num = head_num
  28. self.head_dim = dim // head_num
  29. self.scaler = self.head_dim ** -0.5
  30. self.group_kernel_sizes = group_kernel_sizes
  31. self.window_size = window_size
  32. self.qkv_bias = qkv_bias
  33. self.fuse_bn = fuse_bn
  34. self.down_sample_mode = down_sample_mode
  35. assert self.dim // 4, 'The dimension of input feature should be divisible by 4.'
  36. self.group_chans = group_chans = self.dim // 4
  37. self.local_dwc = nn.Conv1d(group_chans, group_chans, kernel_size=group_kernel_sizes[0],
  38. padding=group_kernel_sizes[0] // 2, groups=group_chans)
  39. self.global_dwc_s = nn.Conv1d(group_chans, group_chans, kernel_size=group_kernel_sizes[1],
  40. padding=group_kernel_sizes[1] // 2, groups=group_chans)
  41. self.global_dwc_m = nn.Conv1d(group_chans, group_chans, kernel_size=group_kernel_sizes[2],
  42. padding=group_kernel_sizes[2] // 2, groups=group_chans)
  43. self.global_dwc_l = nn.Conv1d(group_chans, group_chans, kernel_size=group_kernel_sizes[3],
  44. padding=group_kernel_sizes[3] // 2, groups=group_chans)
  45. self.sa_gate = nn.Softmax(dim=2) if gate_layer == 'softmax' else nn.Sigmoid()
  46. self.norm_h = nn.GroupNorm(4, dim)
  47. self.norm_w = nn.GroupNorm(4, dim)
  48. self.conv_d = nn.Identity()
  49. self.norm = nn.GroupNorm(1, dim)
  50. self.q = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, bias=qkv_bias, groups=dim)
  51. self.k = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, bias=qkv_bias, groups=dim)
  52. self.v = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, bias=qkv_bias, groups=dim)
  53. self.attn_drop = nn.Dropout(attn_drop_ratio)
  54. self.ca_gate = nn.Softmax(dim=1) if gate_layer == 'softmax' else nn.Sigmoid()
  55. if window_size == -1:
  56. self.down_func = nn.AdaptiveAvgPool2d((1, 1))
  57. else:
  58. if down_sample_mode == 'recombination':
  59. self.down_func = self.space_to_chans
  60. # dimensionality reduction
  61. self.conv_d = nn.Conv2d(in_channels=dim * window_size ** 2, out_channels=dim, kernel_size=1, bias=False)
  62. elif down_sample_mode == 'avg_pool':
  63. self.down_func = nn.AvgPool2d(kernel_size=(window_size, window_size), stride=window_size)
  64. elif down_sample_mode == 'max_pool':
  65. self.down_func = nn.MaxPool2d(kernel_size=(window_size, window_size), stride=window_size)
  66. def forward(self, x: torch.Tensor) -> torch.Tensor:
  67. """
  68. The dim of x is (B, C, H, W)
  69. """
  70. # Spatial attention priority calculation
  71. b, c, h_, w_ = x.size()
  72. # (B, C, H)
  73. x_h = x.mean(dim=3)
  74. l_x_h, g_x_h_s, g_x_h_m, g_x_h_l = torch.split(x_h, self.group_chans, dim=1)
  75. # (B, C, W)
  76. x_w = x.mean(dim=2)
  77. l_x_w, g_x_w_s, g_x_w_m, g_x_w_l = torch.split(x_w, self.group_chans, dim=1)
  78. x_h_attn = self.sa_gate(self.norm_h(torch.cat((
  79. self.local_dwc(l_x_h),
  80. self.global_dwc_s(g_x_h_s),
  81. self.global_dwc_m(g_x_h_m),
  82. self.global_dwc_l(g_x_h_l),
  83. ), dim=1)))
  84. x_h_attn = x_h_attn.view(b, c, h_, 1)
  85. x_w_attn = self.sa_gate(self.norm_w(torch.cat((
  86. self.local_dwc(l_x_w),
  87. self.global_dwc_s(g_x_w_s),
  88. self.global_dwc_m(g_x_w_m),
  89. self.global_dwc_l(g_x_w_l)
  90. ), dim=1)))
  91. x_w_attn = x_w_attn.view(b, c, 1, w_)
  92. x = x * x_h_attn * x_w_attn
  93. # Channel attention based on self attention
  94. # reduce calculations
  95. y = self.down_func(x)
  96. y = self.conv_d(y)
  97. _, _, h_, w_ = y.size()
  98. # normalization first, then reshape -> (B, H, W, C) -> (B, C, H * W) and generate q, k and v
  99. y = self.norm(y)
  100. q = self.q(y)
  101. k = self.k(y)
  102. v = self.v(y)
  103. # (B, C, H, W) -> (B, head_num, head_dim, N)
  104. q = rearrange(q, 'b (head_num head_dim) h w -> b head_num head_dim (h w)', head_num=int(self.head_num),
  105. head_dim=int(self.head_dim))
  106. k = rearrange(k, 'b (head_num head_dim) h w -> b head_num head_dim (h w)', head_num=int(self.head_num),
  107. head_dim=int(self.head_dim))
  108. v = rearrange(v, 'b (head_num head_dim) h w -> b head_num head_dim (h w)', head_num=int(self.head_num),
  109. head_dim=int(self.head_dim))
  110. # (B, head_num, head_dim, head_dim)
  111. attn = q @ k.transpose(-2, -1) * self.scaler
  112. attn = self.attn_drop(attn.softmax(dim=-1))
  113. # (B, head_num, head_dim, N)
  114. attn = attn @ v
  115. # (B, C, H_, W_)
  116. attn = rearrange(attn, 'b head_num head_dim (h w) -> b (head_num head_dim) h w', h=int(h_), w=int(w_))
  117. # (B, C, 1, 1)
  118. attn = attn.mean((2, 3), keepdim=True)
  119. attn = self.ca_gate(attn)
  120. return attn * x
  121. def autopad(k, p=None, d=1): # kernel, padding, dilation
  122. """Pad to 'same' shape outputs."""
  123. if d > 1:
  124. k = d * (k - 1) + 1 if isinstance(k, int) else [d * (x - 1) + 1 for x in k] # actual kernel-size
  125. if p is None:
  126. p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-pad
  127. return p
  128. class Conv(nn.Module):
  129. """Standard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation)."""
  130. default_act = nn.SiLU() # default activation
  131. def __init__(self, c1, c2, k=1, s=1, p=None, g=1, d=1, act=True):
  132. """Initialize Conv layer with given arguments including activation."""
  133. super().__init__()
  134. self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p, d), groups=g, dilation=d, bias=False)
  135. self.bn = nn.BatchNorm2d(c2)
  136. self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
  137. def forward(self, x):
  138. """Apply convolution, batch normalization and activation to input tensor."""
  139. return self.act(self.bn(self.conv(x)))
  140. def forward_fuse(self, x):
  141. """Perform transposed convolution of 2D data."""
  142. return self.act(self.conv(x))
  143. class PSABlock(nn.Module):
  144. """
  145. PSABlock class implementing a Position-Sensitive Attention block for neural networks.
  146. This class encapsulates the functionality for applying multi-head attention and feed-forward neural network layers
  147. with optional shortcut connections.
  148. Attributes:
  149. attn (Attention): Multi-head attention module.
  150. ffn (nn.Sequential): Feed-forward neural network module.
  151. add (bool): Flag indicating whether to add shortcut connections.
  152. Methods:
  153. forward: Performs a forward pass through the PSABlock, applying attention and feed-forward layers.
  154. Examples:
  155. Create a PSABlock and perform a forward pass
  156. """
  157. def __init__(self, c, attn_ratio=0.5, num_heads=4, shortcut=True) -> None:
  158. """Initializes the PSABlock with attention and feed-forward layers for enhanced feature extraction."""
  159. super().__init__()
  160. self.attn = SCSA(c)
  161. self.ffn = nn.Sequential(Conv(c, c * 2, 1), Conv(c * 2, c, 1, act=False))
  162. self.add = shortcut
  163. def forward(self, x):
  164. """Executes a forward pass through PSABlock, applying attention and feed-forward layers to the input tensor."""
  165. x = x + self.attn(x) if self.add else self.attn(x)
  166. x = x + self.ffn(x) if self.add else self.ffn(x)
  167. return x
  168. class C2PSASCSA(nn.Module):
  169. """
  170. C2PSA module with attention mechanism for enhanced feature extraction and processing.
  171. This module implements a convolutional block with attention mechanisms to enhance feature extraction and processing
  172. capabilities. It includes a series of PSABlock modules for self-attention and feed-forward operations.
  173. Attributes:
  174. c (int): Number of hidden channels.
  175. cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.
  176. cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c.
  177. m (nn.Sequential): Sequential container of PSABlock modules for attention and feed-forward operations.
  178. Methods:
  179. forward: Performs a forward pass through the C2PSA module, applying attention and feed-forward operations.
  180. Notes:
  181. This module essentially is the same as PSA module, but refactored to allow stacking more PSABlock modules.
  182. Examples:
  183. """
  184. def __init__(self, c1, c2, n=1, e=0.5):
  185. """Initializes the C2PSA module with specified input/output channels, number of layers, and expansion ratio."""
  186. super().__init__()
  187. assert c1 == c2
  188. self.c = int(c1 * e)
  189. self.cv1 = Conv(c1, 2 * self.c, 1, 1)
  190. self.cv2 = Conv(2 * self.c, c1, 1)
  191. self.m = nn.Sequential(*(PSABlock(self.c, attn_ratio=0.5, num_heads=self.c // 64) for _ in range(n)))
  192. def forward(self, x):
  193. """Processes the input tensor 'x' through a series of PSA blocks and returns the transformed tensor."""
  194. a, b = self.cv1(x).split((self.c, self.c), dim=1)
  195. b = self.m(b)
  196. return self.cv2(torch.cat((a, b), 1))
  197. # if __name__ == '__main__':
  198. # x = torch.ones(8, 128, 32, 32)
  199. # channels = x.shape[1]
  200. # model = C2f_SCSA(channels, channels, 1,True)
  201. # output = model(x)
  202. # print(output.shape)


四、添加教程

4.1 修改一

第一还是建立文件,我们找到如下 ultralytics /nn文件夹下建立一个目录名字呢就是'Addmodules'文件夹( 用群内的文件的话已经有了无需新建) !然后在其内部建立一个新的py文件将核心代码复制粘贴进去即可。


4.2 修改二

第二步我们在该目录下创建一个新的py文件名字为'__init__.py'( 用群内的文件的话已经有了无需新建) ,然后在其内部导入我们的检测头如下图所示。

​​


4.3 修改三

第三步找到如下文件'ultralytics/nn/tasks.py'进行导入和注册我们的模块( 用群内的文件的话已经有了无需重新导入直接开始第四步即可)

​​


4.4 修改四

找到文件到如下文件'ultralytics/nn/tasks.py',在其中的parse_model方法中添加即可。

​​


到此就修改完成了,大家可以复制下面的yaml文件运行。


五、正式训练


5.1 yaml文件1

训练信息:YOLO11-C2PSA-SCSA summary: 323 layers, 2,545,435 parameters, 2,545,419 gradients, 6.4 GFLOPs

  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. # YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
  3. # Parameters
  4. nc: 80 # number of classes
  5. scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'
  6. # [depth, width, max_channels]
  7. n: [0.50, 0.25, 1024] # summary: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPs
  8. s: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPs
  9. m: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPs
  10. l: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPs
  11. x: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs
  12. # YOLO11n backbone
  13. backbone:
  14. # [from, repeats, module, args]
  15. - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  16. - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  17. - [-1, 2, C3k2, [256, False, 0.25]]
  18. - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  19. - [-1, 2, C3k2, [512, False, 0.25]]
  20. - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  21. - [-1, 2, C3k2, [512, True]]
  22. - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
  23. - [-1, 2, C3k2, [1024, True]]
  24. - [-1, 1, SPPF, [1024, 5]] # 9
  25. - [-1, 2, C2PSASCSA, [1024]] # 10
  26. # YOLO11n head
  27. head:
  28. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  29. - [[-1, 6], 1, Concat, [1]] # cat backbone P4
  30. - [-1, 2, C3k2, [512, False]] # 13
  31. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  32. - [[-1, 4], 1, Concat, [1]] # cat backbone P3
  33. - [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)
  34. - [-1, 1, Conv, [256, 3, 2]]
  35. - [[-1, 13], 1, Concat, [1]] # cat head P4
  36. - [-1, 2, C3k2, [512, False]] # 19 (P4/16-medium)
  37. - [-1, 1, Conv, [512, 3, 2]]
  38. - [[-1, 10], 1, Concat, [1]] # cat head P5
  39. - [-1, 2, C3k2, [1024, True]] # 22 (P5/32-large)
  40. - [[16, 19, 22], 1, Detect, [nc]] # Detect(P3, P4, P5)


5.2 yaml文件2

此版本训练信息:YOLO11-SCSA summary: 367 layers, 2,601,883 parameters, 2,601,867 gradients, 6.5 GFLOPs

  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. # YOLO11 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect
  3. # Parameters
  4. nc: 80 # number of classes
  5. scales: # model compound scaling constants, i.e. 'model=yolo11n.yaml' will call yolo11.yaml with scale 'n'
  6. # [depth, width, max_channels]
  7. n: [0.50, 0.25, 1024] # summary: 319 layers, 2624080 parameters, 2624064 gradients, 6.6 GFLOPs
  8. s: [0.50, 0.50, 1024] # summary: 319 layers, 9458752 parameters, 9458736 gradients, 21.7 GFLOPs
  9. m: [0.50, 1.00, 512] # summary: 409 layers, 20114688 parameters, 20114672 gradients, 68.5 GFLOPs
  10. l: [1.00, 1.00, 512] # summary: 631 layers, 25372160 parameters, 25372144 gradients, 87.6 GFLOPs
  11. x: [1.00, 1.50, 512] # summary: 631 layers, 56966176 parameters, 56966160 gradients, 196.0 GFLOPs
  12. # YOLO11n backbone
  13. backbone:
  14. # [from, repeats, module, args]
  15. - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  16. - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  17. - [-1, 2, C3k2, [256, False, 0.25]]
  18. - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  19. - [-1, 2, C3k2, [512, False, 0.25]]
  20. - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  21. - [-1, 2, C3k2, [512, True]]
  22. - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
  23. - [-1, 2, C3k2, [1024, True]]
  24. - [-1, 1, SPPF, [1024, 5]] # 9
  25. - [-1, 2, C2PSA, [1024]] # 10
  26. # YOLO11n head
  27. head:
  28. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  29. - [[-1, 6], 1, Concat, [1]] # cat backbone P4
  30. - [-1, 2, C3k2, [512, False]] # 13
  31. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  32. - [[-1, 4], 1, Concat, [1]] # cat backbone P3
  33. - [-1, 2, C3k2, [256, False]] # 16 (P3/8-small)
  34. - [-1, 1, SCSA, []] # 17 (P3/8-small) 小目标检测层输出位置增加注意力机制
  35. - [-1, 1, Conv, [256, 3, 2]]
  36. - [[-1, 13], 1, Concat, [1]] # cat head P4
  37. - [-1, 2, C3k2, [512, False]] # 20 (P4/16-medium)
  38. - [-1, 1, SCSA, []] # 21 (P4/16-medium) 中目标检测层输出位置增加注意力机制
  39. - [-1, 1, Conv, [512, 3, 2]]
  40. - [[-1, 10], 1, Concat, [1]] # cat head P5
  41. - [-1, 2, C3k2, [1024, True]] # 24 (P5/32-large)
  42. - [-1, 1, SCSA, []] # 25 (P5/32-large) 大目标检测层输出位置增加注意力机制
  43. # 注意力机制我这里其实是添加了三个但是实际一般生效就只添加一个就可以了,所以大家可以自行注释来尝试, 上面三个仅建议大家保留一个, 但是from位置要对齐.
  44. # 具体在那一层用注意力机制可以根据自己的数据集场景进行选择。
  45. # 如果你自己配置注意力位置注意from[17, 21, 25]位置要对应上对应的检测层!
  46. - [[17, 21, 25], 1, Detect, [nc]] # Detect(P3, P4, P5)


5.3 训练代码

大家可以创建一个py文件将我给的代码复制粘贴进去,配置好自己的文件路径即可运行。

  1. import warnings
  2. warnings.filterwarnings('ignore')
  3. from ultralytics import YOLO
  4. if __name__ == '__main__':
  5. model = YOLO('yolov8-MLLA.yaml')
  6. # 如何切换模型版本, 上面的ymal文件可以改为 yolov8s.yaml就是使用的v8s,
  7. # 类似某个改进的yaml文件名称为yolov8-XXX.yaml那么如果想使用其它版本就把上面的名称改为yolov8l-XXX.yaml即可(改的是上面YOLO中间的名字不是配置文件的)!
  8. # model.load('yolov8n.pt') # 是否加载预训练权重,科研不建议大家加载否则很难提升精度
  9. model.train(data=r"C:\Users\Administrator\PycharmProjects\yolov5-master\yolov5-master\Construction Site Safety.v30-raw-images_latestversion.yolov8\data.yaml",
  10. # 如果大家任务是其它的'ultralytics/cfg/default.yaml'找到这里修改task可以改成detect, segment, classify, pose
  11. cache=False,
  12. imgsz=640,
  13. epochs=150,
  14. single_cls=False, # 是否是单类别检测
  15. batch=16,
  16. close_mosaic=0,
  17. workers=0,
  18. device='0',
  19. optimizer='SGD', # using SGD
  20. # resume='runs/train/exp21/weights/last.pt', # 如过想续训就设置last.pt的地址
  21. amp=False, # 如果出现训练损失为Nan可以关闭amp
  22. project='runs/train',
  23. name='exp',
  24. )


5.4 训练过程截图


五、本文总结

到此本文的正式分享内容就结束了,在这里给大家推荐我的YOLOv11改进有效涨点专栏,本专栏目前为新开的平均质量分98分,后期我会根据各种最新的前沿顶会进行论文复现,也会对一些老的改进机制进行补充,如果大家觉得本文帮助到你了,订阅本专栏,关注后续更多的更新~