# Improved YOLOv5-Based Real-Time Road pavement Damage Detection in Road Infrastructure Management
## 3 Methodology
### YOLOv5s Architecture
#### 3.1.4 Head  
The YOLOv5 algorithm's head mechanism employs three different YOLO Head classifiers to identify feature images of varying scales: large-scale, medium-scale, and small-scale. The prediction outcome encompasses the projected category, level of confidence, and positioning of each predicted box. Hence, it is essential to compute the losses of the three predicted results distinctly during the formulation of the loss function. The YOLOv5 model's loss function comprises three parts, namely the confidence loss (\(L_{\text{obj}}\)), localization loss (\(L_{\text{box}}\)), and classification loss (\(L_{\text{cls}}\)). The aggregate loss is computed as the summation of three distinct losses, and each is assigned a specific weight. Equation (1) represents the full loss function.  
\[\text{LOSS}=a\times L_{\text{obj}}+b\times L_{\text{cls}}+c\times L_{\text{ box}} \tag{1}\]The weighting factors denoted by \(a\), \(b\), and \(c\) correspond to the three partial losses. Equations (2)-(4) represent all these partial losses. We utilized the default settings as suggested in the YOLOv5 implementation, wherein we set the values of a, b, and c to 1.0. This decision also corresponds with the results of other cutting-edge research, such as YOLOv4 and YOLOv3, where these setup values have exhibited favorable compromises between accuracy and computational efficacy [33; 34].  
\[L_{\text{box}}=1-\text{CIOU} \tag{2}\]  
\[L_{\text{cds}}=\sum_{i=0}^{S^{2}}\prod_{i=0}^{obj}\sum_{c\in\text{class}}(p_{i} (c)-\hat{p}_{i}(c))^{2} \tag{3}\]  
\[\text{l}_{\text{obj}}=\sum_{i=0}^{S^{2}}\sum_{j=0}^{B}\prod_{\text{ij}}^{obj}( C_{i}-\hat{C}_{i})^{2}+\lambda_{\text{noobj}}\sum_{i=0}^{S^{2}}\sum_{j=0}^{B} \prod_{\text{ij}}^{obj}(C_{i}-\hat{C}_{i})^{2} \tag{4}\]  
The symbol \(\prod_{i}^{obj}\) is utilized to ascertain the presence of a detection object in cell \(i\). The \(\prod_{\text{ij}}^{obj}\) is utilized to ascertain the responsibility of the \(j\)th \((j=0,\dots,B)\) prediction box located in cell \(i\) (\(i=0,\dots,S^{2}\)) for detecting the given object. The notation \(p_{i}(c)\) is utilized to indicate the classification score of a specific category C, whereas \(\hat{p}_{i}(c)\) denotes the actual value of the category linked with the prediction box. The weight coefficient in the absence of an object is denoted as \(\lambda_{\text{noobj}}\), while \(C_{i}\) represents the confidence score. Additionally, the intersection portion of the prediction box and the actual box is defined by \(\hat{C}_{i}\).  
Binary cross-entropy loss (BCE) is mainly used in classification and confidence loss, while CIoU (Complete Intersection Over Union) loss is commonly used for localization loss.  
\[L_{p}(q)=-\frac{1}{N}\sum_{i=1}^{N}y_{i}\cdot\log(p(y_{i}))+(1-y_{i})\cdot \log(1-p(y_{i})) \tag{5}\]  
Equation (5) defines the binary cross-entropy loss. In the given equation, \(y_{i}\) denotes the actual label of the sample in the real-world scenario, whereas \(p(y)\) signifies the anticipated likelihood of the data point being affirmative, taking into account all \(N\) data points. The augmented form of the localization loss is described in Equation (6).  
\[L_{\text{box}}(l,g)=1-\text{CIOU}(l,g)=1-\text{IoU}(l,g)+\frac{\rho(l,g)^{2}} {c^{2}}+\alpha v \tag{6}\]  
\[\text{IoU}(l,g)=\frac{l\cap g}{l\cup g} \tag{7}\]  
\[v=\frac{4}{\pi^{2}}\bigg{(}\tan^{-1}\bigg{(}\frac{g_{w}}{g_{h}}\bigg{)}-\tan ^{-1}\bigg{(}\frac{l_{w}}{l_{h}}\bigg{)}\bigg{)}^{2} \tag{8}\]  
\[\alpha=\frac{v}{(1-\text{IoU}(l,g))+v} \tag{9}\]  
The symbols \(l\) and \(g\) in the equation represent the ground truth and prediction box, respectively. The symbol \(\rho\) denotes the Euclidean distance. The parameter \(c\) represents the diagonal length of the smallest possible closed box that can cover both boxes above. The intersection degree of \(IoU\) of two boxes is represented by Equation (7). \(v\) in Equation (8) denotes the aspect ratio's consistency. Finally, the symbol \(\alpha\), denoted in Equation (9), represents the trade-off parameter.