github ultralytics/yolov5 v6.2
v6.2 - YOLOv5 Classification Models, Apple M1, Reproducibility, ClearML and Deci.ai integrations

latest release: v7.0
20 months ago

This release incorporates 401 PRs from 41 contributors since our last release in February 2022. It adds Classification training, validation, prediction and export (to all 11 formats), and also provides ImageNet-pretrained YOLOv5m-cls, ResNet (18, 34, 50, 101) and EfficientNet (b0-b3) models.

My main goal with this release is to introduce super simple YOLOv5 classification workflows just like our existing object detection models. The new v6.2 YOLOv5-cls models below are just a start, we will continue to improve these going forward together with our existing detection models. We'd love your contributions on this effort!

Our next release, v6.3 is scheduled for September and will bring official instance segmentation support to YOLOv5, with a major v7.0 release later this year updating architectures across all 3 tasks - classification, detection and segmentation.

Important Updates

  • Classification Models ⭐ NEW: YOLOv5-cls ImageNet-pretrained classification models are now available for the first time (#8956 by @glenn-jocher)
  • ClearML logging ⭐ NEW: Integration with the open-source experiment tracker ClearML. Installing with pip install clearml will enable the integration and allow users to track every training run in ClearML. This in turn allows users to track and compare runs and even schedule runs remotely. (#8620 by @thepycoder)
  • Deci.ai optimization ⭐ NEW: Automatically compile and quantize YOLOv5 for better inference performance in one click at Deci (#8956 by @glenn-jocher).
  • GPU Export Benchmarks: Benchmark (mAP and speed) all YOLOv5 export formats with python utils/benchmarks.py --weights yolov5s.pt --device 0 for GPU benchmarks or --device cpu for CPU benchmarks (#6963 by @glenn-jocher).
  • Training Reproducibility: Single-GPU YOLOv5 training with torch>=1.12.0 is now fully reproducible, and a new --seed argument can be used (default seed=0) (#8213 by @AyushExel).
  • Apple Metal Performance Shader (MPS) Support: MPS support for Apple M1/M2 devices with --device mps (full functionality is pending torch updates in pytorch/pytorch#77764) (#7878 by @glenn-jocher)

New Classification Checkpoints

We trained YOLOv5-cls classification models on ImageNet for 90 epochs using a 4xA100 instance, and we trained ResNet and EfficientNet models alongside with the same default training settings to compare. We exported all models to ONNX FP32 for CPU speed tests and to TensorRT FP16 for GPU speed tests. We ran all speed tests on Google Colab Pro for easy reproducibility.

Model size
(pixels)
accuracy
top1
accuracy
top5
Train time
90 epochs
4x A100 (hours)
Speed
ONNX-CPU
(ms)
Speed
TensorRT-V100
(ms)
params
(M)
FLOPs
@224 (B)
YOLOv5n-cls 224 64.6 85.4 7:59 3.3 0.5 2.5 0.5
YOLOv5s-cls 224 71.5 90.2 8:09 6.6 0.6 5.4 1.4
YOLOv5m-cls 224 75.9 92.9 10:06 15.5 0.9 12.9 3.9
YOLOv5l-cls 224 78.0 94.0 11:56 26.9 1.4 26.5 8.5
YOLOv5x-cls 224 79.0 94.4 15:04 54.3 1.8 48.1 15.9
ResNet18 224 70.3 89.5 6:47 11.2 0.5 11.7 3.7
ResNet34 224 73.9 91.8 8:33 20.6 0.9 21.8 7.4
ResNet50 224 76.8 93.4 11:10 23.4 1.0 25.6 8.5
ResNet101 224 78.5 94.3 17:10 42.1 1.9 44.5 15.9
EfficientNet_b0 224 75.1 92.4 13:03 12.5 1.3 5.3 1.0
EfficientNet_b1 224 76.4 93.2 17:04 14.9 1.6 7.8 1.5
EfficientNet_b2 224 76.6 93.4 17:10 15.9 1.6 9.1 1.7
EfficientNet_b3 224 77.7 94.0 19:19 18.9 1.9 12.2 2.4
  • All checkpoints are trained to 90 epochs with SGD optimizer with lr0=0.001 and weight_decay=5e-5 at image size 224 and all default settings.
    Runs logged to https://wandb.ai/glenn-jocher/YOLOv5-Classifier-v6-2
  • Accuracy values are for single-model single-scale on ImageNet-1k dataset.
    Reproduce by python classify/val.py --data ../datasets/imagenet --img 224
  • Speed averaged over 100 inference images using a Colab Pro V100 High-RAM instance.
    Reproduce by python classify/val.py --data ../datasets/imagenet --img 224 --batch 1
  • Export to ONNX at FP32 and TensorRT at FP16 done with export.py.
    Reproduce by python export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224

New Classification Model Usage Examples

Train

YOLOv5 classification training supports auto-download of MNIST, Fashion-MNIST, CIFAR10, CIFAR100, Imagenette, Imagewoof, and ImageNet datasets with the --data argument. To start training on MNIST for example use --data mnist.

# Single-GPU
python classify/train.py --model yolov5s-cls.pt --data cifar100 --epochs 5 --img 224 --batch 128

# Multi-GPU DDP
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3

Val

Validate YOLOv5m-cls accuracy on ImageNet-1k dataset:

bash data/scripts/get_imagenet.sh --val  # download ImageNet val split (6.3G, 50000 images)
python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224  # validate

Predict

Use pretrained YOLOv5s-cls.pt to predict bus.jpg:

python classify/predict.py --weights yolov5s-cls.pt --data data/images/bus.jpg
model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s-cls.pt')  # load from PyTorch Hub

Export

Export a group of trained YOLOv5s-cls, ResNet and EfficientNet models to ONNX and TensorRT:

python export.py --weights yolov5s-cls.pt resnet50.pt efficientnet_b0.pt --include onnx engine --img 224

Changelog

🛠️ New Features and Bug Fixes (401)
😃 New Contributors (41)

Don't miss a new yolov5 release

NewReleases is sending notifications on new releases.