1、官网的例子,3天前更新了,所以应该还是很靠谱的

https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data

====================================================

2、安装

Python>=3.8 and PyTorch>=1.7

====================================================

2.1 clone仓库

$ git clone https://github.com/ultralytics/yolov5 # clone repo

切目录

cd yolov5

安装依赖

$ pip install -r requirements.txt # install dependencies

但是需要启动国内的源,否则慢死

================================================

2.2 永久更改pip源

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

================================================

2.3 安装依赖

pip install -r requirements.txt # install dependencies

================================================

3、训练集的配置

dataset.yaml文件

1、从哪里下载这个集合;2、训练集合的目录信息以及验证集合的目录信息;3、类的数量;4、类的名称列表;

=========================================

4.标记你的数据

用CVAT标记

https://github.com/openvinotoolkit/cvat

或者

makesense.ai

https://www.makesense.ai/

导出压缩包

可以看到最后它生成了

最后能看到它生成了59个lables

文档上对图像格式的说明,其实还是很单纯的

一行一个目标,然后跟着的就是目标的坐标,坐标被归一化过

=========================================

组织你的文件夹

官网上的例子是这样的

========================================================

选择模型,没啥说的,选v5s

============================================

目录树结构是这样的:

编写配置文件:

然后运行命令:

python train.py --img 640 --batch 16 --epochs 5 --data fire_switch.yaml --weights yolov5s.pt

它会下载预训练好的模型,14MB大小,然后开始训练自己的数据;

https://blog.csdn.net/weixin_41990671/article/details/107300314

https://zhuanlan.zhihu.com/p/296592676

得改一下图片的参数

我的图片是1080 x 1440的

python train.py --img 1080 1440 --batch 16 --epochs 5 --data fire_switch.yaml --weights yolov5s.pt

然后就很奇怪,给我报告没内存了。。。。

再看吧

python train.py --img 1080 1440 --batch 8 --epochs 5 --data fire_switch.yaml --weights yolov5s.pt

好了,我把batch的size改小了

验证集以及经过模型预测的结果图片,在本地其实都能看到

能看到。。。。我们的模型训练失败了

没有任何有效的预测

===================================================

OK,麻烦才刚刚开始,不是么??

正常 的应该是这样的:

==================================================================

用了一个非常变态的方式训练完成了

python train.py --img 1088 1440 --batch 1 --epochs 100 --data fire_switch.yaml --weights yolov5s.pt