# YOLOv5 — Real-Time Object Detection in PyTorch > YOLOv5 is a family of object detection architectures pre-trained on COCO, offering a range of model sizes from nano to extra-large for real-time inference on images, video, and webcam streams. ## Install Save as a script file and run: # YOLOv5 — Real-Time Object Detection in PyTorch ## Quick Use ```bash pip install ultralytics yolo detect predict model=yolov5su source=bus.jpg ``` ## Introduction YOLOv5 is a widely adopted object detection framework built on PyTorch by Ultralytics. It provides five model sizes (n/s/m/l/x) that trade off speed against accuracy, making it suitable for everything from edge deployment on mobile devices to high-accuracy server workloads. ## What YOLOv5 Does - Detects objects in images and video with bounding boxes and class labels - Supports classification, instance segmentation, and oriented bounding boxes - Exports to ONNX, CoreML, TFLite, TensorRT, and OpenVINO for cross-platform deployment - Trains custom models on user datasets with built-in data augmentation (mosaic, mixup, HSV shifts) - Provides a command-line and Python API for inference, training, and validation ## Architecture Overview YOLOv5 uses a CSPDarknet53 backbone for feature extraction, a PANet neck for multi-scale feature fusion, and a single-stage detection head that predicts bounding boxes, objectness scores, and class probabilities at three scales. The architecture is defined in YAML config files, which allows users to modify depth and width multipliers to create custom-sized models. Anchor-based detection is used by default, but anchor-free heads are available in newer variants. ## Self-Hosting & Configuration - Install via pip (`pip install ultralytics`) or clone the repository directly - Pre-trained weights are downloaded automatically on first use from GitHub releases - Training configs live in YAML files specifying backbone, neck, head, and hyperparameters - Use `--device cpu` or `--device 0` to select CPU or GPU inference - Deploy with TorchServe, Triton Inference Server, or as a Flask/FastAPI microservice ## Key Features - Five model sizes from YOLOv5n (1.9M params) to YOLOv5x (86.7M params) - AutoAnchor computes optimal anchors for custom datasets during training - Multi-GPU and distributed training supported out of the box - Built-in TensorBoard and Weights & Biases logging - Active ecosystem with thousands of community-trained models on Ultralytics HUB ## Comparison with Similar Tools - **YOLOv8/YOLO11** — newer Ultralytics models with anchor-free heads and improved accuracy; YOLOv5 remains popular for its maturity and broad deployment tooling - **Detectron2** — Meta's modular detection platform with more research-oriented flexibility, but heavier setup - **MMDetection** — OpenMMLab framework supporting dozens of architectures; more complex configuration than YOLOv5 - **YOLOX** — anchor-free YOLO variant by Megvii with decoupled head design; less ecosystem support - **EfficientDet** — Google's compound-scaling detector; slower inference than comparable YOLOv5 models ## FAQ **Q: Is YOLOv5 still maintained now that YOLOv8 exists?** A: Yes. Ultralytics continues to maintain YOLOv5 and it receives bug fixes and compatibility updates. Many production systems rely on it. **Q: How do I train on a custom dataset?** A: Organize images and labels in YOLO format, create a dataset YAML, then run `yolo detect train data=custom.yaml model=yolov5s.pt epochs=100`. **Q: Can I run YOLOv5 on a Raspberry Pi?** A: Yes. Export to TFLite or NCNN and use the nano model (YOLOv5n) for real-time inference on ARM devices. **Q: What license does YOLOv5 use?** A: YOLOv5 is released under AGPL-3.0. Commercial use requires an Ultralytics Enterprise License. ## Sources - https://github.com/ultralytics/yolov5 - https://docs.ultralytics.com/yolov5/ --- Source: https://tokrepo.com/en/workflows/asset-db0047d3 Author: Script Depot