Skip to content

参考网站

ultralytics/yolov5: YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite (github.com)

代码推断

python
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # or yolov5n - yolov5x6, custom
# Images
img = 'https://ultralytics.com/images/zidane.jpg'  # or file, Path, PIL, OpenCV, numpy, list
# Inference
results = model(img)
# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.

命令使用

shell
python detect.py --source 0  # webcam
                          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

性能排行

155040763-93c22a27-347c-4e3c-847a-8094621d3f4e.png (2400×1200) (user-images.githubusercontent.com)

640 Figure

155040757-ce0934a3-06a6-43dc-a979-2edbbd69ea0e.png (2400×1200) (user-images.githubusercontent.com)

Pretrained Checkpoints

Modelsize (pixels)mAPval 0.5:0.95mAPval 0.5Speed 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 -

训练

shell
python train.py --data coco.yaml --cfg yolov5n.yaml --weights '' --batch-size 128
                                       yolov5s                                64
                                       yolov5m                                40
                                       yolov5l                                24
                                       yolov5x                                16

90222759-949d8800-ddc1-11ea-9fa1-1c97eed2b963.png (2400×1200) (user-images.githubusercontent.com)