Yolo-Fastestv2训练及部署自己的数据集
训练流程
一、配置环境
1.下载代码
git clone https://github.com/dog-qiuqiu/Yolo-FastestV2.git
2.创建虚拟环境,在虚拟环境下安装相关python依赖包
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple #采用国内源,速度较快
3.测试能否正常使用
python test.py --data data/coco.data --weights modelzoo/coco2017-0.241078ap-model.pth --img img/000139.jpg
二、数据集建立
1.数据集格式
数据集的格式是Yolo格式,每个图像对应一个.txt标签文件cx,cy,w,h。cx,cy是标签框的中心点的坐标,w,h是标签框的宽度和高度。示例如下:
0 0.410156 0.317708 0.807813 0.631250
2.图像与标签位置
数据集图像与对应的标签文件具有同样的名字,存储在同一目录中。结构如下:
-train
- 001.jpg
- 001.txt
- 002.jpg
- 002.txt
-val
- 003.jpg
- 003.txt
-test
- 004.jpg
- 004.txt
3.生成数据集路径.txt文件
路径是图像的绝对路径,示例如下:
/home/dataset/train/001.jpg
python实现:
import os
images_path='/home/dataset/train/'
txt_path='/home/dataset/train.txt'
with open(txt_path,'w') as f:
files_name=os.listdir(images_path)
f.truncate()
for name in files_name:
if name.endswith('.jpg'):
f.write(images_path+name)
f.write('\n')
f.close()
4.生成.names类别标签
./data/coco.names修改成自己数据集的类别。
5.最终构建的数据集目录结构
-train
- 001.jpg
- 001.txt
- 002.jpg
- 002.txt
-train.txt
-val
- 003.jpg
- 003.txt
-val.txt
-test
- 004.jpg
- 004.txt
-test.txt
三、训练
1.根据当前数据集生成锚点anchors
计算适应数据集的anchors,将输出值替换coco.data中的anchors
python genanchors.py --traintxt /home/dataset/train.txt
anchors6.txt文件将在当前目录中生成,anchors6.txt的示例内容如下:
12.64,19.39, 37.88,51.48, 55.71,138.31, 126.91,78.23, 131.57,214.55, 279.92,