Views
No views yet
ultralytics package, including all requirements, in a Python>=3.8 environment with PyTorch>=1.8.pip install ultralyticsyolo command:1# Predict using a pretrained YOLO model (e.g., YOLOv5n) on an image
2yolo predict model=yolov5n.pt source='https://ultralytics.com/images/bus.jpg'yolo command supports various tasks and modes, accepting additional arguments like imgsz=640. Explore the YOLO CLI Docs for more examples.1from ultralytics import YOLO
2
3# Load a pretrained YOLOv5n model
4model = YOLO("yolov5n.pt")
5
6# Train the model on the COCO8 dataset for 100 epochs
7train_results = model.train(
8 data="coco8.yaml", # Path to dataset configuration file
9 epochs=100, # Number of training epochs
10 imgsz=640, # Image size for training
11 device="cpu", # Device to run on (e.g., 'cpu', 0, [0,1,2,3])
12)
13
14# Evaluate the model's performance on the validation set
15metrics = model.val()
16
17# Perform object detection on an image
18results = model("path/to/image.jpg") # Predict on an image
19results[0].show() # Display results
20
21# Export the model to ONNX format for deployment
22path = model.export(format="onnx") # Returns the path to the exported model
| Model | size (pixels) | mAPval 50-95 | mAPval 50 | Speed CPU b1 (ms) | Speed V100 b1 (ms) | Speed V100 b32 (ms) | params (M) | FLOPs @640 (B) |
|---|---|---|---|---|---|---|---|---|
| YOLOv5n | 640 | 28.0 | 45.7 | 45 | 6.3 | 0.6 | 1.9 | 4.5 |
| YOLOv5s | 640 | 37.4 | 56.8 | 98 | 6.4 | 0.9 | 7.2 | 16.5 |
| YOLOv5m | 640 | 45.4 | 64.1 | 224 | 8.2 | 1.7 | 21.2 | 49.0 |
| YOLOv5l | 640 | 49.0 | 67.3 | 430 | 10.1 | 2.7 | 46.5 | 109.1 |
| YOLOv5x | 640 | 50.7 | 68.9 | 766 | 12.1 | 4.8 | 86.7 | 205.7 |
| YOLOv5n6 | 1280 | 36.0 | 54.4 | 153 | 8.1 | 2.1 | 3.2 | 4.6 |
| YOLOv5s6 | 1280 | 44.8 | 63.7 | 385 | 8.2 | 3.6 | 12.6 | 16.8 |
| YOLOv5m6 | 1280 | 51.3 | 69.3 | 887 | 11.1 | 6.8 | 35.7 | 50.0 |
| YOLOv5l6 | 1280 | 53.7 | 71.3 | 1784 | 15.8 | 10.5 | 76.8 | 111.4 |
| YOLOv5x6 + TTA | 1280 1536 | 55.0 55.8 | 72.7 72.7 | 3136 - | 26.2 - | 19.4 - | 140.7 - | 209.8 - |
python val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65python val.py --data coco.yaml --img 640 --task speed --batch 1python val.py --data coco.yaml --img 1536 --iou 0.7 --augment| Model | size (pixels) | mAPbox 50-95 | mAPmask 50-95 | Train time 300 epochs A100 (hours) | Speed ONNX CPU (ms) | Speed TRT A100 (ms) | params (M) | FLOPs @640 (B) |
|---|---|---|---|---|---|---|---|---|
| YOLOv5n-seg | 640 | 27.6 | 23.4 | 80:17 | 62.7 | 1.2 | 2.0 | 7.1 |
| YOLOv5s-seg | 640 | 37.6 | 31.7 | 88:16 | 173.3 | 1.4 | 7.6 | 26.4 |
| YOLOv5m-seg | 640 | 45.0 | 37.1 | 108:36 | 427.0 | 2.2 | 22.0 | 70.8 |
| YOLOv5l-seg | 640 | 49.0 | 39.9 | 66:43 (2x) | 857.4 | 2.9 | 47.9 | 147.7 |
| YOLOv5x-seg | 640 | 50.7 | 41.4 | 62:56 (3x) | 1579.2 | 4.5 | 88.8 | 265.7 |
lr0=0.01 and weight_decay=5e-5 at image size 640 and all default settings.python segment/val.py --data coco.yaml --weights yolov5s-seg.ptpython segment/val.py --data coco.yaml --weights yolov5s-seg.pt --batch 1export.py. python export.py --weights yolov5s-seg.pt --include engine --device 0 --half| Model | size (pixels) | acc top1 | acc top5 | Training 90 epochs 4xA100 (hours) | Speed ONNX CPU (ms) | Speed TensorRT V100 (ms) | params (M) | FLOPs @224 (B) |
|---|---|---|---|---|---|---|---|---|
| YOLOv5n-cls | 224 | 64.6 | 85.4 | 7:59 | 3.3 | 0.5 | 2.5 | 0.5 |
| YOLOv5s-cls | 224 | 71.5 | 90.2 | 8:09 | 6.6 | 0.6 | 5.4 | 1.4 |
| YOLOv5m-cls | 224 | 75.9 | 92.9 | 10:06 | 15.5 | 0.9 | 12.9 | 3.9 |
| YOLOv5l-cls | 224 | 78.0 | 94.0 | 11:56 | 26.9 | 1.4 | 26.5 | 8.5 |
| YOLOv5x-cls | 224 | 79.0 | 94.4 | 15:04 | 54.3 | 1.8 | 48.1 | 15.9 |
| ResNet18 | 224 | 70.3 | 89.5 | 6:47 | 11.2 | 0.5 | 11.7 | 3.7 |
| ResNet34 | 224 | 73.9 | 91.8 | 8:33 | 20.6 | 0.9 | 21.8 | 7.4 |
| ResNet50 | 224 | 76.8 | 93.4 | 11:10 | 23.4 | 1.0 | 25.6 | 8.5 |
| ResNet101 | 224 | 78.5 | 94.3 | 17:10 | 42.1 | 1.9 | 44.5 | 15.9 |
| EfficientNet_b0 | 224 | 75.1 | 92.4 | 13:03 | 12.5 | 1.3 | 5.3 | 1.0 |
| EfficientNet_b1 | 224 | 76.4 | 93.2 | 17:04 | 14.9 | 1.6 | 7.8 | 1.5 |
| EfficientNet_b2 | 224 | 76.6 | 93.4 | 17:10 | 15.9 | 1.6 | 9.1 | 1.7 |
| EfficientNet_b3 | 224 | 77.7 | 94.0 | 19:19 | 18.9 | 1.9 | 12.2 | 2.4 |
lr0=0.001 and weight_decay=5e-5 at image size 224 and all default settings.python classify/val.py --data ../datasets/imagenet --img 224python classify/val.py --data ../datasets/imagenet --img 224 --batch 1export.py. python export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224