## 2 Methods
### Improved Sample Imbalance Handling Mechanism for BE-YOLOv5S Bridge Damage Detection Model  
The problem of sample imbalance has always restricted the development of single-stage object detection networks. With the introduction of Focal Loss, its performance has improved. The main mechanism of action of Focal Loss is to control the weight of positive and negative samples and to control the weight of easy-to-classify and hard-to-classify samples. It is defined in the following Formula (3). Where \(pt\in\) [0,1] represents the prediction confidence score of a candidate frame target, and \(\alpha_{t}\) is used as a balance parameter for balancing positive and negative samples in Focal Loss, \(\gamma\) is the Focal parameter, which increases with the degree of imbalance of positive and negative samples. Through the use of the above definitions, the loss of simple samples can be reduced, and the focus of model learning can be biased towards complex and deep learning samples. However, for bridge damage targets, the traditional Focal Loss uses the same modulation factor for all damage target categories to balance the problem of unbalanced samples, and the problem of high similarity between bridge background and samples cannot be effectively solved. To this end, in the work of this paper, we introduce Equalized Focal Loss [56] to improve the performance of the BE-YOLOv5S bridge damage detection model. Figure 3: PANet and BiFPN network structure. **(a)** is the PANet network structure, and **(b)** is the BiFPN network structure. In this figure, the blue arrows are top-down paths, which convey the semantic information of high-level features, and the red arrows are bottom-up paths, which convey the location information of low-level features. The purple part is an extra path added when the input point and output point are located in the same layer, which is used to fuse more feature information [55]. This paper solves the problem of multi-class sample imbalance in the target of bridge damage by introducing the modulation factor, Focusing Factor, associated with the class. The definition of the Focusing Factor is as follows in Equation (4), where \(\alpha\) and \(p_{t}\) are the same as those in the above Equation (3), \(\gamma_{j}\) is the Focusing Factor of the \(j\)th category, and its function is similar to that of Focal Loss. Here, the value of \(\gamma_{j}\) is larger, which is used to alleviate the problem of serious sample imbalance. Of course, the small value of \(\gamma_{j}\) required for the samples with a small degree of sample imbalance in the bridge damage target is decoupled into two components, which are defined as Equation (5). Among them, \(\gamma b\) represents the Focusing Factor that controls the basic behavior of the classifier, and the parameter \(\gamma^{l}_{v}\geq 0\) represents the first variable with the unbalanced correlation degree of the \(j\)th class, It determines the attention distribution of BE-YOLOv5S in the process of training and learning the bridge damage model, and its value is determined according to the gradient guidance mechanism. The parameter \(g^{i}\) represents the cumulative gradient ratio of the \(j\)th class of positive and negative samples. When the value of \(g^{i}\) is large, it means that the training is balanced; otherwise, it is unbalanced. The hyperparameter \(s\) is a scaling factor that controls the upper limit of \(\gamma^{j}\) in EFL. Through the application of the above definition, compared with Focal Loss, we can independently deal with different categories of damage targets encountered during the training process, thereby further improving the performance of the BE-YOLOv5S model in bridge damage detection. \[FL(p_{t})=-\alpha(1-p_{t})^{\gamma}\log(p_{t}) \tag{3}\]  
\[\text{EFL}=-\alpha(1-p_{t})^{\gamma}\log(p_{t}) \tag{4}\]  
Figure 4: Damage feature extraction map of PANet and BiFPN bridge structures. (**a–d**) are the feature extraction of the four types of damage under the PANet and BiFPN network structures, respectively.) \[