YOLOv5改进——使用深度可分离卷积轻量化C3

YOLOv5 Focus C3 各模块详解及代码实现 关于yolov5的参数的讲解 阅读详情
AI摘要

文章介绍了YOLOv5网络中的C3模块结构,包括Conv、BottleNeck和C3的实现。C3模块由Bottleneck组成,通过使用深度可分离卷积进行轻量化改进,降低了计算复杂度。修改后的DP_C3模块在保持结构不变的情况下,将普通卷积替换为深度可分离卷积,以提高模型效率。

一、C3模块

  在原版YOLOv5网络中,C3模块的结构如图1-1所示,C3结构中的ConvBNSiLU和BottleNeck的结构如图1-2所示:

在这里插入图片描述

图1-1 C3结构图

在这里插入图片描述

图1-2 BottleNeck和ConvBNSiLU结构图

  Conv、BottleNeck、C3的代码如下:

class Conv(nn.Module):
    # Standard convolution  通用卷积模块,包括1卷积1BN1激活,激活默认SiLU,可用变量指定,不激活时用nn.Identity()占位,直接返回输入
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super(Conv, self).__init__()
        self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
        self.bn = nn.BatchNorm2d(c2)
        self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity())

    def forward(self, x):
        return self.act(self.bn(self.conv(x)))

    def fuseforward(self, x):
        return self.act(self.conv(x))


class Bottleneck(nn.Module):
    # Standard bottleneck 残差块
    def __init__(self, c1, c2, shortcut=True, g=1, e=0.5):  # ch_in, ch_out, shortcut, groups, expansion
        super(Bottleneck, self).__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_, c2, 3, 1, g=g)
        self.add = shortcut and c1 == c2

    def forward(self, x):  # 如果shortcut并且输入输出通道相同则跳层相加
        return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))

class C3(nn.Module):  
    # CSP Bottleneck with 3 convolutions
    def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):  # ch_in, ch_out, number, shortcut, groups, expansion
        super(C3, self).__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c1, c_, 1, 1)
        self.cv3 = Conv(2 * c_, c2, 1)  # act=FReLU(c2)
        self.m = nn.Sequential(*[Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)])  # n个残差组件(Bottleneck)
        # self.m = nn.Sequential(*[CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])

    def forward(self, x):
        return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))

二、轻量化C3模块

  轻量化C3的改进思路是将原C3模块中使用的普通卷积,全部替换为深度可分离卷积,其余结构不变,改进后的DP_Conv、DP_BottleNeck、DP_C3的代码如下:

class DP_Conv(nn.Module):
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super(DP_Conv, self).__init__()
        self.conv = nn.Conv2d(c1, c1, kernel_size=3, stride=1, padding=1, groups=c1)
        self.conv = nn.Conv2d(c1, c2, kernel_size=1, stride=s)
        self.bn = nn.BatchNorm2d(c2)
        self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity())

    def forward(self, x):
        return self.act(self.bn(self.conv(x)))

    def fuseforward(self, x):
        return self.act(self.conv(x))

class DP_Bottleneck(nn.Module):
    def __init__(self, c1, c2, shortcut=True, g=1, e=0.5):  # ch_in, ch_out, shortcut, groups, expansion
        super(DP_Bottleneck, self).__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = DP_Conv(c1, c_, 1)
        self.cv2 = DP_Conv(c_, c2, 1)
        self.add = shortcut and c1 == c2

    def forward(self, x):  # 如果shortcut并且输入输出通道相同则跳层相加
        return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))

class DP_C3(nn.Module): 
    # CSP Bottleneck with 3 convolutions
    def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):  # ch_in, ch_out, number, shortcut, groups, expansion
        super(DP_C3, self).__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = DP_Conv(c1, c_, 1)
        self.cv2 = DP_Conv(c1, c_, 1)
        self.cv3 = DP_Conv(2 * c_, c2, 1)  # act=FReLU(c2)
        self.m = nn.Sequential(*[DP_Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)])  # n个残差组件(Bottleneck)
        # self.m = nn.Sequential(*[CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)])

    def forward(self, x):
        return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1))

  修改后的网络结构如下:

# parameters
nc: 20  # number of classes
depth_multiple: 0.33  # model depth multiple
width_multiple: 0.50  # layer channel multiple

# anchors
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

# YOLOv5 backbone
backbone:
  # [from, number, module, args]
  [[-1, 1, DP_Conv, [64, 2]],  # 0-P1/2
   [-1, 1, DP_Conv, [128, 2]],  # 1-P2/4
   [-1, 3, DP_C3, [128]],
   [-1, 1, DP_Conv, [256, 2]],  # 3-P3/8
   [-1, 9, DP_C3, [256]],
   [-1, 1, DP_Conv, [512, 2]],  # 5-P4/16
   [-1, 9, DP_C3, [512]],
   [-1, 1, DP_Conv, [1024, 2]],  # 7-P5/32
   [-1, 3, DP_C3, [1024]],
   [-1, 1, SPPF, [1024, 5]], # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, DP_Conv, [512, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4  # PANet是add, yolov5是concat
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, DP_Conv, [256, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)

   [-1, 1, DP_Conv, [256, 2]],
   [[-1, 14], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [512, False]],  # 20 (P4/16-medium)

   [-1, 1, DP_Conv, [512, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[17, 20, 23], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)  必须在最后一层, 原代码很多默认了Detect是最后, 并没有全改
  ]

卷积神经网络常见结构 卷积神经网络常见结构 卷积神经网络中常见的层类型有: 卷积层(CONV) 激活函数(ACT 或 RELU) 池化层(POOL) 全连接层(FC) Batch normalization(BN) Dropout(DO) 其中常见的组合为: 注: * 操作代表这里需要一次或者多次;?操作符代表这是可选操作,可以出现0次或者多次。 对于以上重复次数的常见选择是: 0<=N... 阅读详情

相关推荐

YOLOv5改进——使用深度可分离卷积轻量化C3_convbnsilu

Standard bottleneck 残差块self.m = nn.Sequential(*[Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)]) # n个残差组件(Bottleneck)

weixin_52182944的博客 693

P8:YOLOv5-C3模块实现

🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍦 参考文章:Pytorch实战 | 第P8周:YOLOv5-C3模块实现🍖 原作者:K同学啊|接辅导、项目定制。

weixin_62299063的博客 3254

YOLOv5算法进阶改进(3)— 引入深度可分离卷积C3模块 | 轻量化网络

深度可分离卷积是一种卷积神经网络中的卷积操作,可以大大减少计算量和参数数量,从而提高模型的效率和准确性。本节课就给大家介绍一下如何在YOLOv5主干网络中引入深度可分离卷积C3模块,希望大家学习之后能够有所收获~!🌈

小哥谈 2142

最新YOLOv5改进——使用深度可分离卷积轻量化C3_convbnsilu

图1-1 C3结构图图1-2 BottleNeck和ConvBNSiLU结构图。

2401_84281720的博客 938

YOLOv5改进实战 | 更换主干网络Backbone(一)之轻量化网络Ghostnet

w94ghz的博客 1万+

YOLOv11-seg改进系列 | 引入YOLOv13的DSC3k2模块,深度可分离卷积全面替换C3k2,轻量化提速不掉点

C3k2是 YOLOv11 的核心特征提取模块,内部使用标准卷积叠加 Bottleneck,表达能力强但计算量较重。对于追求轻量化、部署在资源受限硬件(如 Jetson、手机端、工业相机)的场景,标准卷积带来的参数冗余往往是瓶颈。本文引入来自YOLOv13的DSC3k2将 Bottleneck 内部的标准卷积替换为深度可分离卷积(Depthwise Separable Convolution);提供双模式选择:使用(快速)或DSC3k(更强表达力)作为内部单元。改进前后对比(以配置参数量。

qq_44224801的博客 441

yolov5 C3改进|深度可分离卷积轻量化主干

深度可分离卷积替换主干C3模块

z3447643805的博客 910

YOLOv5改进实战 | 更换主干网络Backbone(四)之轻量化模型MobileNetV3

w94ghz的博客 1482

轻量级残差瓶颈改进YOLOv26深度可分离卷积与通道压缩双重优化

本文详细介绍了基于轻量级残差瓶颈的YOLOv26改进方案。通过深度可分离卷积和通道压缩技术,该方案在显著降低计算复杂度和参数量的同时,保持了良好的检测性能。实验结果表明,改进后的YOLOv26n模型参数量减少19.7%,计算量减少28.2%,推理速度提升37.8%,而精度损失仅为0.7%。轻量级残差瓶颈的成功应用证明了"压缩-提取-恢复"架构在目标检测任务中的有效性。结合跨阶段部分网络的梯度流优化,该方案为边缘设备和移动端应用提供了一个高效的解决方案。

kisshuan12396的博客 330

微信小程序 | 小程序开发

事实上,目前小程序在我们生活中已经随处可见(特别是这次疫情的推动,不管是什么岗位、什么年龄阶段的人,到哪都需要打开健康码)WePY是由腾讯开源的,一款让小程序支持组件化开发的框架,通过预编译的手段让开发者可以选择自己喜欢的开发风格去开发小程序。Mpvue是一个使用Vue开发小程序的前端框架,也是 支持 微信小程序、百度智能小程序,头条小程序 和 支付宝小程序;微信小程序、支付宝小程序、淘宝小程序、抖音小程序、头条小程序、QQ小程序、美团小程序等。,其他平台的小程序往往是平台本身的一些公司或者顺手开发的。

CoderHing的博客~ 1万+

Sigrity Power DC Package Multi-Resistor Compact ET Model Extraction模式提取封装基板电热阻模型

DIE(定义DIE的参数):material设置为silicon(硅),Attach material(贴片的材料,设置为Die Attach),Attach thickness(贴片的材料的厚度,厚度设置为0.001mm,点击ok。Cap为覆盖材料,Material定义材料类型,thickness定义厚度,length和width定义长宽,Adhesive Material为胶的材料,Adhesive Material为胶的厚度,本例不定义,跳过即可。

weixin_54787054的博客 439

105、YOLOv8改进实战:SlimNeck轻量级Neck设计——基于深度可分离卷积的通道压缩策略

本文介绍了一种针对YOLOv8的SlimNeck轻量级Neck设计方法。作者从实际边缘端部署项目中遇到的问题出发,发现标准Neck模块在计算资源受限时性能下降明显。提出的SlimNeck采用深度可分离卷积结合通道压缩策略,在YOLOv8n上实现参数量减少40%的同时仅损失0.5mAP精度。文章详细解析了SlimC2f和SlimBottleneck的代码实现要点,包括通道压缩比例选择、深度卷积参数设置等关键细节,并分享了在Jetson Nano上的实测效果(FPS提升50%)以及训练部署中的实用经验。该方案特

ai技术增长的博客 7

【Unity实战100例】Unity循环UI界面切换卡片功能

功能包括:可以设置半径,高度,速度,元素数量用户可以根据自己的实际需求接入 制作思路:创建每个元素对应的虚拟点,通过旋转管理这些虚拟点,然后把旋转信息和位置信息同步给实际的元素

纯技术流日常开发商业开发记录总结等 7717

[YOLOv7/YOLOv5系列算法改进NO.15]网络轻量化方法深度可分离卷积

​前 言:作为当前先进的深度学习目标检测算法YOLOv5,已经集合了大量的trick,但是还是有提高和改进的空间,针对具体应用场景下的检测难点,可以不同的改进方法。此后的系列文章,将重点对YOLOv5的如何改进进行详细的介绍,目的是为了给那些搞科研的同学需要创新点或者搞工程项目的朋友需要达到更好的效果提供自己的微薄帮助和参考。解决问题:YOLOv5主干特征提取网络采用C3结构,带来较大的参数量,检测速度较慢,应用受限,在某些真实的应用场景如移动或者嵌入式设备,如此大而复杂的模型时难以被应用的。......

m0_70388905的博客 1万+

[RK3568 Android11] 教程之原厂SDK源码适配AIO-3568J板子跑起来

目录 一、前提 二、修改dts设备树 三、适配板子的dts 四、编译系统烧入固件验证 一、前提 因源码是直接使用原厂的SDK,没有使用firefly配套的SDK源码,所以手上这块firefly aio-3568j板子在硬件设计上与原厂使用的板子会有些差异;就是因为这些差异会导致新固件烧入后,debug串口打印许多错误信息,可能的话,系统还会崩溃掉,跑不起来; 主要差异在哪里呢?比如: ● DDR类型和品牌多样性; ...

~未来可期~ 1744

金蝶Apusic应用服务器 未授权目录遍历漏洞复现

由于金蝶Apusic应用服务器/admin/protected/selector/server_file/files、/admin/protected/selector/server_file/folders 等接口没有进行校验和过滤,直接将参数拼接到文件操作中,导致出现目录遍历漏洞,未经身份验证的远程攻击者可通过此漏洞读取系统内部系统文件路径及信息,导致信息泄露,系统处于极不安全状态。

0xSec 2169

目标检测算法——YOLOv5/YOLOv7改进之结合轻量化网络MobileNetV3(降参提速)

深度学习Tricks,第一时间送达。目标检测算法——YOLOv5结合轻量化网络MobileNetV3。

加勒比海带66——【YOLO魔法搭配&论文投稿咨询&Python科研绘图】 2万+

Aurix TC3xx系列MCU DMA模块配置方法(二)

本文主要基于英飞凌Aurix TC3xx系列MCU,通过EB tresos配置工具,介绍DMA驱动模块的配置方法。

m0_38045338的博客 2850

对比yolov5的C3,yolov8的C2f,yolov11的C3k2

C3模块基于CSPNet(Cross Stage Partial Network)思想,由三个卷积层构成,分为两条分支:一条通过多个Bottleneck模块堆叠,另一条直接进行卷积操作,最终将两条分支的特征图拼接后输出。引入轻量化设计,如将第一个卷积的核大小从1x1改为3x3,恢复类似ResNet的Bottleneck结构。:在COCO数据集上,YOLOv11的模型参数比YOLOv8减少22%,同时保持更高的mAP。:通过动态结构和注意力机制,更适合复杂场景的高精度需求,但实现复杂度较高。

weixin_38991876的博客 3911

UEFI 基础教程 (零) - 目录

UEFI 基础教程 (十八) — UEFI Build Process简单分析。UEFI 基础教程 (十五) — 获取UEFI MemoryMap。UEFI 基础教程 (六)   —  PROTOCOL 简单使用。UEFI 基础教程 (十)   —  FileIO 简单使用。UEFI 基础教程 (一)   —  搭建UEFI开发环境。UEFI 基础教程 (九)   —  EVENT 简单使用。UEFI 基础教程 (七)   —  HOB 简单使用。UEFI 基础教程 (八)   —  PCD 简单使用。..

技术联盟 1537

RabbitMQ高级特性 - 生产者消息确认机制

为了保证信息 从生产者 发送到 队列,因此引入了生产者的消息确认机制.通过事务机制实现.通过发送确认机制(confirm 和 return)实现.因为事务机制比较消耗性能,在实际工作中用的也不多,因此这里主要介绍confirm 和 return机制来实现发送放的确认.a)confirm 确认模式如上图,confirm 确认模式主要保障于 生产者 到 交换机 的消息可靠性.如果 Exchange成功收到消息,那么 ConfirmCallback 这个回调 ack 参数就为true。

CYK_byte的博客 1886

【YOLOv7/YOLOv5系列算法改进NO.49】模型剪枝、蒸馏、压缩

网络模型轻量化方法之剪枝、蒸馏、压缩,适应于需要轻量化模型对检测速度有要求的朋友。

m0_70388905的博客 1万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Yolov8相对Yolov5的改进跟优化

YOLOv8 通过架构创新和训练策略优化,显著提升了模型性能,同时保持了 YOLO 系列的高效率特性,是目前更推荐的主流选择。C2f 通过增加跨层连接和更多的分支结构,提升了特征提取能力,同时减少了计算量。Backbone 和 Neck 的深度增加,通过更复杂的特征融合提升检测精度,尤其是在小目标和密集场景中。(任务对齐分配器),动态分配正负样本,替代 YOLOv5 的静态分配策略,提升训练效率。支持基于无标签数据的预训练(如 DETR 风格的预训练),提升小数据集上的表现。

weixin_38991876的博客 3871

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

YOLOv5改进 | 模块缝合 | C3融合RVB提升检测性能【完整代码】

YOLOv5改进,融合改进,C3-RVB

kay_545 2141

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

【YOLOv7改进系列】引入YOLOv5的C3模块

C3模块的第二阶段使用深度可分离的膨胀卷积,扩大了感受野,增强了全局一致性。:C3模块采用两阶段设计,首先使用深度方向的非对称卷积来收集并压缩相邻像素的信息,减轻由于膨胀卷积造成的局部信息丢失问题。总之,C3模块通过创新的结构设计,有效融合了深度可分离卷积和膨胀卷积的优点,实现了轻量化模型设计中的一个关键突破,同时保持了分割和分类任务的高性能表现。:除了语义分割,C3模块还被应用于ImageNet分类任务,展示出替换膨胀卷积并维持或提升性能的能力,进一步验证了其作为深度学习基本构建块的潜力。

2401_84870184的博客 1139
上一篇: 阅读笔记7——Focal Loss
下一篇: 阅读笔记8——NMS
晓shuo
晓shuo 优质创作者: 人工智能技术领域 优质创作者: 人工智能技术领域
博客等级 码龄6年 4万+粉丝 113原创
评论 46
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓shuo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值