当前位置:网站首页>YOLOv7模型推理和训练自己的数据集
YOLOv7模型推理和训练自己的数据集
2022-07-25 06:48:00 【lc_MVP】
前段时间YOLOv7发布,一直没时间去复现,今天正好有时间,简单复现下。
1.必要环境
我的环境是:Windows10+python3.9.7+CUDA11.1+CUDNN8.1.1+torch1.8。此环境配置不再多说,网上有很多的教程。本篇主要记录YOLOv7的使用。
2.YOLOv7安装
2.1进入github官网下载源码和权重文件:
https://github.com/WongKinYiu/yolov7
2.2打开工程,在终端输入命令,安装依赖包
pip install -r requirements.txt我这边在安装依赖包时没有发生错误,若发生错误,请自行百度
3.使用YOLOv7官方模型进行推理

打开detect.py文件,修改权重文件的路径,以及修改推理图片的路径。右键运行就ok,结果会在runs/detect中展现
推理结果十分优异,远超YOLOX的性能。
4.训练自己的数据集
首先工程文件夹设置:

将图片放入images中,xml文件放入Annotations。
先使用txt_write.py文件划分数据集。该文件内容参考本人另一篇YOLOX文章中。
其次使用txt_yolo_label.py文件,数据集转换到yolo数据集格式,转换后可以看到VOCData/labels下生成了每个图的txt文件 。

接着修改cfg/training中你下载的对应模型的yaml文件,我这边下载的yolov7.pt文件,在此更改yolov7.yaml文件,将nc数量变为自己数据集中对应的种类数。

再在data文件夹中备份一份coco.yaml文件,重命名为myvocdataset.yaml,将内容改为如图,其中路径记得改为自己的路径。
train: E:/python_practice/object_detection/yolov7-main/VOC/train.txt
val: E:/python_practice/object_detection/yolov7-main/VOC/val.txt
nc: 2 #类别,改成自己的
names: ['screen','sign']#类别名称
紧接着打开train.py文件,修改如下项:

从上到下,依次是权重文件,cfg配置文件,voc数据文件,超参数文件,和训练轮数。超参数可不修改,其他改为自己所对应的文件。batch-size依据电脑实力更改,我这边配置一般,batch较小,建议将dataloader workers默认设为0,关闭其多线程处理。点击右键运行该文件,程序完美运行。

如出现如下错误:
Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.在train.py中添加如下代码:
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'为了演示yolov7算法,在此就训练了两轮便停止训练,使用训练两轮的模型进行推理。结果如图。

因为只训练了两轮,效果很差,仅识别出框。
到此,YOLOv7复现完成。
边栏推荐
- Restrict Su command and sudo mechanism to promote nmap and console command netstat
- Ant design input search box listens for allowclear event separately
- MySQL remote login
- In container multicast
- 使用 Web API 上传和下载多个文件
- Koa2 learning
- labelme标注不同物体显示不同颜色以及批量转换
- Create a new STM32 project and configure it - based on registers
- 【知识总结】分块和值域分块
- The most comprehensive multi-threaded application tutorial - summary in detail
猜你喜欢

10分钟看懂Jmeter 是如何玩转 redis 数据库的

C control open source library: download of metroframework

【Jailhouse 文章】Base Architectures for virtual-physical computing(2018)

Observer mode
![[sword finger offer] analog implementation ATOI](/img/01/76a3b1fcc6403368a363146d553777.png)
[sword finger offer] analog implementation ATOI

MySQL remote login

Case ---- how efficient is the buffer stream compared with the ordinary input stream and output stream?

睡眠不足有哪些危害?

JSON、

Robot engineering - teaching quality - how to judge
随机推荐
如何学习 C 语言?
[C language] program environment and preprocessing
Discuss the important factors that affect the success or failure of automated testing
Use of golang exec.command
Lpad() function and (row_number() over (order by) +...)
[add, delete, modify, and check the array base]
Ida Pro novice tutorial
C#控件开源库:MetroFramework的下载
你了解PowerBI中的去年同期吗
51 timer initial value calculation
DOM event type
“font/woff“ and “font/woff2“ in file “mime.types“
[C language] document processing and operation
Thread 类的基本用法
机器人工程-教学品质-如何判定
Oracle table creation statement template
Pic16f877xa instruction system (assembly language)
Seekbar attribute reference
Quick sort code implementation
The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell