## 2 Unsafe Behavior Identification Model
### Improved YOLOv5s Model Construction
#### 2.2.1 Introducing the Focal-EIoU Loss Function  
The YOLOv5s model uses the CIoU loss function as a key component in bounding box regression for object detection tasks. The CIoU loss function considers the overlap, center point, and aspect ratio of the bounding box; however, it does not directly address  
Figure 1: YOLOv5s model structure.  
discrepancies in the orientation of the bounding box [24]. Its mathematical formulation is as follows:  
\[L_{CIoU}=1-IoU+\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{c^{2}}+\alpha v \tag{1}\]  
\[\alpha=\frac{v}{1-IoU+v} \tag{2}\]  
\[v=\frac{4}{\pi^{2}}\left(arctan\frac{w^{gt}}{h^{gt}}-arctan\frac{w}{h}\right) ^{2} \tag{3}\]  
In this formula, \(IoU\) represents the intersection-over-union ratio between the predicted and ground truth bounding boxes; \(\rho\) denotes the distance between two points; \(b\) and \(b^{gt}\) represent the center points of the predicted and ground truth boxes, respectively; \(C\) is the diagonal length of the minimum enclosing rectangle between the predicted and ground truth boxes; \(w\) and \(h\) represent the width and height of the predicted box, respectively; \(w^{gt}\) and \(h^{gt}\) represent the width and height of the ground truth box, respectively; \(\alpha\) is a trade-off parameter; and \(v\) is used to measure the consistency of the aspect ratio.  
In complex construction scenarios, the detection targets are often intricate, and there is a high demand for precise orientation. The CIoU loss function, however, may not be sufficient to accurately adjust the orientation of the predicted bounding box. During the early stages of training, when the difference between the predicted and ground truth boxes is substantial, the CIoU loss function can cause the predicted box to \"wander\" as it searches for the optimal position, slowing down model convergence.  
The EIoU loss function addresses the limitations of the CIoU loss function, enhancing the performance of bounding box regression (BBR) in object detection. Compared to CIoU, EIoU introduces additional components, such as width and height loss; separates the aspect ratio; and incorporates focal clustering of high-quality anchor boxes. EIoU explicitly measures differences across three geometric factors in BBR: overlap area, center point, and side lengths. This enables more accurate and efficient measurements, focusing on high-quality examples and anchor boxes with smaller regression errors. Furthermore, EIoU can be combined with focal loss to form Focal-EIoU, which improves both convergence speed and positioning accuracy [25]. The Focal-EIoU loss function (Equations (4) and (5)) addresses two critical limitations of standard CIoU. The first is imbalanced gradient allocation: CIoU's aspect ratio term causes gradient dominance during late training stages, leading to localization plateaus, and Focal-EIoU introduces a dynamic focusing parameter, \(\gamma\), that prioritizes high-quality anchors and can significantly address localization drift. The second is scale sensitivity: separating the width/height loss components of EIoU can reduce the variance of mAP across scales by about 20%.  
The Focal-EIoU formula is as follows:  
\[L_{EIoU}=L_{IoU}+L_{dis}+L_{asp}=1-IoU+\frac{\rho^{2}\big{(}b,b^{gt}\big{)}}{ c^{2}}+\frac{\rho^{2}(w,w^{gt})}{C_{iw}^{2}}+\frac{\rho^{2}\big{(}h,h^{gt} \big{)}}{C_{h}^{2}} \tag{4}\]  
where \(C_{iw}\) is the width of the minimum bounding box and \(C_{h}\) is the height of the minimum bounding box.  
\[L_{Focal-EIoU}=~{}IoU^{\gamma}L_{EIoU} \tag{5}\]  
where \(\gamma\) is used to control the deviation of the curve curvature.