Abstract:In this paper, the YOLOv5 target detection algorithm was used as the base algorithm to improve accuracy for PCB defect detection. Firstly, an appropriate data augmentation method is selected through experiments. For the problem of small PCB defect size, the P2 detection head was added to the original three detection heads. A new PANet multi-feature fusion structure was designed to realize efficient two-way cross-scale connection and weighted feature layer fusion. For the problem of the complex PCB background, the CBAM attention module is introduced to enhance image information, the Transformer module is introduced to enhance the algorithm’s ability to capture PCB defect information at different locations. Finally, through these improvements, the mAP accuracy of the algorithm increased by 11. 3% while the FPS droped by only 7. 2.