1.克隆yolov5仓库
git clone https://github.com/ultralytics/yolov5
2.安装python3.7、Pytorch1.7.0环境
3.安装yolov5环境
pip install -r requirements.txt
4.数据集与配置文件
#数据集来源
https://universe.roboflow.com/dataset-9xayt/fire-data-annotations-lwfou
在…/datasets保存数据集
在data目录创建 fire.yaml
内容:
path: …/datasets/fire #dataset path
train: train/images
val: test/images
#test: test/images #optional
nc: 1
names: [‘Fire’]
4.开始训练
#epochs default 300
python train.py --img 640 --batch 16 --epochs 300 --data fire.yaml --weights yolov5s.pt
5.输出的结果在 runs/train/expxx
6.使用模型进行推理
python detect.py --weights runs/train/expxx/weights/best.pt --source
0 # cam
img.jpg # image
vid.mp4 # video
path/ # directory
‘path/*.jpg’ # glob
‘https://youtu.be/Zgi9g1ksQHc’ # YouTube
‘rtsp://example.com/media.mp4’ # RTSP, RTMP, HTTP stream