标签:github sdk 切换 脚本 权重 整理 strong anaconda imp
CUDA和pytorch安装好的基础上,将YOLOv5的源码拷到本地。$ git clone https://github.com/ultralytics/yolov5.git
Anaconda的shell里面,安装官方给好的配置文件requirements.txt。$ pip install -U -r requirements.txt
在下载好的
YOLOv5源码的目录下执行。
requirements.txt文件主要是对以下内容进行安装,如果某一步报错,针对问题切换方法即可。bmatplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
Pillow
PyYAML>=5.3.1
scipy>=1.4.1
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.41.0
tensorboard>=2.4.1
seaborn>=0.11.0
pandas
pycocotools>=2.0
thop
pycocotools安装时容易出问题,建议提前在VS里面把SDK类东西装好。
XML文件。YOLOv5只能训练格式为{seq、x_center/image_width、y_center/image_height、width/image_width、height/image_height}的.txt文件,于是编写python脚本将XML文件转为.txt。import xml.dom.minidom as xmldom
import os
def data2txt(d1,d2,d3,d4,file_name):
fd = open(file_name+‘.txt‘,‘w‘)
fd.write(‘0 ‘+str(d1)+‘ ‘+str(d2)+‘ ‘+str(d3)+‘ ‘+str(d4))
fd.close
def xml2data(file_name):
ele = xmldom.parse(os.path.abspath(file_name)).documentElement
size = ele.getElementsByTagName("size")
image_width = int(size[0].getElementsByTagName("width")[0].firstChild.data)
image_height = int(size[0].getElementsByTagName("height")[0].firstChild.data)
bndbox = ele.getElementsByTagName("bndbox")
xmin = int(bndbox[0].getElementsByTagName("xmin")[0].firstChild.data)
ymin = int(bndbox[0].getElementsByTagName("ymin")[0].firstChild.data)
xmax = int(bndbox[0].getElementsByTagName("xmax")[0].firstChild.data)
ymax = int(bndbox[0].getElementsByTagName("ymax")[0].firstChild.data)
xcenter = (xmax + xmin)/2
ycenter = (ymax + ymin)/2
width = abs(xmax-xmin)
height = abs(ymax-ymin)
data2txt(xcenter/image_width,ycenter/image_height,width/image_width,height/image_height,file_name[:-4])
if __name__ == "__main__":
for i in range(1,465):
file_name = str(i)+‘.xml‘
addlen = 10-len(file_name)
for j in range(addlen):
file_name = ‘0‘+file_name
xml2data(file_name)
train.py对整理好的数据集进行训练。$ python train.py --img 640 --batch 16 --cfg ./models/yolov5s.yaml --weights ‘‘
训练好的数据集权重会放在
./runs/train/exp/weights。
train.py进行参数解析:| 参数 | 作用 |
|---|---|
| epochs | 数据集被迭代的次数 |
| batch | 每次权重更新所需分析的图片数 |
| hyp | 超参数配置文件 |
| cfg | 存储模型结构的配置文件 |
| data | 数据集的配置文件 |
| img | 输入图片宽高 |
| rect | 矩形训练 |
| resume | 恢复最近保存的模型训练 |
| nosave | 仅保存最后的checkpoint |
| notest | 仅测试最后的epoch |
| evolve | 进化超参数 |
| bucket | gsutil bucket |
| cache-images | 缓存图像(加快训练速度) |
| weights | 权重文件 |
| name | 重命名 |
| device | 设备 |
| adam | 使用adam优化 |
| multi-scale | 多尺度训练 |
| single-cls | 单类别训练集 |
加粗的参数对计算机的性能有要求,可以根据实际情况调整。
其中
epochs一般选择50~200,太小欠拟合,太大过拟合。
$ python detect.py --source {image_file}
$ python detect.py --source {stream_url}
$ python detect.py --weights {pt_path}
标签:github sdk 切换 脚本 权重 整理 strong anaconda imp
原文地址:https://www.cnblogs.com/cheuhxg/p/14832355.html