1. Introduction
The relentless miniaturization and increasing complexity of electronic devices have placed unprecedented demands on the quality and reliability of Printed Circuit Boards (PCBs). As the foundational substrate for interconnecting electronic components, any defect in a PCB—such as open circuits, shorts, spurs, or mouse bites—can lead to catastrophic system failures [
1]. Traditional inspection methods, including manual visual inspection and electrical testing, are not only labor-intensive and costly but also prone to human fatigue and subjective error, making them unsuitable for modern high-volume, precision manufacturing [
2,
3].
The advent of deep learning, particularly convolutional neural networks (CNNs), has revolutionized automated visual inspection. Among these, single-stage object detectors like the YOLO (You Only Look Once) series have gained prominence for their compelling trade-off between speed and accuracy [
4]. The YOLOv5 architecture, in particular, has been widely adopted for industrial tasks, including PCB defect detection [
5,
6]. However, a significant limitation of standard CNNs, including YOLOv5, is their deterministic nature. They produce point estimates for bounding boxes and class probabilities without any inherent measure of the model’s
confidence or
uncertainty in its predictions [
7]. In the context of PCB inspection, this translates to a critical shortcoming: the model may output a high-confidence score for a blatant false positive or miss a subtle defect with no indication of its uncertainty. This lack of self-awareness limits the trustworthiness of such systems in real-world, safety-critical applications.
Bayesian deep learning offers a principled framework to address this very issue [
7,
8]. By treating the weights of a neural network as probability distributions rather than fixed values, Bayesian Neural Networks (BNNs) can naturally quantify
epistemic uncertainty (model uncertainty due to lack of training data) and
aleatoric uncertainty (inherent data noise) [
9]. This allows for more reliable and interpretable predictions. While full BNNs can be computationally prohibitive, numerous approximate inference techniques, such as Monte Carlo Dropout [
8] and ensemble methods [
10], have made Bayesian principles practically applicable to large-scale vision tasks. A Bayesian perspective encourages models that are not just accurate but also
well-calibrated, meaning a prediction with a confidence score of 90% should be correct 90% of the time [
11].
Surprisingly, the integration of Bayesian thinking into PCB defect detection remains largely unexplored. Most existing works focus on architectural modifications to boost mean Average Precision (mAP) but neglect the crucial aspect of predictive uncertainty [
5,
6,
12]. This gap is especially pronounced for small defect detection, where features are scarce and ambiguity is high—a scenario where uncertainty estimation is most valuable.
While the aforementioned advancements in deep learning have significantly improved the accuracy of PCB defect detection, the integration of Bayesian principles offers a promising direction to further enhance model reliability and interpretability in real-world applications.
In this paper, we argue that a Bayesian reinterpretation of the PCB defect detection pipeline can yield significant improvements in both performance and reliability. We propose MFE-YOLO, an enhanced YOLOv5 model that embeds Bayesian principles at multiple stages. Our contributions are not merely heuristic improvements but are motivated by a probabilistic understanding of the detection problem. The small size and often ambiguous appearance of PCB defects can be viewed as a source of aleatoric uncertainty, while the limited diversity of public datasets contributes to epistemic uncertainty. Our approach directly tackles these challenges.
First, to mitigate the data limitation and bias present in existing single-background datasets, we construct a multi-background PCB defect dataset encompassing a variety of substrate colors and board shapes. This improves the model’s robustness and generalization across different visual conditions encountered in practice.
Second, we enhance the feature representation by integrating the Convolutional Block Attention Module (CBAM) [
13]. From a Bayesian standpoint, the channel and spatial attention mechanisms in CBAM can be interpreted as a form of
feature-wise uncertainty weighting. By learning to attenuate less informative features (e.g., complex backgrounds) and amplify salient ones (e.g., defect edges), the network is effectively performing a Bayesian marginalization over feature maps, reducing the influence of noisy or confounding inputs. This leads to a more robust and focused feature extraction process.
Third, we identify a key weakness in the commonly used CIoU loss function for bounding box regression. Its reliance on aspect ratio difference can fail when the predicted and target boxes have identical ratios but different scales. To address this, we redesign the loss function, proposing FIoU. More importantly, we frame this redesign within a probabilistic context. The FIoU loss incorporates absolute dimensional differences, which can be linked to modeling the uncertainty in the scale of the bounding box. This results in a more stable and accurate regression, particularly for small objects where localization error is most critical.
In summary, the main contributions of this paper are as follows:
- (1)
Construction of a multi-background color PCB dataset, serving as a broader prior distribution for training a robust, uncertainty-aware defect detector.
- (2)
Proposal of an improved YOLOv5-based PCB defect detection model, where the integrated CBAM attention mechanism acts as a Bayesian feature weighting module to suppress background noise and enhance defect-specific features.
- (3)
Redesign of the FIoU loss function based on the CIoU loss, incorporating a probabilistic perspective on bounding box scale to improve regression accuracy and implicitly model localization uncertainty.
Through extensive ablation studies and comparisons, we demonstrate that our Bayesian-enhanced MFE-YOLO not only achieves superior detection accuracy but also paves the way for more reliable, calibrated, and trustworthy automated optical inspection systems.
3. The Method in This Paper
The PCB defect detection algorithm studied in this paper primarily focuses on identifying surface defects on PCBs. According to the definition provided by the International Society for Optics and Photonics (SPIE), a target occupying less than 0.12% of the entire image is defined as a small target. Based on this criterion, most of the targets examined in this study fall into the small target category. Therefore, the selected network must not only ensure fast, real-time, and accurate detection but also—and especially—maintain a high detection accuracy for small targets. Considering the challenges in PCB defect detection, it is noted that PCBs used in different applications may vary in trace width, layout, and background color. This often leads to complex background information and limited target feature representation. To address these issues, this paper proposes an improved YOLOv5 object detection algorithm for detecting six types of defects in PCBs. The improvements mainly focus on three components: the Backbone, the loss function, and the Head. The architecture of the modified YOLOv5 model is shown in
Figure 4.
3.1. Improvement of the Backbone
In YOLOv5, the Backbone, which serves as the feature extraction module, is primarily composed of four key components: the Focus, CBL, CSP, and SPP modules. Research has shown that introducing an attention mechanism into the original network can enhance the model’s ability to focus on locally salient information, thereby effectively improving the accuracy of object detection. To leverage this, the present study incorporates the CBAM (Convolutional Block Attention Module) into the original Backbone structure. CBAM is an attention mechanism that combines both spatial and channel attentions. This module sequentially infers attention weights along the channel and spatial dimensions from the input feature map. The original input features are then multiplied by the resulting attention weights to achieve adaptive feature refinement. The structure of the CBAM is illustrated in
Figure 5.
Among them, the feature map undergoes channel and spatial attention mechanisms, sequentially reassigning weight coefficients to different regions in the channel and spatial dimensions. This reduces the weights of non-target regions and weakens the features of background areas while further enhancing the weights of target regions and highlighting target features. The channel attention expression is:
where
is the sigmoid operation,
,
is the number of neurons,
is the reduction ratio,
are the weights of the multilayer perceptron,
represents average pooling, and
represents max pooling.
The spatial attention expression is:
where
represents the size of the convolution kernel,
represents average pooling, and
represents max pooling.
The improvement in this paper primarily involves adding a CBAM layer after the CSP layer in the Backbone network. After the feature map passes through the CBAM layer, it is reweighted based on the learned attention coefficients, enabling the network to focus more on critical regions and effectively enhancing the feature representation capability of the model. The modified Backbone network is illustrated in
Figure 6.
3.2. Neck and Redesign of the Head Part
An analysis of the six types of PCB defects detected in this study reveals that the vast majority of these defects occupy less than 0.1% of the total PCB area, categorizing them as small targets. However, the original YOLOv5 model exhibits a significantly higher missed detection rate for small targets compared to larger ones. The primary reason for this limitation lies in the design of the YOLOv5 network. The Head section of the original model contains only three detection layers. Given an input image size of 640 × 640, the output feature maps have dimensions of 80 × 80, 40 × 40, and 20 × 20, respectively. These correspond to the detection of targets larger than 8 × 8, 16 × 16, and 32 × 32 pixels. In the actual PCB images collected for this system, after resizing to 640 × 640, the defects are also scaled down. As a result, many of the actual defect targets become smaller than the minimum detectable size supported by the original detection layers, leading to relatively low precision in defect detection.
Based on the aforementioned analysis of the detection targets and the YOLOv5 network model, this study draws inspiration from the improvement concept of TPH-YOLOv5 [
18] and enhances the original Head component of YOLOv5 by adding a dedicated detection head specifically designed for small target defect detection. As a result, the network now outputs feature maps at four different scales: 160 × 160, 80 × 80, 40 × 40, and 20 × 20. Compared to the original network, which could detect targets as small as 8 × 8 pixels, the improved model is capable of detecting targets as small as 4 × 4 pixels, significantly enhancing the network’s sensitivity to small targets. Although the addition of a small target detection head increases the computational load and complexity of the model to some extent, it substantially improves the detection performance for small targets and effectively enhances the accuracy of small target detection. The structure of the modified Head network is illustrated in
Figure 7.
3.3. Loss Function Redesign
The loss function in object detection tasks typically consists of classification loss and bounding box regression loss. This section focuses on improving the bounding box regression loss. Currently, commonly used bounding box regression losses in object detection are mostly improved based on IoU (Intersection over Union) loss. The formula for calculating IoU is as follows:
where
is the ground truth box area, and
is the predicted box area.
IoU loss can measure the distance between predicted bounding boxes and ground truth boxes, thereby accurately reflecting detection performance. However, as can be seen from the calculation method above, when the predicted box and the ground truth box do not intersect, the IoU value becomes zero. In such cases, IoU loss fails to effectively quantify the distance between the two boxes, which hinders accurate learning of bounding box regression.
The authors of YOLOv5 adopt CIoU (Complete Intersection over Union) as the bounding box regression loss function. CIoU takes into account the distance between the target and the anchor, the overlap rate, and the scale, which makes the bounding box regression more stable and avoids the divergence issue that occurs during training with standard IoU. The formula for calculating CIoU is as follows:
where
are the coordinates of the center point of the predicted box,
are the coordinates of the center point of the ground truth box,
represents the Euclidean distance between the center points of the predicted box and the ground truth box, and
represents the diagonal distance of the smallest enclosing box that contains both the predicted box and the ground truth box,
and
. The calculation formulas are:
where
and
represent the width and height of the ground truth box, and
and
represent the width and height of the predicted box.
An analysis of CIoU reveals that it employs the relative ratios of width and height rather than their actual values. According to the definition of
, whenever the predicted bounding box satisfies the condition
, the penalty term based on relative proportions in CIoU ceases to function. To address this limitation, this paper proposes a redesigned loss function named FIoU, building upon the concept of CIoU. While the original CIoU loss uses the Euclidean distance between the centers of the predicted and ground truth bounding boxes as a penalty term, the proposed FIoU loss adopts a simplified single distance metric between the centers, reducing computational complexity compared to the Euclidean distance. Furthermore, to overcome the drawback of CIoU’s reliance on relative width and height ratios rather than actual values, FIoU incorporates the absolute differences in width and height between the predicted and ground truth boxes as penalty terms. This redesign effectively resolves the limitations associated with the use of relative proportions in CIoU. The formula for the proposed FIoU loss is defined as follows:
where
and
represent the width and height of the smallest enclosing box that contains both the predicted box and the ground truth box,
and
represent the distance between the center points of the ground truth box and the predicted box, and
and
represent the differences in width and height between the ground truth box and the predicted box. The
,
,
, and
calculation formulas are:
where
and
represent the coordinates of the center point of the ground truth box;
and
represent the coordinates of the center point of the predicted bounding box;
and
represent the width and height of the ground truth bounding box; and
and
represent the width and height of the predicted bounding box.
The proposed FIoU shares the common goal of enhancing bounding box regression with several recent IoU variants, yet it is designed with distinct motivations and formulations tailored for small defect detection. EIoU (Efficient IoU) [
19] decomposes the geometric loss into center distance, width, and height differences using the normalized squared distances
. While effective, its width/height penalty remains a relative measure scaled by the enclosing box dimensions
. In contrast, FIoU directly penalizes the absolute squared differences
, which provides a more direct and sensitive penalty for scale errors of small objects, where absolute pixel deviations are critical. SIoU (Scylla IoU) [
20] introduces an angular cost term to reshape the regression trajectory, prioritizing directionality. FIoU [
21], however, maintains a focus on the fundamental geometric factors (center, width, height) without introducing angular complexity, ensuring stable and interpretable gradients, especially beneficial when dealing with the often near-axis-aligned PCB defects. From a Bayesian perspective, the explicit penalty on absolute width/height differences in FIoU can be interpreted as imposing a prior on the scale uncertainty of the bounding box. This formulation encourages the model to not only match the aspect ratio but also to be confident in the absolute size of the predicted region, thereby providing an implicit measure of localization uncertainty related to object scale—a crucial aspect for reliably assessing small, ambiguous defects.
In summary, the formula for the redesigned bounding box regression loss function, FIoU loss, proposed in this paper, is as follows:
4. Experimental Testing and Result Analysis
The experiments for the defect detection algorithm in this study were conducted on a Windows 10 operating system, where a model based on the improved YOLOv5 defect detection algorithm was implemented and trained. The development and testing were carried out on a computer platform equipped with an AMD 5800X processor (Santa Clara, CA, USA), an NVIDIA Quadro M6000 graphics card, and 32 GB of RAM (Santa Clara, CA, USA). The deep learning environment utilized PyTorch 1.7.1, Python 3.8, and CUDA 11.3. To select the best-performing network model, the dataset was divided into training, validation, and test sets in an 8:1:1 ratio. The resulting sample sizes for the three subsets were 15,796 images, 1975 images, and 1975 images, respectively. The training parameter settings for the network model are provided in
Table 2.
4.1. Construction of the Dataset
The construction of a defect dataset primarily serves the purpose of supporting the defect detection network model. To address the issue of insufficient defect samples, this study enhances the original public dataset by incorporating manually annotated images, thereby increasing the diversity of the dataset. The PCB defect dataset constructed in this work consists of two main sources: (a) public datasets and (b) images acquired using digital imaging devices. Since the PCBs in public datasets typically have a uniform green background, they cannot meet the requirements for detecting defects in PCBs with diverse background colors. Therefore, this study combines defective PCB images collected through flatbed scanning to construct a multi-background-color PCB defect dataset. Due to the scarcity of defective PCBs in practice, the currently collected defect samples are insufficient to meet the demands of detection accuracy and model generalization. To further expand the number of defect samples, this paper employs data augmentation techniques to increase the quantity of defective samples, thereby improving the robustness and generalization ability of the defect detection model.
The constructed multi-background PCB dataset encompasses a wide variety of PCB appearances to ensure robustness and generalizability. The PCBs vary in shape, including rectangular, circular, and irregular layouts. The background colors extend beyond the conventional green to include blue, red, black, and white substrates, simulating real-world manufacturing scenarios. This diversity in shape and appearance helps the model learn invariant features across varying PCB designs, thereby strengthening its applicability in practical industrial inspection systems. Some examples of the dataset are shown in
Figure 8.
Based on the IPC-A-600K standard, this study establishes a defect detection criterion for printed circuit boards (PCBs). The public PCB dataset used is from the Open Intelligent Robotics Laboratory of Peking University, which consists of 1386 images—including 693 original images and another 693 generated by randomly rotating the original images. The construction of a defect dataset aims to support the training of defect detection network models. To address the issue of insufficient defective samples and the limitation of the public dataset (which only contains PCBs with a uniform green background, thus failing to meet the need for detecting defects in PCBs with diverse background colors), this study augments the original public dataset by adding defect samples with varied background colors to enhance sample diversity. A self-built dataset of 709 images was created, resulting in a combined dataset of 1402 images. To further expand the dataset, common data augmentation techniques were applied, including random flipping, random rotation, random brightness adjustment, and random noise injection. After augmentation, the total number of images reached 5120. To adapt the images to the network and minimize information loss during resizing, all augmented images were cropped to a unified size of 1000 × 1000 pixels. The final defect dataset contains 19,746 images.
Table 3 provides a breakdown of the quantity of each type of defect after data augmentation.
4.2. Evaluation Metrics
To objectively evaluate the effectiveness of the improvements in both the original and modified network models, this study employs mean Average Precision (mAP) as the key evaluation metric, which represents the mean of Average Precision (AP) across all categories. The calculation of detection performance is based on a confusion matrix, where True Positives (TP) denote positive samples correctly predicted as positive, False Negatives (FN) indicate positive samples incorrectly predicted as negative, False Positives (FP) refer to negative samples mistakenly predicted as positive, and True Negatives (TN) represent negative samples correctly predicted as negative. AP is defined as the area under the Precision–Recall (PR) curve, with Precision and Recall calculated from the confusion matrix to comprehensively assess the detection accuracy and robustness of the model:
In accordance with the definitions of mAP in COCO and VOC datasets, the specific mAP metric is further categorized into mAP@0.5 and mAP@0.5:0.95. Here, mAP@0.5 represents the average precision calculated at an IoU threshold of 0.5, while mAP@0.5:0.95 denotes the average of AP values computed over multiple IoU thresholds ranging from 0.5 to 0.95 with a step size of 0.05. A higher mAP value indicates better overall performance of the network model and higher accuracy in defect detection.
4.3. CBAM Experiment
To validate the effectiveness of incorporating the CBAM attention mechanism, this study employs heatmaps to visualize and compare the feature representations of both the modified network with CBAM and the original network. The improved architecture integrates the attention mechanism at three specific locations. For analysis, the feature heatmaps from the 17th layer of both networks are extracted and superimposed onto the original image through weighted fusion.
Figure 9 illustrates a comparative visualization of the original image fused with heatmaps from the 17th layer of both the baseline network and the CBAM-enhanced network.
As intuitively observed from
Figure 9, the incorporation of the CBAM attention mechanism into the original network significantly enhances its ability to capture defect location information and increases the model’s focus on defective regions. This effectively demonstrates that, compared to the baseline model, the CBAM-augmented network exhibits substantially improved attention to local defect features while suppressing interference from global non-defective background information. For defect detection tasks involving small targets and complex backgrounds, the enhanced network can more rapidly locate and emphasize defect-related features, thereby further improving detection accuracy.
While the CBAM enhances feature discrimination, it is crucial to quantify its impact on model complexity and inference efficiency for practical deployment. To this end, we measure and compare the key computational metrics—parameters, FLOPs, and inference frames per second (FPS)—for the baseline YOLOv5s model and its variants integrated with different attention mechanisms (CBAM, SE, CA, ECA). The results are summarized in
Table 4. All FPS measurements are conducted on the same NVIDIA Quadro M6000 GPU with a batch size of 1, input size of 640 × 640, and averaged over 100 runs.
To further validate the effectiveness of the CBAM attention mechanism, this study incorporates four different attention mechanisms—CBAM, SE, CA, and ECA—into the original network for training. A comparative analysis of the detection accuracy among these four attention-enhanced variants is conducted based on the experimental results.
Table 4 presents the performance metrics of the original network augmented with each of the four attention mechanisms.
As presented in
Table 4, incorporating the CBAM introduces a modest increase in computational overhead. Compared to the baseline, CBAM adds approximately 1.0% more parameters and 3.2% more FLOPs, resulting in an inference speed of 158 FPS, which represents a 4.2% decrease relative to the baseline’s 165 FPS. In contrast, other attention mechanisms like SE, CA, and ECA incur negligible or zero parameter growth and less than 1% FLOPs increase, with correspondingly smaller impacts on FPS (0.6% to 1.8% reduction).
However, this marginal computational cost is justified by the significant gain in detection accuracy. CBAM achieves the highest mAP@0.5 (87.5%) and mAP@0.5:0.95 (55.1%) among all attention variants, outperforming the second-best (CA) by 1.0% and 0.7%, respectively. The CBAM-enhanced model maintains a high inference speed well above typical real-time requirements (e.g., >30 FPS for most industrial inspection lines), demonstrating an excellent accuracy-efficiency trade-off. This analysis confirms that while CBAM does increase computational load, the resultant performance improvement for small, ambiguous PCB defects substantiates its inclusion, and the model remains highly suitable for deployment in real-time automated optical inspection systems.
4.4. Loss Function Experiment
An effective loss function can accelerate network convergence and improve detection accuracy. To validate the effectiveness of the proposed loss function, this study employs the simulation tool introduced in DIoU to compare the regression loss curves during training for IoU, GIoU, DIoU, CIoU, and the proposed FIoU. The comparison of the loss curves corresponding to these five IoU variants is shown in
Figure 9. As is visually evident from
Figure 10, the proposed FIoU loss exhibits faster convergence speed and lower loss values compared to IoU, GIoU, DIoU, and CIoU.
To further validate the effectiveness of the proposed FIoU loss function, this study compares the regression behavior of the bounding box center point, width, height, and position between the original CIoU Loss used in YOLOv5 and the improved FIoU loss. Specifically, the ground truth bounding box (gt, shown in black) is set as [0, 0, 1, 1], while the predicted bounding box (pred, shown in red) is defined as [10, 10.5, 0.5, 3.5]. The regression changes in the predicted box’s center point, width, height, and position under CIoU loss are illustrated in
Figure 11.
The regression process of the bounding box center point, width, height, and position based on the proposed FIoU loss is illustrated in
Figure 12.
An analysis of the bounding box regression behavior—including center point, width, height, and position—between CIoU and the proposed FIoU reveals clear advantages of the latter. As shown in
Figure 10 and
Figure 11a,b, after 100 training iterations, the distance between the predicted and ground truth center points is significantly larger with CIoU compared to FIoU. Furthermore,
Figure 10 and
Figure 11c,d indicate that FIoU achieves close alignment with the ground truth width and height after approximately 130 iterations. In contrast, CIoU—which focuses on relative aspect ratio rather than absolute size—converges to the correct width-to-height ratio around 160 iterations but fails to match the actual dimensions of the ground truth box. A comprehensive comparison of
Figure 10 and
Figure 11e–j further confirms that the proposed FIoU loss enables faster, more accurate, and more stable regression than the original CIoU loss used in YOLOv5, demonstrating the effectiveness of the FIoU design.
To further substantiate the advantages of the proposed FIoU, we extend our comparison to include two other advanced IoU-based loss functions: EIoU and SIoU. All experiments are conducted under the same settings as in
Section 4.4. The quantitative results of mAP@0.5 and mAP@0.5:0.95 for YOLOv5s equipped with different regression losses are summarized in
Table 5.
The results in
Table 5 demonstrate that FIoU achieves the highest detection accuracy among all compared loss functions. While EIoU and SIoU both outperform the original CIoU, showing the benefits of their respective designs (decoupled dimension loss and angular consideration), FIoU surpasses them by a clear margin (+1.4% and +1.1% in mAP@0.5 over EIoU and SIoU, respectively, and +2.5% and +2.2% in mAP@0.5:0.95). This superior performance validates our design rationale: for the specific challenge of small PCB defect detection, directly and sensitively penalizing absolute scale mismatches (as in FIoU) is more effective than relying on relative dimension penalties (EIoU) or reshaping the regression path with angular costs (SIoU). The significant gain in the stricter mAP@0.5:0.95 metric is particularly noteworthy, indicating that FIoU contributes to more precise localization across varying IoU thresholds, which is essential for high-quality inspection.
4.5. Ablation Experiment
To further validate the effectiveness of the proposed algorithm, this study conducts five ablation experiments based on the original YOLOv5s network using the same dataset, including the original YOLOv5s model, dataset expansion, incorporation of an attention mechanism, addition of a detection head, and replacement of the loss function. A comparative analysis of the ablation results is provided in
Table 6 and
Table 7, while the Precision–Recall (PR) curves for each experiment are illustrated in
Figure 13.
Analysis of the ablation experiments demonstrates the effectiveness of each improvement: Dataset expansion in Experiment 2 increased mAP@0.5 by 4.2%, confirming enhanced generalization and robustness; the attention mechanism in Experiment 3 further improved mAP by 1% and elevated detection accuracy across all defect categories, validating its role in emphasizing target features and suppressing background interference; Experiment 4, with the added small-object detection head, achieved gains of 3.7% in mAP@0.5 and 1.8% in mAP@0.5:0.95, notably improving precision for micro-defects like cracks 1.9%, shorts 5.0%, and burrs 6.6%, proving enhanced utilization of low-level detailed features; finally, replacing CIoU with FIoU in Experiment 5 refined bounding box regression, boosting mAP@0.5 to 93.9% and mAP@0.5:0.95 to 59.6%, with the overall improvement driven significantly by superior detection performance on small targets.
4.6. Comparative Experiments with State-of-the-Art Detectors
To clearly define the operational limits of the proposed MFE-YOLO algorithm for practical industrial applications, we analyze its detection performance on defects at critical geometric dimensions. This analysis addresses the minimum detectable feature sizes that are essential for high-precision PCB inspection. The PCB samples in our constructed dataset primarily represent conventional manufacturing processes, with typical design rules including a minimum conductor clearance of 0.15 mm and a minimum drilled hole diameter of 0.2 mm. These specifications establish the baseline geometric context for our model’s validated performance.
To quantitatively assess the model’s robustness near these manufacturing limits, we conducted a targeted evaluation. We filtered subsets from the test set containing defects whose sizes are at or close to these critical thresholds. Specifically, we identified all “Missing Hole” defect samples with hole diameters
≤ 0.25 mm and all potential “Short” defect regions where the clearance between conductors is
≤0.18 mm. The detection performance of MFE-YOLO on these challenging, critically sized subsets is summarized in
Table 8.
The results in
Table 8 demonstrate that MFE-YOLO maintains high detection accuracy even for defects at the challenging lower bound of typical design rules. For “Missing Hole” defects with diameters down to 0.25 mm, the model achieves an F1-Score of 87.0%. For “Short” defects in regions with clearances as narrow as 0.18 mm—where the thin copper bridge is extremely subtle—the model still attains an F1-Score of 84.4%. This robust performance confirms the efficacy of our improvements, particularly the dedicated small-object detection head and the FIoU loss, in handling the most demanding cases of miniaturization.
These quantitative gains are visually substantiated in
Figure 14, which provides a side-by-side comparison of detection results for critical-size defects. As shown, the original YOLOv5 model (
Figure 14a) produces detection boxes with noticeable localization errors or incomplete coverage for both Missing Hole and Short defects. In contrast, the proposed MFE-YOLO model generates significantly more accurate and complete bounding boxes (highlighted in yellow), aligning closely with the actual defect boundaries. This qualitative improvement directly corresponds to the enhanced precision and recall metrics reported in
Table 8, offering concrete visual evidence of how the integrated improvements—the small-object detection head for capturing fine-grained features and the FIoU loss for refined bounding box regression—collectively elevate the model’s capability in pinpointing subtle, miniaturized defects.
4.7. Comparison with State-of-the-Art Models
To thoroughly evaluate the performance of the proposed MFE-YOLO model and situate its advancements within the current landscape, we conducted a comprehensive comparison against several prominent and recent object detection architectures. These include the latest iteration in the YOLO series, YOLOv8 [
22]; the efficient and scalable EfficientDet-D1 [
23]; and the transformer-based end-to-end detector DETR (with a ResNet-50 backbone) [
18]. All models were trained and evaluated on our constructed multi-background PCB defect dataset under identical conditions: the same train/val/test split, input image size of 640 × 640, and hardware environment (NVIDIA Quadro M6000). Key performance metrics are reported in
Table 9, encompassing detection accuracy (mAP@0.5, mAP@0.5:0.95), model complexity (Parameters, GFLOPs), and inference speed (Frames Per Second, FPS).
As presented in
Table 9, the proposed MFE-YOLO achieves the highest detection accuracy among all compared models, attaining 93.9% mAP@0.5 and 59.6% mAP@0.5:0.95. This represents a significant improvement of +2.7% and +1.8% in mAP@0.5 and mAP@0.5:0.95, respectively, over YOLOv8s. This performance gain underscores the collective efficacy of our contributions—the multi-background dataset mitigating data bias, the CBAM enhancing feature discrimination, the dedicated small-object detection head, and the FIoU loss refining localization—particularly for the challenging task of detecting minuscule defects against complex backgrounds.
In terms of model efficiency, EfficientDet-D1 exhibits the lowest computational footprint (6.6M parameters, 11.8 GFLOPs) and the fastest inference speed (158 FPS), benefiting from its compound scaling strategy. However, this efficiency comes at the cost of detection accuracy, which is notably lower than MFE-YOLO, especially on the stricter mAP@0.5:0.95 metric (−4.3%). The transformer-based DETR model, while elegant for its anchor-free and end-to-end design, demonstrates considerably higher complexity (41.0M params, 86.5 GFLOPs) and the slowest inference speed (45 FPS), making it less suitable for scenarios where real-time processing is often required.
MFE-YOLO strikes a compelling balance between accuracy and efficiency. Although it introduces a moderate increase in parameters and GFLOPs compared to YOLOv8s, its inference speed of 128 FPS demonstrates its practical feasibility. The substantial improvement in detection accuracy, especially for critical small defects, justifies this computational cost, as it directly leads to more reliable detection performance.
4.8. Analysis of Misclassifications and Model Behavior
To gain deeper insight into the failure modes and limitations of the proposed MFE-YOLO model, we conducted a detailed analysis of misclassified samples from the test set. This analysis aims to identify which defect categories are prone to confusion and to understand the model’s behavior under challenging conditions. The confusion matrix for the six defect categories on the test set, using the final MFE-YOLO model from Experiment Five (
Table 6), is presented in
Table 10.
A detailed examination of the confusion matrix
Table 9 reveals insightful patterns regarding the model’s performance and remaining challenges. The defects Missing Hole and Spurious Copper demonstrate the highest correct classification rates of 98.7% and 97.1%, respectively. Their distinct and localized visual signatures—a clear material absence in a defined area and unintended copper residue—allow the model to learn robust and reliable representations. The primary sources of error are concentrated in two specific confusion pairs. The most significant mutual confusion occurs between Spur and Mouse Bite (4.3% and 1.5%, respectively), both representing geometric imperfections along trace edges. This ambiguity, especially in low-resolution or noisy image regions where differentiating a small protrusion from an indentation is difficult, exemplifies a classic case of aleatoric uncertainty arising from inherent visual similarity. An asymmetric confusion is observed between Short and Open Circuit, where Short circuits are misclassified as Open Circuit 3.1% of the time, more frequently than the reverse (1.4%). This suggests the model may be more sensitive to the strong edge features of a broken trace than to the faint, thin bridge characteristic of a short, potentially misinterpreting an extremely faint connection as a break in continuity.
In particularly ambiguous cases, such as with the Spur defect, which has the lowest individual accuracy (90.3%), errors are distributed across several classes (Mouse Bite, Missing Hole, Short). This indicates that small, localized edge anomalies can activate features associated with multiple defect types. While the integrated CBAM attention mechanism is crucial for focusing on the anomalous region, its efficacy can be limited when the salient distinguishing features are excessively subtle, allowing the final classification to be influenced by secondary, shared characteristics. Furthermore, some confusion, notably between Short and Open Circuit, can be exacerbated by poor localization. An imprecise bounding box that fails to fully encapsulate a thin, short bridge may only capture one side, making the region appear as an open circuit. The proposed FIoU loss function addresses this issue by enhancing bounding box regression stability for small, thin objects, thereby helping to reduce this category of localization-induced misclassification, as evidenced by the improved Average Precision for both classes in
Table 7. This fine-grained error analysis confirms that the remaining challenges for MFE-YOLO are semantically meaningful, stemming from genuine visual ambiguities between specific defect pairs. It highlights that future work could focus on developing more discriminative features or loss functions for geometrically similar edge defects and exploring structural reasoning to incorporate connectivity constraints for more reliable distinction between shorts and open circuits.
While a comprehensive per-color quantitative breakdown is not provided in this study, the design of our approach inherently addresses color variability. Firstly, the multi-background dataset explicitly includes PCBs with green, blue, red, black, and white substrates, training the model on a color-diverse prior. Secondly, the integrated CBAM attention mechanism is designed to suppress irrelevant background features (which include color information) and amplify structural and contrast-based defect signatures. The confusion patterns observed in
Table 9 (e.g., Spur vs. Mouse Bite) are primarily related to geometric ambiguity rather than background color. The significant overall performance gain on the mixed-color dataset (
Table 6, Experiment Five) suggests that the model has learned to generalize across the color variations present in the training data. A dedicated analysis separating performance by substrate color remains an interesting direction for future work to further validate color invariance.
4.9. Visualization Experiment
To further demonstrate the effectiveness of the improved network proposed in this study, visual comparisons were conducted from two perspectives. First, to assess the model’s generalization capability, three additional PCB samples featuring novel circuit layouts and distinct backgrounds were examined. Second, to evaluate its robustness against background variations, three PCB samples with identical circuit layouts but different background colors were tested. The detection results from both the original and improved models are presented in
Figure 15.
Figure 15a displays the detection results on PCBs with novel layouts and appearances. When confronted with unseen designs, the original model struggled, resulting in missed detections. In contrast, the improved MFE-YOLO model successfully identified the target defects while maintaining a low false-positive rate. This confirms the model’s strong generalization capability, which is essential for deployment in real-world scenarios with diverse PCB designs.
Figure 15b shows a comparison of detection results on PCBs with identical layouts. It can be observed that the original YOLOv5 model exhibited inconsistent performance: it successfully detected defects on the green background but failed to detect the same defect types on the red and blue backgrounds. Conversely, the improved MFE-YOLO model consistently identified all defects across all three color variations. This indicates that the proposed enhancements—particularly training on the multi-background dataset and the integrated CBAM attention mechanism—effectively suppress color-specific biases, enabling the network to focus on invariant structural defect features and demonstrating excellent color robustness.
In summary, visual evidence from both generalization and controlled scenarios collectively confirms that the proposed MFE-YOLO model significantly improves detection accuracy and effectively reduces the missed detection rate on both unseen PCB layouts and varying background colors. This validates the overall effectiveness and practical utility of our proposed improvements.