YOLOv5训练步骤
git clone https://github.com/ultralytics/yolov5.git
cd yolov5
pip install -U -r requirements.txt
命令行运行:
python detect.py
支持视频的检测,包括本地摄像头、本地视频文件、m3u8播放地址和rtsp实时流,地址都是跟在参数–source后面:
本地摄像头使用的命令:
python detect.py --source 0
基于rtsp的网络摄像头使用的命令:
python detect.py --source “rtsp://user:password@192.168.1.100:554/cam/realmonitor?channel=1&subtype=1”
有多块显卡,可以选择具体使用哪块显示进行检测,0表示第一块,1表示第二块,cpu表示不使用gpu:python detect.py --device 0
查看 .py 的参数:python detect.py -h
指定权重:python detect.py --source inference/images/horses.jpg --weights weights/yolov5x.pt
利用yolo5训练自己的模型:
训练命令:
python train.py --img-size 640 --batch 13 --epochs 10 --data ‘/yolov5/data/data.yaml’ --cfg ‘/yolov5/models/yolov5s.yaml’ --weights weights/yolov5s.pt
python train.py --img 640 --batch 8 --epoch 100 --data data/data.yaml --cfg models/yolov5s.yaml --weights weights/yolov5s.pt --device ‘0’ # 0号GPU
验证命令:
python test.py --data data/data.yaml --weights runs/exp/weights/best.pt --augment
Augment=数据增强
测试命令:
单张图片测试:
python detect.py --weights runs/exp4/weights/best.pt --source inference/images/1.jpg --output inference/oneoutput/ --device 0
整个文件夹图片测试:
python detect.py --weights runs/exp4/weights/best.pt --source inference/test/ --device 0 --save-txt
图片目录检测:
python detect.py --source inference/test --weights runs/exp/weights/best.pt --output inference/muoutput --conf-thres 0.5
视频测试:
python detect.py --source inference/2.mp4 --weights runs/exp/weights/best.pt --output inference/oneoutput/ --device 0
优化:rate:学习率,默认为0.001,可以根据自己的训练情况调整,一般为0.01,0.003,0.001等