Skip to content

YoloV5模型检测

关键参数

  1. weights:训练好的模型文件
  2. source:检测的目标,可以是单张图片、文件夹、屏幕或者摄像头等
  3. conf-thres:置信度阈值,越低框越多,越高框越少
  4. iou-thres:IOU阈值,越低框越少,越少框越多

weights

训练好的模型文件

Modelsize (pixels)mAPval 50-95mAPval 50Speed CPU b1 (ms)Speed V100 b1 (ms)Speed V100 b32 (ms)params (M)FLOPs @640 (B)
YOLOv5n64028.045.7456.30.61.94.5
YOLOv5s64037.456.8986.40.97.216.5
YOLOv5m64045.464.12248.21.721.249.0
YOLOv5l64049.067.343010.12.746.5109.1
YOLOv5x64050.768.976612.14.886.7205.7
YOLOv5n6128036.054.41538.12.13.24.6
YOLOv5s6128044.863.73858.23.612.616.8
YOLOv5m6128051.369.388711.16.835.750.0
YOLOv5l6128053.771.3178415.810.576.8111.4
YOLOv5x6 + TTA1280 153655.0 55.872.7 72.73136 -26.2 -19.4 -140.7 -209.8 -

使用不同的模型推理(预测/识别)到的可能数据不同,时间也有所不同

image-20240907204654175

source

检测的目标,可以是单张图片、文件夹、屏幕或者摄像头等

image-20240908162426826

对图片检测

python detect.py--weights yolov5s.pt --source data/images/bus.jpg

对屏幕检测

python detect.py--weights yolov5s.pt --source screen

对摄像头检测

python detect.py --weights yolov5s.pt --source 0

conf-thres

置信度阈值,越低框越多,越高框越少

image-20240908163929943

iou-thres

IOU國值,越低框越少,越高框越多

image-20240908163943751

classes

指定检测的类别

简化代码 hub_detect.ipynb

python
import torch

# Model
model = torch.hub.load("./", "yolov5s", source='local') 
# 第一个参数为模型所在的文件夹,第二个参数为模型名称,第三个参数为模型来源本地为local

#Images
img = "./data/images/zidane.jpg"

# Inference
results = model(img)

# Results
results.show()

Released under the MIT License.