# Deep Learning-Based Automatic Safety Helmet Detection System for Construction Safety
## 3 Methodology
### YOLOv5  
In the past few years, the YOLO framework has become very popular for object detection because of its single-stage deep learning nature, which detects an object in a single run with relatively better accuracy and speed than other deep learning models such as R-CNN, Faster R-CNN, etc. [38] Among different YOLO versions, YOLOv5 was selected for this study for helmet detection due to its higher accuracy and faster execution as compared to other YOLO variants. Furthermore, YOLOv5x comprised the largest architecture of all versions of YOLOv5 architecture [39]. It uses CSPDarknet53 [40] as a backbone for feature extraction, which solves the problem of repetitive gradient information in the big backbone. Additionally, it integrates changes in the gradient with the feature map, increasing the accuracy and reducing the model size by decreasing the number of parameters.  
The YOLO network consists of three networks: the backbone network, neck network, and detect or head network. Table 1 compares YOLOv3, YOLOv4, and YOLOv5 [39]. All the YOLO architectures use the same neural network type (Fully Connected) and head (YOLO layer), but the neck and backbone are different.  
As discussed earlier, YOLOv5x was used because it uses CSPDarknet53 as the backbone for feature extraction, achieving better accuracy and reducing the model size. Further, to boost the information flow, it uses the Path Aggregation Network (PANet) [41] as the neck. For propagation of low-level features, PANet uses the Feature Pyramid Network (FPN) with an enhanced bottom-up path. PANet also enhances the use of efficient localization signals in lower layers, which can significantly improve object location accuracy. Finally, the head of YOLOv5x uses the YOLO layer, which generates three different sizes of feature maps to achieve multiple-scale prediction. Multi-scale detection enhances the accuracy of the model by predicting small to large objects efficiently. Figure 5 shows the general architecture of the YOLOv5 model; first, the images are fed to CSPDarknet53 to extract the essential features, then fed to PANet for feature fusion, and finally, the YOLO layer will generate the result (class, score, location, size) [40].  
\begin{table}
\begin{tabular}{c c c c} \hline \hline  & **YOLOv3** & **YOLOv4** & **YOLOv5** \\ \hline
**Network Type** & Fully Connected & Fully Connected & Fully Connected \\
**Backbone for Feature Extraction** & Darknet-53 & CSPDarknet53 & CSPDarknet53 \\
**Neck** & Feature Pyramid Network & Spatial pyramid pooling and & Path Aggregation Network \\
**Head** & YOLO Layer & YOLO Layer & YOLO Layer \\ \hline \hline \end{tabular}
\end{table}
Table 1: Comparison between Different YOLO Architectures [39].  
Figure 4: Power-law transformation: (**a**) Original Images (**b**) Enhanced Images.  
YOLOv5x uses Generalized Intersection over Union (GIoU)-based [40] loss function for the bounding box regression represented in Equation (3). The normal IoU loss function (Equation (2)) is limited to the cases where the predicted bounding box and target bounding box overlap with each other, but it does not work in non-overlapping cases. When dealing with non-overlapping situations, GIoU loss assists by gradually raising the predicted box's size until it overlaps with the ground truth.  
\[\text{IoU}=\frac{\left|\text{B}\cap\text{ B}^{\prime}\right|}{\left|\text{B}\cup\text{ B}^{\prime}\right|} \tag{2}\]  
\[\text{GIoU}=\text{IoU}-\frac{\left|\text{C}/\left(\text{B}\cup\text{ B}^{\prime}\right)\right|}{\left|\text{C}\right|} \tag{3}\]  
where B and B\({}^{\prime}\) are the predicted and ground truth bounding boxes, and C is the smallest bounding box covering both the B and B\({}^{\prime}\). The loss function used for YOLOv5x is 1-GIoU which holds properties such as symmetry, triangular inequality, and imperceptible identity [42].