For Printed Circuit Board (PCB) surface defect detection, traditional detection methods mostly focus on template matching-based reference method and manual detections, which have the disadvantages of low defect detection efficiency, large errors in defect identification and localization, and low versatility of detection methods. In order to further meet the requirements of high detection accuracy, real-time and interactivity required by the PCB industry in actual production life. In the current work, we improve the Youonly-look-once (YOLOv4) defect detection method to train and detect six types of PCB small target defects. Firstly, the original Cross Stage Partial Darknet53 (CSPDarknet53) backbone network is preserved for PCB defect feature information extraction, and secondly, the original multi-layer cascade fusion method is changed to a single-layer feature layer structure to greatly avoid the problem of uneven distribution of priori anchor boxes size in PCB defect detection process. Then, the K-means++ clustering method is used to accurately cluster the anchor boxes to obtain the required size requirements for the defect detection, which further improves the recognition and localization of small PCB defects. Finally, the improved YOLOv4 defect detection model is compared and analyzed on PCB dataset with multi-class algorithms. The experimental results show that the average detection accuracy value of the improved defect detection model reaches 99.34%, which has better detection capability, lower leakage rate and false detection rate for PCB defects in comparison with similar defect detection algorithms.