Abstract:Aiming at the problem that the defect detection model of printed circuit boards in the environment of limited computing resources of industrial edge devices is difficult to balance lightweight and detection accuracy, a lightweight PCB defect detection algorithm based on YOLOv12n is proposed. Firstly, the design of the fusion token mixer adopts the C3K2-CF module of depthwise separable convolution, which not only reduces the number of parameters but also enhances the perception ability for small targets. Secondly, a new feature fusion enhancement network FFEN is proposed to ensure the integrity of the target information in cross-scale feature transfer, thereby strengthening the model’s ability to pay attention to the target. Secondly, a feature-focused fusion module FFF is designed to fully integrate multi-scale context information and enhance the model’s ability to extract complex features. Finally, to address the issue of missed detection of small targets in PCB defect detection, the task-aligned dynamic detection head TADDH is introduced. This enabled the information exchange channel between the localization and classification dual detection heads to be established, thereby improving the detection accuracy of the model for small-sized defects. The experimental results show that, compared with the original YOLOv12n model, the improved algorithm achieves an mAP@0.5 of 98.6% on the PKU-Market-PCB dataset with data augmentation. The stricter mAP@0.5:0.95 metric has been improved by 7.2%. The parameter count and computational cost have been reduced by 47.2% and 16.9%, respectively. On the Deep PCB public dataset, the improved model achieved a detection accuracy of 97.5% mAP@0.5, representing a 2.5% improvement over mAP@0.5:0.95. It can be seen from this that the improved algorithm effectively achieves high-precision PCB defect detection and meets the detection requirements of generalized small targets in industrial scenarios.