当前位置:网站首页>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复现完成。
边栏推荐
- Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
- C#--MetroFramework框架调用metroModernUI库,并在工具栏使用
- 分层强化学习综述:Hierarchical reinforcement learning: A comprehensive survey
- In container multicast
- The ultimate difference between MVC and three-tier architecture
- Download and run the C open source control metroframework demo project
- 2022深圳杯
- Argocd user management, RBAC control, script login, APP synchronization
- Baidu SEM bidding avoidance
- Leetcode46 Full Permutation (Introduction to backtracking)
猜你喜欢

常吃发酵馒头是否会伤害身体

不只是日志收集,项目监控工具Sentry的安装、配置、使用

2022 "strong country Cup" preliminary WP (with script and detailed process)

Labelme labels different objects, displays different colors and batch conversion

Qt实战案例(53)——利用QDrag实现拖拽拼图功能

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

Quick sort code implementation

C#控件开源库:MetroFramework的下载

Create a new STM32 project and configure it - based on registers

C#--MetroFramework框架调用metroModernUI库,并在工具栏使用
随机推荐
Not only log collection, but also the installation, configuration and use of project monitoring tool sentry
在C# WinForms应用程序中安装,配置和使用MetroFramework
[jailhouse article] base architectures for virtual physical computing (2018)
Scientific computing library numpy Foundation & Improvement (Understanding + explanation of important functions)
Cointelegraph撰文:依托最大的DAO USDD成为最可靠的稳定币
Some common interview questions about IO stream and string
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 link with game glitch (SPFA finds positive and negative links)
Review of three traversal methods of map
Introduction to bridging mode and sharing mode
Shell run command
Thread 类的基本用法
【transformer】DeiT
Create a new STM32 project and configure it - based on registers
[Yugong series] July 2022 go teaching course 015 assignment operators and relational operators of operators
The most comprehensive multi-threaded application tutorial - summary in detail
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern
[knowledge summary] block and value range block
Mlx90640 infrared thermal imager temperature measurement module development notes (I)
Pic16f877xa instruction system (assembly language)
Lpad() function and (row_number() over (order by) +...)