yolov5使用

2023-11-05

参考网址:https://zhuanlan.zhihu.com/p/501798155

源码下载及使用

release下载source及pt文件(yolov5s.pt)
https://github.com/ultralytics/yolov5/tags
https://github.com/ultralytics/yolov5/releases/tag/v5.0

安装yolov5训练所需的第三方库
1. 安装anaconda,版本conda -V 进入yolo5目录下 cd [path_to_yolov5]
2. 新建虚拟环境 conda create -n yolov5GPU python=3.7 -y
3. 激活虚拟环境 conda activate yolov5GPU
4. pip install -r requirements.txt
5. 将xx.pt复制在yolov5文件夹下
6. PyCharm打开yolov5源码,File->Settings->Project:yolov5-5.0->Python Interpreter->Add->Conda Enviroment->Existing environment (D:\ProgramData\Anaconda3\envs\yolov5\python.exe),保存后,右下角显示Python3.7(yolo5)
7. PyCharm运行detect.py,提示错误 AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
进入 D:\ProgramData\Anaconda3\envs\yolov5\lib\site-packages\torch\nn\modules\upsampling.py 行号:155 编辑并保存
def forward(self, input: Tensor) -> Tensor:
#return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
# recompute_scale_factor=self.recompute_scale_factor)
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)

train时,提示错误 
问题1:AssertionError: Label class 1 exceeds nc=1 in data/fire.yaml. Possible class labels are 0-0
解决:注释掉train.py中的一行代码 #assert mlc < nc, 'Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g' % (mlc, nc, opt.data, nc - 1)

问题2:
Traceback (most recent call last):
File "G:/yolov/yolov5-5.0/train.py", line 543, in <module>
train(hyp, opt, device, tb_writer)
File "G:/yolov/yolov5-5.0/train.py", line 304, in train
loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size
File "G:\yolov\yolov5-5.0\utils\loss.py", line 117, in __call__
tcls, tbox, indices, anchors = self.build_targets(p, targets) # targets
File "G:\yolov\yolov5-5.0\utils\loss.py", line 211, in build_targets
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices
RuntimeError: result type Float can't be cast to the desired output type __int64

解决:loss.py 行号:1136

for i in range(self.nl):
            anchors, shape = self.anchors[i], p[i].shape
            gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]]  # xyxy gain
 
            # Match targets to anchors
            t = targets * gain  # shape(3,n,7)
            if nt:
                # Matches
                r = t[..., 4:6] / anchors[:, None]  # wh ratio
                j = torch.max(r, 1 / r).max(2)[0] < self.hyp['anchor_t']  # compare
                # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t']  # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2))
                t = t[j]  # filter
 
                # Offsets
                gxy = t[:, 2:4]  # grid xy
                gxi = gain[[2, 3]] - gxy  # inverse
                j, k = ((gxy % 1 < g) & (gxy > 1)).T
                l, m = ((gxi % 1 < g) & (gxi > 1)).T
                j = torch.stack((torch.ones_like(j), j, k, l, m))
                t = t.repeat((5, 1, 1))[j]
                offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j]
            else:
                t = targets[0]
                offsets = 0
 
            # Define
            bc, gxy, gwh, a = t.chunk(4, 1)  # (image, class), grid xy, grid wh, anchors
            a, (b, c) = a.long().view(-1), bc.long().T  # anchors, image, class
            gij = (gxy - offsets).long()
            gi, gj = gij.T  # grid indices
 
            # Append
            indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1)))  # image, anchor, grid
            tbox.append(torch.cat((gxy - gij, gwh), 1))  # box
            anch.append(anchors[a])  # anchors
            tcls.append(c)  # class

return tcls, tbox, indices, anch

测试:
conda activate yolov5GPU
python detect.py --weights yolov5s.pt --source data/images/bus.jpg # 测试结果保存在runs/detect

conda activate yolov5GPU
python detect.py --weights yolov5s.pt --source test.mp4

自己训练模型

1.收集数据集(image/train/001.jpg)

dataset #(数据集名字:例如fire) 
├── images      
       ├── train          
              ├── xx.jpg     
       ├── val         
              ├── xx.jpg 
├── labels      
       ├── train          
              ├── xx.txt     
       ├── val         
              ├── xx.txt 

2.标注数据集(label/train/001.txt),可使用yolov5目标识别实现半自动化标注,用labelimg进行校验

3.训练数据集(weight/best.pt),在yaml文件内不要使用中文

yolov5-5.0/data/fire.yaml

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: G:\yolov\datasets\fire  # dataset root dir
train: G:\yolov\datasets\fire\images\train  # train images (relative to 'path')
val: G:\yolov\datasets\fire\images\val  # val images (relative to 'path')
test:  # test images (optional)

# Classes
nc: 1  # number of classes
names: ['fire']  # class names

yolov5-5.0/data/catdog.yaml

path: ../datasets/catdog
train: ../datasets/catdog/images/train
val: ../datasets/catdog/images/val

# Classes
nc: 2
names: ['cat', 'dog']

yolov5-5.0/models/yolov5s_catdog.yaml

修改 nc :2

python train.py --weights yolov5s.pt --data data/fire.yaml --workers 1 --batch-size 8 

python train.py --img 640 --batch 16 --epochs 300 --data ./data/catdog.yaml --cfg ./models/yolov5s_catdog.yaml --weights ./weights/yolov5s.pt --device 0

4.模型测试,目标检测(objname=people;potion=box_l, box_t, box_r, box_b;confidence=0.6;name=29)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

yolov5使用 的相关文章

随机推荐

  • QSettings读取int文件解析失败

    问题 QSettings解析失败 ini文件如下 System name CPMS with IIoT by R Campro Precision Machinery Co Ltd gs sys id CAMPRO gs cod csub
  • AI引擎助力,CamScanner智能高清滤镜开启扫描新纪元!

    文章目录 写在前面 突破图像处理难点 扫描全能王的独特优势 耳听为虚 眼见为实 产品背后的主要核心 AI Scan助力 深度学习助力智能文档处理的国际化进程 品味智能文档处理的轻松与精准 写在前面 在数字化快速发展的今天 我们时常会遇到需要
  • 产品经理漫谈四

    每几天一篇 业界学习知识分享 请关注 如有同感请加vip阅读 产品经理如何给足一线 渠道 区域销售足够信心 思考 人性 商业 利益共同体 尊重时效 尊重承诺 价值方向 行业动态符合 具有更大兼容性 服务体系建立 笔者认为 除了产品包含市场方
  • 芯片验证从零开始系列(三)——SystemVerilog的连接设计和测试平台

    芯片验证从零开始系列 三 SystemVerilog的连接设计和测试平台 接口interface modport 验证环境结构 激励发生器 监测器 检测器 测试平台和设计间的竞争原因 断言 总结 声明 未经作者允许 禁止转载 推荐一个IC
  • AD域服务器下如何批量创建用户及修改AD域的最大返回条目数。

    最近在用户现场遇到一个问题就是通过ldap导入用户 发现导入失败 经过分析得知是AD域服务器设置的最大返回条目数默认为1000 当数据超过1000 通过ldap search s获取数据时就会异常 通过抓包分析得知是 报文回复不全导致无法解
  • 史上最全 App功能测试点分析

    1 2测试周期 测试周期可按项目的开发周期来确定测试时间 一般测试时间为两三周 即 15个工作日 根据项目情况以及版本质量可适当缩短或延长测试时间 正式测试前先向主管确认项目排期 1 3测试资源 测试任务开始前 检查各项测试资源 产品功能需
  • [k8s]笔记01

    1 k8s是什么 k8s是一套自动化容器运维的开源平台 2 k8s可以做什么 能在物理机或虚拟集群上调度和运行程序容器 快速精准地部署应用程序 即时伸缩应用程序 无缝展现新特征 限制硬件用量仅为所需资源 3 k8s概念 1 Cluster集
  • java8新特性从入门到应用 第二章 Streams数据流

    java8新特性从入门到应用 第二章 Stream 数据流 特点介绍 Stream组成 源 中间操作 筛选与切片 映射 排序 Stream的终止操作 查找与匹配 归约 收集 Collector 接口API 此流非彼流 估计第一眼看到这个标题
  • springboot定时任务出错 Unexpected use of scheduler.

    最近在使用springboot的定时器写定时任务时 项目启动就会报以下的错误 java lang IllegalStateException Unexpected use of scheduler 困扰了很久 因为以前也写过定时器 但没遇到
  • 北大硕士7年嵌入式学习经验分享

    大家现在状态是怎么样的 这几年技术进步怎么样 职场晋升 管理水平有没有提升 欢迎留言 本文内容来自于知乎 觉得内容很不错 分享给大家 下文的我代表的是原作者 作者 梦人亦冷 链接 https www zhihu com question 3
  • ip地址0.0.0.0与127.0.0.1的区别

    最近在项目开发中发现一个奇怪的问题 当服务器与客户端在同一台机器上时 用服务器ip 本地主机ip 192 168 1 xxx 127 0 0 1以及0 0 0 0都能登陆服务器 于是找点资料研究一下 其实 最开始是发现服务器ip填0能登陆成
  • MyBatis框架搭建及教程(详解)

    MyBatis文章目录 Mybatis框架的搭建以及使用教程 目录 简介 一 MyBatis框架搭建步骤 1 1 配置XML 1 2 编写MyBatis框架核心配置文件 1 3 创建实体类 1 4 创建Mapper接口 1 5 创建SQL映
  • doesnt exist table_MYSQL ERROR 1146 Table doesnt exist 解析

    原创转载请注明出处 源码版本 5 7 14 在MYSQL使用innodb的时候我们有时候会看到如下报错 ERROR 1146 42S02 Table test test1bak doesn t exist 首先总结下原因 缺少frm文件 i
  • Mybatis映射文件中动态sql语句

    目录 Mybatis映射文件深入 动态sql语句 官方文档中动态sql 动态SQL之if 测试示例if 动态sql之foreach 测试示例foreach sql片段的抽取 Mybatis映射文件深入知识小结 Mybatis映射文件深入 动
  • 分段,分页与段页式存储管理

    一 分页存储管理 1 基本思想 用户程序的地址空间被划分成若干固定大小的区域 称为 页 相应地 内存空间分成若干个物理块 页和块的大小相等 可将用户程序的任一页放在内存的任一块中 实现了离散分配 1 等分内存 页式存储管理将内存空间划分成等
  • Go 定时器(timer)

    创建一个定时器 package main import fmt time func main timer time NewTimer time Second 3 3秒定时器 fmt Printf timertype timer fmt Pr
  • Mysql 8配置驱动

    1 依赖的注入 spring datasource url jdbc mysql localhost 3306 你的数据库名 useUnicode true characterEncoding utf 8 serverTimezone As
  • SpringBoot中的注解@SpringBootApplication和(@Configuration......)

    以下选自官方的文档 这里写链接内容 Many Spring Boot developers always have their main class annotated with Configuration EnableAutoConfig
  • Ping报文分析

    打开Windows虚拟 执行ipconfig的操作 用Kali执行Ping操作 并用Kali自带wireshark分析 可以看到Ping报文发送的是ICMP数据报文 通过网上查阅资料可知 ICMP报头格式 ICMP报文包含在IP数据报中 I
  • yolov5使用

    参考网址 https zhuanlan zhihu com p 501798155 源码下载及使用 release下载source及pt文件 yolov5s pt https github com ultralytics yolov5 ta