需要 Python>=3.8.0 且预先安装 PyTorch>=1.8;模型权重会从最新 release 自动下载,首次运行需联网;训练耗时较长,YOLOv5n/s/m/l/x 在单张 V100 上约需 1/2/4/6/8 天。

yolov5
ultralyticsAGPL-3.0活跃维护基于 PyTorch 的目标检测全家桶,覆盖训练、推理、实例分割、图像分类和模型导出,开箱即用,适合快速落地视觉任务。
Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txtREADME 提到训练在单张 NVIDIA V100 GPU 上进行,并给出 V100-16GB 对应的批大小;未说明 CPU 推理或其他 GPU 型号要求。
基于 PyTorch 的 YOLOv5 目标检测、实例分割与分类模型,开箱即用
基于 PyTorch 的目标检测全家桶,覆盖训练、推理、实例分割、图像分类和模型导出,开箱即用,适合快速落地视觉任务。
核心能力
- 用 PyTorch Hub 一行代码加载 yolov5n/s/m/l/x 模型做推理
- detect.py 支持图片、视频、摄像头、RTSP 流和 YouTube 链接
- train.py 可复现 COCO 训练,支持多 GPU 与 AutoBatch 自动批大小
- 提供目标检测、实例分割、图像分类三类视觉任务
- 结果可 print/show/save/crop 或转 pandas 处理
容易踩的坑
- v7.0v7.0 - YOLOv5 SOTA Realtime Instance Segmentation最新正式版2022-11-22 · 2022-11-22 15:29 UTC
Our new YOLOv5 v7.0 instance segmentation models are the fastest and most accurate in the world, beating all current SOTA benchmarks. We've made them super simple to train, validate and deploy. See full details in our Release Notes and visit our YOLOv5 Segmentation Colab Notebook for quickstart tutorials.
Our primary goal with this release is to introduce super simple YOLOv5 segmentation workflows just like our existing object detection models. The new v7.0 YOLOv5-seg models below are just a start, we will continue to improve these going forward together with our existing detection and classification models. We'd love your feedback and contributions on this effort!
This release incorporates 280 PRs from 41 contributors since our last release in August 2022.
Important Updates
- Segmentation Models ⭐ NEW: SOTA YOLOv5-seg COCO-pretrained segmentation models are now available for the first time (https://github.com/ultralytics/yolov5/pull/9052 by @glenn-jocher, @AyushExel and @Laughing-q)
- Paddle Paddle Export: Export any YOLOv5 model (cls, seg, det) to Paddle format with python export.py --include paddle (https://github.com/ultralytics/yolov5/pull/9459 by @glenn-jocher)
- YOLOv5 AutoCache: Use
python train.py --cache ramwill now scan available memory and compare against predicted dataset RAM usage. This reduces risk in caching and should help improve adoption of the dataset caching feature, which can significantly speed up training. (https://github.com/ultralytics/yolov5/pull/10027 by @glenn-jocher) - Comet Logging and Visualization Integration: Free forever, Comet lets you save YOLOv5 models, resume training, and interactively visualise and debug predictions. (https://github.com/ultralytics/yolov5/pull/9232 by @DN6)
New Segmentation Checkpoints
We trained YOLOv5 segmentations models on COCO for 300 epochs at image size 640 using A100 GPUs. We exported all models to ONNX FP32 for CPU speed tests and to TensorRT FP16 for GPU speed tests. We ran all speed tests on Google Colab Pro notebooks for easy reproducibility.
Model size(pixels) mAPbox50-95 mAPmask50-95 Train time300 epochsA100 (hours) SpeedONNX CPU(ms) SpeedTRT A100(ms) params(M) FLOPs@640 (B) [YOLOv5n-seg](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolo - v6.2v6.2 - YOLOv5 Classification Models, Apple M1, Reproducibility, ClearML and Deci.ai integrations2022-08-17 · 2022-08-17 10:26 UTC
查看更新说明
This release incorporates 401 PRs from 41 contributors since our last release in February 2022. It adds Classification training, validation, prediction and export (to all 11 formats), and also provides ImageNet-pretrained YOLOv5m-cls, ResNet (18, 34, 50, 101) and EfficientNet (b0-b3) models.
My main goal with this release is to introduce super simple YOLOv5 classification workflows just like our existing object detection models. The new v6.2 YOLOv5-cls models below are just a start, we will continue to improve these going forward together with our existing detection models. We'd love your contributions on this effort!
Our next release, v6.3 is scheduled for September and will bring official instance segmentation support to YOLOv5, with a major v7.0 release later this year updating architectures across all 3 tasks - classification, detection and segmentation.
Important Updates
- Classification Models ⭐ NEW: YOLOv5-cls ImageNet-pretrained classification models are now available for the first time (https://github.com/ultralytics/yolov5/pull/8956 by @glenn-jocher)
- ClearML logging ⭐ NEW: Integration with the open-source experiment tracker ClearML. Installing with
pip install clearmlwill enable the integration and allow users to track every training run in ClearML. This in turn allows users to track and compare runs and even schedule runs remotely. (https://github.com/ultralytics/yolov5/pull/8620 by @thepycoder) - Deci.ai optimization ⭐ NEW: Automatically compile and quantize YOLOv5 for better inference performance in one click at Deci (https://github.com/ultralytics/yolov5/pull/8956 by @glenn-jocher).
- GPU Export Benchmarks: Benchmark (mAP and speed) all YOLOv5 export formats with
python utils/benchmarks.py --weights yolov5s.pt --device 0for GPU benchmarks or--device cpufor CPU benchmarks (https://github.com/ultralytics/yolov5/pull/6963 by @glenn-jocher). - Training Reproducibility: Single-GPU YOLOv5 training with
torch>=1.12.0is now fully reproducible, and a new--seedargument can be used (default seed=0) (https://github.com/ultralytics/yolov5/pull/8213 by @AyushExel). - Apple Metal Performance Shader (MPS) Support: MPS support for Apple M1/M2 devices with
--device mps(full functionality is pending torch updates in https://github.com/pytorch/pytorch/issues/77764) (https://github.com/ultralytics/yolov5/pull/7878 by @glenn-jocher)
New Classification Checkpoints
We trained YOLOv5-cls classification models on ImageNet for 90 epochs using a 4xA100 instance, and we trained ResNet and EfficientNet models alongside with the same default training settings to compare. We exported all models to ONNX FP32 for CPU speed tests and to TensorRT FP16 for GPU speed tests. We ran all speed tests on Google Colab Pro for easy reproducibility.
| Model
- v6.1v6.1 - TensorRT, TensorFlow Edge TPU and OpenVINO Export and Inference2022-02-22 · 2022-02-22 11:35 UTC
查看更新说明
This release incorporates many new features and bug fixes (271 PRs from 48 contributors) since our last release in October 2021. It adds TensorRT, Edge TPU and OpenVINO support, and provides retrained models at
--batch-size 128with new default one-cycle linear LR scheduler. YOLOv5 now officially supports 11 different formats, not just for export but for inference (both detect.py and PyTorch Hub), and validation to profile mAP and speed results after export.Format export.py --includeModel PyTorch - yolov5s.ptTorchScript torchscriptyolov5s.torchscriptONNX onnxyolov5s.onnxOpenVINO openvinoyolov5s_openvino_model/TensorRT engineyolov5s.engineCoreML coremlyolov5s.mlmodelTensorFlow SavedModel saved_modelyolov5s_saved_model/TensorFlow GraphDef pbyolov5s.pbTensorFlow Lite tfliteyolov5s.tfliteTensorFlow Edge TPU edgetpuyolov5s_edgetpu.tfliteTensorFlow.js tfjsyolov5s_web_model/Usage examples (ONNX shown):
Export: python export.py --weights yolov5s.pt --include onnx Detect: python detect.py --weights yolov5s.onnx PyTorch Hub: model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s.onnx') Validate: python val.py --weights yolov5s.onnx Visualize: https://netron.appImportant Updates
- TensorRT support: TensorFlow, Keras, TFLite, TF.js model export now fully integrated using
python export.py --include saved_model pb tflite tfjs(https://github.com/ultralytics/yolov5/pull/5699 by @imyhxy) - Tensorflow Edge TPU support ⭐ NEW: New smaller YOLOv5n (1.9M params) model below YOLOv5s (7.5M params), exports to 2.1 MB INT8 size, ideal for ultralight mobile solutions. (https://github.com/ultralytics/yolov5/pull/3630 by @zldrobit)
- OpenVINO support: YOLOv5 ONNX models are now compatible with both OpenCV DNN and ONNX Runtime (https://github.com/ultralytics/yolov5/pull/6057 by @glenn-jocher).
- Export Benchmarks: Benchmark (mAP and speed) all YOLOv5 export formats with
python utils/benchmarks.py --weights yolov5s.pt. Currently operates on CPU, future updates will implement GPU support. (https://github.com/ultralytics/yolov5/pull/6613 by @glenn-jocher). - Architecture: no changes
- Hyperparameters: minor change
- hyp-scratch-large.yaml
lrfreduced from 0.2 to 0.1 (https://github.com/ultralytics/yolov5/pull/6525 by @glenn-jocher).
- hyp-scratch-large.yaml
- Training: Default Learning Rate (LR
- TensorRT support: TensorFlow, Keras, TFLite, TF.js model export now fully integrated using
- v6.0v6.0 - YOLOv5n 'Nano' models, Roboflow integration, TensorFlow export, OpenCV DNN support2021-10-12 · 2021-10-12 07:08 UTC
查看更新说明
This release incorporates many new features and bug fixes (465 PRs from 73 contributors) since our last release v5.0 in April, brings architecture tweaks, and also introduces new P5 and P6 'Nano' models: YOLOv5n and YOLOv5n6. Nano models maintain the YOLOv5s depth multiple of 0.33 but reduce the YOLOv5s width multiple from 0.50 to 0.25, resulting in ~75% fewer parameters, from 7.5M to 1.9M, ideal for mobile and CPU solutions.
Example usage:
python detect.py --weights yolov5n.pt --img 640 # Nano P5 model trained at --img 640 (28.4 [email protected]:0.95) python detect.py --weights yolov5n6.pt --img 1280 # Nano P6 model trained at --img 1280 (34.0 mAP0.5:0.95)Important Updates
-
Roboflow Integration ⭐ NEW: Train YOLOv5 models directly on any Roboflow dataset with our new integration! (https://github.com/ultralytics/yolov5/issues/4975 by @Jacobsolawetz)
-
YOLOv5n 'Nano' models ⭐ NEW: New smaller YOLOv5n (1.9M params) model below YOLOv5s (7.5M params), exports to 2.1 MB INT8 size, ideal for ultralight mobile solutions. (https://github.com/ultralytics/yolov5/discussions/5027 by @glenn-jocher)
-
TensorFlow and Keras Export: TensorFlow, Keras, TFLite, TF.js model export now fully integrated using
python export.py --include saved_model pb tflite tfjs(https://github.com/ultralytics/yolov5/pull/1127 by @zldrobit) -
OpenCV DNN: YOLOv5 ONNX models are now compatible with both OpenCV DNN and ONNX Runtime (https://github.com/ultralytics/yolov5/pull/4833 by @SamFC10).
-
Model Architecture: Updated backbones are slightly smaller, faster and more accurate.
- Replacement of
Focus()with an equivalentConv(k=6, s=2, p=2)layer (https://github.com/ultralytics/yolov5/issues/4825 by @thomasbi1) for improved exportability - New
SPPF()replacement forSPP()layer for reduced ops (https://github.com/ultralytics/yolov5/pull/4420 by @glenn-jocher) - Reduction in P3 backbone layer
C3()repeats from 9 to 6 for improved speeds - Reorder places
SPPF()at end of backbone - Reintroduction of shortcut in the last
C3()backbone layer - Updated hyperparameters with increased mixup and copy-paste augmentation
- Replacement of
New Results
- COCO AP val denotes [email protected]:0.95 metric measured on the 5000-image COCO val2017 dataset over various inference sizes from 256 to 1536.
- GPU Speed measures average inference time per image on COCO val2017 dataset using a AWS p3.2xlarge V100 instance at batch-size 32.
- EfficientDet data from google/automl at batch size 8.
- Reproduce by
python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt
mAP improves from +0.3% to +1.1% across all models, and ~5% FLOPs reduction produces slight speed improvements and a reduced CUDA memory footprint. Example YOLOv5l before and after metrics:
|YOLOv5lLarge|size(pixels) |mAPval0.5:0.95 |mAPval0.5 |SpeedCPU b1(ms) |SpeedV100 b1(ms) |Speed<su
-
- v5.0v5.0 - YOLOv5-P6 1280 models, AWS, Supervise.ly and YouTube integrations2021-04-11 · 2021-04-11 17:25 UTC
查看更新说明
This release implements YOLOv5-P6 models and retrained YOLOv5-P5 models. All model sizes YOLOv5s/m/l/x are now available in both P5 and P6 architectures:
- YOLOv5-P5 models (same architecture as v4.0 release): 3 output layers P3, P4, P5 at strides 8, 16, 32, trained at
--img 640
python detect.py --weights yolov5s.pt # P5 models yolov5m.pt yolov5l.pt yolov5x.pt- YOLOv5-P6 models: 4 output layers P3, P4, P5, P6 at strides 8, 16, 32, 64 trained at
--img 1280
python detect.py --weights yolov5s6.pt # P6 models yolov5m6.pt yolov5l6.pt yolov5x6.ptExample usage:
# Command Line python detect.py --weights yolov5m.pt --img 640 # P5 model at 640 python detect.py --weights yolov5m6.pt --img 640 # P6 model at 640 python detect.py --weights yolov5m6.pt --img 1280 # P6 model at 1280# PyTorch Hub model = torch.hub.load('ultralytics/yolov5', 'yolov5m6') # P6 model results = model(imgs, size=1280) # inference at 1280Notable Updates
- YouTube Inference: Direct inference from YouTube videos, i.e.
python detect.py --source 'https://youtu.be/NUsoVlDFqZg'. Live streaming videos and normal videos supported. (https://github.com/ultralytics/yolov5/pull/2752) - AWS Integration: Amazon AWS integration and new AWS Quickstart Guide for simple EC2 instance YOLOv5 training and resuming of interrupted Spot instances. (https://github.com/ultralytics/yolov5/pull/2185)
- Supervise.ly Integration: New integration with the Supervisely Ecosystem for training and deploying YOLOv5 models with Supervise.ly (https://github.com/ultralytics/yolov5/issues/2518)
- Improved W&B Integration: Allows saving datasets and models directly to Weights & Biases. This allows for --resume directly from W&B (useful for temporary environments like Colab), as well as enhanced visualization tools. See this blog by @AyushExel for details. (https://github.com/ultralytics/yolov5/pull/2125)
Updated Results
P6 models include an extra P6/64 output layer for detection of larger objects, and benefit the most from training at higher resolution. For this reason we trained all P5 models at 640, and all P6 models at 1280.
- GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS.
- EfficientDet data from google/automl at batch size 8.
- Reproduce by
python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt
- April 11, 2021: v5.0 release: YOLOv5-P6 1280 models, AWS, Supervise.ly and YouTube integrations.
- January 5, 2021: [v4.0 release](https://github.com/ultralytics/yolov5
- YOLOv5-P5 models (same architecture as v4.0 release): 3 output layers P3, P4, P5 at strides 8, 16, 32, trained at
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية
Ultralytics YOLOv5 🚀 is a fast, accurate, and easy-to-use computer vision model developed by Ultralytics. Based on the PyTorch framework, YOLOv5 is renowned for its speed, accuracy, and simplicity. It incorporates insights and best practices from extensive research and development, making it a popular and reliable choice for a wide range of vision AI tasks, including object detection, image segmentation, and image classification.
We hope the resources here help you get the most out of YOLOv5. Please browse the YOLOv5 Docs for detailed information, raise an issue on GitHub for support, and join our Discord community for questions and discussions!
To request an Enterprise License, please complete the form at Ultralytics Licensing.
🚀 Explore the Ultralytics YOLO Ecosystem
YOLOv5 is a mature, production-proven model that remains an excellent choice for fast and reliable object detection, instance segmentation, and image classification. If your project calls for the newest architectures, additional tasks such as pose estimation and oriented object detection (OBB), or a unified Python and CLI interface, the actively maintained ultralytics package brings the latest Ultralytics YOLO models together in one place. Explore the Ultralytics Docs to find the best fit for your use case.
# Install the ultralytics package for the latest Ultralytics YOLO models
pip install ultralytics
📚 Documentation
See the YOLOv5 Docs for full documentation on training, testing, and deployment. See below for quickstart examples.
Clone the repository and install dependencies in a Python>=3.8.0 environment. Ensure you have PyTorch>=1.8 installed.
# Clone the YOLOv5 repository
git clone https://github.com/ultralytics/yolov5
# Navigate to the cloned directory
cd yolov5
# Install required packages
pip install -r requirements.txt
Use YOLOv5 via PyTorch Hub for inference. Models are automatically downloaded from the latest YOLOv5 release.
import torch
# Load a YOLOv5 model (options: yolov5n, yolov5s, yolov5m, yolov5l, yolov5x)
model = torch.hub.load("ultralytics/yolov5", "yolov5s") # Default: yolov5s
# Define the input image source (URL, local file, PIL image, OpenCV frame, numpy array, or list)
img = "https://ultralytics.com/images/zidane.jpg" # Example image
# Perform inference (handles batching, resizing, normalization automatically)
results = model(img)
# Process the results (options: .print(), .show(), .save(), .crop(), .pandas())
results.print() # Print results to console
results.show() # Display results in a window
results.save() # Save results to runs/detect/exp
The detect.py script runs inference on various sources. It automatically downloads models from the latest YOLOv5 release and saves the results to the runs/detect directory.
# Run inference using a webcam
python detect.py --weights yolov5s.pt --source 0
# Run inference on a local image file
python detect.py --weights yolov5s.pt --source img.jpg
# Run inference on a local video file
python detect.py --weights yolov5s.pt --source vid.mp4
# Run inference on a screen capture
python detect.py --weights yolov5s.pt --source screen
# Run inference on a directory of images
python detect.py --weights yolov5s.pt --source path/to/images/
# Run inference on a text file listing image paths
python detect.py --weights yolov5s.pt --source list.txt
# Run inference on a text file listing stream URLs
python detect.py --weights yolov5s.pt --source list.streams
# Run inference using a glob pattern for images
python detect.py --weights yolov5s.pt --source 'path/to/*.jpg'
# Run inference on a YouTube video URL
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4'
# Run inference on an RTSP, RTMP, or HTTP stream
python detect.py --weights yolov5s.pt --source 'rtsp://example.com/media.mp4'
The commands below demonstrate how to reproduce YOLOv5 COCO dataset results. Both models and datasets are downloaded automatically from the latest YOLOv5 release. Training times for YOLOv5n/s/m/l/x are approximately 1/2/4/6/8 days on a single NVIDIA V100 GPU. Using Multi-GPU training can significantly reduce training time. Use the largest --batch-size your hardware allows, or use --batch-size -1 for YOLOv5 AutoBatch. The batch sizes shown below are for V100-16GB GPUs.
# Train YOLOv5n on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml --batch-size 128
# Train YOLOv5s on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5s.yaml --batch-size 64
# Train YOLOv5m on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5m.yaml --batch-size 40
# Train YOLOv5l on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5l.yaml --batch-size 24
# Train YOLOv5x on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5x.yaml --batch-size 16
- Train Custom Data 🚀 RECOMMENDED: Learn how to train YOLOv5 on your own datasets.
- Tips for Best Training Results ☘️: Improve your model's performance with expert tips.
- Multi-GPU Training: Speed up training using multiple GPUs.
- PyTorch Hub Integration: Easily load models using PyTorch Hub.
- Model Export (TFLite, ONNX, CoreML, TensorRT) 🚀: Convert your models to various deployment formats like ONNX or TensorRT.
- NVIDIA Jetson Deployment: Deploy YOLOv5 on NVIDIA Jetson devices.
- Test-Time Augmentation (TTA): Enhance prediction accuracy with TTA.
- Model Ensembling: Combine multiple models for better performance.
- Model Pruning/Sparsity: Optimize models for size and speed.
- Hyperparameter Evolution: Automatically find the best training hyperparameters.
- Transfer Learning with Frozen Layers: Adapt pretrained models to new tasks efficiently using transfer learning.
- Architecture Summary: Understand the YOLOv5 model architecture.
- Ultralytics Platform Training 🚀 RECOMMENDED: Train and deploy YOLO models using Ultralytics Platform.
- ClearML Logging: Integrate with ClearML for experiment tracking.
- Neural Magic DeepSparse Integration: Accelerate inference with DeepSparse.
- Comet Logging: Log experiments using Comet ML.
🧩 Integrations
Our key integrations with leading AI platforms extend the functionality of Ultralytics' offerings, enhancing tasks like dataset labeling, training, visualization, and model management. Discover how Ultralytics, in collaboration with partners like Weights & Biases, Comet ML, Roboflow, and Intel OpenVINO, can optimize your AI workflow. Explore more at Ultralytics Integrations.
🤔 Why YOLOv5?
YOLOv5 is designed for simplicity and ease of use. We prioritize real-world performance and accessibility.
- COCO AP val denotes the mean Average Precision (mAP) at Intersection over Union (IoU) thresholds from 0.5 to 0.95, measured on the 5,000-image COCO val2017 dataset across various inference sizes (256 to 1536 pixels).
- GPU Speed measures the average inference time per image on the COCO val2017 dataset using an AWS p3.2xlarge V100 instance with a batch size of 32.
- EfficientDet data is sourced from the google/automl repository at batch size 8.
- Reproduce these results using the command:
python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt
Pretrained Checkpoints
This table shows the performance metrics for various YOLOv5 models trained on the COCO dataset.
| Model | Size(pixels) | mAPval50-95 | mAPval50 | SpeedCPU b1(ms) | SpeedV100 b1(ms) | SpeedV100 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] | 12801536 | 55.055.8 | 72.772.7 | 3136- | 26.2- | 19.4- | 140.7- | 209.8- |
- The 640-pixel rows report the legacy anchor-based YOLOv5 checkpoints, while their links open the corresponding anchor-free YOLOv5u successor models on Ultralytics Platform. P6 links continue to download the legacy 1280-pixel checkpoints directly.
- All checkpoints were trained for 300 epochs using default settings. Nano (n) and Small (s) models use hyp.scratch-low.yaml hyperparameters, while Medium (m), Large (l), and Extra-Large (x) models use hyp.scratch-high.yaml.
- mAPval values represent single-model, single-scale performance on the COCO val2017 dataset.Reproduce using:
python val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65 - Speed metrics are averaged over COCO val images using an AWS p3.2xlarge V100 instance. Non-Maximum Suppression (NMS) time (~1 ms/image) is not included.Reproduce using:
python val.py --data coco.yaml --img 640 --task speed --batch 1 - TTA (Test Time Augmentation) includes reflection and scale augmentations for improved accuracy.Reproduce using:
python val.py --data coco.yaml --img 1536 --iou 0.7 --augment
🖼️ Segmentation
The YOLOv5 release v7.0 introduced instance segmentation models designed for easy training, validation, and deployment. For full details, see the Release Notes and explore the YOLOv5 Segmentation Colab Notebook for quickstart examples.
YOLOv5 segmentation models were trained on the COCO dataset for 300 epochs at an image size of 640 pixels using A100 GPUs. Models were exported to ONNX FP32 for CPU speed tests and TensorRT FP16 for GPU speed tests. All speed tests were conducted on Google Colab Pro notebooks for reproducibility.
| Model | Size(pixels) | mAPbox50-95 | mAPmask50-95 | Train Time300 epochsA100 (hours) | SpeedONNX CPU(ms) | SpeedTRT 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 |
- All checkpoints were trained for 300 epochs using the SGD optimizer with
lr0=0.01andweight_decay=5e-5at an image size of 640 pixels, using default settings.Training runs are logged at https://wandb.ai/glenn-jocher/YOLOv5_v70_official. - Accuracy values represent single-model, single-scale performance on the COCO dataset.Reproduce using:
python segment/val.py --data coco.yaml --weights yolov5s-seg.pt - Speed metrics are averaged over 100 inference images using a Colab Pro A100 High-RAM instance. Values indicate inference speed only (NMS adds approximately 1ms per image).Reproduce using:
python segment/val.py --data coco.yaml --weights yolov5s-seg.pt --batch 1 - Export to ONNX (FP32) and TensorRT (FP16) was performed using
export.py.Reproduce using:python export.py --weights yolov5s-seg.pt --include engine --device 0 --half
Train
YOLOv5 segmentation training supports automatic download of the COCO128-seg dataset via the --data coco128-seg.yaml argument. For the full COCO-segments dataset, download it manually using bash data/scripts/get_coco.sh --train --val --segments and then train with python segment/train.py --data coco.yaml.
# Train on a single GPU
python segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640
# Train using Multi-GPU Distributed Data Parallel (DDP)
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640 --device 0,1,2,3
Val
Validate the mask mean Average Precision (mAP) of YOLOv5s-seg on the COCO dataset:
# Download COCO validation segments split (780MB, 5000 images)
bash data/scripts/get_coco.sh --val --segments
# Validate the model
python segment/val.py --weights yolov5s-seg.pt --data coco.yaml --img 640
Predict
Use the pretrained YOLOv5m-seg.pt model to perform segmentation on bus.jpg:
# Run prediction
python segment/predict.py --weights yolov5m-seg.pt --source data/images/bus.jpg
# Load model from PyTorch Hub (Note: Inference support might vary)
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5m-seg.pt")
![]() | ![]() |
|---|
Export
Export the YOLOv5s-seg model to ONNX and TensorRT formats:
# Export model
python export.py --weights yolov5s-seg.pt --include onnx engine --img 640 --device 0
🏷️ Classification
YOLOv5 release v6.2 introduced support for image classification model training, validation, and deployment. Check the Release Notes for details and the YOLOv5 Classification Colab Notebook for quickstart guides.
YOLOv5-cls classification models were trained on ImageNet for 90 epochs using a 4xA100 instance. ResNet and EfficientNet models were trained alongside under identical settings for comparison. Models were exported to ONNX FP32 (CPU speed tests) and TensorRT FP16 (GPU speed tests). All speed tests were run on Google Colab Pro for reproducibility.
| Model | Size(pixels) | Acctop1 | Acctop5 | Training90 epochs4xA100 (hours) | SpeedONNX CPU(ms) | SpeedTensorRT 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 |
- All checkpoints were trained for 90 epochs using the SGD optimizer with
lr0=0.001andweight_decay=5e-5at an image size of 224 pixels, using default settings.Training runs are logged at https://wandb.ai/glenn-jocher/YOLOv5-Classifier-v6-2. - Accuracy values (top-1 and top-5) represent single-model, single-scale performance on the ImageNet-1k dataset.Reproduce using:
python classify/val.py --data ../datasets/imagenet --img 224 - Speed metrics are averaged over 100 inference images using a Google Colab Pro V100 High-RAM instance.Reproduce using:
python classify/val.py --data ../datasets/imagenet --img 224 --batch 1 - Export to ONNX (FP32) and TensorRT (FP16) was performed using
export.py.Reproduce using:python export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224
Train
YOLOv5 classification training supports automatic download for datasets like MNIST, Fashion-MNIST, CIFAR10, CIFAR100, Imagenette, Imagewoof, and ImageNet using the --data argument. For example, start training on MNIST with --data mnist.
# Train on a single GPU using CIFAR-100 dataset
python classify/train.py --model yolov5s-cls.pt --data cifar100 --epochs 5 --img 224 --batch 128
# Train using Multi-GPU DDP on ImageNet dataset
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3
Val
Validate the accuracy of the YOLOv5m-cls model on the ImageNet-1k validation dataset:
# Download ImageNet validation split (6.3GB, 50,000 images)
bash data/scripts/get_imagenet.sh --val
# Validate the model
python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224
Predict
Use the pretrained YOLOv5s-cls.pt model to classify the image bus.jpg:
# Run prediction
python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg
# Load model from PyTorch Hub
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s-cls.pt")
Export
Export trained YOLOv5s-cls, ResNet50, and EfficientNet_b0 models to ONNX and TensorRT formats:
# Export models
python export.py --weights yolov5s-cls.pt resnet50.pt efficientnet_b0.pt --include onnx engine --img 224
☁️ Environments
Get started quickly with our pre-configured environments. Click the icons below for setup details.
🤝 Contribute
We welcome your contributions! Making YOLOv5 accessible and effective is a community effort. Please see our Contributing Guide to get started. Share your feedback through the YOLOv5 Survey. Thank you to all our contributors for making YOLOv5 better!
📜 License
Ultralytics provides two licensing options to meet different needs:
- AGPL-3.0 License: An OSI-approved open-source license ideal for academic research, personal projects, and testing. It promotes open collaboration and knowledge sharing. See the LICENSE file for details.
- Enterprise License: Tailored for commercial applications, this license allows seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. For commercial use cases, please contact us via Ultralytics Licensing.
📧 Contact
For bug reports and feature requests related to YOLOv5, please visit GitHub Issues. For general questions, discussions, and community support, join our Discord server!


