# EGS-YOLO: A Fast and Reliable Safety Helmet Detection Method Modified Based on YOLOv7
## 3 Proposed Method EGS-YOLO
### EIOU Loss  
The loss function is crucial in judging the difference between the forecast and the true value. The Intersection over Union (IOU) ratio is a widely used index to indicate the precision of prediction boxes in object detection tasks. Many loss functions based on IOU have been proposed to optimize detection. DIOU [33] loss makes it more robust by considering the distance and area of overlap between the target and the forecast. CIOU (Complete Intersection over Union) adds two new losses, a detection box scale, and an aspect to make the target box regression more stable. The idea of EIOU [34] is to separate the impact factors of the aspect ratio of the predicted box and the real box and to calculate the length and width of the predicted box and the real box separately. The original loss function of YOLOv7 is CIOU, which adequately takes into account the overlap area, center-of-mass distance, and aspect ratio between the predicted and real boxes. The CIOU contains three main components: loss of target box and prediction box position, classification loss, and loss of target confidence. The CIOU is presented in Equation (9). \[L_{CIOU}=1-IOU+\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{c^{2}}+\alpha v \tag{9}\]  
\[\alpha=\frac{v}{(1-IOU)+v} \tag{10}\]  
\[v=\frac{4}{\pi^{2}}\bigg{(}\bigg{(}arctan\frac{w^{gt}}{h^{gt}}\bigg{)}-arctan \frac{w}{h}\bigg{)}^{2} \tag{11}\]  
The ratio of the intersection and concatenation between two bounding boxes is defined as IOU. The centroids of the prediction and real frames are represented by \(b\) and \(b^{gt}\), respectively. The Euclidean distance between the center of mass in the prediction box and the center of mass in the real box is designated by \(\rho\big{(}b,b^{gt}\big{)}\). In Equation (10), the weighting factor is indicated by \(\alpha\). In Equation (11), the similarity of the aspect ratios is characterized by \(v\). The width and height of the real box are, respectively, represented by \(w^{gt}\) and \(h^{gt}\); the width, and height of the prediction box are, respectively, indicated by \(w\) and \(h\). The bounding box regression problem in object detection is represented in Figure 13. The orange section is the true box, and the light blue section is the predicted box. The overlap of the yellow and blue boxes is used to assess how well the predicted and true boxes match. Figure 13: Predict box and true box (the yellow part is the true box, and the light blue part is the predict box). Although CIOU effectively solves the problem that IOU cannot handle non-overlapping bounding boxes, there are inevitably low-quality samples in the training set. Additionally, there exists some ambiguity in the aspect ratio in CIOU, and \(v\) has a flaw that ignores the true relationship between width and height, affecting the speed of model convergence. The EIOU loss function is proposed to solve this problem effectively. Therefore, the EIOU loss function is adopted in our study. The EIOU is presented in Equation (12). \[L_{EIOU}=L_{IOU}+L_{dis}+L_{asp}\] \[=1-IOU+\frac{\rho^{2}\left(b,b\delta^{t}\right)}{(w^{c})^{2}+(k^{ t})^{2}}+\frac{\rho^{2}\left(w,w^{ct}\right)}{(w^{c})^{2}}+\frac{\rho^{2} \left(h,b\delta^{t}\right)}{(k^{c})^{2}} \tag{12}\]  
\(L_{IOU}\) is the overlap loss, \(L_{dis}\) is the center distance loss, \(L_{asp}\) is the loss of width and height, \(w^{c}\) is the minimum rectangle width that can surround the two bounding boxes, \(h^{c}\) is the minimum rectangle height that can surround two bounding boxes. The EIOU loss function carries over the advantages of CIOU, such as distance loss. Additionally, EIOU minimizes the gap between the width and height of the predicted and real boxes, which accelerates model convergence, making it better overall. EIOU introduces more geometric information, effectively reducing the accumulation of errors in multiple dimensions of the prediction frame. This helps the model adjust the size and position of the prediction box more accurately during training.