# Ultralytics YOLOv3

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

- Category: Multimodal Generation / Vision & Understanding
- Language: Python
- Licence: AGPL-3.0
- Repository: https://github.com/ultralytics/yolov3
- Website: https://docs.ultralytics.com/models/yolov3/
- Canonical page: https://ai-tldr.dev/tools/yolov3/

## In short

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.

1. Clone the repo and install dependencies

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

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

```python
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
```

3. Detect objects in images, video, streams or the webcam

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

```bash
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
```

4. Train on COCO

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

```bash
# 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
```

5. Validate and export

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

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

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

```python
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")
```

## 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
