YOLOv5 : The Latest Model for Object Detection

David Cochard
axinc-ai
Published in
4 min readMar 29, 2021

This is an introduction to「YOLOv5」, a machine learning model that can be used with ailia SDK. You can easily use this model to create AI applications using ailia SDK as well as many other ready-to-use ailia MODELS.

Overview

YOLOv5 is the latest object detection model developed by ultralytics, the same company that developed the Pytorch version of YOLOv3, and was released in June 2020.

YOLOv5 variants

YOLOv5 is available in four models, namely s, m, l, and x, each one of them offering different detection accuracy and performance as shown below.

Source:https://github.com/ultralytics/yolov5

The mAP (accuracy) of YOLOv5 s is 55.6 with 17GFlops (computational power).

Source:https://github.com/ultralytics/yolov5

As a comparison YOLOv3-416 had an mAP of 55.3 for 65.86 GFlops.

Source:https://pjreddie.com/darknet/yolo/

YOLOv5 s achieves the same accuracy as YOLOv3-416 with about 1/4 of the computational complexity.

The output from YOLOv5

When given a 640x640 input image, the model outputs the following 3 tensors.

(1, 3, 80, 80, 85) # anchor 0
(1, 3, 40, 40, 85) # anchor 1
(1, 3, 20, 20, 85) # anchor 2

The breakdown of the output is [cx, cy, w, h, conf, pred_cls(80)].

Using YOLOv5 with Pytorch

Use the following command to run YOLOv5 , the model will be automatically downloaded.

python detect.py --source in.mp4

Exporting YOLOv5 to ONNX

You can export YOLOv5 to ONNX with the following commands.

python3 models/export.py --weights yolov5s.pt --img 640 --batch 1
python3 models/export.py --weights yolov5m.pt --img 640 --batch 1
python3 models/export.py --weights yolov5l.pt --img 640 --batch 1

You can also use the optional argument --img-size to specify the recognition resolution individually in the order of height and width.

python3 models/export.py — weights yolov5m.pt --img-size 640 1280 — batch 1

Accuracy and performance comparison with YOLOv3

The inference speed has been measured using a MacBook Pro 13 with Intel Core i5 2.3GH (conf_thres=0.25, nms_thres=0.45).

Source:https://pixabay.com/ja/photos/%E3%83%AD%E3%83%B3%E3%83%89%E3%83%B3%E5%B8%82-%E9%8A%80%E8%A1%8C-%E3%83%AD%E3%83%B3%E3%83%89%E3%83%B3-4481399/

In the results below, we can see that using the model YOLOv5 s gives similar results as the full YOLOv3 model, with about 75% less operations.

YOLOv3 tiny (640x640)(48ms)

YOLOv4 tiny(640x640) (59ms)

YOLOv5 s (640x640)(98ms)

YOLOv3 (640x640)(477ms)

YOLOv4 (640x640) (653ms)

YOLOv5 m (640x640)(229ms)

YOLOv5 l (640x640)(438ms)

Using YOLOv5 with ailia SDK

You can use YOLOv5 with ailia SDK with the following command.

python3 yolov5.py -i input.jpg

ax Inc. has developed ailia SDK, which enables cross-platform, GPU-based rapid inference.

ax Inc. provides a wide range of services from consulting and model creation, to the development of AI-based applications and SDKs. Feel free to contact us for any inquiry.

--

--