位置: IT常识 - 正文

YOLOv5 6.0/6.1结合ASFF(yolov5 教程)

编辑:rootadmin
YOLOv5 6.0/6.1结合ASFF

推荐整理分享YOLOv5 6.0/6.1结合ASFF(yolov5 教程),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:yolov2结构,yolov2结构,yolov5结构解析,yolov5结构解析,yolov5结构解析,yolov3.cfg,yolov5搭建,yolov5 教程,内容如对您有帮助,希望把文章链接给更多的朋友!

YOLOv5 6.0/6.1结合ASFF

前言

YOLO小白纯干货分享!!!

一、主要修改代码YOLOv5 6.0/6.1结合ASFF(yolov5 教程)

二、使用步骤1. models/common.py:加入要修改的代码, 类ASFFV5 class ASFFV5(nn.Module): class ASFFV5(nn.Module): def __init__(self, level, multiplier=1, rfb=False, vis=False, act_cfg=True): """ ASFF version for YoloV5 only. Since YoloV5 outputs 3 layer of feature maps with different channels which is different than YoloV3 normally, multiplier should be 1, 0.5 which means, the channel of ASFF can be 512, 256, 128 -> multiplier=1 256, 128, 64 -> multiplier=0.5 For even smaller, you gonna need change code manually. """ super(ASFFV5, self).__init__() self.level = level self.dim = [int(1024*multiplier), int(512*multiplier), int(256*multiplier)] #print("dim:",self.dim) self.inter_dim = self.dim[self.level] if level == 0: self.stride_level_1 = Conv(int(512*multiplier), self.inter_dim, 3, 2) #print(self.dim) self.stride_level_2 = Conv(int(256*multiplier), self.inter_dim, 3, 2) self.expand = Conv(self.inter_dim, int( 1024*multiplier), 3, 1) elif level == 1: self.compress_level_0 = Conv( int(1024*multiplier), self.inter_dim, 1, 1) self.stride_level_2 = Conv( int(256*multiplier), self.inter_dim, 3, 2) self.expand = Conv(self.inter_dim, int(512*multiplier), 3, 1) elif level == 2: self.compress_level_0 = Conv( int(1024*multiplier), self.inter_dim, 1, 1) self.compress_level_1 = Conv( int(512*multiplier), self.inter_dim, 1, 1) self.expand = Conv(self.inter_dim, int( 256*multiplier), 3, 1) # when adding rfb, we use half number of channels to save memory compress_c = 8 if rfb else 16 self.weight_level_0 = Conv( self.inter_dim, compress_c, 1, 1) self.weight_level_1 = Conv( self.inter_dim, compress_c, 1, 1) self.weight_level_2 = Conv( self.inter_dim, compress_c, 1, 1) self.weight_levels = Conv( compress_c*3, 3, 1, 1) self.vis = vis def forward(self, x_level_0, x_level_1, x_level_2): #s,m,l """ # 128, 256, 512 512, 256, 128 from small -> large """ # print('x_level_0: ', x_level_0.shape) # print('x_level_1: ', x_level_1.shape) # print('x_level_2: ', x_level_2.shape) x_level_0=x[2] x_level_1=x[1] x_level_2=x[0] if self.level == 0: level_0_resized = x_level_0 level_1_resized = self.stride_level_1(x_level_1) level_2_downsampled_inter = F.max_pool2d( x_level_2, 3, stride=2, padding=1) level_2_resized = self.stride_level_2(level_2_downsampled_inter) #print('X——level_0: ', level_2_downsampled_inter.shape) elif self.level == 1: level_0_compressed = self.compress_level_0(x_level_0) level_0_resized = F.interpolate( level_0_compressed, scale_factor=2, mode='nearest') level_1_resized = x_level_1 level_2_resized = self.stride_level_2(x_level_2) elif self.level == 2: level_0_compressed = self.compress_level_0(x_level_0) level_0_resized = F.interpolate( level_0_compressed, scale_factor=4, mode='nearest') x_level_1_compressed = self.compress_level_1(x_level_1) level_1_resized = F.interpolate( x_level_1_compressed, scale_factor=2, mode='nearest') level_2_resized = x_level_2 # print('level: {}, l1_resized: {}, l2_resized: {}'.format(self.level, # level_1_resized.shape, level_2_resized.shape)) level_0_weight_v = self.weight_level_0(level_0_resized) level_1_weight_v = self.weight_level_1(level_1_resized) level_2_weight_v = self.weight_level_2(level_2_resized) # print('level_0_weight_v: ', level_0_weight_v.shape) # print('level_1_weight_v: ', level_1_weight_v.shape) # print('level_2_weight_v: ', level_2_weight_v.shape) levels_weight_v = torch.cat( (level_0_weight_v, level_1_weight_v, level_2_weight_v), 1) levels_weight = self.weight_levels(levels_weight_v) levels_weight = F.softmax(levels_weight, dim=1) fused_out_reduced = level_0_resized * levels_weight[:, 0:1, :, :] +\ level_1_resized * levels_weight[:, 1:2, :, :] +\ level_2_resized * levels_weight[:, 2:, :, :] out = self.expand(fused_out_reduced) if self.vis: return out, levels_weight, fused_out_reduced.sum(dim=1) else: return out2. models/yolo.py:添加 类ASFF_Detect

然后在yolo.py 中 Detect 类下面,添加一个ASFF_Detect类

class ASFF_Detect(nn.Module): #add ASFFV5 layer and Rfb stride = None # strides computed during build export = False # onnx export def __init__(self, nc=80, anchors=(), multiplier=0.5,rfb=False,ch=()): # detection layer super(ASFF_Detect, self).__init__() self.nc = nc # number of classes self.no = nc + 5 # number of outputs per anchor self.nl = len(anchors) # number of detection layers self.na = len(anchors[0]) // 2 # number of anchors self.grid = [torch.zeros(1)] * self.nl # init grid self.l0_fusion = ASFFV5(level=0, multiplier=multiplier,rfb=rfb) self.l1_fusion = ASFFV5(level=1, multiplier=multiplier,rfb=rfb) self.l2_fusion = ASFFV5(level=2, multiplier=multiplier,rfb=rfb) a = torch.tensor(anchors).float().view(self.nl, -1, 2) self.register_buffer('anchors', a) # shape(nl,na,2) self.register_buffer('anchor_grid', a.clone().view(self.nl, 1, -1, 1, 1, 2)) # shape(nl,1,na,1,1,2) self.m = nn.ModuleList(nn.Conv2d(x, self.no * self.na, 1) for x in ch) # output conv

接着在 yolo.py的parse_model 中把函数放到模型的代码里: (大概在283行左右)

if m in [Conv, GhostConv, Bottleneck, GhostBottleneck, SPP, DWConv, MixConv2d, Focus, CrossConv, BottleneckCSP,CBAM,ResBlock_CBAM, C3]: c1, c2 = ch[f], args[0] if c2 != no: # if not output c2 = make_divisible(c2 * gw, 8) args = [c1, c2, *args[1:]] if m in [BottleneckCSP, C3]: args.insert(2, n) # number of repeats n = 1 elif m is nn.BatchNorm2d: args = [ch[f]] elif m is Concat: c2 = sum([ch[x] for x in f]) elif m is ASFF_Detect: args.append([ch[x] for x in f]) if isinstance(args[1], int): # number of anchors args[1] = [list(range(args[1] * 2))] * len(f) elif m is Contract: c2 = ch[f] * args[0] ** 2 elif m is Expand: c2 = ch[f] // args[0] ** 2 elif m is ASFFV5: c2=args[1] else: c2 = ch[f]3.models/yolov5s-asff.yaml

在models文件夹下新建对应的yolov5s-asff.yaml 文件 然后将yolov5s.yaml的内容复制过来,将 head 部分的最后一行进行修改; 将[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) ] 修改成下面:

[[17, 20, 23], 1, ASFF_Detect, [nc, anchors]], # Detect(P3, P4, P5) ]4.查看网络结构

修改 models/yolo.py --cfg models/yolov5s-asff.yaml 接下来run yolo.py 即可查看网络结构

5.将train.py 中 --cfg中的 yaml 文件修改成本文文件即可,开始训练总结

本人在多个数据集上做了大量实验,针对不同的数据集效果不同,需要大家进行实验。有效果有提升的情况占大多数。

最后,希望能互粉一下,做个朋友,一起学习交流。

本文链接地址:https://www.jiuchutong.com/zhishi/300716.html 转载请保留说明!

上一篇:2022年微信小程序授权登录的最新实现方案(2022年微信小程序游戏)

下一篇:【windows Server 2019系列】 构建IIS服务器(windowsserver2012r2远程协助灰色)

  • 拼多多怎么隐藏个人信息(拼多多怎么隐藏手机号和姓名)

    拼多多怎么隐藏个人信息(拼多多怎么隐藏手机号和姓名)

  • xrxsmax区别(xr,xsmax哪个好)

    xrxsmax区别(xr,xsmax哪个好)

  • 荣耀30青春版的像素是多少(荣耀30青春版的膜和别的型号通用)

    荣耀30青春版的像素是多少(荣耀30青春版的膜和别的型号通用)

  • iphonex顶部红点闪烁(iphone小红点)

    iphonex顶部红点闪烁(iphone小红点)

  • 苹果11开箱带膜吗(苹果11带不带膜)

    苹果11开箱带膜吗(苹果11带不带膜)

  • 代码28是什么驱动(win10代码28是什么驱动)

    代码28是什么驱动(win10代码28是什么驱动)

  • vivo什么意思中文意思(vivo是什么意)

    vivo什么意思中文意思(vivo是什么意)

  • 计算机网络病毒来源(计算机网络病毒的传播途径)

    计算机网络病毒来源(计算机网络病毒的传播途径)

  • 表格不能筛选的原因(excle表格筛选)

    表格不能筛选的原因(excle表格筛选)

  • 怎样设置收款语音播报(怎样设置收款语音音响功能)

    怎样设置收款语音播报(怎样设置收款语音音响功能)

  • 国内通用流量包是什么(国内通用流量包括澳门吗)

    国内通用流量包是什么(国内通用流量包括澳门吗)

  • 电脑睡眠还会继续下载吗(电脑睡眠还会继续渲染吗)

    电脑睡眠还会继续下载吗(电脑睡眠还会继续渲染吗)

  • 相机中iso是什么意思(相机iso是什么功能)

    相机中iso是什么意思(相机iso是什么功能)

  • iphonex电池容量多大(iphonexs电池容量)

    iphonex电池容量多大(iphonexs电池容量)

  • 逗拍怎么制作视频(逗拍怎么制作抖音视频)

    逗拍怎么制作视频(逗拍怎么制作抖音视频)

  • 手机没有卡能上微信吗(手机没有卡能上网吗怎么办)

    手机没有卡能上微信吗(手机没有卡能上网吗怎么办)

  • 手机垃圾怎么清理干净(手机垃圾怎么清除干净)

    手机垃圾怎么清理干净(手机垃圾怎么清除干净)

  • 怎么举报主播让他封号(怎么举报主播让别人看到)

    怎么举报主播让他封号(怎么举报主播让别人看到)

  • 苹果11pro max双卡双待怎么设置(苹果11promax双卡双待吗)

    苹果11pro max双卡双待怎么设置(苹果11promax双卡双待吗)

  • iphone11耳机是无线耳机吗(苹果11耳机有线还是无线)

    iphone11耳机是无线耳机吗(苹果11耳机有线还是无线)

  • p30pro发布会时间(华为p30pro发布时间和上市时间)

    p30pro发布会时间(华为p30pro发布时间和上市时间)

  • 苹果8有animoji表情吗(iphone8可以用手表解锁吗)

    苹果8有animoji表情吗(iphone8可以用手表解锁吗)

  • x27是5g手机吗(vivox27是不是5g)

    x27是5g手机吗(vivox27是不是5g)

  • 内存条2400和3000区别(内存条2400和3000差别大吗)

    内存条2400和3000区别(内存条2400和3000差别大吗)

  • Win10 21H2 Build 21354 ISO 太阳谷官方镜像预览版下载

    Win10 21H2 Build 21354 ISO 太阳谷官方镜像预览版下载

  • CSS 实现文字渐变色(css字体设置渐变色)

    CSS 实现文字渐变色(css字体设置渐变色)

  • 个人所得税申报操作流程
  • 交个税步骤
  • 预收账款期末余额计算公式
  • 收到发票未收到款
  • 新车检测费能入什么科目
  • 专家评审费属于劳务费吗
  • 支付外国公司费用要交税吗
  • 资本公积可以随时撤出来吗
  • 企业出资怎么填写
  • 基建贷款贴息账户有哪些
  • 总分类一般采用什么格式
  • 物业用房的装修费可以在土地增值税清算时扣除吗
  • 增值税普票没有校验码
  • 汽车违章罚款在哪里缴纳
  • 一般纳税人的主表
  • 多认证的增值税怎么处理
  • 科技型中小企业怎么认定
  • 收到进项税额发票怎么处理
  • 腾讯手游助手使命召唤怎么滑铲
  • 价外费用含义
  • 股票股利和现金股利的共同点
  • mac dash
  • 土地使用税的税目写什么
  • 农产品核定扣除办法
  • php数组实现原理
  • zend framework手册
  • 员工宿舍装宽带
  • css样式修改
  • javascript高阶
  • 售后租回交易的第二年利息怎么算
  • 燃气管道安装费和暖气管道安装费两个的欠条怎么写
  • mongodb bi
  • dedecms配置
  • python中的参数传递
  • 三免三减半递延所得税案例
  • 修理费账务处理
  • 数据库镜像是什么意思
  • 往来会计和应收应付有什么区别
  • 兼职会计人员的职责
  • 小规模纳税人申报增值税的操作流程
  • 不满足收入确认条件的会计分录
  • 什么是现金什么是现金流
  • 合并报表抵消分录的基本原理
  • 法人可以是办税人员吗
  • 城市维护建设税的计税依据
  • 构建固定资产的借款利息资本化文件依据
  • 长期借款利息计入应付利息吗
  • 企业购入投资性房地产
  • 非限定性净资产 限定性净资产
  • 季度初资产总额怎么算
  • 公司收到劳务发票交个税吗
  • 企业建账前应考虑什么
  • 物业管理企业应按职工工资总额的1.5%计提工会经费
  • 触发器中instead of
  • Xp系统的桌面文件在哪里
  • macbookair怎么开启
  • linux清屏幕命令
  • 2016年最火的歌曲排行前100首
  • xp开机提示explorer
  • windows屏幕上有多个窗口时
  • parallel capacitor
  • 电脑开机后出现win7画面后一直黑屏
  • PHP 7.0.0 Alpha 2 发布
  • cocos3d物理引擎
  • 用python三角形
  • cocos js
  • vs开发web教程
  • Ext JS 4官方文档之三 -- 类体系概述与实践
  • js最简单的代码
  • jquery图片效果
  • python相似模块用例
  • python jsonp
  • android设计模式与最佳实践 电子版
  • 国家税务局网站发票验真伪
  • 小规模纳税人开专票
  • 江西国家税务局官网
  • 江之都财税服务集团有限公司地址
  • 定额发票怎么入账
  • 入职培训结束寄语
  • 国税合并地税
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设