位置: 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远程协助灰色)

  • airpods左右耳音量不一样怎么调(airpods左右耳音量不一样正常吗)

    airpods左右耳音量不一样怎么调(airpods左右耳音量不一样正常吗)

  • 微信消息显示更多怎么全部显示(微信消息显示更多信息)

    微信消息显示更多怎么全部显示(微信消息显示更多信息)

  • 怎么用蓝牙耳机连接电脑(电脑怎么用蓝牙耳机)

    怎么用蓝牙耳机连接电脑(电脑怎么用蓝牙耳机)

  • 苹果11铃声如何设置自己的歌(苹果11铃声如何设置渐强)

    苹果11铃声如何设置自己的歌(苹果11铃声如何设置渐强)

  • 以太网的接口类型是什么(以太网接口包括)

    以太网的接口类型是什么(以太网接口包括)

  • 惠普光影精灵5和暗影精灵5的区别 (惠普光影精灵5多少钱)

    惠普光影精灵5和暗影精灵5的区别 (惠普光影精灵5多少钱)

  • 公众号保存的文章在哪里(公众号保存文章)

    公众号保存的文章在哪里(公众号保存文章)

  • 高清是1080p吗(高清好还是1080p哪个清楚)

    高清是1080p吗(高清好还是1080p哪个清楚)

  • 手机wps语音朗读不见了(手机wps语音朗读怎么换声音)

    手机wps语音朗读不见了(手机wps语音朗读怎么换声音)

  • 华为畅享11plus什么时候上市(畅享11plus参数)

    华为畅享11plus什么时候上市(畅享11plus参数)

  • 微信对方忙会收到提示吗(微信对方忙对方那边会显示么)

    微信对方忙会收到提示吗(微信对方忙对方那边会显示么)

  • 苹果手机会不会被别人监控(苹果手机会不会爆炸)

    苹果手机会不会被别人监控(苹果手机会不会爆炸)

  • ipad关机充电自动开机怎么回事(ipad关机时充电)

    ipad关机充电自动开机怎么回事(ipad关机时充电)

  • ipad充不进电怎么回事开不了机(iPad充不进电怎么回事)

    ipad充不进电怎么回事开不了机(iPad充不进电怎么回事)

  • 苹果7如何拍全景照片(苹果如何拍全屏照片)

    苹果7如何拍全景照片(苹果如何拍全屏照片)

  • 怎么用手机给乐视电视按软件(怎么用手机给乐高充电)

    怎么用手机给乐视电视按软件(怎么用手机给乐高充电)

  • 快手反名是什么意思(快手反名是什么意思啊)

    快手反名是什么意思(快手反名是什么意思啊)

  • 魅族隐私模式怎么关闭(魅族隐私模式怎么找不到了)

    魅族隐私模式怎么关闭(魅族隐私模式怎么找不到了)

  • 苹果笔一代和二代区别(苹果笔一代和二代笔头一样吗)

    苹果笔一代和二代区别(苹果笔一代和二代笔头一样吗)

  • 苹果手机怎么调声音(苹果手机怎么调震动和静音)

    苹果手机怎么调声音(苹果手机怎么调震动和静音)

  • 淘宝查号怎么查(淘宝查号查出狐狸是什么意思)

    淘宝查号怎么查(淘宝查号查出狐狸是什么意思)

  • iphonex支持5g吗(苹果x支持5g嘛?)

    iphonex支持5g吗(苹果x支持5g嘛?)

  • 怎么检查苹果手机是不是新机(怎么检查苹果手机有没有被监控)

    怎么检查苹果手机是不是新机(怎么检查苹果手机有没有被监控)

  • iphone6拍照技巧(iphone6拍照使用技巧)(苹果6拍照如何)

    iphone6拍照技巧(iphone6拍照使用技巧)(苹果6拍照如何)

  • 北京市增值税发票
  • 小规模纳税人起征点和免征额
  • 资源税应该如何计算
  • 资管产品增值税由谁承担
  • 增值税应纳税额是要交的钱吗
  • 我公司租了个人的房子如何入账
  • 服务费的增值税怎么算
  • 租厂房需要交租赁税吗
  • 注册资本余额为100万亿元
  • 测绘费能否在土地出让
  • 票据和结算凭证上的签章
  • 外汇结款怎么办理
  • 上一年度凭证不填可以吗
  • 企业付装修费怎么入账
  • 股票转让所得不交增值税
  • 转账支票背书有时间限制吗
  • 定额发票上盖什么章
  • 商砼税收政策
  • 学校需要开发票吗,学校的纳税人识别号是什么?
  • 啤酒消费税的计税基础
  • 固定资产报废处置账务处理
  • 停车费属于不动产租赁服务税率
  • 营改增一般纳税人申请过渡性财政扶持资金
  • 现金折扣税务会计
  • 总部员工调往下属单位
  • 公允价值上升是收益还是损失
  • 期初未缴税额和期末未缴税额
  • 公司处置车辆税金怎么算
  • 备抵法计提坏账准备的公式
  • 去年的管理费用怎么冲
  • 礼品应该计入会计分录
  • 苹果14出来13会下架吗
  • php strlen函数和mb_strlen
  • 银行存款调账怎么调
  • 客户尾款不付会计分录
  • PHP:pcntl_setpriority()的用法_PCNTL函数
  • 如何区分货币财富和收入
  • 消费税的会计分录怎么写
  • 委托开发软件如何入账
  • 阿里云搭建hexo
  • 本地部署stable diffusion需要什么显卡
  • timit数据集
  • java pdf生成工具
  • spring bootcsdn
  • 土地出让金返还比例是多少
  • 使用的拼音
  • php解释器工作流程
  • phpcms怎么用
  • 付报刊费计入什么科目
  • 未确认融资费用怎么算
  • js array()
  • 土地被政府收回会计分录
  • 车辆保险费怎么入账
  • mongodb 分组计数
  • python中with语句的用法
  • 筹建养老院国家有哪些优惠政策?
  • 所得税汇算清缴退税会计分录怎么做
  • 年收益率与年化利率是一样?
  • 开出商业承兑汇票怎么做分录
  • 限定性和非限定性资产
  • 企业职工薪酬如何确定
  • 培训费产生的差额怎么算
  • mysql 5.7.18 winx64 免安装 配置方法
  • 涌泉的准确位置图 图解
  • vidaa 破解
  • windows命令提示符命令大全
  • win8换win10系统步骤
  • ubuntu系统怎么用
  • win xp 内存
  • linux终端有哪些
  • win7报错0xc0000428
  • 安装音乐库
  • jquery.parsejson
  • javascript面向对象编程
  • jQuery ajax的功能实现方法详解
  • listview的item
  • unity获取手机型号
  • 安卓手机管家删除的照片怎么恢复
  • 事业单位录用备案表审核快吗
  • 国家税务总局每家公司都可以注册吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设