ultralytics/yolov5

★ 58,010⑂ 17,469

Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.

58,010Star
17,469Fork
380Watch
32Issue
PythonLanguage
AGPL-3.0License
Created 2020-05-18 · last push 2026-09-14 · repository size 18126 KB · default branch master

README

https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics YOLO banner

中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية

https://github.com/ultralytics/yolov5/blob/HEAD/YOLOv5 CI Testing https://github.com/ultralytics/yolov5/blob/HEAD/Docker Pulls https://github.com/ultralytics/yolov5/blob/HEAD/Discord https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics Forums https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics Reddit
https://github.com/ultralytics/yolov5/blob/HEAD/Run on Gradient https://github.com/ultralytics/yolov5/blob/HEAD/Open In Colab https://github.com/ultralytics/yolov5/blob/HEAD/Open In Kaggle

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.

https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics GitHub https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics LinkedIn https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics Twitter https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics YouTube https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics TikTok https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics BiliBili https://github.com/ultralytics/yolov5/blob/HEAD/space https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics Discord


🚀 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
https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics YOLO performance comparison

📚 Documentation

See the YOLOv5 Docs for full documentation on training, testing, and deployment. See below for quickstart examples.

Install

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

Inference with PyTorch Hub

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

Inference with detect.py

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'

Training

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
https://github.com/ultralytics/yolov5/blob/HEAD/YOLOv5 Training Results

Tutorials

🧩 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.

https://github.com/ultralytics/yolov5/blob/HEAD/Ultralytics active learning integrations

🤔 Why YOLOv5?

YOLOv5 is designed for simplicity and ease of use. We prioritize real-world performance and accessibility.

https://github.com/ultralytics/yolov5/blob/HEAD/YOLOv5 Performance Chart

YOLOv5-P5 640 Figure

https://github.com/ultralytics/yolov5/blob/HEAD/YOLOv5 P5 640 Performance Chart

Figure Notes

Pretrained Checkpoints

This table shows the performance metrics for various YOLOv5 models trained on the COCO dataset.

| 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]](https://docs.ultralytics.com/yolov5/tutorials/test-time-augmentation) | 1280
1536 | 55.0
55.8 | 72.7
72.7 | 3136
- | 26.2
- | 19.4
- | 140.7
- | 209.8
- |

Table Notes
  • 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.

Segmentation Checkpoints

More Image Trending projects