# MAS-YOLO: A Lightweight Detection Algorithm for PCB Defect Detection Based on Improved YOLOv12
## 3 Experiment and Analysis
### Experimental Process
#### 3.3.4 The Comparison of the Impact of Loss Functions on the Training Process  
To assess the influence of the Slide Alignment Loss on training performance, the YOLOv12 model was trained using four loss functions: CIoU, DIoU, GIoU, and SAL. The two datasets were merged for the experiments. Figure 4 visualizes the loss curves during the training process. Table 7 presents the loss values obtained from model training with different loss functions over large epochs (from 250 epochs to 400 epochs).  
Observing the loss curves in Figure 4 and the loss data in Table 7, it is evident that all loss functions tend to stabilize after approximately 300 epochs. This indicates that the model has effectively learned the underlying data patterns and undergone gradual optimization during training. Among the loss functions, the Slide Alignment Loss (SAL) demonstrates the fastest convergence rate and achieves the lowest loss value, underscoring its superiority in model performance.  
The data analysis in Table 7 further reveals that the model's performance stabilizes between 300 and 400 epochs, with no significant improvements observed from additional  
\begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Loss Function** & **250 epochs** & **275 epochs** & **300 epochs** & **325 epochs** & **350 epochs** & **375 epochs** & **400 epochs** \\ \hline CIoU & 0.0284 & 0.0279 & **0.0278** & 0.0277 & **0.0278** & **0.0278** & **0.0278** \\ DIoU & 0.0278 & 0.0275 & **0.0274** & **0.0274** & **0.0274** & **0.0274** & **0.0274** \\ GIoU & 0.0278 & 0.0269 & **0.0266** & **0.0266** & 0.0265 & **0.0266** & **0.0266** \\ SAL & 0.0221 & 0.0219 & **0.0218** & **0.0218** & **0.0218** & **0.0218** & **0.0218** \\ \hline \hline \end{tabular}
\end{table}
Table 7: Table of loss values for different loss functions under large epochs.  
Figure 4: Loss curves of training model optimized by different loss functions.  
training(As shown in the bold data in Table 7). Training beyond this point risks overfitting and incurs unnecessary computational resource consumption. To balance convergence and generalization capabilities, all subsequent model validation experiments were conducted at the 300-epoch mark.  
The data in Table 8 further demonstrate that the model trained with SAL outperformed other loss functions in key performance indicators such as mAP, precision, and recall. This is because, unlike other loss functions, the SAL function introduces an adaptive weight factor based on the consideration of center deviation, size ratio, and angle differences. It specifically focuses on difficult samples with varying morphology, size, and angle characteristics of defects by dynamically adjusting its attention based on the difficulty of the samples. This enhances the overall convergence effect of the training process, better balancing precision and recall, and effectively improving the model's detection accuracy and generalization ability.  
Based on the results from the figures and tables, it can be concluded that introducing the SAL function significantly improves the performance of the YOLOv12 model in PCB defect detection tasks, particularly for detecting small-sized and complex, easily confused PCB defects, where its effectiveness is especially remarkable.