当前位置:网站首页>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复现完成。
边栏推荐
- Create a new STM32 project and configure it - based on registers
- Easy to use code statistics tool
- 【每日一题】剑指 Offer II 115. 重建序列
- Easy to understand: basic knowledge of MOS tube
- 长安链双花交易防范策略
- C control open source library: download of metroframework
- 2022深圳杯
- The income of bank financial management is getting lower and lower. Now which financial products have high income?
- JVM tuning summary -xms -xmx -xmn -xss
- HTX00001_ Keil51 bug encountered in serial port parsing
猜你喜欢

Cointegraph wrote: relying on the largest Dao usdd to become the most reliable stable currency

C # --metroframework framework calls the metromodernui library and uses it in the toolbar

Labelme labels different objects, displays different colors and batch conversion

Restrict Su command and sudo mechanism to promote nmap and console command netstat

Not only log collection, but also the installation, configuration and use of project monitoring tool sentry

Keilc51 usage details (III)

labelme标注不同物体显示不同颜色以及批量转换

Quick sort code implementation

The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell

MySQL remote login
随机推荐
Keil uvisin5 code auto completion or code Association
C # read Beckhoff variable
Recycleview realizes horizontal sliding of overlapping items
微生物健康,不要排斥人体内微生物
JS array = number assignment changes by one, causing the problem of changing the original array
What does "TTL" mean in domain name resolution?
LeetCode46全排列(回溯入门)
容器内组播
[jailhouse article] base architectures for virtual physical computing (2018)
Over adapter mode
A scene application of 2D animation
Restrict Su command and sudo mechanism to promote nmap and console command netstat
探讨影响自动化测试成败的重要因素
Thread 类的基本用法
Standard C language 89
Quick sort code implementation
Detailed explanation of the difference, working principle and basic structure between NMOS and PMOS
MySQL index collation summary
Standard C language 6
What are the hazards of insufficient sleep?