PCB defect detection method based on improved YOLO algorithm
Patent Information
- Application Number
- CN202610787888.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-03
- Publication Date
- 2026-10-30
AI Technical Summary
[0006]本发明的目的在于解决原始YOLOv11在PCB缺陷检测中存在的微小缺陷特征易丢失、复杂背景判别性差、多尺度特征融合效率低等问题,提供了基于改进的YOLO算法的PCB缺陷检测方法,本发明的方法,通过优化骨干网络特征提取与颈部网络特征融合,构建了高精度、高实时性的检测模型
1、针对PCB微小缺陷易丢失的问题,本发明在骨干网络末端引入扩散模块,该模块融合动态时间混合编码、多阶段轻量级扩散与通道注意力门控,能够强化微小缺陷特征提取与去噪;实验表明,在PCB数据集上,单独加入扩散模块使mAP@0.5从原始YOLOv11的91.4%提升至93.4%,召回率从87.0%提升至91.4%;在NEU-DET数据集上,单独加入扩散模块使mAP@0.5从81.9%提升至82.8%,尤其是对低对比度、细微的裂纹缺陷(crazing)提升幅度达4.2个百分点。
Smart Images

Figure CN123015353A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and industrial defect detection, and more specifically, to a PCB defect detection method based on an improved YOLO algorithm. Background Technology
[0002] Printed circuit boards (PCBs), serving as the support structure for electronic components and the carrier of electrical connections, are a crucial element in industrial defect detection. Common electronic devices, such as home televisions, laptops, and smartphones, rely heavily on PCBs for their core control components. PLC controllers and frequency converters used in industrial production also incorporate PCBs of varying specifications. The quality of PCBs directly determines the performance, reliability, and lifespan of electronic products. However, during product manufacturing, various factors, including material properties, process deviations, equipment precision limitations, and external environmental factors, lead to numerous defects such as short circuits, open circuits, vias, burrs, residual copper, and rodent bites. Even minor defects can cause complete board malfunction or even serious safety accidents.
[0003] Traditional PCB defect inspection primarily relies on physical non-destructive testing (NDT) and traditional machine vision. While physical inspection (magnetic particle, ultrasonic, eddy current, etc.) does not damage the workpiece, it is costly, inefficient, highly dependent on human experience, and poorly adaptable to complex workpieces. Traditional visual inspection, based on algorithms such as threshold segmentation, edge detection, and template matching, suffers from poor robustness to small, low-contrast, and complex background defects, and lacks generalization ability. Traditional machine learning depends on manually designed features such as HOG and SIFT, which involves cumbersome feature engineering and has a relatively low detection limit when faced with diverse defects.
[0004] Deep learning has become a mainstream approach due to its end-to-end automatic feature learning, with the YOLO series widely used in industrial real-time inspection due to its balance of speed and accuracy. However, the original YOLOv11 still has significant shortcomings in PCB defect detection: the backbone network does not sufficiently extract features of small, weakly textured defects, and details are easily lost in high-level features; the neck network uses simple concat splicing and fusion, failing to distinguish the importance of high and low-level features, resulting in low multi-scale fusion efficiency; the model has weak ability to suppress complex background noise, and the detection rate of difficult-to-detect defects is not high. Therefore, there is an urgent need for an improved solution that can significantly improve the detection accuracy of small PCB defects and the ability to discriminate in complex backgrounds while maintaining real-time performance.
[0005] To address these issues, this application proposes a PCB defect detection method based on an improved YOLO algorithm. Summary of the Invention
[0006] The purpose of this invention is to solve the problems of easy loss of small defect features, poor discrimination against complex backgrounds, and low efficiency of multi-scale feature fusion in the original YOLOv11 for PCB defect detection. This invention provides a PCB defect detection method based on an improved YOLO algorithm. The method of this invention constructs a high-precision and high-real-time detection model by optimizing the feature extraction of the backbone network and the feature fusion of the neck network.
[0007] The above-mentioned objective of the present invention is achieved as follows: A PCB defect detection method based on an improved YOLO algorithm is characterized by the following steps: Obtain the PCB image to be inspected; The PCB image is input into the improved YOLOv11 target detection model to obtain defect detection results; The improved YOLOv11 target detection model includes a backbone network, a neck network, and a detection head; The backbone network includes a convolutional layer, a C3k2 module, an SPPF module, a diffusion module, and a C2PSA module connected in sequence. The neck network includes a PANet bidirectional structure, which includes a Concat_BiFPN module. The detection head has a decoupled head structure.
[0008] Furthermore, the diffusion module includes a dynamic time mechanism unit, a multi-stage lightweight diffusion structure unit, and a channel attention gating and residual fusion unit connected in sequence.
[0009] Furthermore, the dynamic time mechanism unit is used to: randomly generate a time step t for each batch of samples during training, map the scalar t to a vector with the same number of input feature channels through a time encoder consisting of a fully connected layer and an activation function, and then multiply this vector with the input feature map.
[0010] Furthermore, the multi-stage lightweight diffusion structure unit adopts a lightweight design that combines depthwise separable convolution and point convolution. The diffusion path is formed by stacking multiple stages to gradually refine and enhance the features.
[0011] Furthermore, the channel attention gating and residual fusion unit is used to: obtain global statistical information for each channel through global average pooling, and then generate a channel weight vector between 0 and 1 through a small neural network with a bottleneck structure and a sigmoid activation function. This weight vector is multiplied with the diffused feature map channel by channel. Then, through a learnable residual weight α, the enhanced features are weighted and fused with the original input features, i.e., the P5 features output by the SPPF module.
[0012] Furthermore, the Concat_BiFPN module is used for: Define a learnable scalar weight W for each of the two input feature maps. 0 and W 1 ; For W 0 and W 1 Perform fast normalization, which involves dividing each weight by the sum of the other two weights and adding a minimum value to obtain the normalized weight. 0 and weight 1 and weight 0 +weight 1 =1; Multiply each input feature map by its corresponding normalized weight; The two weighted feature maps are then stitched together.
[0013] Furthermore, in the improved YOLOv11 object detection model: The backbone network extracts features from the 640×640×3 input image and generates feature maps at four scales: P2 / 4, P3 / 8, P4 / 16, and P5 / 32 in sequence. The SPPF module performs multi-scale pooling on the P5 features output from level 9. The diffusion module enhances the P5 feature output by SPPF; The C2PSA module performs secondary refinement on the P5 features output by the diffusion module, and outputs optimized P5 features.
[0014] Furthermore, in the neck network: The optimized P5 features, after upsampling, are weighted and fused with the P4 features output from backbone network level 9 through the Concat_BiFPN module, and then integrated by the C3k2 module. After upsampling, the integrated features are combined with the P3 features output from layer 7 of the backbone network through a second weighted fusion by the Concat_BiFPN module, and then processed by the C3k2 module to generate Output1.
[0015] Furthermore, in the neck network: Output1, after being downsampled by convolution, is weighted and fused with the integrated features by the Concat_BiFPN module, and then processed by the C3k2 module to generate Output2.
[0016] Furthermore, in the neck network: Output2, after being downsampled by convolution, is concatenated with the optimized P5 features through the Concat module, and then processed by the C3k2 module to generate Output3.
[0017] Compared with the prior art, the present invention has the following beneficial effects: 1. To address the issue of easily missing minute defects in PCBs, this invention introduces a diffusion module at the end of the backbone network. This module integrates dynamic temporal hybrid coding, multi-stage lightweight diffusion, and channel attention gating, which can enhance the extraction and denoising of minute defect features. Experiments show that on the PCB dataset, adding the diffusion module alone improves mAP@0.5 from 91.4% in the original YOLOv11 to 93.4%, and the recall rate from 87.0% to 91.4%. On the NEU-DET dataset, adding the diffusion module alone improves mAP@0.5 from 81.9% to 82.8%, especially for low-contrast, minute crack defects (crazing), the improvement is as high as 4.2 percentage points.
[0018] 2. To address the issue of low efficiency in multi-scale feature fusion, this invention replaces the ordinary Concat concatenation in the neck network with the Concat_BiFPN adaptive weighted fusion module, which achieves adaptive weighted fusion of high and low layer features through learnable weights. On the PCB dataset, adding the Concat_BiFPN module alone improves mAP@0.5 to 92.2%.
[0019] 3. The complete improved model of this invention achieves 94.1% mAP@0.5 on the PCB dataset, an improvement of 2.7 percentage points compared to the original YOLOv11; and 51.3% mAP@0.95, an improvement of 3.5 percentage points; with a precision of 93.5% and a recall of 92.8%, achieving the highest recall while maintaining high precision. On the NEU-DET dataset, mAP@0.5 reaches 83.5%, an improvement of 1.6 percentage points compared to the original YOLOv11. Meanwhile, the FPS of this invention is 86, meeting the industrial real-time detection requirements (≥30 FPS), achieving a balance between high precision and high efficiency.
[0020] 4. The ablation experiments in this invention demonstrate that the diffusion module achieves positive gains on both datasets, especially in terms of its universality in improving recall. The combination strategy of "diffusion module enhanced features + Concat_BiFPN fused features" is robust to various scenarios. Even on the NEU-DET dataset with complex defect features and high background noise, the defects of a single module can be offset by the complementarity of the modules to achieve net gains.
[0021] In summary, this invention significantly improves the detection accuracy and generalization ability of industrial defects such as PCBs and metal surfaces while maintaining the real-time inference speed of industrial applications. It can be widely used for high-precision detection of industrial defects such as PCBs and metal surfaces. Attached Figure Description
[0022] Figure 1 This is an example diagram of a PCB board and defect detection in an embodiment of the present invention; Figure 2 This is a diagram of the YOLOv1 network structure in an embodiment of the present invention; Figure 3 This is a diagram of the YOLOv2 network structure in an embodiment of the present invention; Figure 4 This is a structural diagram of the YOLOv11 module in an embodiment of the present invention; Figure 5 This is a flowchart of the diffusion module of the present invention in an embodiment of the present invention; Figure 6 This is a flowchart of the Concat_BiFPN module of the present invention in an embodiment of the present invention; Figure 7 This is a network structure diagram of the improved algorithm of the present invention in an embodiment of the present invention; Figure 8 This is a diagram illustrating the PCB dataset in an embodiment of the present invention; Figure 9 This is a diagram illustrating the NEU-DET dataset in an embodiment of the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the following description is provided in conjunction with the appendix. Figure 1-9 The present invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0024] This invention provides a PCB defect detection method based on an improved YOLO algorithm, aiming to solve the problems of easy loss of small defect features, poor discrimination against complex backgrounds, and low efficiency of multi-scale feature fusion in the original YOLOv11 PCB defect detection.
[0025] The relevant theories and methods of the present invention will be explained below.
[0026] 1. Convolutional Neural Network (CNN): A type of deep learning architecture specifically designed for processing data with a grid-like topological structure (such as images and videos). Its core idea originates from the simulation of biological visual systems. Through mechanisms such as local connectivity, weight sharing, and spatial downsampling, it can efficiently and automatically learn translation-invariant hierarchical feature representations from raw pixels. A typical CNN consists of alternating stacks of convolutional layers, pooling layers, and fully connected layers. Through end-to-end training, it extracts complex features layer by layer, from low-level edges and textures to high-level semantic concepts.
[0027] The main structure of a convolutional neural network includes: convolutional layers extract local features by sliding convolutional kernels; activation layers commonly use nonlinear functions such as ReLU to achieve nonlinear mapping; pooling layers (such as max pooling and average pooling) are used for feature compression; and fully connected layers are responsible for integrating features and outputting classification or regression results.
[0028] The convolution operation is as follows: Let the input feature map be X, the convolution kernel be W, the bias be b, and the output feature map be Y. Then, the two-dimensional convolution can be represented as: (1) Where f is the activation function, k represents the k-th convolutional kernel, the convolution operation is to perform a weighted summation of each pixel, then feed the result into the activation function, and finally into the pooling layer. The pooling operation is as follows: (2) Where (m,n) represents an input image with m rows and n columns, and the (i,j)th sliding window performs downsampling operations such as taking the maximum value or average value on the feature map output by the convolutional layer. The final output is: (3) (4) (5) 2. Attention Mechanism: Inspired by the human visual system, which subconsciously focuses visual attention on more important parts of a scene while ignoring irrelevant information, the attention mechanism in deep learning learns weights to allow the model to adaptively and selectively process input information.
[0029] Channel attention focuses on which features are more important. It learns the weights of each feature channel, making the model pay more attention to the channels with rich information. The most representative work is the Squeeze-and-Excitation Network (SENet). Its operation consists of two steps: (1) Squeeze: Global average pooling is performed on the feature map of each channel to obtain a channel descriptor, which represents the global distribution of the features of that channel; (2) Excitation: The descriptor is input into a small two-layer fully connected network (usually with dimensionality reduction and restoration), and the weights of each channel (between 0 and 1) are generated by the sigmoid activation function. Finally, the learned weights are multiplied back onto the corresponding channels of the original feature map to complete the relabeling of the features.
[0030] Spatial attention focuses on which locations in an image are more important. It learns features. Figure 2 The weights at each location in the spatial dimension highlight the regions where the target might appear. Typically, a two-dimensional attention map can be obtained by pooling along the channel dimension (such as max pooling and average pooling), or spatial weights can be generated through convolution with small kernels. The Convolutional Block Attention Module (CBAM) is a typical module that sequentially fuses channel attention and spatial attention.
[0031] The introduction of self-attention and the Transformer lies in their ability to calculate the correlation between any two locations in a feature map, thereby capturing long-range dependencies. The core of the Transformer architecture is the multi-head self-attention mechanism. Vision Transformer (ViT) successfully introduced it into image classification tasks. DETR (DEtectionTRansformer) is the first end-to-end object detector entirely based on Transformer. It abandons hand-designed components such as anchor boxes and non-maximum suppression (NMS) and directly outputs detection results through set prediction.
[0032] 3. Feature Pyramid Network Technology: A core challenge in object detection is the scale variation problem. Feature pyramids are a classic and effective paradigm for solving multi-scale detection problems.
[0033] The core idea of classic image pyramids is to construct scaled versions of the input image at different resolutions and then perform detection independently on each scale. This method is computationally very expensive. FPN proposes an efficient, built-in multi-scale feature generation method, which is a top-down structure with lateral connections. FPN first performs a bottom-up forward propagation through the backbone network to obtain feature maps at different stages. Then, starting from the deepest high-semantic feature map C5, it upsamples it (e.g., using nearest neighbor interpolation) to make it the same size as the feature map of the previous stage C4. Next, the upsampled feature map is added element-wise to the C4 feature map, which has undergone channel adjustment via 1×1 convolution. This process is repeated upwards, passing high-level semantic information to low-level high-resolution feature maps, thereby generating a series of feature pyramids that integrate strong semantics and high resolution.
[0034] The Path Aggregation Network (PANet) argues that while the top-down path of the Functional Processing Network (FPN) enhances the semantics of low-level features, it struggles to propagate precise location information from lower levels back to higher levels. Therefore, PANet adds a bottom-up path enhancement layer to the FPN. This bottom-up path starts from the lowest layer P3 of the FPN output, downsamples it using a convolution with a stride of 2, and fuses it with features from the corresponding FPN layer, thus ensuring that precise low-level location information is also passed to higher-level features.
[0035] Bidirectional Feature Pyramid Network (BiFPN) is a further simplification and optimization based on PANet. It first removes nodes with only one input edge, assuming these nodes contribute little to feature fusion. Then, it treats each bidirectional (top-down and bottom-up) path as a repeatable basic unit. Crucially, BiFPN introduces a learnable weight parameter for each input edge. During feature fusion (such as addition or concatenation), it doesn't simply treat feature maps of different resolutions equally, but uses learnable weights to reflect the differences in importance of different input features, and employs a fast normalization fusion method for weighted summation and normalization. This invention's improvement to the Concat operation in the YOLOv11 neck network, namely the Concat_BiFPN module, is inspired by this learnable weight fusion idea of BiFPN.
[0036] 4. YOLO Algorithm: The basic idea of the YOLO algorithm can be summarized as divide and conquer and regression prediction. Taking YOLOv1 as an example, ... Figure 2As shown, it divides the input image into an S×S grid. Each grid cell is responsible for predicting B bounding boxes and their confidence scores. Each bounding box prediction contains 5 values (x, y, w, h, confidence), where (x, y) is the offset of the box center relative to the top-left corner of the grid cell, (w, h) are the proportions of the box's width and height relative to the entire image, and confidence reflects the model's confidence that the box contains the target, defined as... In addition, each grid cell predicts C conditional class probabilities Pr(Class_i | Object). During the detection task, the class conditional probabilities are multiplied by the confidence score of each box to obtain a specific confidence score for each box for each class.
[0037] In existing technologies, the design of the YOLO algorithm has evolved from anchor-box based to anchor-free. YOLOv2 introduced the anchor-box mechanism, such as... Figure 3 As shown, this method borrows from Faster R-CNN, using K-means clustering to pre-define a set of prior boxes with different scales and aspect ratios on the dataset. Each grid point no longer directly predicts the absolute size of the box, but rather predicts the offset relative to the predefined anchor box. The latest versions of YOLOv8, YOLOv10 / v11, etc., have moved to an anchor-free design, directly predicting the distances (i.e., l, t, r, b) from the center point of the target to the four sides of the bounding box.
[0038] The backbone network is responsible for extracting multi-level feature maps from the input image. From the custom network inspired by GoogLeNet in YOLOv1, to DarkNet-19 / 53 based on DarkNet in YOLOv2 / v3, and then to CSPDarknet53 introduced in YOLOv4, the design of the backbone network has increasingly focused on the optimization of gradient flow and computational efficiency. The CSPNet structure splits the feature maps and partially bypasses subsequent layers for fusion, effectively alleviating the problem of gradient repetition during optimization. This idea was inherited and developed by subsequent versions such as YOLOv5, YOLOv8 / v11.
[0039] The neck network, located between the backbone network and the detection head, is responsible for fusing and reprocessing the multi-level features extracted by the backbone network. From the simple FPN structure in YOLOv3, to the PANet structure introduced in YOLOv4, and then to the CSP-PAN structure that combines PANet with the CSP structure in YOLOv5 / v8, the feature fusion capability of the neck network has become increasingly stronger.
[0040] The total loss function of the YOLO algorithm It consists of three parts: (6) For bounding box regression loss CIoU Loss is employed. CIoU, based on DIoU, additionally considers the aspect ratio consistency between the predicted and ground truth bounding boxes, providing a more comprehensive measure of the similarity between the two boxes. For classification loss... Binary cross-entropy loss is employed. For each predicted bounding box, a binary classification (whether it belongs to that class) is performed independently for all categories. For the confidence loss... The binary cross-entropy loss is also used. , , It is a hyperparameter that balances different loss terms, and there are already default optimization settings in YOLOv11.
[0041] The implementation of the present invention will be described in detail below with reference to specific embodiments.
[0042] Example: Improved YOLOv11 Algorithm Design To address the issues of the original YOLOv11 in PCB defect detection, such as the easy loss of small defect features, poor discrimination against complex backgrounds, and low efficiency of multi-scale feature fusion, this embodiment proposes an improved scheme design. By optimizing the feature extraction of the backbone network and the feature fusion of the neck network, a high-precision and high-real-time detection model is constructed.
[0043] 1. YOLOv11 Architecture and Limitations: As a mainstream single-stage object detection model, YOLOv11's core consists of three parts: a backbone network, a neck network, and a detection head. Each module has a clear division of labor and works collaboratively, forming an end-to-end detection pipeline. The YOLOv11 module structure is as follows: Figure 4 As shown.
[0044] In the implementation of this embodiment, the shortcomings of YOLOv11 in PCB defect detection are analyzed as follows: (1) Backbone network: The C3k2 module is insufficient in extracting features of small and low-contrast defects, the SPPF module only performs simple multi-scale fusion, lacks feature enhancement and denoising capabilities, and the high-level feature P5 is weakly represented. (2) Neck network: Ordinary Concat splicing is used, and high and low layer features are equally weighted, which fails to highlight the key role of shallow detail features in small defects, and the multi-scale fusion effect is poor.
[0045] To address these issues, this invention proposes two core improvements: adding a diffusion module at the backbone end; and replacing Concat with a Concat_BiFPN adaptive weighted fusion module. The detection head retains its original decoupling head structure to ensure speed and stability.
[0046] 2. Diffusion module design: such as Figure 5As shown, the diffusion module is placed after SPPF and is used to enhance, denoise and reconstruct high-level P5 features. It consists of three parts: dynamic time mechanism, multi-stage lightweight diffusion structure, channel attention gating and residual fusion.
[0047] 2.1 Dynamic Time Mechanism Design: To address the insufficient adaptability of existing diffusion schemes, this embodiment designs a dynamic time mechanism in the diffusion module. During training, this mechanism randomly generates a time step t (normalized to the [0,1] interval) for each batch of samples. A small time encoder (composed of a fully connected layer and an activation function) maps the scalar t to a vector with the same number of input feature channels. This vector is then multiplied with the input feature map, applying a time-step-dependent, controllable intensity perturbation to the features.
[0048] The main advantage of the dynamic time mechanism lies in effectively compensating for the shortcomings of existing diffusion schemes: First, it injects randomness into the model during the training phase, forcing the network to learn more robust representations of various potential change patterns of features (such as changes in defect shape, contrast, and size). This is very suitable for PCB defects with varying shapes, sizes, and contrasts, solving the problem of poor adaptability of existing diffusion schemes to different defects. Second, as an implicit data augmentation method, it can improve the generalization ability of the model without adding extra training samples, avoiding overfitting of the model on the PCB defect dataset.
[0049] 2.2 Multi-stage Lightweight Diffusion Structure: Existing diffusion enhancement modules mostly adopt ordinary convolutional structures, which have high parameter count and computational cost, easily leading to a decrease in model inference speed and making it difficult to adapt to the real-time detection requirements of industry. This embodiment adopts a lightweight design combining depthwise separable convolution and point convolution: depthwise separable convolution is responsible for efficiently extracting features in the spatial dimension, performing convolution operations only on each channel individually, significantly reducing the number of parameters and computational cost; point convolution is responsible for realizing information interaction and transformation between channels, integrating feature information from different channels, and improving the discriminative power of features.
[0050] This design achieves deep nonlinear transformation of features with extremely low parameter count and computational cost. It avoids a decrease in model inference speed and can form a diffusion path through the stacking of multiple stages, allowing features to be gradually refined and enhanced. This amplifies and highlights subtle defect features while gradually suppressing background noise.
[0051] 2.3 Channel Attention Gating and Residual Fusion: After multi-stage diffusion enhancement, the contribution of each channel to the final PCB defect detection task is different. Some channels contain a large amount of background noise or irrelevant features. If these are not filtered, they will affect the subsequent feature fusion and detection accuracy. The existing diffusion module does not introduce a feature selection mechanism, which cannot distinguish between useful defect features and noise features, and can easily lead to noise being enhanced simultaneously.
[0052] To address this deficiency, this embodiment introduces a channel attention gating mechanism at the end of the module. Global average pooling is used to obtain global statistical information for each channel. This information is then passed through a small neural network with a bottleneck structure (dimensionality reduction -> non-linear activation -> dimensionality increase) and a sigmoid activation function to generate a channel weight vector between 0 and 1. This weight vector is multiplied channel-by-channel with the diffused feature map, adaptively enhancing key feature channels related to defects while suppressing irrelevant or noisy channels, allowing the model to focus on the most discriminative defect features.
[0053] Furthermore, to address issues such as vanishing gradients and training difficulties that may result from excessively deep diffusion modules, this embodiment employs a learnable residual weight α to weightedly fuse the enhanced features with the original input features (P5 features output by the SPPF module). This residual connection ensures smooth gradient flow, prevents training difficulties caused by excessive module depth, and allows the network to adaptively determine the degree of fusion: if the diffusion enhancement effect is good, the network automatically increases the weight of the enhanced features; if the diffusion enhancement introduces noise, it increases the weight of the original features, further improving the stability and adaptability of the module.
[0054] 3. Improved Bidirectional Feature Pyramid Network: Drawing inspiration from BiFPN, this embodiment replaces traditional feature concatenation with learnable weights + fast normalization fusion. Its specific implementation is as follows... Figure 6 As shown.
[0055] The Concat_BiFPN module works by defining a learnable scalar weight for each of the two input feature maps during initialization. and During forward propagation, these two weights are quickly normalized by dividing each weight by the sum of the two weights (with a minimum value added to prevent division by zero). This results in normalized weights. and The sum of these values is 1, and all are positive. Then, each input feature map is multiplied by its corresponding normalized weight, and finally, they are concatenated to complete the fusion of multi-scale features.
[0056] The advantages of the Concat_BiFPN module are: it solves the core shortcomings of the original Concat operation and makes up for the defects of the existing weighted fusion scheme. Specifically, it is reflected in three aspects: (1) The network can automatically learn the optimal contribution ratio of feature maps of different resolutions during fusion through gradient descent. For example, in the early stage of network training, the weights of shallow and deep features may be similar. As training progresses, the network will automatically learn to give higher weights to shallow features when fusion, so as to better capture the details of small defects. When fusion of high-level features, the weights are appropriately reduced to reduce the interference of redundant information. (2) The normalization operation ensures that the weights will not grow indefinitely, making the training process more stable and avoiding the model non-convergence problem caused by uncontrolled weights in the existing weighted scheme. (3) The number of parameters added is negligible (only 2 scalars), and hardly introduces any additional computational burden. Without affecting the model inference speed, it achieves a significant improvement in feature fusion effect.
[0057] 4. The complete network structure of the improved YOLOv11 algorithm: as follows Figure 7 As shown, the overall process of the improved model is as follows.
[0058] (1) Backbone Network (Layers 1-12): The backbone network is responsible for extracting multi-scale features from the input PCB image of 640×640×3. The core improvements are concentrated in layers 10-12. Layers 1-9 follow the original YOLOv11 structure, and downsampling and feature transformation are completed through convolutional layers and C3k2 modules to generate feature maps of four scales: P2 / 4 (160×160), P3 / 8 (80×80), P4 / 16 (40×40), and P5 / 32 (20×20). The P5 features output from layer 9 are multi-scale pooled and receptive field expanded by the SPPF module in layer 10. The diffusion module in layer 11 performs depth enhancement on the P5 features output from SPPF. Through dynamic temporal mechanism, multi-stage lightweight convolution and channel attention gating, it amplifies small defect features and suppresses background noise, solving the problems of low signal-to-noise ratio and insufficient defect representation of P5 features. The level 12 C2PSA module further refines the diffusion-enhanced P5 features. By integrating a lightweight attention mechanism, it further focuses on defect-related features and filters background interference, ultimately outputting optimized P5 features, providing high-quality input for multi-scale fusion of the neck network.
[0059] (2) Neck Network (Levels 13-24): The neck network is based on the PANet bidirectional structure. The core improvement is to replace all Concat operations with Concat_BiFPN modules (Levels 14, 17, 20) to achieve adaptive weighted fusion of multi-scale features.
[0060] The optimized P5 features output from layer 12 are upsampled in layer 13 and then weighted and fused with the P4 features output from layer 9 of the backbone network via the Concat_BiFPN module in layer 14. These fused features are then integrated via the C3k2 module in layer 15. The fused features are upsampled in layer 16 and then weighted and fused again with the P3 features output from layer 7 of the backbone network via the Concat_BiFPN module in layer 17. After processing by the C3k2 module in layer 18, a high-resolution feature map, Output1 (80×80), is generated for small to medium-sized defect detection.
[0061] Output1 is downsampled by Conv at level 19 and fused with the P4 output at level 15. The fused feature is then weighted by the Concat_BiFPN module at level 20 and processed by the C3k2 module at level 21 to generate Output2 (40×40), which is used for medium-sized defect detection.
[0062] Output2, after being downsampled by Conv at level 22, is combined with the optimized P5 features output from level 12 through the Concat module at level 23 (original structure, adapted for large-scale feature fusion). After being processed by the C3k2 module at level 24, Output3 (20×20) is generated for large-size defect detection.
[0063] (3) Detection Head: The YOLOv11 standard decoupled head structure is adopted. Defect classification and bounding box regression are completed on the feature maps of three scales: Output1, Output2 and Output3, respectively, to achieve full-scale accurate detection of small, medium and large-sized defects of PCB, while retaining the real-time reasoning capability of the model.
[0064] The following is an analysis of the experiments and results of the above embodiments of the present invention. 1. Dataset Introduction: The PCB Defect Dataset is a publicly available dataset widely used in defect detection performance evaluation. For example... Figure 8 As shown, this dataset contains 1386 high-resolution PCB images captured by an industrial camera, exhibiting high image quality and clear backgrounds. The dataset labels six common PCB defect types: missing holes, mouse bites, short circuits, spurs, copper residue, and open circuits. These defects exhibit diversity in scale, shape, and contrast, demonstrating good representativeness. For rigorous evaluation, this embodiment randomly divides the dataset into training, validation, and test sets in an 8:1:1 ratio, ensuring a roughly balanced distribution of each defect type across the three sets during the partitioning process.
[0065] like Figure 9 As shown, to verify the generalization ability of the proposed method, this embodiment uses the NEU-DET metal surface defect dataset. This dataset contains 1800 grayscale images of hot-rolled steel strip surfaces, including six types of defects: cracks, inclusions, patches, pitted surfaces, rolled-in scale, and scratches. The dataset is randomly divided into training, validation, and test sets in an 8:1:1 ratio. Although this dataset belongs to a different domain than PCB, its defects also share characteristics such as small size and low contrast, making it suitable for cross-domain performance evaluation.
[0066] 2. Experimental environment configuration: The experiment in this embodiment is conducted in the following hardware and software environment.
[0067] (1) Hardware environment: The GPU is an NVIDIA GeForce RTX 4090 (24GB GDDR6X video memory) for fast training and inference of the model; the CPU is an Intel Core i9-13900K (24 cores and 32 threads) for data loading and preprocessing; the memory is 64GB DDR5 RAM to ensure the smoothness of large-scale data batch processing; the storage is a 2TB NVMe SSD for fast reading and writing of large datasets and model files.
[0068] (2) Software environment: Linux operating system, PyTorch 2.0.1 + CUDA 11.8 + cuDNN 8.6.0, using GPU for accelerated computing; Python 3.8.18, key libraries include OpenCV 4.7.0 (image processing), NumPy, SciPy, Matplotlib (data analysis and visualization) and Ultralytics YOLO (lightweight version, baseline model).
[0069] (3) Training parameters: The input size was uniformly adjusted to 640×640 pixels; the batch size was set to 16; the optimizer used stochastic gradient descent (SGD), the momentum was 0.937, and the weight decay was 0.0005 to suppress overfitting; the learning rate was set to 0.01; a total of 150 epochs were trained to ensure that the model converged fully; data augmentation was enabled with Mosaic enhancement, random horizontal flipping, random scaling (scale range 0.5-1.5), and color space perturbation (hue, saturation, and brightness adjustment).
[0070] 3. Analysis of PCB defect detection results: The detailed performance comparison results of different target detection models on the PCB defect test set are shown in Table 1.
[0071] Table 1 Comparison of different methods on the PCB dataset
[0072] Based on the above results, the following conclusions can be drawn: The performance of each model in PCB defect detection tasks varies significantly, and the method of this invention shows a clear advantage in key indicators. The mAP@0.5 index of this invention reaches 94.1%, significantly higher than other comparative models, improving by 2.7 percentage points compared to the second-best YOLOv11, and by 56.5 percentage points compared to the basic model SSD. The mAP@0.95 index of this invention is 51.3%, also leading all comparative models, and improving by 3.5 percentage points compared to YOLOv11 (47.8%). The method of this invention achieves a precision of 93.5% and a recall of 92.8%, achieving the highest recall while maintaining high precision. Although the parameter count (64.06M) and GFLOPS (201.6) of this invention are higher than those of the lightweight YOLO series models, its FPS (86) still meets the industrial real-time detection requirements (≥30 FPS). Compared to the two-stage model FastR-CNN, the method of this invention achieves significantly higher precision while maintaining a similar level of FPS.
[0073] The advantage of this invention's method lies in the fact that, across all models, the AP for the missing_hole category remains above 0.92, while the AP for categories such as mouse_bite and spur is lower in some models (e.g., mouse_bite AP is only 0.214 in the SSD model). In this invention's method, the AP for each defect category is at a high level: missing_hole 0.994, mouse_bite 0.929, open_circuit 0.895, short 0.967, spur 0.915, and spurious_copper 0.943. Looking at the all-class curves for each model, the mAP@0.5 of this invention's method is 0.941, the highest among all models. The PR curve of this invention's method maintains a high precision (Precision > 0.8) even in the high recall range (Recall > 0.8), and is smoother overall.
[0074] To further analyze the model performance, the detection results of the baseline model and the method of this invention for each defect category in the PCB dataset are shown in Table 2.
[0075] Table 2 Performance comparison between baseline methods and the proposed method
[0076] The above analysis shows that the diffusion module significantly improves most defect categories, especially for defects with complex shapes and indistinct features such as "mouse_bite" and "spur", with improvements of 8.9% and 6.8% respectively.
[0077] 4. NEU-DET Defect Detection Result Analysis: The detailed performance comparison results of different target detection models on the NEU-DET defect test set are shown in Table 3.
[0078] Table 3 Comparison of different methods on the NEU-DET dataset
[0079] The above analysis shows that on the NEU-DET dataset, the method of this invention achieves an mAP@0.5 of 83.5%, which is 1.6 percentage points higher than YOLOv11. The precision and recall are 82.4% and 73.5%, respectively. The FPS reaches 86, meeting the requirements for real-time industrial detection.
[0080] The method of this invention achieves balanced and excellent performance across various defects, with crazing at 0.646, inclusion at 0.885, patches at 0.943, pitted surface at 0.879, rolled-in scale at 0.759, and scrapes at 0.899. The method of this invention achieves an mAP@0.5 of 0.835 across all classes, significantly higher than other comparative models.
[0081] To analyze the model performance in more depth, this embodiment provides a detailed statistical analysis of the detection results for each defect category in the NEU-DET dataset, as shown in Table 4.
[0082] Table 4 Performance comparison between baseline methods and the proposed method
[0083] The above analysis shows that on the NEU-DET dataset, the diffusion module provides a stable improvement for most categories, especially for low-contrast, subtle defects such as "crazing" (+4.2%).
[0084] 5. Ablation Experiment: In order to verify the independent contribution of the diffusion module, an ablation experiment was designed in this embodiment, as shown in Table 5.
[0085] Table 5 Ablation experiments for testing the performance of each module
[0086] The above analysis leads to the following conclusions: The diffusion module is the core incremental module, achieving positive gains on both datasets (PCB +2.0%, NEU-DET +0.9%), especially demonstrating universality in improving recall; Concat_BiFPN has strong scenario adaptability, showing only a small gain on PCB and negligible improvement on NEU-DET. The method of this invention is optimal on both datasets, proving that the combined strategy of "diffusion module feature enhancement + Concat_BiFPN feature fusion" possesses scenario robustness.
[0087] In summary, the module gain is more significant under the PCB dataset due to its regular defect features and simple background; however, the module gain is limited under the NEU-DET dataset due to its complex defect features and high background noise. Although the diffusion module proposed in this invention can maintain real-time detection speed on high-performance hardware, it achieves a good balance between performance and efficiency.
[0088] As demonstrated by the above embodiments of the present invention, this invention addresses the problems of easy loss of small target features, large interference from complex backgrounds, and poor multi-scale fusion performance in PCB defect detection. Based on YOLOv11, a diffusion module is added to the end of the backbone network. This module integrates dynamic temporal hybrid coding, multi-stage lightweight diffusion, and channel attention gating to enhance the extraction and denoising of small defect features. The ordinary splicing of the neck network is replaced with Concat_BiFPN adaptive weighted fusion, which uses learnable weights to achieve adaptive weighted fusion of high and low-level features, thus improving the accuracy of multi-scale defect detection. Experiments on the PCB and NEU-DET datasets show that the improved model achieves mAP@0.5 of 94.1% and 83.5%, respectively, representing improvements of 2.7 and 1.6 percentage points compared to the original model, while maintaining industrial-grade real-time inference speed, meeting the requirements of high-precision and high-efficiency industrial defect detection.
[0089] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A PCB defect detection method based on an improved YOLO algorithm, characterized in that, Includes the following steps: Obtain the PCB image to be inspected; The PCB image is input into the improved YOLOv11 target detection model to obtain defect detection results; The improved YOLOv11 target detection model includes a backbone network, a neck network, and a detection head; The backbone network includes a convolutional layer, a C3k2 module, an SPPF module, a diffusion module, and a C2PSA module connected in sequence. The neck network includes a PANet bidirectional structure, which includes a Concat_BiFPN module. The detection head has a decoupled head structure.
2. The method according to claim 1, characterized in that, The diffusion module includes a dynamic time mechanism unit, a multi-stage lightweight diffusion structure unit, and a channel attention gating and residual fusion unit connected in sequence.
3. The method according to claim 2, characterized in that, The dynamic time mechanism unit is used to: randomly generate a time step t for each batch of samples during training, map the scalar t into a vector with the same number of input feature channels through a time encoder consisting of a fully connected layer and an activation function, and then multiply this vector with the input feature map.
4. The method according to claim 2, characterized in that, The multi-stage lightweight diffusion structure unit adopts a lightweight design that combines depthwise separable convolution and point convolution. It forms a diffusion path by stacking multiple stages to gradually refine and enhance features.
5. The method according to claim 2, characterized in that, The channel attention gating and residual fusion unit is used to: obtain global statistical information of each channel through global average pooling, and then generate a channel weight vector between 0 and 1 through a small neural network with a bottleneck structure and a sigmoid activation function. This weight vector is multiplied with the diffused feature map channel by channel. Then, the enhanced features are weighted and fused with the original input features, i.e., the P5 features output by the SPPF module, through a learnable residual weight α.
6. The method according to claim 1, characterized in that, The Concat_BiFPN module is used for: Define a learnable scalar weight W for each of the two input feature maps. 0 and W 1 ; For W 0 and W 1 Perform fast normalization, which involves dividing each weight by the sum of the other two weights and adding a minimum value to obtain the normalized weight. 0 and weight 1 and weight 0 +weight 1 =1; Multiply each input feature map by its corresponding normalized weight; The two weighted feature maps are then stitched together.
7. The method according to claim 1, characterized in that, In the improved YOLOv11 object detection model: The backbone network extracts features from the 640×640×3 input image and generates feature maps at four scales: P2 / 4, P3 / 8, P4 / 16, and P5 / 32 in sequence. The SPPF module performs multi-scale pooling on the P5 features output from level 9. The diffusion module enhances the P5 feature output by SPPF; The C2PSA module performs secondary refinement on the P5 features output by the diffusion module, and outputs optimized P5 features.
8. The method according to claim 7, characterized in that, In the neck network: The optimized P5 features, after upsampling, are weighted and fused with the P4 features output from backbone network level 9 through the Concat_BiFPN module, and then integrated by the C3k2 module. After upsampling, the integrated features are combined with the P3 features output from layer 7 of the backbone network through a second weighted fusion by the Concat_BiFPN module, and then processed by the C3k2 module to generate Output1.
9. The method according to claim 8, characterized in that, In the neck network: Output1, after being downsampled by convolution, is weighted and fused with the integrated features by the Concat_BiFPN module, and then processed by the C3k2 module to generate Output2.
10. The method according to claim 9, characterized in that, In the neck network: Output2, after being downsampled by convolution, is concatenated with the optimized P5 features through the Concat module, and then processed by the C3k2 module to generate Output3.
