long blogs

进一步有进一步惊喜


  • Home
  • Archive
  • Tags
  •  

© 2025 long

Theme Typography by Makito

Proudly published with Hexo

yolov5自己训练数据使用指南

Posted at 2025-08-07 python 

准备如下

训练集准备

图片数据\标签数据

假设训练集的项目称为ipc20
需要按照如下目录编排

1
2
3
4
5
6
7
8
9
10
11
ipc20
├── images
│ └── trains
│ ├── 0001.jpg
│ ├── 0002.jpg
│ └── 0003.jpg
└── labels
├── trains
│ ├── 0001.txt
│ ├── 0002.txt
│ └── 0003.txt

如果改了images/trains的目录名改成images/trains1,对应标签目录名也需要同步更改labels/trains1

yolov会自己寻找图片对应的labels的所在地方的。

配置yaml

1
2
3
4
5
6
7
8
# 相对于项目根目录
path: data/datasets/ipc20
# 相对于path目录
train: images/trains
val: images/trains
test:
names:
0: ipc

训练

1
$ python train.py --img 640 --batch 16 --epochs 3 --data ./my_dataset/my_dataset.yaml --weights ./my_model/yolov5s.pt

至少训练50-100次才有效果

检测

1
python detect.py --weights runs/train/exp/weights/best.pt --data my_dataset/my_dataset.yaml --source 0001.jpg

Share 

 Previous post: labelIm的bug修复 Next post: 数字极简 

© 2025 long

Theme Typography by Makito

Proudly published with Hexo