Ultralytics YOLOv5 🚀 ist ein hochmodernes (SOTA) Computervisionsmodell, das von Ultralytics entwickelt wurde. Basierend auf dem PyTorch-Framework ist YOLOv5 für seine Benutzerfreundlichkeit, Geschwindigkeit und Genauigkeit bekannt. Es vereint Erkenntnisse aus umfangreicher Forschung und Entwicklung mit Best Practices und ist somit eine beliebte Wahl für verschiedene visuelle KI-Aufgaben.
Projektadresse: https://github.com/ultralytics/yolov5
YOLOv5 unterstützt verschiedene Computer Vision Aufgaben:
Zu den wichtigsten Merkmalen gehören Echtzeit-Inferenz, Unterstützung für verschiedene Trainingstechniken wie Test Time Augmentation (TTA) und Modell-Ensembling sowie Kompatibilität mit Exportformaten wie TFLite, ONNX, CoreML und TensorRT.
YOLOv5 bietet verschiedene Modellgrößen, um unterschiedlichen Anforderungen gerecht zu werden:
Modell | Parameteranzahl (M) | Geschwindigkeit | Genauigkeit | Anwendungsbereich |
---|---|---|---|---|
YOLOv5n | 1.9 | Am schnellsten | Niedriger | Mobile Geräte, Edge Computing |
YOLOv5s | 7.2 | Schnell | Mittel | Allgemeine Anwendungen |
YOLOv5m | 21.2 | Mittel | Höher | Ausgewogene Leistung |
YOLOv5l | 46.5 | Langsamer | Hoch | Hohe Präzisionsanforderungen |
YOLOv5x | 86.7 | Am langsamsten | Am höchsten | Höchste Präzisionsanforderungen |
Leistung auf dem COCO-Datensatz:
# Klonen des Repository
git clone https://github.com/ultralytics/yolov5
cd yolov5
# Installation der Abhängigkeiten
pip install -r requirements.txt
import torch
# Laden des YOLOv5-Modells
model = torch.hub.load("ultralytics/yolov5", "yolov5s")
# Definition der Eingabebildquelle
img = "https://ultralytics.com/images/zidane.jpg"
# Ausführen der Inferenz
results = model(img)
# Verarbeitung der Ergebnisse
results.print() # Ausgabe der Ergebnisse in der Konsole
results.show() # Anzeige der Ergebnisse in einem Fenster
results.save() # Speichern der Ergebnisse in runs/detect/exp
# Inferenz mit der Kamera
python detect.py --weights yolov5s.pt --source 0
# Inferenz mit einer lokalen Bilddatei
python detect.py --weights yolov5s.pt --source img.jpg
# Inferenz mit einer Videodatei
python detect.py --weights yolov5s.pt --source vid.mp4
# Inferenz mit einem Bildverzeichnis
python detect.py --weights yolov5s.pt --source path/to/images/
# Inferenz mit einem YouTube-Video
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4'
# Training von YOLOv5s auf dem COCO-Datensatz, 300 Epochen
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5s.yaml --batch-size 64
# Training von YOLOv5m
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5m.yaml --batch-size 40
# Training von YOLOv5l
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5l.yaml --batch-size 24
# Verwendung von Multi-GPU-verteiltem Training
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 train.py --data coco.yaml --weights '' --cfg yolov5s.yaml --batch-size 64 --device 0,1,2,3
YOLOv5 v7.0 führte die Instanzsegmentierungsfunktion ein und erreichte auf dem COCO-Datensatz modernste Leistung.
Modell | mAP^box | mAP^mask | Parameteranzahl (M) | Geschwindigkeit (ms) |
---|---|---|---|---|
YOLOv5n-seg | 27.6 | 23.4 | 2.0 | 59.2 |
YOLOv5s-seg | 37.6 | 32.0 | 7.6 | 63.7 |
YOLOv5m-seg | 45.0 | 37.1 | 22.0 | 89.5 |
YOLOv5l-seg | 49.0 | 39.9 | 47.8 | 168.4 |
YOLOv5x-seg | 50.7 | 41.4 | 88.8 | 265.7 |
# Training des Segmentierungsmodells
python segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640
# Validierung des Segmentierungsmodells
python segment/val.py --weights yolov5s-seg.pt --data coco.yaml --img 640
# Verwendung des Segmentierungsmodells zur Vorhersage
python segment/predict.py --weights yolov5m-seg.pt --source data/images/bus.jpg
YOLOv5 v6.2 fügte die Bildklassifizierungsfunktion hinzu. Hier sind die Ergebnisse des Trainings für 90 Epochen auf dem ImageNet-Datensatz:
Modell | Top1-Genauigkeit | Top5-Genauigkeit | Parameteranzahl (M) | Geschwindigkeit (ms) |
---|---|---|---|---|
YOLOv5s-cls | 71.5% | 90.2% | 5.5 | 1.7 |
YOLOv5m-cls | 75.9% | 92.9% | 13.0 | 2.8 |
YOLOv5l-cls | 78.0% | 94.0% | 27.4 | 4.9 |
YOLOv5x-cls | 79.0% | 94.4% | 55.4 | 8.7 |
# Training auf dem CIFAR-100-Datensatz
python classify/train.py --model yolov5s-cls.pt --data cifar100 --epochs 5 --img 224 --batch 128
# Validierung des ImageNet-Modells
python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224
# Bildklassifizierungsvorhersage
python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg
YOLOv5 unterstützt verschiedene Bereitstellungsformate:
# Export in das ONNX-Format
python export.py --weights yolov5s.pt --include onnx
# Export in das TensorRT-Format
python export.py --weights yolov5s.pt --include engine
# Export in das CoreML-Format (für iOS)
python export.py --weights yolov5s.pt --include coreml
# Export in das TFLite-Format (für mobile Geräte)
python export.py --weights yolov5s.pt --include tflite
Verbesserung der Vorhersagegenauigkeit durch Reflexions- und Skalierungserweiterung:
python val.py --data coco.yaml --img 1536 --iou 0.7 --augment
Kombination mehrerer Modelle für eine bessere Leistung:
python val.py --data coco.yaml --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
Automatische Suche nach optimalen Trainingshyperparametern:
python train.py --data coco.yaml --evolve 300
YOLOv5 ist tief in mehrere Mainstream-KI-Plattformen integriert:
YOLOv5 ist ein wichtiger Meilenstein im Bereich der Objekterkennung und hat sich aufgrund seiner hervorragenden Leistung, Benutzerfreundlichkeit und seines Funktionsumfangs zu einem bevorzugten Framework für akademische Forschung und industrielle Anwendungen entwickelt. Ob Anfänger oder professioneller Entwickler, jeder kann im YOLOv5-Ökosystem die passende Lösung finden.