# MAS-YOLO: A Lightweight Detection Algorithm for PCB Defect Detection Based on Improved YOLOv12
## 4 Discussion and Conclusions  
To address the challenges of small target features that are difficult to recognize and strong background interference caused by complex wiring in PCB defect detection tasks, this paper proposes a lightweight detection algorithm based on an improved YOLOv12. Through the integration of the Median-enhanced Channel and Spatial Attention Block, which merges channel and spatial attention mechanisms, the feature extraction capability is significantly enhanced, leading to an increase in detection accuracy by 6.7 and 7.5 percentage points on two experimental datasets, respectively, compared to the original YOLOv12. At the same time, an Adaptive Hierarchical Feature Integration Network was designed to achieve adaptive weighted fusion of multi-scale features, effectively improving the model's ability to detect small defects and adapt to complex scenes. The detection accuracy is further improved by 4.1 and 4.8 percentage points on the two datasets. Additionally, to optimize the bounding box regression process and overcome the limitations of traditional loss functions for small targets and irregularly shaped defects, Slide Alignment Loss is introduced, further enhancing detection accuracy and robustness. The improved MAS-YOLO model achieves an average detection accuracy mAP of 93.2% in PCB defect detection tasks, a 7.8 percentage point improvement over the original model, while maintaining a real-time detection speed of 49.7 frames per second, fully meeting the real-time detection requirements of industrial production lines. Statistical analysis was conducted to confirm the significance of these improvements. Using bootstrapping with 1000 resamples, the 95% confidence interval for the original YOLOv12 model's mAP was found to be [84.8%, 86.0%], while for MAS-YOLO, it was [92.9%, 93.5%]. A paired \(t\)-test also revealed a statistically significant improvement (t = \(-\)12.45, \(p\) < 0.001) in MAS-YOLO compared to YOLOv12. These results underscore that the improvements are statistically significant. The enhanced model not only strengthens the recognition of small target defects but also adapts more accurately to complex background scenes. During the test, the detection system can deliver 14 TOPS at 10 W and 21 TOPS at 15 W of power consumption, despite being deployed on a low-resource platform like the Jetson Xavier NX. In terms of latency and power usage, it shows impressive performance with low latency and efficient power consumption. For instance, when handling full HD 1920 \(\times\) 1080 images, the latency is 50-70 ms, and the power consumption is approximately 10-15 W. These features make it an ideal choice for real-time industrial defect detection tasks. Future work will focus on further optimizing the model's lightweight design to promote the practical industrial application of this algorithm in PCB defect detection. Furthermore, the MAS-YOLO model, with its enhanced capability for small target detection in dense scenes, shows great potential for application in other practical problems involving small object detection. The model's unique features, such as the Median-enhanced Channel and Spatial Attention Block and the Adaptive Hierarchical Feature Integration Network, make it highly adaptable to various scenarios where small objects are densely packed and backgrounds are complex. For instance, in agricultural monitoring, the model could be used to detect small pests or diseases on crops. In medical imaging, it might help identify subtle anomalies in X-rays or MRIs. Traffic monitoring is another area where the model could excel, potentially improving the detection of vehicles in crowded urban environments. These potential applications highlight the model's versatility and its promising future in diverse fields. Conceptualization, X.Y., L.W. and Z.Z. ; methodology, X.Y., L.W. and Z.Z. ; software, X.Y. ; validation, Z.Z. ; formal analysis, X.Y. and L.W. ; investigation, Z.Z. ; resources, L.W. ; data curation, L.W. ; writing--original draft preparation, X.Y. ; writing--review and editing, L.W.