This release incorporates many new features and bug fixes (465 PRs from 73 contributors) since our last release v5.0 in April, brings architecture tweaks, and also introduces new P5 and P6 'Nano' models: YOLOv5n and YOLOv5n6. Nano models maintain the YOLOv5s depth multiple of 0.33 but reduce the YOLOv5s width multiple from 0.50 to 0.25, resulting in ~75% fewer parameters, from 7.5M to 1.9M, ideal for mobile and CPU solutions.
Example usage:
python detect.py --weights yolov5n.pt --img 640 # Nano P5 model trained at --img 640 (28.4 mAP@0.5:0.95)
python detect.py --weights yolov5n6.pt --img 1280 # Nano P6 model trained at --img 1280 (34.0 mAP0.5:0.95)
Important Updates
-
Roboflow Integration ⭐ NEW: Train YOLOv5 models directly on any Roboflow dataset with our new integration! (#4975 by @Jacobsolawetz)
-
YOLOv5n 'Nano' models ⭐ NEW: New smaller YOLOv5n (1.9M params) model below YOLOv5s (7.5M params), exports to 2.1 MB INT8 size, ideal for ultralight mobile solutions. (#5027 by @glenn-jocher)
-
TensorFlow and Keras Export: TensorFlow, Keras, TFLite, TF.js model export now fully integrated using
python export.py --include saved_model pb tflite tfjs
(#1127 by @zldrobit) -
OpenCV DNN: YOLOv5 ONNX models are now compatible with both OpenCV DNN and ONNX Runtime (#4833 by @SamFC10).
-
Model Architecture: Updated backbones are slightly smaller, faster and more accurate.
- Replacement of
Focus()
with an equivalentConv(k=6, s=2, p=2)
layer (#4825 by @thomasbi1) for improved exportability - New
SPPF()
replacement forSPP()
layer for reduced ops (#4420 by @glenn-jocher) - Reduction in P3 backbone layer
C3()
repeats from 9 to 6 for improved speeds - Reorder places
SPPF()
at end of backbone - Reintroduction of shortcut in the last
C3()
backbone layer - Updated hyperparameters with increased mixup and copy-paste augmentation
- Replacement of
New Results
Figure Notes (click to expand)
python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt
mAP improves from +0.3% to +1.1% across all models, and ~5% FLOPs reduction produces slight speed improvements and a reduced CUDA memory footprint. Example YOLOv5l before and after metrics:
YOLOv5l Large | size (pixels) | mAPval 0.5:0.95 | mAPval 0.5 | Speed CPU b1 (ms) | Speed V100 b1 (ms) | Speed V100 b32 (ms) | params (M) | FLOPs @640 (B) |
---|---|---|---|---|---|---|---|---|
v5.0 (previous) | 640 | 48.2 | 66.9 | 457.9 | 11.6 | 2.8 | 47.0 | 115.4 |
v6.0 (this release) | 640 | 48.8 | 67.2 | 424.5 | 10.9 | 2.7 | 46.5 | 109.1 |
Pretrained Checkpoints
Model | size (pixels) | mAPval 0.5:0.95 | mAPval 0.5 | Speed CPU b1 (ms) | Speed V100 b1 (ms) | Speed V100 b32 (ms) | params (M) | FLOPs @640 (B) |
---|---|---|---|---|---|---|---|---|
YOLOv5n | 640 | 28.4 | 46.0 | 45 | 6.3 | 0.6 | 1.9 | 4.5 |
YOLOv5s | 640 | 37.2 | 56.0 | 98 | 6.4 | 0.9 | 7.2 | 16.5 |
YOLOv5m | 640 | 45.2 | 63.9 | 224 | 8.2 | 1.7 | 21.2 | 49.0 |
YOLOv5l | 640 | 48.8 | 67.2 | 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 | 34.0 | 50.7 | 153 | 8.1 | 2.1 | 3.2 | 4.6 |
YOLOv5s6 | 1280 | 44.5 | 63.0 | 385 | 8.2 | 3.6 | 16.8 | 12.6 |
YOLOv5m6 | 1280 | 51.0 | 69.0 | 887 | 11.1 | 6.8 | 35.7 | 50.0 |
YOLOv5l6 | 1280 | 53.6 | 71.6 | 1784 | 15.8 | 10.5 | 76.8 | 111.4 |
YOLOv5x6 + TTA | 1280 1536 | 54.7 55.4 | 72.4 72.3 | 3136 - | 26.2 - | 19.4 - | 140.7 - | 209.8 - |
Table Notes (click to expand)
- All checkpoints are trained to 300 epochs with default settings. Nano models use hyp.scratch-low.yaml hyperparameters, all others use hyp.scratch-high.yaml.
- mAPval values are for single-model single-scale on COCO val2017 dataset.
Reproduce bypython val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65
- Speed averaged over COCO val images using a AWS p3.2xlarge instance. NMS times (~1 ms/img) not included.
Reproduce bypython val.py --data coco.yaml --img 640 --conf 0.25 --iou 0.45
- TTA Test Time Augmentation includes reflection and scale augmentations.
Reproduce bypython val.py --data coco.yaml --img 1536 --iou 0.7 --augment
Changelog
Changes between previous release and this release: v5.0...v6.0
Changes since this release: v6.0...HEAD
New Features and Bug Fixes (465)
--save-crop
bug fix by @glenn-jocher in #3102
--include torchscript onnx coreml
argument by @CristiFati in #3137
onnx>=1.9.0
by @glenn-jocher in #3143
--opset-version
by @CristiFati in #3154
device
argument to PyTorch Hub models by @cgerum in #3104
plot_one_box()
default color=(128, 128, 128)
by @yeric1789 in #3240
--image-weights
not combined with DDP by @glenn-jocher in #3275
batch_size % utilized_device_count
by @glenn-jocher in #3276
crops = results.crop()
return values by @yeric1789 in #3282
git clone
master by @glenn-jocher in #3311
@torch.no_grad()
decorator by @glenn-jocher in #3312
hashlib
by @glenn-jocher in #3350
.train()
mode fix by @ChaofWang in #3362
*.txt
labels by @glenn-jocher in #3366
--weights URL
definition by @glenn-jocher in #3373
cv2.imread(img, -1)
for IMREAD_UNCHANGED by @tudoulei in #3379
is_pip()
function by @glenn-jocher in #3391
cv2.imread(img, -1)
for IMREAD_UNCHANGED" by @glenn-jocher in #3395
alpha=beta=32.0
by @glenn-jocher in #3455
timeout()
class by @glenn-jocher in #3460
check_git_status()
5 second timeout by @glenn-jocher in #3464
check_requirements()
offline-handling by @glenn-jocher in #3466
output_names
argument for ONNX export with dynamic axes by @SamSamhuns in #3456
test.py
and detect.py
inference to FP32 default by @edificewang in #3423
github.actor
bug fix by @glenn-jocher in #3483
model.eval()
call if opt.train=False
by @developer0hye in #3475
opencv-python
by @glenn-jocher in #3495
opencv-python
by @glenn-jocher in #3507
develop
branch into master
by @glenn-jocher in #3518
--half
argument for test.py and detect.py by @glenn-jocher in #3532
dataset_stats()
for HUB by @glenn-jocher in #3536
pycocotools
pip install by @glenn-jocher in #3547
check_python(minimum=3.6.2)
by @glenn-jocher in #3548
opt
from `create_dataloader()`` by @glenn-jocher in #3552
is_coco
argument from test()
by @glenn-jocher in #3553
half
argument by @glenn-jocher in #3557
sys.path.append()
by @glenn-jocher in #3579
normalize=True
flag by @glenn-jocher in #3586
normalize=True
fix by @glenn-jocher in #3587
dataset_stats()
by @glenn-jocher in #3593
check_file()
by @glenn-jocher in #3622
**/*.torchscript.pt
by @glenn-jocher in #3634
verify_image_label()
by @glenn-jocher in #3635
is_coco
list fix by @thanhminhmr in #3646
dataset_stats()
to list of dicts by @glenn-jocher in #3657
/weights
directory by @glenn-jocher in #3659
train(hyp, *args)
to accept hyp
file or dict by @glenn-jocher in #3668
WORLD_SIZE
and RANK
retrieval by @glenn-jocher in #3670
torch.distributed.run
with gloo
backend by @glenn-jocher in #3680
total_batch_size
variable by @glenn-jocher in #3697
train.run()
method by @glenn-jocher in #3700
if dist.is_nccl_available()
by @glenn-jocher in #3705
img2label_paths()
order by @glenn-jocher in #3720
check_datasets()
for dynamic unzip path by @glenn-jocher in #3732
data/hyps
directory by @glenn-jocher in #3747
w
by @glenn-jocher in #3748
path
attribute by @glenn-jocher in #3753
xyxy2xywhn()
by @developer0hye in #3765
nn.MultiheadAttention
fix by @glenn-jocher in #3768
accumulate
by @yellowdolphin in #3722
feature_visualization()
by @glenn-jocher in #3807
dataset_stats()
with updated data.yaml by @glenn-jocher in #3819
TransformerBlock()
by @glenn-jocher in #3821
LoadStreams()
dataloader frame skip issue by @feras-oughali in #3833
AutoShape()
detections in ascending order by @glenn-jocher in #3843
--evolve 300
generations CLI argument by @san-soucie in #3863
*.yaml
reformat by @glenn-jocher in #3875
utils/augmentations.py
by @glenn-jocher in #3877
hyp['anchors']
fix by @glenn-jocher in #3887
map_location=device
by @glenn-jocher in #3894
/root/hub/cache/dir
by @johnohagan in #3904
torch.hub.list('ultralytics/yolov5')
pathlib bug by @glenn-jocher in #3921
setattr()
default for Hub PIL images by @jmiranda-laplateforme in #3923
feature_visualization()
CUDA fix by @glenn-jocher in #3925
dataset_stats()
for zipped datasets by @glenn-jocher in #3926
albumentations>=1.0.2
by @glenn-jocher in #3966
np.random.random()
to random.random()
by @glenn-jocher in #3967
albumentations>=1.0.2
by @glenn-jocher in #3972
Ensemble()
visualize fix by @seven320 in #3973
probability
to p
by @glenn-jocher in #3980
test.py
to val.py
by @glenn-jocher in #4000
--sync-bn
known issue by @glenn-jocher in #4032
val.py
refactor by @glenn-jocher in #4053
super().__init__()
by @glenn-jocher in #4065
nc
and names
handling in check_dataset() by @glenn-jocher in #4066
export.py
by @glenn-jocher in #4080
export.py
by @glenn-jocher in #4089
--img-size
floor by @glenn-jocher in #4099
log_training_progress()
by @imyhxy in #4126
opset_version
to opset
by @glenn-jocher in #4135
loggers
by @glenn-jocher in #4137
export.py
ONNX inference suggestion by @glenn-jocher in #4146
--data path/to/dataset.zip
feature by @glenn-jocher in #4185
@try_except
decorator by @glenn-jocher in #4224
requirements.txt
location by @glenn-jocher in #4225
max_pool2d()
warning by @glenn-jocher in #4227
python train.py --freeze N
argument by @IneovaAI in #4238
profile()
for CUDA Memory allocation by @glenn-jocher in #4239
train.py
and val.py
callbacks by @kalenmike in #4220
DWConvClass()
by @glenn-jocher in #4274
python train.py --cache disk
by @junjihashimoto in #4049
int(mlc)
by @glenn-jocher in #4385
utils.google_utils
to utils.downloads
by @glenn-jocher in #4393
yolov5s-ghost.yaml
by @glenn-jocher in #4412
encoding='ascii'
by @glenn-jocher in #4413
plot_one_box(use_pil=False)
by @glenn-jocher in #4416
SPPF()
layer by @glenn-jocher in #4420
attempt_load
import by @OmidSa75 in #4428
--weights yolov5s.pt
by @glenn-jocher in #4458
check_requirements(('coremltools',))
by @glenn-jocher in #4478
install=True
argument to check_requirements
by @glenn-jocher in #4512
python models/yolo.py --profile
by @glenn-jocher in #4541
image_weights
DDP code by @glenn-jocher in #4579
Profile()
profiler by @glenn-jocher in #4587
plot_one_box
when label is None
by @karasawatakumi in #4588
Annotator()
class by @glenn-jocher in #4591
plots.py
to class-first by @glenn-jocher in #4595
on_train_end()
speed improvements by @glenn-jocher in #4605
Detect()
inputs by @YukunXia in #4608
check_git_status()
warning by @glenn-jocher in #4610
matplotlib
plots after opening by @glenn-jocher in #4612
torch.jit.trace()
--sync-bn
fix by @glenn-jocher in #4615
plot_evolve()
string argument by @glenn-jocher in #4639
is_coco
on missing data['val']
key by @glenn-jocher in #4642
ComputeLoss
code by @zhiqwang in #4701
check_suffix()
by @glenn-jocher in #4712
check_yaml()
comment by @glenn-jocher in #4713
user_config_dir('Ultralytics')
by @glenn-jocher in #4715
crops = results.crop()
dictionary by @ELHoussineT in #4676
multi_label
option for NMS with PyTorch Hub by @jeanbmar in #4728
onnx-simplifier
requirements check by @Zegorax in #4730
user_config_dir()
for GCP/AWS functions by @glenn-jocher in #4726
--data from_HUB.zip
by @glenn-jocher in #4732
detect.py
timing by @glenn-jocher in #4741
callbacks
to train function in W&B sweep by @jveitchmichaelis in #4742
is_writeable()
for 3 OS support by @glenn-jocher in #4743
.gitignore
by @glenn-jocher in #4747
.dockerignore
by @glenn-jocher in #4748
is_writeable()
for 2 methods by @glenn-jocher in #4744
user_config_dir()
decision making by @glenn-jocher in #4755
path.absolute()
with path.resolve()
by @glenn-jocher in #4763
export.py
by @glenn-jocher in #4479
--int8
argument by @glenn-jocher in #4799
--resume
fix by @glenn-jocher in #4802
forward()
method profiling by @glenn-jocher in #4816
PIL.ImageDraw.text(anchor=...)
removal, reduce to >=7.1.2
by @glenn-jocher in #4842
cache_labels()
by @glenn-jocher in #4845
cache_version
definition by @glenn-jocher in #4846
init_seeds()
by @glenn-jocher in #4849
print_args()
by @glenn-jocher in #4850
sys.path.append(str(ROOT))
by @glenn-jocher in #4852
check_requirements()
usage by @glenn-jocher in #4855
LOGGER.info()
by @glenn-jocher in #4863
check_font()
RANK -1 remove progress by @glenn-jocher in #4864
os.system('unzip file.zip')
-> ZipFile.extractall()
by @glenn-jocher in #4919
root
referenced before assignment by @glenn-jocher in #4920
best.pt
on train end by @glenn-jocher in #4889
check_file()
search space by @glenn-jocher in #4933
cwd
by @glenn-jocher in #4954
ROOT
logic by @glenn-jocher in #4955
roboflow
by @glenn-jocher in #4956
isascii()
method calls for python 3.6 by @d57montes in #4958
ROOT
Pytorch Hub custom model bug by @glenn-jocher in #4974
--img 64
CI tests by @glenn-jocher in #4979
torch.hub.load()
test by @glenn-jocher in #4986
opt.device
on --task study
by @glenn-jocher in #5031
--save-period
locally by @glenn-jocher in #5047
yaml.safe_load()
ignore emoji errors by @glenn-jocher in #5060
ADD
Arial.ttf by @glenn-jocher in #5084
OSError
by @glenn-jocher in #5106
requests
to requirements.txt by @sandstorm12 in #5112
LOCAL_RANK
to torch_distributed_zero_first()
by @qiningonline in #5114
--device
for --task study
by @glenn-jocher in #5118
--speed
and --study
usages by @glenn-jocher in #5120
pad = 0.0 if task == 'speed' else 0.5
by @glenn-jocher in #5121
ROOT
as relative path by @maltelorbach in #5129
Detect()
anchors for ONNX <> OpenCV DNN compatibility by @SamFC10 in #4833
detect.py
in order to support torch script by @andreiionutdamian in #5109
New Contributors (73)