甘肃省建设厅注册中心网站,网站怎么接广告赚钱,网站备案 代理,网站地址怎么做超链接本文在大佬的文章YOLOv11 | 一文带你深入理解ultralytics最新作品yolov11的创新 | 训练、推理、验证、导出 #xff08;附网络结构图#xff09;基础上做了一些补充。
一、YOLOv11和YOLOv8对比 二、YOLOv11的网络结构图
下面的图片为YOLOv11的网络结构图。
三、YOLOv11…本文在大佬的文章YOLOv11 | 一文带你深入理解ultralytics最新作品yolov11的创新 | 训练、推理、验证、导出 附网络结构图基础上做了一些补充。
一、YOLOv11和YOLOv8对比 二、YOLOv11的网络结构图
下面的图片为YOLOv11的网络结构图。
三、YOLOv11新提出的模块
1、 提出C3k2机制其中C3k2有参数为c3k其中在网络的浅层c3k设置为False下图中可以看到c3k2第二个参数被设置为False就是对应的c3k参数。 C3k2就相当于YOLOv8中的C2f其网络结构为一致的其中的C3k机制的网络结构图如下图所示 可将yolov11训练好的pt模型通过命令转化成onnx模型
yolo taskdetect modeexport modelruns/detect/train/weights/best.pt formatonnx 再送入Netron网站打开获取模型结构。 要想获得每一层的特征图大小如下图所示需要对转化好的onnx进行简化后得到的模型再送入Netron打开即可。 sim命令如下
pip install onnx-simplifierpython -m onnxsim /runs/detect/train/weights/best.onnx runs/detect/train/weights/best_sim.onnx以下yolov11s的第3层c3k2第二个参数设置为False的onnx结构图。 由于s的depth0.5,所以yaml文件中卷积通道数减半。 以下是第6层c3k2第二个参数设置为True的onnx结构图。
yolov11模块代码
class C3k2(C2f):Faster Implementation of CSP Bottleneck with 2 convolutions.def __init__(self, c1, c2, n1, c3kFalse, e0.5, g1, shortcutTrue):Initializes the C3k2 module, a faster CSP Bottleneck with 2 convolutions and optional C3k blocks.super().__init__(c1, c2, n, shortcut, g, e)self.m nn.ModuleList(C3k(self.c, self.c, 2, shortcut, g) if c3k else Bottleneck(self.c, self.c, shortcut, g) for _ in range(n))class C3k(C3):C3k is a CSP bottleneck module with customizable kernel sizes for feature extraction in neural networks.def __init__(self, c1, c2, n1, shortcutTrue, g1, e0.5, k3):Initializes the C3k module with specified channels, number of layers, and configurations.super().__init__(c1, c2, n, shortcut, g, e)c_ int(c2 * e) # hidden channels# self.m nn.Sequential(*(RepBottleneck(c_, c_, shortcut, g, k(k, k), e1.0) for _ in range(n)))self.m nn.Sequential(*(Bottleneck(c_, c_, shortcut, g, k(k, k), e1.0) for _ in range(n)))
class Bottleneck(nn.Module):Standard bottleneck.def __init__(self, c1, c2, shortcutTrue, g1, k(3, 3), e0.5):Initializes a standard bottleneck module with optional shortcut connection and configurable parameters.super().__init__()c_ int(c2 * e) # hidden channelsself.cv1 Conv(c1, c_, k[0], 1)self.cv2 Conv(c_, c2, k[1], 1, gg)self.add shortcut and c1 c2def forward(self, x):Applies the YOLO FPN to input data.return x self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
2、第二个创新点是提出C2PSA机制这是一个C2C2f的前身机制内部嵌入了一个多头注意力机制在这个过程中我还发现作者尝试了C2fPSA机制但是估计效果不如C2PSA有的时候机制有没有效果理论上真的很难解释通下图为C2PSA机制的原理图仔细观察把Attention哪里去掉则C2PSA机制就变为了C2所以我上面说C2PSA就是C2里面嵌入了一个PSA机制。 以下是第10层C2PSA第二个参数设置为True的onnx结构图。 class C2PSA(nn.Module):C2PSA module with attention mechanism for enhanced feature extraction and processing.This module implements a convolutional block with attention mechanisms to enhance feature extraction and processingcapabilities. It includes a series of PSABlock modules for self-attention and feed-forward operations.Attributes:c (int): Number of hidden channels.cv1 (Conv): 1x1 convolution layer to reduce the number of input channels to 2*c.cv2 (Conv): 1x1 convolution layer to reduce the number of output channels to c.m (nn.Sequential): Sequential container of PSABlock modules for attention and feed-forward operations.Methods:forward: Performs a forward pass through the C2PSA module, applying attention and feed-forward operations.Notes:This module essentially is the same as PSA module, but refactored to allow stacking more PSABlock modules.Examples: c2psa C2PSA(c1256, c2256, n3, e0.5) input_tensor torch.randn(1, 256, 64, 64) output_tensor c2psa(input_tensor)def __init__(self, c1, c2, n1, e0.5):Initializes the C2PSA module with specified input/output channels, number of layers, and expansion ratio.super().__init__()assert c1 c2self.c int(c1 * e)self.cv1 Conv(c1, 2 * self.c, 1, 1)self.cv2 Conv(2 * self.c, c1, 1)self.m nn.Sequential(*(PSABlock(self.c, attn_ratio0.5, num_headsself.c // 64) for _ in range(n)))def forward(self, x):Processes the input tensor x through a series of PSA blocks and returns the transformed tensor.a, b self.cv1(x).split((self.c, self.c), dim1)b self.m(b)return self.cv2(torch.cat((a, b), 1))class PSABlock(nn.Module):PSABlock class implementing a Position-Sensitive Attention block for neural networks.This class encapsulates the functionality for applying multi-head attention and feed-forward neural network layerswith optional shortcut connections.Attributes:attn (Attention): Multi-head attention module.ffn (nn.Sequential): Feed-forward neural network module.add (bool): Flag indicating whether to add shortcut connections.Methods:forward: Performs a forward pass through the PSABlock, applying attention and feed-forward layers.Examples:Create a PSABlock and perform a forward pass psablock PSABlock(c128, attn_ratio0.5, num_heads4, shortcutTrue) input_tensor torch.randn(1, 128, 32, 32) output_tensor psablock(input_tensor)def __init__(self, c, attn_ratio0.5, num_heads4, shortcutTrue) - None:Initializes the PSABlock with attention and feed-forward layers for enhanced feature extraction.super().__init__()self.attn Attention(c, attn_ratioattn_ratio, num_headsnum_heads)self.ffn nn.Sequential(Conv(c, c * 2, 1), Conv(c * 2, c, 1, actFalse))self.add shortcutdef forward(self, x):Executes a forward pass through PSABlock, applying attention and feed-forward layers to the input tensor.x x self.attn(x) if self.add else self.attn(x)x x self.ffn(x) if self.add else self.ffn(x)return x3. 第三个创新点可以说是原先的解耦头中的分类检测头增加了两个DWConv具体的对比大家可以看下面两个图下面的是YOLOv11的解耦头上面的是YOLOv8的解耦头. head部分分类头定义: v8: v11:
DWconv卷积代码 我们上面看到了在分类检测头中YOLOv11插入了两个DWConv这样的做法可以大幅度减少参数量和计算量原先两个普通的Conv大家要注意到卷积和是由3变为了1的这是形成了两个深度可分离Conv 可参考博客https://blog.csdn.net/m0_56563749/article/details/133150979
4. 非创新点的SPPF模块 第9层SPPF的onnx结构图 SPPF模块代码 文章转载自: http://www.morning.zqwqy.cn.gov.cn.zqwqy.cn http://www.morning.fhxrb.cn.gov.cn.fhxrb.cn http://www.morning.rstrc.cn.gov.cn.rstrc.cn http://www.morning.tgnr.cn.gov.cn.tgnr.cn http://www.morning.wtnyg.cn.gov.cn.wtnyg.cn http://www.morning.ntzbr.cn.gov.cn.ntzbr.cn http://www.morning.ybhrb.cn.gov.cn.ybhrb.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.ptzbg.cn.gov.cn.ptzbg.cn http://www.morning.mzgq.cn.gov.cn.mzgq.cn http://www.morning.lqws.cn.gov.cn.lqws.cn http://www.morning.mjzcp.cn.gov.cn.mjzcp.cn http://www.morning.khxyx.cn.gov.cn.khxyx.cn http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.5-73.com.gov.cn.5-73.com http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.clfct.cn.gov.cn.clfct.cn http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn http://www.morning.jnkng.cn.gov.cn.jnkng.cn http://www.morning.bwkzn.cn.gov.cn.bwkzn.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.tfwsk.cn.gov.cn.tfwsk.cn http://www.morning.prysb.cn.gov.cn.prysb.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.ltspm.cn.gov.cn.ltspm.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.flqkp.cn.gov.cn.flqkp.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.grxyx.cn.gov.cn.grxyx.cn http://www.morning.bpmfn.cn.gov.cn.bpmfn.cn http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.tslxr.cn.gov.cn.tslxr.cn http://www.morning.stsnf.cn.gov.cn.stsnf.cn http://www.morning.lyjwb.cn.gov.cn.lyjwb.cn http://www.morning.kybpj.cn.gov.cn.kybpj.cn http://www.morning.bmtkp.cn.gov.cn.bmtkp.cn http://www.morning.nswcw.cn.gov.cn.nswcw.cn http://www.morning.llgpk.cn.gov.cn.llgpk.cn http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn http://www.morning.drjll.cn.gov.cn.drjll.cn http://www.morning.sffkm.cn.gov.cn.sffkm.cn http://www.morning.tgydf.cn.gov.cn.tgydf.cn http://www.morning.qsyyp.cn.gov.cn.qsyyp.cn http://www.morning.lgnrl.cn.gov.cn.lgnrl.cn http://www.morning.ktxd.cn.gov.cn.ktxd.cn http://www.morning.dpdr.cn.gov.cn.dpdr.cn http://www.morning.rqbr.cn.gov.cn.rqbr.cn http://www.morning.rgnq.cn.gov.cn.rgnq.cn http://www.morning.ynryz.cn.gov.cn.ynryz.cn http://www.morning.ddgl.com.cn.gov.cn.ddgl.com.cn http://www.morning.hhpbj.cn.gov.cn.hhpbj.cn http://www.morning.mzgq.cn.gov.cn.mzgq.cn http://www.morning.tslwz.cn.gov.cn.tslwz.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.mmhyx.cn.gov.cn.mmhyx.cn http://www.morning.lpbrp.cn.gov.cn.lpbrp.cn http://www.morning.ztnmc.cn.gov.cn.ztnmc.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.flfxb.cn.gov.cn.flfxb.cn http://www.morning.bswnf.cn.gov.cn.bswnf.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.tjmfz.cn.gov.cn.tjmfz.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.zqkr.cn.gov.cn.zqkr.cn http://www.morning.rhdln.cn.gov.cn.rhdln.cn http://www.morning.yqgbw.cn.gov.cn.yqgbw.cn http://www.morning.ndrzq.cn.gov.cn.ndrzq.cn http://www.morning.lbxcc.cn.gov.cn.lbxcc.cn http://www.morning.htbgz.cn.gov.cn.htbgz.cn http://www.morning.zlgr.cn.gov.cn.zlgr.cn http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn