1. Introduction
With the continuous development of electronic technology, the assembly of PCB also changes. The number of electronic components such as resistors, capacitors, and integrated circuits on printed circuit PCBs has been increasing, leading to the development of miniaturization, integration, and diversification of PCB boards. Surface Mount Technology (SMT) has enabled the high-density and high-speed automatic assembly of components. The development of these technologies has brought challenges to PCB inspection technology. Conducting fast and accurate detection and identification of defects on PCB has become key to improving PCB quality.
PCB components vary greatly in type, appearance, and size, making manual inspection methods based on human vision and electrical testing [
1] unable to meet the demands of automated production. Machine vision (MV) methods based on image processing have also been widely used for various PCB defect detection tasks [
2,
3,
4,
5,
6]. These machine vision methods have strict requirements for size matching between the PCB board and the inspected image, which is relatively difficult to achieve. Additionally, the detection efficiency of these methods is closely related to the quality of the images, and they are typically used for detecting single defects; hence the actual defect detection rate is relatively low.
As the electronic manufacturing industry advances toward high-density and high-integration development, PCB surface defect detection is required not only to meet detection accuracy requirements but also to comply with industrial quality control standards. According to PCB quality acceptance standards such as GOST R 56251-2014 and IPC-A-600, defects including open circuits, short circuits, missing holes, mouse bites, spurs, and spurious copper may affect circuit connection reliability and product performance. Therefore, these defects are regarded as critical defects that require focused inspection during PCB production.
In recent years, deep learning-based object detection methods have been widely applied in the field of PCB defect detection. The YOLO series of models has attracted considerable attention due to its high detection accuracy and real-time performance. However, existing YOLO models still face challenges such as a large number of parameters, insufficient detection capability for small target defects, and high industrial deployment costs. To address these issues, researchers have proposed methods including GhostNet [
7], coordinate attention [
8], lightweight detection heads, and improved bounding box loss functions. Nevertheless, the comprehensive application of these methods in complex PCB defect scenarios still requires further research.
Recently, the performance of computers is continuously enhancing. Machine learning techniques, including Deep Learning (DL) [
9] and Convolutional Neural Networks (CNNs), have been widely applied in the field of PCB defect detection [
10,
11]. Additionally, the Region-based Convolutional Neural Network (R-CNN) [
12,
13] and similar networks [
14,
15] have been introduced subsequently and applied to PCB surface defect detection. These networks achieve object detection through two steps: they extract object regions and then classify and recognize these regions using CNNs. These aforementioned methods leverage the inherent multi-scale and pyramidal hierarchy of deep convolutional networks to achieve high detection accuracy, but the two-stage detection limits the detection speed. It is worth noting that there are a large number of tiny targets in PCB defects (e.g., mouse bites, burrs, etc.), whose pixel proportion is typically less than 0.01%, posing a serious challenge for detection. Systematic reviews by Tong et al. [
16] and Liu et al. [
17] indicate that the core difficulty in small object detection lies in the easy loss of small target information in deep feature maps, along with insufficient semantic information in shallow feature maps. To address this issue, this paper introduces a P2 small object detection head into YOLOv8, fusing high-resolution shallow features with deep semantic features to improve the detection accuracy of tiny defects. To address the issue that two-stage models are too slow for real-time detection, single-stage networks such as the YOLO series [
18,
19] directly classify and regress on the input, and are widely applied in industrial detection [
20].
1.1. Motivation and Contributions
This paper addresses the challenges of small target detection difficulty, high model complexity, and insufficient industrial deployment efficiency in PCB surface defect detection tasks by collaboratively optimizing the lightweight design and detection performance of YOLOv8L [
21]. The main contributions are as follows:
The RepGhostBottleneck is used to replace the Bottleneck structure in the original YOLOv8 backbone network, significantly reducing the number of model parameters and computational complexity while maintaining feature extraction capability;
The Coordinate Attention (CA) mechanism is introduced to enhance the model’s ability to represent fine-grained defect features and positional information;
A P2 small target detection head is added to improve the model’s detection capability for tiny PCB defects;
The WIoU loss function is adopted to optimize the bounding box regression process, thereby improving target localization accuracy and model generalization ability;
The effectiveness of the proposed method is validated on a hybrid dataset constructed from a public PCB defect dataset and an actual industrial dataset, achieving a synergistic improvement in detection accuracy and inference efficiency.
It should be noted that the term “lightweight” in this paper is relative to the original YOLOv8L baseline (43.7 M parameters). The final model in this paper has 34.0 M parameters, representing a reduction of approximately 22%. Compared with extremely lightweight detectors (e.g., PCB-YOLO with 2.3 M parameters), our model places greater emphasis on achieving a favorable balance between detection accuracy and model complexity, making it suitable for industrial inspection scenarios that demand high accuracy.
1.2. Organization
The remaining part of our paper is organized as follows. The YOLOv8 model and improvements are presented in
Section 1. In
Section 2, data preparation and experimental configuration are described. Furthermore, experimental validation is provided in
Section 3. Finally, the conclusions of the paper are presented in
Section 4.
4. Experimental Results and Analysis
The loss curves of the improved YOLOv8 algorithm during training are shown in
Figure 7. As the number of training epochs increases, the loss gradually decreases and the algorithm tends to converge. In
Figure 7, the left side shows the localization loss on the training set, the middle shows the class loss, and the right side shows the distribution focal loss.
From the training curves, it can be observed that the model exhibits good convergence characteristics and stability in the task of detecting the six types of PCB defects.
In the early stage of training, the , , and all decrease rapidly, indicating that the model can quickly learn the basic features of target localization and class discrimination. Subsequently, the loss functions enter a phase of gradual decline and stabilize after approximately 100 epochs, demonstrating that the model parameters are progressively converging.
The loss curves on the validation set are consistent with those on the training set, and the gap between them remains small, with no obvious divergence. This indicates that the model does not suffer from significant overfitting, and that the data distribution and annotation quality are relatively consistent, giving the model good generalization ability. In terms of performance metrics, mAP@0.5 reaches approximately 0.97, and mAP@0.5:0.95 reaches approximately 0.91. The model maintains strong detection capability even under high IoU criteria, demonstrating high localization accuracy and high-quality bounding box regression.
As shown in
Figure 8, the normalized confusion matrix further illustrates the model’s classification capability and misclassification patterns across different categories. The values on the main diagonal are all above 0.92, indicating that the model can effectively distinguish between different defect types, even for morphologically similar defects such as short circuit and burr, where it still maintains high accuracy. The misclassification rate for the background category is low, ranging from approximately 3% to 8%, demonstrating that the model can suppress false positives in irrelevant regions and possesses strong engineering practicality. The few misclassifications between categories mainly occur between defects with similar morphology, which is an acceptable margin of error in industrial inspection.
Figure 9 presents the Precision–Recall curves for each category along with the overall mAP@0.5 metric. The model exhibits high precision and high recall across all defect categories, with the curves closely clustered near the top-right corner, indicating excellent performance in both reducing false positives and minimizing missed detections. The overall mAP@0.5 reaches 0.976, demonstrating that the proposed model can achieve high reliability and strong robustness in industrial PCB inspection tasks.
As shown in
Figure 10, the F1 curve reflects the overall balance between precision and recall under different confidence thresholds. Experimental results show that the F1 score remains at a high level of 0.96–0.98 over a wide confidence interval, enabling both low false positive rate and low missed detection rate at moderate confidence thresholds. Moreover, the curve is relatively flat in the range of 0.1 to 0.9, indicating that the model is insensitive to threshold variations and possesses strong robustness, making it suitable for threshold fine-tuning according to specific requirements in practical industrial deployment.
As shown in
Table 1, after replacing the Bottleneck in the original C2f module with RepGhostBottleneck, the number of parameters decreased from 9.6 M to 6.0 M, a reduction of 37.5%; FLOPs decreased from 27.2 G to 16.8 G, a reduction of 38.2%; and inference time decreased from 16.8ms to 12.4ms, a reduction of 26.2%. This indicates that RepGhostBottleneck can effectively compress model size and improve computational efficiency.
As shown in
Table 2, the proposed method achieves 97.6% mAP@0.5 on the public PCB dataset, outperforming TDD-Net [
12] (94.2%), Cascade R-CNN [
24] (95.1%), PCB-YOLOv4 [
25] (93.8%), and PCB-YOLO [
26] (95.6%). In terms of the number of parameters, although the proposed method (34.0 M) has more parameters than the lightweight model PCB-YOLO (2.30 M), it achieves a 2.0 percentage point improvement in detection accuracy. Compared with traditional methods, the parameter count of the proposed method is significantly lower than that of Cascade R-CNN (68.0 M) and PCB-YOLOv4 (52.3 M). Overall, the proposed method strikes a good balance between detection accuracy and model complexity.
To further validate the effectiveness of the proposed method, this study compares its performance with that of mainstream single-stage object detection algorithms, namely YOLOv5, YOLOv7, and YOLOv8, on the task of PCB surface defect detection. Under the same AP@0.5 condition, detection accuracy was evaluated for six types of defects: missing hole, mouse bite, open circuit, short circuit, burr, and miscellaneous copper. The experimental results are shown in
Table 3. The proposed method significantly outperforms the other methods in detection accuracy for each defect type.
In addition, to validate the effectiveness of the improvement strategies, this study conducted ablation experiments. The baseline model was YOLOv8, with mAP@0.5, mAP@0.5:0.95, and average detection speed used as evaluation metrics.
Table 4 presents the results of the ablation experiments: compared to the original YOLOv8 network, the proposed method achieves a 6.6% improvement in mAP@0.5, an 8% improvement in mAP@0.5:0.95, and an increase in average detection speed of approximately 2 frames per second. These results demonstrate that the improvement strategies achieve significant gains in both accuracy and efficiency.
As shown in
Table 4, the effectiveness of each improved module is progressively validated through ablation experiments. Baseline model: The original YOLOv8L achieves 91.0% mAP@0.5 and 83.0% mAP@0.5:0.95 on the PCB dataset, with 43.7 M parameters and an FPS of 30. Introducing RepGhostBottleneck: After replacing the Bottleneck in the C2f module with RepGhostBottleneck, the number of parameters is reduced to 27.3 M (a decrease of 37.5%), FPS increases to 36, while mAP@0.5 increases to 93.5% and mAP@0.5:0.95 increases to 86.0%. This indicates that the RepGhost module enhances feature representation capability through a feature reuse mechanism while compressing the model size. Adding the CA attention mechanism: After adding the CA coordinate attention module after the C2f layer, mAP@0.5 further improves to 94.7%, mAP@0.5:0.95 improves to 87.0%, the number of parameters increases by only 0.3 M, and FPS remains unchanged. Adding the P2 small object detection head: After adding the P2 small object detection head to the original three detection heads, mAP@0.5 reaches 97.6% and mAP@0.5:0.95 reaches 91.0%, representing improvements of 6.6 and 8.0 percentage points, respectively, compared to the baseline. Although the number of parameters increases to 34.0 M and FPS slightly decreases from 36 to 34, the detection accuracy is significantly improved, validating the effectiveness of the P2 head for small defect detection.
Overall, all improved modules have made positive contributions to the final performance. The proposed method achieves a good balance between detection accuracy (97.6% mAP@0.5) and model efficiency (34.0 M parameters, 34 FPS).
As shown in
Table 5, TensorRT is used to accelerate the model inference. On an NVIDIA RTX 4070 GPU, under FP32 precision, the inference latency is 19.6 ms, the FPS is 51, the model size is 70.4 MB, and mAP@0.5 remains at 97.6%. Under FP16 precision, the inference latency decreases to 15.4 ms, the FPS increases to 65, the model size is compressed to 50.5 MB, and mAP@0.5 drops by only 0.2 percentage points. After INT8 quantization, the inference latency further decreases to 12.2 ms, the FPS reaches 82, the model size is compressed to 32.3 MB, and mAP@0.5 is 95.8%.
Although the proposed method achieves high detection accuracy in PCB defect detection tasks, there are still some challenging detection scenarios. As shown in
Figure 11, which presents some detection results of the proposed method on the PCB surface defect detection task. Six types of defects are annotated with bounding boxes in different colors: yellow for short circuits, purple for open circuits, light yellow for mouse bites, cyan for burrs, green for missing holes, and gray for stray copper. The detection performance of the model varies across different defect categories. Specifically, the detection accuracy for mouse bites (mAP = 97.0%) and burrs (mAP = 98.2%) is relatively lower than that for other categories (short circuits and open circuits both exceed 97.8%). The reasons for this are analyzed as follows:
Mouse bites: This type of defect appears as tiny hole-like depressions on the PCB substrate, typically with a diameter of less than 0.2 mm, occupying only about 10 × 10 pixels in the image. The small size results in nearly complete loss of information in deep feature maps, relying on the P2 small object detection head for recovery.
Burrs: This type of defect appears at the edges of circuit traces, having the same color as normal copper lines, with only tiny protrusions in shape. The low contrast makes it easy for the model to misclassify burrs as normal circuit edges.
Nevertheless, the AP values of the model for both types of defects still exceed 97%, indicating that the proposed CA attention and P2 head mechanisms effectively alleviate the above issues.
Limitations: It should be noted that the proposed method has currently only been evaluated on a single combined dataset (public dataset + industrial dataset collected from the same production line), where the lighting conditions, imaging parameters, and defect distributions are relatively fixed. Therefore, the cross-dataset generalization capability of the model under different PCB production lines, different lighting conditions, and different imaging devices has not yet been validated. This is the main limitation of the proposed method at present.
Overall, the proposed method can effectively improve the detection performance of common PCB defects. However, there remains room for further optimization for targets with extreme aspect ratios and defects under complex lighting conditions. In the future, we will consider introducing rotated object detection, Transformer architectures, and defect segmentation methods to further enhance the robustness and generalization capability of the model.
In addition, this method has not been specifically optimized for elongated defects (e.g., long scratches and long cracks with an aspect ratio greater than 10:1). The anchor box mechanism of the YOLO series algorithms is based on preset aspect ratios and responds inadequately to targets with extreme aspect ratios. In future work, we plan to introduce Deformable Convolutional Networks (DCNs) or strip attention mechanisms to enhance the feature extraction capability for slender defects.
5. Conclusions
This paper proposes a PCB surface defect detection method based on an improved YOLOv8 architecture. Compared with the original YOLOv8L baseline, this method achieves a relatively lightweight design with a reduction in the number of parameters by approximately 22%. It should be noted that the term “lightweight” in this paper is relative to the chosen baseline. Compared with extremely lightweight detectors, the proposed model places greater emphasis on the balance between detection accuracy and efficiency. To address the challenges of small defect scales, high detection difficulty, and strict requirements for industrial deployment efficiency, RepGhostBottleneck is introduced to construct a lightweight backbone network. Furthermore, YOLOv8 is enhanced by incorporating the Coordinate Attention mechanism, a P2 small target detection head, and the WIoU loss function.
Experimental results show that the proposed method achieves 97.6% mAP@0.5 and 91% mAP@0.5:0.95 on the constructed dataset, demonstrating significant improvements in both detection accuracy and inference efficiency compared to the original YOLOv8 model. Moreover, the method can effectively detect various PCB surface defects, including missing holes, mouse bites, open circuits, short circuits, spurs, and spurious copper, indicating strong potential for industrial application.
This paper proposes a PCB surface defect detection method based on an improved YOLOv8 architecture. Compared with the original YOLOv8L baseline, this method achieves a relatively lightweight design with a reduction in the number of parameters by approximately 22%. It should be noted that the term “lightweight” in this paper is relative to the chosen baseline. Compared with extremely lightweight detectors, the proposed model places greater emphasis on the balance between detection accuracy and efficiency. Future work will focus on Transformer-based feature extraction methods, rotated object detection techniques, and deployment optimization on edge computing devices to further enhance the applicability of the model in real industrial environments.