█

AI/TLDR

Buy me a coffee
Buy me a coffee

Ultralytics YOLOv3

Ultralytics' PyTorch repo for training, running and exporting the classic YOLOv3, YOLOv3-SPP and YOLOv3-tiny object detectors

Vision & UnderstandingOpen source
Language
Python
License
AGPL-3.0
$git clone https://github.com/ultralytics/yolov3
IN SHORT

What is Ultralytics YOLOv3?

Ultralytics YOLOv3 is a PyTorch implementation of YOLOv3 (You Only Look Once, version 3), the real-time object detector originally developed by Joseph Redmon. YOLOv3 treats detection as a single regression problem: one forward pass over the whole image predicts bounding boxes and class probabilities, with no separate region-proposal stage. It sits in the Vision & Understanding category of the Multimodal Generation tools and is open-source, written in Python and licensed AGPL-3.0.

Overview

Ultralytics YOLOv3 is a PyTorch implementation of YOLOv3 (You Only Look Once, version 3), the real-time object detector originally developed by Joseph Redmon. YOLOv3 treats detection as a single regression problem: one forward pass over the whole image predicts bounding boxes and class probabilities, with no separate region-proposal stage. The repository packages three detection models — YOLOv3, YOLOv3-SPP and YOLOv3-tiny — together with scripts for training, validation, inference and export, all pretrained on the 80-class COCO dataset and downloaded automatically from the repo's release assets on first use.

The architecture follows the original design: a Darknet-53 backbone with residual connections, predictions at three feature-map scales so small, medium and large objects are all covered, three anchor boxes per scale (nine in total), and an independent logistic classifier per class so one box can carry several overlapping labels. YOLOv3-SPP adds a Spatial Pyramid Pooling block for a larger receptive field and a small accuracy gain; YOLOv3-tiny uses a compact backbone and detects at two scales for CPU and edge devices. Models are defined declaratively in models/*.yaml and built by parse_model() in models/yolo.py, so the architecture can be inspected and changed without writing Python.

It sits alongside two other Ultralytics codebases in this catalogue. Like the YOLOv5 repo, it is a clone-and-run project driven by standalone train.py, val.py, detect.py and export.py scripts plus PyTorch Hub, but it covers only object detection and only the YOLOv3 family. The ultralytics pip package is where Ultralytics hosts its newer YOLO generations; its docs also offer YOLOv3u, a variant that keeps YOLOv3's backbone and neck but swaps in the anchor-free, objectness-free split head from YOLOv8. Reach for this repo when you specifically want the anchor-based YOLOv3 models as a well-understood baseline. It is dual-licensed: AGPL-3.0 for open-source use, or an Ultralytics Enterprise License for commercial products.

What it does

  • Three pretrained COCO detectors — yolov3.pt, yolov3-spp.pt and yolov3-tiny.pt — that download automatically on first use
  • One-line PyTorch Hub loading via torch.hub.load("ultralytics/yolov3", ...) with the yolov3, yolov3_spp and yolov3_tiny entrypoints
  • detect.py inference on webcams, images, videos, screen capture, directories, glob patterns and RTSP/RTMP/HTTP streams, saving results to runs/detect
  • train.py and val.py for training from scratch or on custom data and measuring accuracy, with training logs, curves and prediction mosaics written to runs/train
  • export.py to TorchScript, ONNX, OpenVINO, TensorRT, CoreML and PaddlePaddle
  • Architecture defined in plain YAML files (models/yolov3.yaml, yolov3-spp.yaml, yolov3-tiny.yaml) that you can read and edit

Getting started

The repo is cloned and run in place. The README asks for Python 3.8 or newer and PyTorch 1.8 or newer; pretrained weights and the COCO dataset download automatically when a command needs them.

Clone the repo and install dependencies

bashbash
git clone https://github.com/ultralytics/yolov3
cd yolov3
pip install -r requirements.txt

Run a pretrained model through PyTorch Hub

Pick yolov3, yolov3_spp or yolov3_tiny. The input can be a local file, URL, PIL image, OpenCV frame or numpy array.

pythonpython
import torch

model = torch.hub.load("ultralytics/yolov3", "yolov3", pretrained=True)

results = model("https://ultralytics.com/images/zidane.jpg")

results.print()  # print detections to the console
results.show()  # display the annotated image
results.save()  # save the annotated image to runs/detect/exp
A photo of two men in suits with YOLOv3 detections drawn on it: red person boxes and green tie boxes, each labelled with a confidence score
The kind of annotated image inference produces: person and tie detections with confidence scores on the zidane.jpg sample image.Ultralytics YOLOv3 tutorial notebook ↗

Detect objects in images, video, streams or the webcam

detect.py downloads the model if needed and saves results to runs/detect.

bashbash
python detect.py --weights yolov3.pt --source 0          # webcam
python detect.py --weights yolov3.pt --source img.jpg    # image
python detect.py --weights yolov3.pt --source vid.mp4    # video
python detect.py --weights yolov3.pt --source screen     # screenshot
python detect.py --weights yolov3.pt --source path/      # directory
python detect.py --weights yolov3.pt --source 'rtsp://example.com/media.mp4'  # stream

Train on COCO

Choose the architecture with --cfg and use the largest --batch-size your hardware allows. Training output lands in runs/train.

bashbash
# YOLOv3-tiny
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov3-tiny.yaml --batch-size 64

# YOLOv3
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov3.yaml --batch-size 32

# YOLOv3-SPP
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov3-spp.yaml --batch-size 16
A file browser showing a training run folder with a confusion matrix, precision-recall curves, results.csv, hyperparameter YAML files and train and validation image mosaics
What a training run leaves behind: metrics, PR and F1 curves, a confusion matrix, labelled batch mosaics and the weights folder.Ultralytics YOLOv3 tutorial notebook ↗

Validate and export

Check accuracy on COCO, then export for deployment. --include also accepts torchscript, openvino, engine (TensorRT), coreml and paddle.

bashbash
python val.py --weights yolov3.pt --data coco.yaml
python export.py --weights yolov3.pt --include onnx

Or use the YOLOv3u variant from the ultralytics package

The Ultralytics docs also publish YOLOv3u checkpoints (yolov3u.pt, yolov3-tinyu.pt, yolov3-sppu.pt) with an anchor-free head, loaded through the ultralytics package instead of this repo.

pythonpython
from ultralytics import YOLO

model = YOLO("yolov3u.pt")
model.info()

results = model.train(data="coco8.yaml", epochs=100, imgsz=640)
results = model("path/to/bus.jpg")

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Reach for it when you need the original anchor-based YOLOv3, YOLOv3-SPP or YOLOv3-tiny as a well-understood detection baseline for a comparison or paper
  • Reach for it when an existing pipeline or deployment is already built on YOLOv3 checkpoints and you want to retrain or re-export them with maintained scripts
  • Reach for it when you want a small, CPU-friendly detector (YOLOv3-tiny) exported to ONNX, OpenVINO, TensorRT or CoreML for an edge device
  • Reach for it when you want to study or modify a classic single-stage detector whose layers are laid out in readable YAML files

How Ultralytics YOLOv3 compares

Ultralytics YOLOv3 alongside other open-source vision & understanding tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
PaddleOCR★ 93.5kA toolkit for detecting and recognizing text in images across many languages, plus document parsing.
OpenCV★ 91.8kThe long-standing open-source computer-vision library for C++, Python and Java; version 5 rewrote the DNN engine and added ONNX-based LLM and VLM inference in-library.
Ultralytics YOLO★ 63.9kA framework for training and running YOLO models for real-time object detection, segmentation, and tracking.
YOLOv5★ 58.3kUltralytics' PyTorch repo for training, running and exporting YOLOv5 object-detection, instance-segmentation and classification models with plain scripts and PyTorch Hub.
Supervision★ 51.8kA Python toolkit for processing, annotating, and visualizing detections and segmentations from many vision models.
MediaPipe★ 38kGoogle's on-device ML framework: ready-to-run vision, text and audio tasks with one cross-platform API for Android, iOS, web, desktop and edge.
MMDetection★ 33.1kAn OpenMMLab toolbox with many object detection and instance segmentation algorithms for research and production.
Ultralytics YOLOv3★ 10.6kUltralytics' PyTorch repo for training, running and exporting the classic YOLOv3, YOLOv3-SPP and YOLOv3-tiny object detectors