学习资源站

YOLOv11改进-主干_Backbone篇-利用轻量化卷积优化PP-HGNetV2改进主干(轻量化版本,全网独家创新)

一、本文介绍

Hello,大家好,上一篇博客我们讲了利用 HGNetV2去替换YOLOv8的主干 ,经过结构的研究我们可以发现在HGNetV2的网络中有大量的卷积存在,所以我们可以用一种更加 轻量化 的卷积去优化HGNetV2从而达到更加轻量化的效果 亲测优化后的HGNetV2网络比正常HGNetV2精度更高轻量化效果更好,非常适合轻量化的读者) ,同时HGNetV2的网络结构目前还没有推出论文,所以其理论知识在网络上也是非常的少,我也是根据网络结构图进行了分析,给大家进行讲解网络结构原理 (亲测替换之后主干GFLOPs降低到7.4,精度mAP提高0.06)



二、HGNetV2原理讲解

本文论文地址: RT-DETR论文地址

本文代码来源: HGNetV2的代码来源


2.1 HGNetV2的网络结构讲解

PP-HGNet 骨干网络的整体结构如下:

其中,PP-HGNet是由多个HG-Block组成,HG-Block的细节如下:

上面的图表是PP-HGNet 神经网络 架构的概览,下面我对其中的每一个模块进行分析:

1. Stem层: 这是网络的初始预处理层,通常包含 卷积层 ,开始从原始输入数据中提取特征。

2. HG(层次图)块: 这些块是网络的核心 组件 ,设计用于以层次化的方式处理数据。每个HG块可能处理数据的不同抽象层次,允许网络从低级和高级特征中学习。

3. LDS(可学习的下采样)层: 位于HG块之间的这些层可能执行下采样操作,减少特征图的空间维度,减少计算负载并可能增加后续层的感受野。

4. GAP(全局平均池化): 在最终分类之前,使用GAP层将特征图的空间维度减少到每个特征图一个向量,有助于提高网络对输入数据空间变换的鲁棒性。

5. 最终的卷积和全连接(FC)层: 网络以一系列执行最终分类任务的层结束。这通常涉及一个卷积层(有时称为1x1卷积)来组合特征,然后是将这些特征映射到所需输出类别数量的全连接层。

这种架构的主要思想是利用层次化的方法来提取特征,其中复杂的模式可以在不同的规模和抽象层次上学习,提高网络处理复杂图像数据的能力。

这种分层和高效的处理对于图像分类等复杂任务非常有利,在这些任务中,精确预测至关重要的是在不同规模上识别复杂的模式和特征。图表还显示了HG块的扩展视图,包括多个不同滤波器大小的卷积层,以捕获多样化的特征,然后通过一个元素级相加或连接的操作(由+符号表示)在数据传递到下一层之前。


2.2 轻量化卷积

我这里利用的轻量化卷积只是官方仓库里面包含的四种,这个文章其实是给大家打开一个思路,这里的HGNet利用大量的卷积处理,所以我们能够替换其中大量的卷积从而达到优化和涨点的效果。

这几种卷积都是非常经典的了,其中RepConv只支持卷积核为3所以我也进行了一定的处理,原理就不再描述了。


三、HGNetV2的代码

这里的结构我们复制' ultralytics /nn/modules'目录下然后创建一个py文件粘贴进去即可,添加教程看章节四。

  1. import torch
  2. import torch.nn as nn
  3. import math
  4. import numpy as np
  5. __all__ = ['Light_HGBlock']
  6. def autopad(k, p=None, d=1): # kernel, padding, dilation
  7. """Pad to 'same' shape outputs."""
  8. if d > 1:
  9. k = d * (k - 1) + 1 if isinstance(k, int) else [d * (x - 1) + 1 for x in k] # actual kernel-size
  10. if p is None:
  11. p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-pad
  12. return p
  13. class Conv(nn.Module):
  14. """Standard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation)."""
  15. default_act = nn.SiLU() # default activation
  16. def __init__(self, c1, c2, k=1, s=1, p=None, g=1, d=1, act=True):
  17. """Initialize Conv layer with given arguments including activation."""
  18. super().__init__()
  19. self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p, d), groups=g, dilation=d, bias=False)
  20. self.bn = nn.BatchNorm2d(c2)
  21. self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
  22. def forward(self, x):
  23. """Apply convolution, batch normalization and activation to input tensor."""
  24. return self.act(self.bn(self.conv(x)))
  25. def forward_fuse(self, x):
  26. """Perform transposed convolution of 2D data."""
  27. return self.act(self.conv(x))
  28. class LightConv(nn.Module):
  29. """
  30. Light convolution with args(ch_in, ch_out, kernel).
  31. https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/backbones/hgnet_v2.py
  32. """
  33. def __init__(self, c1, c2, k=1, act=nn.ReLU()):
  34. """Initialize Conv layer with given arguments including activation."""
  35. super().__init__()
  36. self.conv1 = Conv(c1, c2, 1, act=False)
  37. self.conv2 = DWConv(c2, c2, k, act=act)
  38. def forward(self, x):
  39. """Apply 2 convolutions to input tensor."""
  40. return self.conv2(self.conv1(x))
  41. class DWConv(Conv):
  42. """Depth-wise convolution."""
  43. def __init__(self, c1, c2, k=1, s=1, d=1, act=True): # ch_in, ch_out, kernel, stride, dilation, activation
  44. """Initialize Depth-wise convolution with given parameters."""
  45. super().__init__(c1, c2, k, s, g=math.gcd(c1, c2), d=d, act=act)
  46. class DWConvTranspose2d(nn.ConvTranspose2d):
  47. """Depth-wise transpose convolution."""
  48. def __init__(self, c1, c2, k=1, s=1, p1=0, p2=0): # ch_in, ch_out, kernel, stride, padding, padding_out
  49. """Initialize DWConvTranspose2d class with given parameters."""
  50. super().__init__(c1, c2, k, s, p1, p2, groups=math.gcd(c1, c2))
  51. class ConvTranspose(nn.Module):
  52. """Convolution transpose 2d layer."""
  53. default_act = nn.SiLU() # default activation
  54. def __init__(self, c1, c2, k=2, s=2, p=0, bn=True, act=True):
  55. """Initialize ConvTranspose2d layer with batch normalization and activation function."""
  56. super().__init__()
  57. self.conv_transpose = nn.ConvTranspose2d(c1, c2, k, s, p, bias=not bn)
  58. self.bn = nn.BatchNorm2d(c2) if bn else nn.Identity()
  59. self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
  60. def forward(self, x):
  61. """Applies transposed convolutions, batch normalization and activation to input."""
  62. return self.act(self.bn(self.conv_transpose(x)))
  63. def forward_fuse(self, x):
  64. """Applies activation and convolution transpose operation to input."""
  65. return self.act(self.conv_transpose(x))
  66. class Focus(nn.Module):
  67. """Focus wh information into c-space."""
  68. def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):
  69. """Initializes Focus object with user defined channel, convolution, padding, group and activation values."""
  70. super().__init__()
  71. self.conv = Conv(c1 * 4, c2, k, s, p, g, act=act)
  72. # self.contract = Contract(gain=2)
  73. def forward(self, x):
  74. """
  75. Applies convolution to concatenated tensor and returns the output.
  76. Input shape is (b,c,w,h) and output shape is (b,4c,w/2,h/2).
  77. """
  78. return self.conv(torch.cat((x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]), 1))
  79. # return self.conv(self.contract(x))
  80. class GhostConv(nn.Module):
  81. """Ghost Convolution https://github.com/huawei-noah/ghostnet."""
  82. def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
  83. """Initializes Ghost Convolution module with primary and cheap operations for efficient feature learning."""
  84. super().__init__()
  85. c_ = c2 // 2 # hidden channels
  86. self.cv1 = Conv(c1, c_, k, s, None, g, act=act)
  87. self.cv2 = Conv(c_, c_, 5, 1, None, c_, act=act)
  88. def forward(self, x):
  89. """Forward propagation through a Ghost Bottleneck layer with skip connection."""
  90. y = self.cv1(x)
  91. return torch.cat((y, self.cv2(y)), 1)
  92. class RepConv(nn.Module):
  93. """
  94. RepConv is a basic rep-style block, including training and deploy status.
  95. This module is used in RT-DETR.
  96. Based on https://github.com/DingXiaoH/RepVGG/blob/main/repvgg.py
  97. """
  98. default_act = nn.SiLU() # default activation
  99. def __init__(self, c1, c2, k=3, s=1, p=1, g=1, d=1, act=True, bn=False, deploy=False):
  100. """Initializes Light Convolution layer with inputs, outputs & optional activation function."""
  101. super().__init__()
  102. assert k == 3 and p == 1
  103. self.g = g
  104. self.c1 = c1
  105. self.c2 = c2
  106. self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
  107. self.bn = nn.BatchNorm2d(num_features=c1) if bn and c2 == c1 and s == 1 else None
  108. self.conv1 = Conv(c1, c2, k, s, p=p, g=g, act=False)
  109. self.conv2 = Conv(c1, c2, 1, s, p=(p - k // 2), g=g, act=False)
  110. def forward_fuse(self, x):
  111. """Forward process."""
  112. return self.act(self.conv(x))
  113. def forward(self, x):
  114. """Forward process."""
  115. id_out = 0 if self.bn is None else self.bn(x)
  116. return self.act(self.conv1(x) + self.conv2(x) + id_out)
  117. def get_equivalent_kernel_bias(self):
  118. """Returns equivalent kernel and bias by adding 3x3 kernel, 1x1 kernel and identity kernel with their biases."""
  119. kernel3x3, bias3x3 = self._fuse_bn_tensor(self.conv1)
  120. kernel1x1, bias1x1 = self._fuse_bn_tensor(self.conv2)
  121. kernelid, biasid = self._fuse_bn_tensor(self.bn)
  122. return kernel3x3 + self._pad_1x1_to_3x3_tensor(kernel1x1) + kernelid, bias3x3 + bias1x1 + biasid
  123. @staticmethod
  124. def _pad_1x1_to_3x3_tensor(kernel1x1):
  125. """Pads a 1x1 tensor to a 3x3 tensor."""
  126. if kernel1x1 is None:
  127. return 0
  128. else:
  129. return torch.nn.functional.pad(kernel1x1, [1, 1, 1, 1])
  130. def _fuse_bn_tensor(self, branch):
  131. """Generates appropriate kernels and biases for convolution by fusing branches of the neural network."""
  132. if branch is None:
  133. return 0, 0
  134. if isinstance(branch, Conv):
  135. kernel = branch.conv.weight
  136. running_mean = branch.bn.running_mean
  137. running_var = branch.bn.running_var
  138. gamma = branch.bn.weight
  139. beta = branch.bn.bias
  140. eps = branch.bn.eps
  141. elif isinstance(branch, nn.BatchNorm2d):
  142. if not hasattr(self, "id_tensor"):
  143. input_dim = self.c1 // self.g
  144. kernel_value = np.zeros((self.c1, input_dim, 3, 3), dtype=np.float32)
  145. for i in range(self.c1):
  146. kernel_value[i, i % input_dim, 1, 1] = 1
  147. self.id_tensor = torch.from_numpy(kernel_value).to(branch.weight.device)
  148. kernel = self.id_tensor
  149. running_mean = branch.running_mean
  150. running_var = branch.running_var
  151. gamma = branch.weight
  152. beta = branch.bias
  153. eps = branch.eps
  154. std = (running_var + eps).sqrt()
  155. t = (gamma / std).reshape(-1, 1, 1, 1)
  156. return kernel * t, beta - running_mean * gamma / std
  157. def fuse_convs(self):
  158. """Combines two convolution layers into a single layer and removes unused attributes from the class."""
  159. if hasattr(self, "conv"):
  160. return
  161. kernel, bias = self.get_equivalent_kernel_bias()
  162. self.conv = nn.Conv2d(
  163. in_channels=self.conv1.conv.in_channels,
  164. out_channels=self.conv1.conv.out_channels,
  165. kernel_size=self.conv1.conv.kernel_size,
  166. stride=self.conv1.conv.stride,
  167. padding=self.conv1.conv.padding,
  168. dilation=self.conv1.conv.dilation,
  169. groups=self.conv1.conv.groups,
  170. bias=True,
  171. ).requires_grad_(False)
  172. self.conv.weight.data = kernel
  173. self.conv.bias.data = bias
  174. for para in self.parameters():
  175. para.detach_()
  176. self.__delattr__("conv1")
  177. self.__delattr__("conv2")
  178. if hasattr(self, "nm"):
  179. self.__delattr__("nm")
  180. if hasattr(self, "bn"):
  181. self.__delattr__("bn")
  182. if hasattr(self, "id_tensor"):
  183. self.__delattr__("id_tensor")
  184. class Light_HGBlock(nn.Module):
  185. """
  186. HG_Block of PPHGNetV2 with 2 convolutions and LightConv.
  187. https://github.com/PaddlePaddle/PaddleDetection/blob/develop/ppdet/modeling/backbones/hgnet_v2.py
  188. """
  189. def __init__(self, c1, cm, c2, k=3, n=6, num=1, shortcut=False, act=True):
  190. """Initializes a CSP Bottleneck with 1 convolution using specified input and output channels."""
  191. super().__init__()
  192. block = Conv
  193. if num == 1:
  194. block = GhostConv
  195. elif num == 2:
  196. block = RepConv # RepConv Only supported k = 3
  197. k = 3
  198. elif num == 3:
  199. block = DWConv
  200. elif num == 4:
  201. block = LightConv
  202. self.m = nn.ModuleList(block(c1 if i == 0 else cm, cm, k=k, act=act) for i in range(n))
  203. self.sc = Conv(c1 + n * cm, c2 // 2, 1, 1, act=act) # squeeze conv
  204. self.ec = Conv(c2 // 2, c2, 1, 1, act=act) # excitation conv
  205. self.add = shortcut and c1 == c2
  206. def forward(self, x):
  207. """Forward pass of a PPHGNetV2 backbone layer."""
  208. y = [x]
  209. y.extend(m(y[-1]) for m in self.m)
  210. y = self.ec(self.sc(torch.cat(y, 1)))
  211. return y + x if self.add else y


四、手把手教你添加HGNetV2

4.1 手把手教你添加HGNetV2

这里的添加方法比较特殊,和之前的都不一样,但是也很简单修改三处即可使用。

4.1.1 修改一

我们找到如下的文件'ultralytics/nn/tasks.py',在开头的地方导入我们刚才创建文件的模块。

4.1.2 修改二

按照如下图所示添加即可


4.1.3 修改三

本文以及默认大家用的是以及集成过RT-DETR代码的ultralytics仓库了(其中以及包含了HGNet的代码文件),所以我们只需要添加几行代码就能够回复官方删除掉的功能。

我们首先需要找到'ultralytics/nn/tasks.py'文件然后找到'def parse_model(d, ch, verbose=True):  # model_dict, input_channels(3)'

下面的代码我们看到大概基本的样子的.

复制此处的代码按照下面的图片进行添加即可,不要自己打!

  1. cm = make_divisible(min(cm, max_channels) * width, 8)
  2. c2 = make_divisible(min(c2, max_channels) * width, 8)
  3. n = n_ = max(round(n * depth), 1) if n > 1 else n # depth gain

到此我们就完成了官方的代码修复,我们此时运行代码比如V8n那么你就会发现的大幅度的减少了参数量,


4. 2 使用说明

这里有一个参数,需要大家修改,在章节2.2我说了我用了好几个卷积可以提供大家选择,所以这里分别可以有四个卷积可以给大家使用,大家可以看下面的代码。

  1. if num == 1:
  2. block = GhostConv
  3. elif num == 2:
  4. block = RepConv # RepConv Only supported k = 3
  5. k = 3
  6. elif num == 3:
  7. block = DWConv
  8. elif num == 4:
  9. block = LightConv

如果我们想要使用RepConv为例,那么我们修改图中的红框位置的地方我们设置为2此时使用的就是RepConv,默认使用的是3也就是DWConv,实验结果也是这个跑出来的。


4.3 HGNet-l的yaml文件

此版本训练信息:YOLO11-LightHGNetV2-l summary: 424 layers, 2,381,262 parameters, 2,381,246 gradients, 7.1 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, HGStem, [32, 48]] # 0-P2/4
  16. - [-1, 6, Light_HGBlock, [48, 128, 3]] # stage 1
  17. - [-1, 1, DWConv, [128, 3, 2, 1, 1]] # 2-P3/8
  18. - [-1, 6, Light_HGBlock, [96, 512, 3]] # stage 2
  19. - [-1, 1, DWConv, [512, 3, 2, 2, False]] # 4-P3/16
  20. - [-1, 6, Light_HGBlock, [192, 1024, 5, 3, False]] # cm, c2, k, light, shortcut
  21. - [-1, 6, Light_HGBlock, [192, 1024, 5, 3, True]]
  22. - [-1, 6, Light_HGBlock, [192, 1024, 5, 3, True]] # stage 3
  23. - [-1, 1, DWConv, [1024, 3, 2, 1, False]] # 8-P4/32
  24. - [-1, 6, Light_HGBlock, [384, 2048, 5, 3, False]] # stage 4
  25. - [-1, 1, SPPF, [1024, 5]] # 10
  26. - [-1, 1, C2PSA, [1024]] # 11
  27. # YOLOv10.0n head
  28. head:
  29. - [-1, 1, nn.Upsample, [None, 2, "nearest"]] # 12
  30. - [[-1, 7], 1, Concat, [1]] # cat backbone P4
  31. - [-1, 2, C3k2, [512, False]] # 14
  32. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  33. - [[-1, 3], 1, Concat, [1]] # cat backbone P3
  34. - [-1, 2, C3k2, [256, False]] # 17 (P3/8-small)
  35. - [-1, 1, Conv, [256, 3, 2]]
  36. - [[-1, 14], 1, Concat, [1]] # cat head P4
  37. - [-1, 2, C3k2, [512, False]] # 20 (P4/16-medium)
  38. - [-1, 1, SCDown, [512, 3, 2]]
  39. - [[-1, 11], 1, Concat, [1]] # cat head P5
  40. - [-1, 2, C3k2, [1024, True]] # 23 (P5/32-large)
  41. - [[17, 20, 23], 1, v10Detect, [nc]] # Detect(P3, P4, P5)


4.4 HGNetV2-x的yaml文件

此版本训练信息:YOLO11-LightHGNetV2-x summary: 460 layers, 2,643,782 parameters, 2,643,766 gradients, 8.0 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, HGStem, [32, 64]] # 0-P2/4
  16. - [-1, 6, Light_HGBlock, [64, 128, 3]] # stage 1
  17. - [-1, 1, DWConv, [128, 3, 2, 1, False]] # 2-P3/8
  18. - [-1, 6, Light_HGBlock, [128, 512, 3]]
  19. - [-1, 6, Light_HGBlock, [128, 512, 3, 3, True]] # 4-stage 2
  20. - [-1, 1, DWConv, [512, 3, 2, 1, False]] # 5-P3/16
  21. - [-1, 6, Light_HGBlock, [256, 1024, 5, 3, False]] # cm, c2, k, light, shortcut
  22. - [-1, 6, Light_HGBlock, [256, 1024, 5, 3, True]]
  23. - [-1, 6, Light_HGBlock, [256, 1024, 5, 3, True]]
  24. - [-1, 6, Light_HGBlock, [256, 1024, 5, 3, True]]
  25. - [-1, 6, Light_HGBlock, [256, 1024, 5, 3, True]] # 10-stage 3
  26. - [-1, 1, DWConv, [1024, 3, 2, 1, False]] # 11-P4/32
  27. - [-1, 6, Light_HGBlock, [512, 2048, 5, 3, False]]
  28. - [-1, 6, Light_HGBlock, [512, 2048, 5, 3, True]] # 13-stage 4
  29. - [-1, 1, SPPF, [1024, 5]] # 14
  30. - [-1, 1, PSA, [1024]] # 15
  31. # YOLOv10.0n head
  32. head:
  33. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  34. - [[-1, 10], 1, Concat, [1]] # cat backbone P4
  35. - [-1, 2, C3k2, [512, False]] # 18
  36. - [-1, 1, nn.Upsample, [None, 2, "nearest"]]
  37. - [[-1, 4], 1, Concat, [1]] # cat backbone P3
  38. - [-1, 2, C3k2, [256, False]] # 21 (P3/8-small)
  39. - [-1, 1, Conv, [256, 3, 2]]
  40. - [[-1, 18], 1, Concat, [1]] # cat head P4
  41. - [-1, 2, C3k2, [512, False]] # 24 (P4/16-medium)
  42. - [-1, 1, SCDown, [512, 3, 2]]
  43. - [[-1, 15], 1, Concat, [1]] # cat head P5
  44. - [-1, 2, C3k2, [1024, False]] # 27 (P5/32-large)
  45. - [[21, 24, 27], 1, v10Detect, [nc]] # Detect(P3, P4, P5)

4.5 训练代码

  1. import warnings
  2. warnings.filterwarnings('ignore')
  3. from ultralytics import YOLO
  4. if __name__ == '__main__':
  5. model = YOLO('ultralytics/cfg/models/v8/yolov8-C2f-FasterBlock.yaml')
  6. # model.load('yolov8n.pt') # loading pretrain weights
  7. model.train(data=r'替换数据集yaml文件地址',
  8. # 如果大家任务是其它的'ultralytics/cfg/default.yaml'找到这里修改task可以改成detect, segment, classify, pose
  9. cache=False,
  10. imgsz=640,
  11. epochs=150,
  12. single_cls=False, # 是否是单类别检测
  13. batch=4,
  14. close_mosaic=10,
  15. workers=0,
  16. device='0',
  17. optimizer='SGD', # using SGD
  18. # resume='', # 如过想续训就设置last.pt的地址
  19. amp=False, # 如果出现训练损失为Nan可以关闭amp
  20. project='runs/train',
  21. name='exp',
  22. )


五、运行成功记录

下面的图片是证明成功运行的截图,确保我发的改进机制是可用的。


六、本文总结

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