参考:https://blog.csdn.net/qq_42932308/article/details/115217935
1. 数据集标签文件的格式转化
visdrone数据集默认标签格式为.txt,转化为.xml文件后,修改参数,就可在使用yolov5项目直接训练。
说明: 创建数据集标签转换脚本visdrone2yolo.py,修改root_dir,将train、val、test文件的labels文件转换得到annotations_voc文件,并将该文件复制到训练数据集目录下。
2.修改配置文件
修改 data/VisDrone.yaml
train: ../datasets/images/train # train images (relative to 'path') 6471 images
val: ../datasets/images/val # val images (relative to 'path') 548 images
test: ../datasets/images/test # test images (optional) 1610 images
# Classes
nc: 10 # number of classes
names: ['pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', 'awning-tricycle', 'bus', 'motor']
修改 models/yolo5l.yaml
nc: 10 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
3. 下载预训练模型
Releases · ultralytics/yolov5 (github.com)
python detect.py --weights yolov5s.pt # P5 models
yolov5m.pt
yolov5l.pt
yolov5x.pt
将下载得到的yolov5l.pt复制到weights文件夹下。
开始训练
python train.py --data data/VisDrone.yaml --cfg models/yolov5s.yaml --weights weights/yolov5s.pt --batch-size 1 --epochs 30
python train.py --data data/coco128.yaml --cfg models/yolov5s.yaml --weights weights/yolov5s.pt --batch-size 1 --epochs 10
4.训练过程
配置:GTX1050ti 4G
数据集:训练集6471,验证集548
模型:yolov5s
batch-size = 1
结果:30min/epoch
问题1 :RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:79] data. DefaultCPUAllocator: not enough memory: you tried to allocate 105436960 bytes
验证时,显示内存不足。
解决:尝试减少训练集:使用4000张图片训练(删除9999966_00000_d_0000034 ~ 9999999_00887_d_0000407)