YOLOv5 is a computer vision model family developed by Ultralytics and implemented using PyTorch. It is designed for fast and accurate computer vision tasks and is widely known for its ease of training, inference, deployment, and customization. The official Ultralytics repository currently supports object detection, instance segmentation, image classification, training, validation, and model export workflows.
Unlike YOLOv1, YOLOv2, and YOLOv3, which were originally associated with Joseph Redmon’s Darknet framework, YOLOv5 is maintained in its own Ultralytics repository and uses a Python and PyTorch-based workflow.
What Is YOLOv5?
YOLOv5 is part of the You Only Look Once family of real-time computer vision models.
Its main goal is to provide a practical balance between:
- Detection accuracy
- Inference speed
- Model size
- Ease of training
- Deployment flexibility
The official repository describes YOLOv5 as a fast, accurate, and easy-to-use computer vision model based on PyTorch.
YOLOv5 can be used for tasks including:
- Object detection
- Instance segmentation
- Image classification
These capabilities make it useful for both research and production-oriented computer vision workflows.
YOLOv5 and PyTorch
YOLOv5 is built on the PyTorch deep learning framework.
This is an important difference from earlier Darknet-based YOLO versions.
Using PyTorch provides a Python-first workflow for:
- Model training
- Custom dataset support
- Inference
- Validation
- Transfer learning
- GPU acceleration
- Exporting models
- Integration with other Python tools
The repository currently documents installation in a Python 3.8 or newer environment with PyTorch installed.
YOLOv5 Repository Structure
The YOLOv5 repository contains several important directories and scripts.
Major directories include:
modelsdatautilsclassifysegmenttests
Important top-level scripts include:
train.pydetect.pyval.pyexport.pybenchmarks.pyhubconf.py
These files handle the major YOLOv5 workflows such as training, inference, validation, exporting, and benchmarking.
YOLOv5 Model Variants
YOLOv5 is available in several model sizes.
The main detection models include:
- YOLOv5n
- YOLOv5s
- YOLOv5m
- YOLOv5l
- YOLOv5x
The letters represent different model scales.
YOLOv5n
YOLOv5n is the Nano model.
It is the smallest model in the standard family and is designed for low computational requirements and fast inference.
YOLOv5s
YOLOv5s is the Small model.
It provides a lightweight architecture with a strong balance between speed and detection performance.
YOLOv5m
YOLOv5m is the Medium model.
It increases model capacity and accuracy compared with Nano and Small variants.
YOLOv5l
YOLOv5l is the Large model.
It provides higher detection performance but requires more processing power and memory.
YOLOv5x
YOLOv5x is the Extra-Large model.
It offers the highest capacity among the standard YOLOv5 variants while also requiring the most computational resources.
The official repository provides pretrained checkpoints for all five standard model sizes.
YOLOv5 Model Size and Performance
The official repository provides COCO validation results for the standard models at a 640-pixel input size.
For example:
| Model | Parameters | mAP 50-95 |
|---|---|---|
| YOLOv5n | 1.9M | 28.0 |
| YOLOv5s | 7.2M | 37.4 |
| YOLOv5m | 21.2M | 45.4 |
| YOLOv5l | 46.5M | 49.0 |
| YOLOv5x | 86.7M | 50.7 |
The larger models generally provide higher accuracy while requiring more memory and computational power.
YOLOv5 Input Resolution
The standard YOLOv5 detection checkpoints are commonly evaluated at an image size of:
640 pixels
The repository also includes larger P6 model variants that use a 1280-pixel input size.
Image size affects the balance between:
- Detection accuracy
- GPU memory consumption
- Processing speed
- Small object detection
Higher resolutions can provide more image detail, while smaller resolutions typically allow faster inference.
How YOLOv5 Works
YOLOv5 follows the single-stage object detection philosophy.
An input image is processed through one neural network that directly produces object detection predictions.
The general process is:
- Load the input image.
- Resize and prepare the image for the model.
- Extract visual features.
- Generate bounding box predictions.
- Predict object confidence.
- Predict object classes.
- Filter low-confidence predictions.
- Apply post-processing.
- Return final detected objects.
This approach avoids a separate region proposal stage and makes YOLOv5 suitable for real-time and near-real-time applications.
YOLOv5 Bounding Boxes
For object detection, YOLOv5 predicts bounding boxes around objects.
A bounding box represents:
- Object position
- Object width
- Object height
- Confidence
- Predicted class
The standard legacy YOLOv5 checkpoints in the repository use an anchor-based detection design. The current repository notes that these legacy 640-pixel YOLOv5 checkpoints are anchor-based.
YOLOv5 Training
YOLOv5 includes a dedicated training script:
train.py
The official repository provides commands for training YOLOv5n, YOLOv5s, YOLOv5m, YOLOv5l, and YOLOv5x models on the COCO dataset.
Training allows users to:
- Train from scratch
- Use pretrained weights
- Fine-tune a model
- Train on custom datasets
- Adjust batch size
- Configure epochs
- Modify model architecture
- Tune hyperparameters
The official examples use 300 training epochs for the standard COCO model configurations.
Custom Dataset Training
One of the strongest features of YOLOv5 is support for custom datasets.
Users can train a YOLOv5 model on their own object classes by preparing:
- Training images
- Validation images
- Annotation labels
- Dataset configuration
- Model configuration
This makes YOLOv5 useful for specialized applications where the standard COCO object classes are not enough.
Possible custom use cases include:
- Product detection
- Industrial defect detection
- Vehicle recognition
- Medical image research
- Wildlife monitoring
- Safety equipment detection
- Agriculture
- Robotics
YOLOv5 Inference
YOLOv5 includes:
detect.py
for running inference.
The official repository shows that detect.py can process several types of input sources, including:
- Webcam
- Local image
- Local video
- Screen capture
- Image directory
- Lists of image paths
- Stream URLs
- Glob patterns
- YouTube videos
- RTSP streams
- RTMP streams
- HTTP streams
This flexibility makes YOLOv5 suitable for both static-image and real-time video applications.
PyTorch Hub Support
YOLOv5 can also be loaded through PyTorch Hub.
The repository provides examples for loading models such as:
- yolov5n
- yolov5s
- yolov5m
- yolov5l
- yolov5x
PyTorch Hub simplifies inference because model weights can be downloaded automatically.
YOLOv5 Validation
The repository includes:
val.py
for model validation.
Validation can be used to evaluate model performance on a dataset using metrics such as:
- Precision
- Recall
- mAP
- IoU-based accuracy
The official performance table reports mAP values using COCO validation data and IoU thresholds from 0.5 to 0.95.
Mean Average Precision
A major performance metric for object detection is mAP, or mean Average Precision.
The YOLOv5 repository reports metrics including:
mAP50-95
This evaluates detection performance across multiple Intersection over Union thresholds between 0.50 and 0.95.
It also reports:
mAP50
which measures performance at an IoU threshold of 0.50.
These metrics make it easier to compare different YOLOv5 model sizes.
YOLOv5 Export
YOLOv5 includes a dedicated:
export.py
script.
The repository documents support for exporting models into deployment formats including:
- ONNX
- TensorRT
- TensorFlow Lite
- CoreML
These export options make it easier to deploy YOLOv5 outside a normal PyTorch environment.
Exporting can be useful for:
- Mobile applications
- Edge devices
- Production inference servers
- Embedded systems
- GPU-optimized deployment
- Cross-platform applications
YOLOv5 on NVIDIA GPUs
YOLOv5 can take advantage of CUDA-enabled NVIDIA GPUs through PyTorch.
GPU acceleration can significantly reduce:
- Training time
- Inference latency
- Batch processing time
The official repository provides benchmark results using NVIDIA V100 GPUs and also documents multi-GPU training.
Multi-GPU Training
YOLOv5 supports multi-GPU training.
This allows training workloads to be distributed across multiple GPUs.
For larger datasets and models, multi-GPU training can significantly reduce overall training time compared with using a single GPU.
YOLOv5 AutoBatch
The repository supports an AutoBatch option.
Users can specify:
--batch-size -1
to allow YOLOv5 to determine an appropriate batch size based on available hardware resources.
This can simplify training setup when GPU memory limitations are unknown.
YOLOv5 Instance Segmentation
YOLOv5 later expanded beyond standard bounding-box detection.
The repository includes a dedicated:
segment
directory for instance segmentation.
Instance segmentation identifies objects while also predicting a pixel-level mask for each detected instance.
The official repository states that YOLOv5 v7.0 introduced YOLOv5 instance segmentation models.
Available segmentation variants include:
- YOLOv5n-seg
- YOLOv5s-seg
- YOLOv5m-seg
- YOLOv5l-seg
- YOLOv5x-seg
YOLOv5 Image Classification
The repository also contains a:
classify
directory.
This provides image classification capabilities alongside detection and segmentation.
Image classification predicts the category of an entire image instead of identifying individual object locations.
This expands YOLOv5 beyond its original object detection use case.
YOLOv5 Transfer Learning
YOLOv5 supports transfer learning.
A pretrained model can be adapted to a new custom dataset instead of training completely from scratch.
Transfer learning can provide:
- Faster training
- Reduced data requirements
- Better initial features
- Improved convergence
The repository also provides guidance for freezing pretrained layers during transfer learning.
Test-Time Augmentation
YOLOv5 supports Test-Time Augmentation, commonly called TTA.
TTA can use operations such as:
- Image scaling
- Reflection
to generate additional predictions during inference.
These predictions can improve accuracy, although additional processing typically makes inference slower.
Model Ensembling
The YOLOv5 ecosystem also supports model ensembling.
Model ensembling combines predictions from multiple models.
This can sometimes improve detection performance compared with relying on a single model, although it also increases computational cost.
YOLOv5 Model Pruning
YOLOv5 includes documentation related to model pruning and sparsity.
Pruning reduces unnecessary model components to help improve efficiency.
Potential benefits include:
- Smaller model size
- Reduced computational requirements
- Faster deployment
The actual improvement depends on deployment hardware and optimization support.
YOLOv5 Hyperparameter Evolution
YOLOv5 includes support for hyperparameter evolution.
This process can automatically search for better combinations of training parameters.
Parameters that can influence training include:
- Learning rate
- Momentum
- Weight decay
- Data augmentation values
- Loss-related settings
Hyperparameter optimization can improve model performance on custom datasets.
YOLOv5 vs YOLOv3
YOLOv5 represents a major change in tooling compared with YOLOv3.
| Feature | YOLOv3 | YOLOv5 |
|---|---|---|
| Main framework | Darknet | PyTorch |
| Main language workflow | C/CUDA | Python |
| Training script | Darknet commands | train.py |
| Detection script | Darknet CLI | detect.py |
| Validation | Darknet workflow | val.py |
| Export support | More limited | Multiple deployment formats |
| Custom training workflow | Available | Simplified |
| PyTorch Hub | No | Yes |
| Instance segmentation | No standard YOLOv3 repo support | Yes |
| Classification workflow | Separate | Included |
YOLOv5 provides a more modern Python-based development environment than the original Darknet YOLO implementations.
Advantages of YOLOv5
Easy to Use
The repository provides Python scripts for most common computer vision tasks.
Multiple Model Sizes
Users can select Nano, Small, Medium, Large, or Extra-Large models depending on their hardware and accuracy requirements.
Fast Inference
YOLOv5 is designed for efficient object detection.
Custom Training
Users can train models on their own datasets.
PyTorch Ecosystem
YOLOv5 benefits from compatibility with PyTorch and Python tools.
Multiple Deployment Formats
Models can be exported for different inference environments.
Multiple Computer Vision Tasks
The repository supports object detection, segmentation, and classification.
Strong Documentation and Tooling
The repository includes training, validation, inference, export, benchmarking, and deployment resources.
YOLOv5 Limitations
YOLOv5 also has limitations.
Larger Models Require More Hardware
Models such as YOLOv5l and YOLOv5x require substantially more computational resources than YOLOv5n and YOLOv5s.
Accuracy and Speed Tradeoff
Higher-capacity models usually improve accuracy but reduce inference speed.
Training Requires Labeled Data
Custom object detection training requires correctly annotated datasets.
Deployment Optimization Can Vary
Performance can differ significantly depending on:
- Hardware
- Export format
- Precision
- Image size
- Batch size
YOLOv5 Use Cases
YOLOv5 can be applied to many computer vision tasks.
Examples include:
- Vehicle detection
- Person detection
- Traffic monitoring
- Security cameras
- Industrial inspection
- Agriculture
- Wildlife monitoring
- Robotics
- Retail analytics
- Manufacturing
- Drone vision
- Sports analysis
- Custom object recognition
Its ability to train on custom data makes it suitable for specialized detection problems.
YOLOv5 and COCO
YOLOv5 pretrained object detection models are commonly trained and evaluated using the COCO dataset.
The repository provides commands for reproducing COCO training results.
Standard YOLOv5 models are trained for 300 epochs in the official examples, and their reported accuracy results are measured on COCO validation data.
Why YOLOv5 Became Popular
YOLOv5 became widely adopted because it made YOLO-style object detection easier to use within the Python ecosystem.
Important factors include:
- PyTorch implementation
- Simple training commands
- Pretrained models
- Multiple model sizes
- Custom dataset support
- Easy inference
- GPU acceleration
- Multiple export formats
- Active tooling
- Strong practical performance
The repository emphasizes simplicity, accessibility, and real-world performance as major design goals.
Frequently Asked Questions
What is YOLOv5?
YOLOv5 is a computer vision model family developed by Ultralytics using PyTorch. It supports object detection as well as additional tasks such as instance segmentation and image classification.
Who developed YOLOv5?
YOLOv5 was developed by Ultralytics.
Is YOLOv5 based on Darknet?
No. YOLOv5 uses PyTorch rather than Joseph Redmon’s original Darknet framework.
What programming language does YOLOv5 use?
The YOLOv5 repository uses a Python-based workflow built around PyTorch.
What YOLOv5 models are available?
The standard detection models include:
- YOLOv5n
- YOLOv5s
- YOLOv5m
- YOLOv5l
- YOLOv5x
What is YOLOv5s?
YOLOv5s is the Small YOLOv5 model. It offers a lightweight balance between inference speed, model size, and detection accuracy.
What is YOLOv5n?
YOLOv5n is the Nano model and is the smallest standard YOLOv5 detection model.
What is YOLOv5x?
YOLOv5x is the Extra-Large model and has the highest capacity among the standard YOLOv5n/s/m/l/x family.
What image size does YOLOv5 use?
The standard pretrained detection checkpoints are commonly evaluated using 640-pixel images. Larger P6 variants use 1280-pixel inputs.
Can YOLOv5 detect custom objects?
Yes. YOLOv5 supports training on custom datasets with user-defined object classes.
Does YOLOv5 support segmentation?
Yes. The repository includes YOLOv5 instance segmentation models and dedicated segmentation training, validation, prediction, and export workflows.
Does YOLOv5 support image classification?
Yes. Image classification tools are included in the repository.
Can YOLOv5 run on a webcam?
Yes. The official detect.py workflow supports webcam input.
Can YOLOv5 process video?
Yes. YOLOv5 can perform inference on local videos and supported network streams.
Can YOLOv5 be exported?
Yes. The repository provides tools for exporting YOLOv5 models into several deployment formats, including ONNX, TensorRT, CoreML, and TensorFlow Lite.
Is YOLOv5 still useful?
Yes. Ultralytics describes YOLOv5 as a mature, production-proven model that remains suitable for fast and reliable object detection, instance segmentation, and image classification.
Conclusion
YOLOv5 brought YOLO-style object detection into a practical PyTorch and Python ecosystem.
Its combination of multiple model sizes, straightforward custom training, pretrained weights, flexible inference sources, GPU acceleration, validation tools, and broad export support made it one of the most accessible YOLO implementations.
The repository has also expanded beyond object detection to include instance segmentation and image classification, making YOLOv5 a broader computer vision toolkit.
Although newer Ultralytics architectures are now available, YOLOv5 remains useful for existing projects, education, research, custom model training, and production-oriented computer vision applications where a mature PyTorch-based workflow is preferred.