First Helmet Detector using YOLOv5
By: Luís Rita
Tags: Helmet, Deep Learning, Yolov5, Cycleai, Detector

First Helmet Detector using YOLOv5

CycleAI: Empowering cyclists in fighting for their own safety

CycleAI: Empowering cyclists in fighting for their own safety [Image by Author].

Mobility is a priority theme for the European Union in the context of urban development. At the same time, hundreds of people, including cyclists and pedestrians, lose their lives on the roads. Therefore, planning and ordering of cities through appropriate infrastructures is urging, alongside a safe and efficient transport network aimed at active mobility — both on foot and by bicycle.

It is now presented the object detection model that was trained to identify whether cyclists are wearing a helmet and, potentially, studying their prevalence.

YOLOv5

YOLOv5 is the most recent version of YOLO which was originally developed by Joseph Redmon. First version runs in a framework called Darknet which was purposely built to execute YOLO [1].

Version 5 is the second model that was not developed by the original author (after version 4), and the first running in a state-of-the-art machine learning framework — PyTorch [2].

YOLOv5 GitHub repository contains a pre-trained model in the MS Coco dataset. Plus, benchmark tests (Figure 1) on the same dataset and detailed documentation on how to execute or retrain it using different data.

Figure 1 The most up to date YOLO model is the version 5 (July 2020). It was released with 4 different sets of weights varying in accuracy and storage requirements. The presence of EfficientDet (the most accurate OD model) highlights the speed of detection of YOLOv5, while keeping the same high accuracy [2].

In Table 1, there is a comparison in terms of precision, speed and storage requirements for each YOLOv5 set of available weights.

Table 1 Specifications for all sets of weights released with YOLOv5. Generally, as average precision increases, more processing power is required from the GPU to be executed. Adapted from [2].

The architecture of YOLOv5 consists in three important parts, as in any single-stage object detector: model backbone, neck and head. The first is used to extract the main features of a given input image. In version 5, Cross Stage Partial Networks are used. These have shown significant improvements in processing time with deeper networks. Model neck PANet was used to obtain feature pyramids and helps generalizing the model on object scaling. The final detection part is performed by the head of the model (same as in YOLOv3 and YOLOv4). It applies anchor boxes on features and generates output vectors including class probabilities and bounding boxes.

Each potential detection has an associated confidence score. This indicates how certain is the model about the presence of an object inside the bounding box and, at the same time, whether the box is capturing it correctly.

Open Images Dataset V6

There are multiple datasets with images containing labelled objects. For training YOLOv5, it was used a set of 1000 images containing helmets, out of the available ~5000 in the Open Images Dataset V6. This assured we got both an affordable and precise model.

Dataset of images was split in a training, validation and testing subsets (Figure 2).

Figure 2 Training, validation and testing subsets of images [Image by Author].

Official description of Open Images Dataset V6 below [3]:

A dataset of ~9 million varied images with rich annotations. The images are very diverse and often contain complex scenes with several objects (8.4 per image on average). It contains image-level labels annotations, object bounding boxes, object segmentations, visual relationships, localized narratives, and more.

Helmet Detector

Dataset with the images containing helmets (original set of images in Figure 3) was preprocessed and augmented in the online Roboflow app (Figure 4). YOLOv5x was trained with Google Colab (notebook). One NVIDIA P100 GPU was allocated and the training was completed in 6 hours.

Figure 3 Original training dataset of images from Open Images Dataset V6 [3].

Augmented collection of training images increased up until 2400. Selected augmented options were flip (horizontal), rotation (between -15º and +15º) and brightness (between -25% and +25%).

Figure 4 Training images after augmentation step [Image by Author].

Finally, the model was tested in the fraction of images that was kept to achieve this same step (Figure 5).

Figure 5 Using the most accurate set of weights to perform inference in the test set of images [Image by Author].

Using 2100 training images, it was achieved relatively high levels of precision and recall around the epoch 500 (Figure 6).

Figure 6 Variation of multiple accuracy measures of the model in respect to the number of trained generations [Image by Author].

CycleAI

Description

CycleAI is a social project that seeks solutions for a sustainable urban mobility policy through AI.

Our idea consists of creating models powered by deep learning algorithms, translating risk factors into an analytical measure of risk and safety through artificial intelligence.

This project — experimental to date — was firstly developed by Luís Rita, a doctoral engineer at Imperial College London, with the collaboration of Miguel Peliteiro, a medical doctor violently ran over while cycling on a bike path.

Luís had already developed a mechanism that would allow composing object detection and image segmentation models in order to detect cyclists’ road risk factors from Google Street View images of London, United Kingdom.

Want to give us a hand? All help is appreciated towards greener and safer cities. Hit us up to find more about our project and its applications!

Facebook | LinkedIn | Instagram | Twitter

Prizes

References

[1] J. Redmon, S. Divvala, R. Girshick e A. Farhadi, “You Only Look Once: Unified, Real-Time Object Detection,” em Computer Vision and Pattern Recognition, 2016.

[2] G. Jocher, “YOLOv5,” Ultralytics, 23 July 2020. [Online]. Available: https://github.com/ultralytics/yolov5. [Accessed in 1 November 2020].

[3] “Open Images Dataset,” Google Open Source. [Online]. Available: https://opensource.google/projects/open-images-dataset. [Accessed in 17 November 2020].