# Detection of Welding Defects Tracked by YOLOv4 Algorithm
## 4 Experiment
### Experimental Results and Analysis  
#### 4.4.1 Comparison with Other Object Detection Models  
To comprehensively evaluate the performance of the YOLOv4-cs2 model, several commonly used evaluation metrics are employed, including _Precision_, _Recall_, _AP_ (Average Precision), and _mAP_ (mean Average Precision). The calculation formulas for _Precision_ and _Recall_ are defined in Equations (4) and (5). \[Precision=\frac{TP}{TP+FP} \tag{4}\]  
\[Recall=\frac{TP}{TP+FN} \tag{5}\]  
Taking slag inclusions as an example, in Equations (4) and (5) _TP_ represents the number of slag inclusions correctly detected, _FP_ represents the number of slag inclusions incorrectly detected, and _FN_ represents the number of slag inclusions that were not detected. To evaluate its performance in detecting external substances, the proposed YOLOv4-cs2 model is compared with several other object detection methods, including YOLOv4, YOLOv3, YOLOv4-Tiny, CenterNet, and SSD. Table 3 summarizes the results in terms of accuracy and recall. As shown in Table 3, the YOLOv4-Tiny, CenterNet, and SSD models exhibit higher accuracy rates for detecting the three types of defects. However, their recall rates for these defects are relatively low, particularly for incomplete penetration defects. While YOLOv3 and YOLOv4 show improved recall rates for all three types of defects while maintaining accuracy, their recall rates for specific defects, such as pores, remain low. Due to the lack of obvious edge features and the tendency to lose edge information after convolution, deepening the network is crucial for extracting robust edge information from pores. YOLOv4-cs1 modifies the feature fusion mode of residual network blocks, thereby adjusting the network depth and ensuring proper gradient flow. Removing the downsampling layer helps minimize the loss of edge information, leading to better overall prediction results compared to the original YOLOv4 model, with a significant improvement in recall rate. YOLOv4-cs2 builds upon YOLOv4-cs1 by adding two SPP (Spatial Pyramid Pooling) modules to enhance the semantic information of feature maps obtained from residual blocks. Additionally, it refines the large residual edges within the residual blocks, thereby improving the extraction of edge features. As shown in Table 3, although the accuracy rates for pores and slag inclusion have slightly decreased, the recall rates for these two \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Model**} & \multicolumn{2}{c}{**Pores**} & \multicolumn{2}{c}{**Slag inclusions**} & \multicolumn{2}{c}{**Incomplete Penetration**} \\ \cline{2-7}  & _Precision_ & _Recall_ & _Precision_ & _Recall_ & _Precision_ & _Recall_ \\ \hline YOLOv4-cs2 & 91.81\% & 83.12\% & 92.19\% & 92\% & 87.19\% & 51.96\% \\ YOLOv4-cs1 & 92.97\% & 73.88\% & 94.1\% & 85.68\% & 89.6\% & 46.8\% \\ YOLOv4 & 97.28\% & 57.33\% & 94.2\% & 73.47\% & 81.12\% & 58.36\% \\ YOLOv3 & 97.31\% & 65.07\% & 98.42\% & 79.05\% & 93.8\% & 48.10\% \\ YOLOv4-Tiny & 94.05\% & 47.26\% & 98.38\% & 64.11\% & 93.75\% & 8.42\% \\ Centernet & 99.71\% & 18.76\% & 99.77\% & 45.79\% & 99.9\% & 0.11\% \\ SSD & 95.26\% & 43.33\% & 97.56\% & 63.26\% & 99.9\% & 1.12\% \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Comparison of results of different models. defects have significantly improved--by 25.79% and 18.53%, respectively--compared to the original YOLOv4 model. Moreover, they are 9.24% and 6.32% higher than those of the YOLOv4-cs1 model. As shown in Table 3, the detection accuracy rate of the YOLOv4-cs2 model has decreased, while the recall rate has increased. To provide a comprehensive evaluation, the \(F1\) score is introduced, which represents the harmonic mean of precision and recall. The formula for calculating the \(F1\) score is defined in Equation (6). \[F1=\frac{2\times Precision\times Recall}{Precision+Recall} \tag{6}\]  
The values of \(F1\) for three defects, calculated through the above equations, are shown in Table 4.  
A higher \(F1\) value indicates better detection performance of the model.