A printed circuit board defect detection method and system based on deep learning
By introducing the NA2C2f and C3K2-SSMSCA modules, the problems of local dependence and insufficient global context capture in the existing technology of printed circuit board defect detection are solved, and higher detection accuracy and feature extraction effect are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGSHU INSTITUTE OF TECHNOLOGY
- Filing Date
- 2026-05-27
- Publication Date
- 2026-06-23
AI Technical Summary
In the detection of defects on printed circuit boards, existing technologies such as YOLOv1 and YOLO-EMAC models cannot effectively capture local dependencies and global context, resulting in poor extraction and localization of small defect features, and they are easily overwhelmed by large targets and background noise.
The system introduces a cross-stage fusion module NA2C2f that integrates neighborhood and region functions, and a spatial channel attention module C3K2-SSMSCA based on a state space model. Combined with multi-head self-attention and adaptive pooling mechanisms, it enhances feature extraction and localization capabilities.
It improves the accuracy of printed circuit board defect detection, can more effectively capture fine-grained features, reduce interference from non-defect targets and background noise, and improve detection results.
Smart Images

Figure CN122265289A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a printed circuit board defect detection method and system based on deep learning, belonging to the technical field of defect detection. Background Art
[0002] Printed circuit board defect detection is beneficial to improving the reliability and lifespan of electronic products, reducing production costs, and is crucial for improving the performance of electronic products. It is an indispensable quality control link in electronic manufacturing. Due to the small size of printed circuit board defects, their characteristic information is relatively limited and has a small granularity, making it easy to be submerged by the characteristics of large targets and background noise. Therefore, printed circuit board defect detection is relatively difficult. Compared with methods such as manual inspection, flying probe testing, and automatic optical inspection, the detection method based on deep learning not only has a low usage cost but also has a high detection accuracy.
[0003] The prior art YOLOv12 uses a regional attention mechanism for feature extraction, but there is a lack of information interaction between different regions, and the coverage range of each region is too large to effectively capture local dependencies, so it cannot effectively encode and locate small printed circuit board defects. In addition, YOLOv12 lacks a spatial and channel weighting mechanism, so it cannot prevent the features of printed circuit board defects from being submerged by the features of large targets and background noise, and cannot effectively retain the features of printed circuit board defects.
[0004] There is also the YOLO-EMAC model that uses a multi-scale window attention mechanism to extract the features of printed circuit board defects. However, different windows are isolated from each other, lacking information interaction and lacking translation equivariance, so it cannot effectively capture local dependencies. Moreover, the window size is relatively limited, unable to effectively capture global context. The channel attention mechanism of YOLO-EMAC uses global pooling to extract channel information, and global pooling will lose a large amount of local details and spatial position information, which is not conducive to the feature extraction and positioning of printed circuit board defects. And the channel attention mechanism of YOLO-EMAC uses one-dimensional convolution to obtain channel weights, and convolution cannot capture long-distance dependencies, cannot model global context, and cannot dynamically adjust parameters according to the input content, resulting in YOLO-EMAC being unable to effectively enhance useful channels and unable to effectively suppress irrelevant channels, thus unable to effectively extract the features of printed circuit board defects. In addition, YOLO-EMAC does not have a spatial attention mechanism and cannot learn how to emphasize and suppress spatial information, so it cannot emphasize meaningful features and suppress meaningless features in the spatial dimension. Summary of the Invention
[0005] To address the shortcomings of the existing technologies, this invention provides a deep learning-based method for detecting defects in printed circuit boards (PCBs), solving the problem of poor feature extraction and localization of PCB defects and improving the accuracy of PCB defect detection. This invention also provides a system for implementing this method.
[0006] The technical solution of this invention is a method for detecting defects in printed circuit boards based on deep learning, comprising the following steps: Industrial cameras are used to capture images of printed circuit boards, and the printed circuit board images are preprocessed. The pre-processed printed circuit board image is input into the pre-trained improved YOLOv12 printed circuit board defect detection model to obtain the detection results, including the type, location and bounding box of each defect, and the detection results are saved.
[0007] The improvements to the YOLOv12 printed circuit board defect detection model are as follows: A new cross-stage fusion module NA2C2f for neighborhood and region integration is introduced into the network architecture of the YOLOv12 model. A new integrated module, C3K2-SSMSCA, based on the state-space model and the C3K2 module, is introduced into the network architecture of the YOLOv12 model.
[0008] Furthermore, the NA2C2f module includes a novel neighborhood and region-based multi-head self-attention module, NAMHSA. The NAMHSA module can effectively capture not only the global context but also local dependencies and maintain translational variability, thereby effectively capturing fine-grained features of printed circuit board defects.
[0009] Furthermore, the NAMHSA module first uses a dynamic Tanh function (DyT) to suppress data extrema; then it executes a neighborhood attention module and a region attention module with bottleneck structures in parallel, and concatenates their results along the channel dimension; then it uses 1×1 convolutions and 3×3 convolutions in parallel to extract features, concatenates their results along the channel dimension, and then uses 1×1 convolutions for feature fusion and channel number adjustment; then it performs residual connections; then it uses the DyT function for processing; then it executes an MLP layer; and finally it performs residual connections again.
[0010] Furthermore, the NA2C2f module first uses the first 1×1 convolution to adjust the number of channels; then it performs feature extraction by stacking NAMHSA modules, with each pair of NAMHSA modules forming a layer; then it concatenates the result of the first 1×1 convolution and the output of each NAMHSA layer in the channel dimension; finally, it uses the second 1×1 convolution to perform feature fusion and adjust the number of channels.
[0011] Furthermore, the C3K2-SSMSCA module includes a novel spatial attention module SSMSA based on a state-space model and a novel channel attention module SSMCA based on a state-space model. The SSMSA module can emphasize meaningful features and suppress meaningless features in the spatial dimension, while the SSMCA module can effectively reduce the loss of local details and spatial location information, effectively enhancing useful channels and suppressing irrelevant channels. Thus, the C3K2-SSMSCA module can effectively reduce interference from non-defect targets and background noise, and can effectively and adaptively extract printed circuit board defect features.
[0012] Furthermore, the SSMSA module first encodes the input feature map using the two-dimensional selective scanning module SS2D; then it encodes using 3×3 convolution and reduces the number of channels to 1 / 16 of the original; then it uses 1×1 convolution to reduce the number of channels to 1; then it uses the sigmoid function to map each pixel to the (0, 1) interval, thereby obtaining the weight of each pixel; finally, it multiplies each pixel of the input feature map by the corresponding weight.
[0013] Furthermore, the SSMCA module first uses the Fast Spatial Pyramid Pooling (SPPF) module for feature extraction; then it uses the Adaptive Average Pooling (APS) module to reduce the spatial dimension; then it flattens the data matrix of each channel into a one-dimensional vector, treats this vector as a word, and uses the number of channels as the number of words, thus forming a word sequence; then it uses the SS2D module to encode this sequence; then it uses a 1×1 convolution to reduce the dimension of each word in the sequence to 1; then it uses the sigmoid function to map each word to the (0, 1) interval, thereby obtaining the weight of each channel of the input feature map; finally, it multiplies each channel of the input feature map by the corresponding weight.
[0014] Furthermore, the fusion process of the C3K2-SSMSCA module for the C3K2 module, SMSA module, and SSMCA module is as follows: First, the C3K2 module is used for encoding; then the SMSA module and SSMCA module are executed in parallel, and their results are concatenated in the channel dimension; then, 3×3 convolution is used for encoding; finally, 1×1 convolution is used to adjust the number of channels.
[0015] Another technical solution of the present invention is: a printed circuit board defect detection system based on deep learning, comprising: The acquisition module is used to acquire images of printed circuit boards; The preprocessing module is used to preprocess the printed circuit board image; The inference module is used to perform defect detection on the pre-processed printed circuit board image using a pre-trained improved YOLOv12 printed circuit board defect detection model, and obtain the detection results, including the type, location and bounding box of each defect. The storage module is used to store the original printed circuit board images and defect detection results.
[0016] Compared with the prior art, the advantages of the technical solution provided by the present invention are as follows: This invention combines neighborhood attention and region attention mechanisms to effectively capture both global context and local dependencies while preserving translational variability. The state-space model-based spatial attention mechanism effectively encodes features at each spatial location, enabling it to effectively learn how to emphasize and suppress spatial information. The channel attention mechanism, combining a state-space model and adaptive pooling, reduces the loss of local details and spatial location information in each channel, effectively encoding features for each channel, thereby enhancing useful channels and suppressing irrelevant channels. Overall, this invention can more effectively capture fine-grained features of printed circuit board defects, thus improving the detection accuracy of printed circuit board defects. Attached Figure Description
[0017] Figure 1 This is a flowchart illustrating a deep learning-based printed circuit board defect detection method as an example.
[0018] Figure 2 The diagram shows the structural framework of the improved YOLOv12 printed circuit board defect detection model for an embodiment.
[0019] Figure 3 This is a schematic diagram of the structure of the cross-stage fusion module NA2C2f for neighborhood and region integration in this embodiment.
[0020] Figure 4 This is a schematic diagram of the NAMHSA multi-head self-attention module based on neighborhood and region, as an example.
[0021] Figure 5 The diagram shows the structure of the C3K2-SSMSCA module, which integrates the spatial channel attention module and the C3K2 module based on the state space model, as an example.
[0022] Figure 6 This is a schematic diagram of the spatial attention module SSMSA based on the state space model, as shown in the embodiment.
[0023] Figure 7 This is a schematic diagram of the channel attention module SSMCA based on the state space model, as shown in the embodiment. Detailed Implementation
[0024] The present invention will be further described below with reference to embodiments: like Figure 1 As shown, the printed circuit board defect detection method based on deep learning involved in this embodiment includes the following steps: Step 1: Use an industrial camera to acquire images of printed circuit boards, preprocess and annotate them to form a dataset for model training, and divide it into training set and validation set.
[0025] Preprocessing includes image scaling, boundary padding, pixel normalization, and data augmentation. Data annotation uses bounding boxes to outline each defect in the image and assigns a category label, providing supervision signals for the model.
[0026] Step 2: Build an improved YOLOv12 printed circuit board defect detection model and train it using the dataset mentioned above.
[0027] The structure of the improved YOLOv12 printed circuit board defect detection model is as follows: Figure 2 As shown, the improvements to the YOLOv12 printed circuit board defect detection model are as follows: A new cross-stage fusion module NA2C2f for neighborhood and region integration is introduced into the network architecture of the YOLOv12 model. A new integrated module, C3K2-SSMSCA, based on the state-space model and the C3K2 module, is introduced into the network architecture of the YOLOv12 model.
[0028] like Figure 3 As shown, the NA2C2f module includes a new neighborhood and region-based multi-head self-attention module NAMHSA.
[0029] like Figure 4 As shown, the NAMHSA module first uses the dynamic Tanh function DyT for processing; then, it executes the bottleneck-structured neighborhood attention module and the area attention module AreaAttention in parallel, and concatenates their results along the channel dimension; then, it uses 1×1 convolution and 3×3 convolution in parallel for feature extraction, concatenates their results along the channel dimension, and then uses 1×1 convolution for feature fusion and channel number adjustment; then, it performs residual connections; then it uses the DyT function for processing; then it executes the MLP layer; and finally, it executes residual connections again. The bottleneck-structured neighborhood attention module first executes a 1×1 convolution to reduce the number of channels to 1 / 4 of the original number, then executes the NeighborhoodAttention module with a kernel size of 5×5, and finally executes a 1×1 convolution to restore the number of channels. The MLP layer executes a 1×1 convolution, a GELU activation function, and a 1×1 convolution in sequence.
[0030] like Figure 3 As shown, the NA2C2f module first uses the first 1×1 convolution to adjust the number of channels; then it performs feature extraction by stacking NAMHSA modules, with each pair of NAMHSA modules forming a layer; then it concatenates the result of the first 1×1 convolution and the output of each NAMHSA layer in the channel dimension; finally, it uses the second 1×1 convolution to perform feature fusion and adjust the number of channels.
[0031] like Figure 5 As shown, the C3K2-SSMSCA module includes a new spatial attention module SSMSA based on a state-space model and a new channel attention module SSMCA based on a state-space model.
[0032] like Figure 6 As shown, the SSMSA module first encodes the input feature map using the two-dimensional selective scanning module SS2D; then it encodes using 3×3 convolution and reduces the number of channels to 1 / 16 of the original; then it uses 1×1 convolution to reduce the number of channels to 1; then it uses the sigmoid function to map each pixel to the (0, 1) interval, thereby obtaining the weight of each pixel; finally, it multiplies each pixel of the input feature map by the corresponding weight.
[0033] like Figure 7 As shown, the SSMCA module first uses the Fast Spatial Pyramid Pooling (SPPF) module for feature extraction; then it uses the Adaptive Average Pooling (APP) module to reduce the spatial dimension to 4×4; then it flattens the data matrix of each channel into a one-dimensional vector, treats this vector as a word, and uses the number of channels as the number of words, thus forming a word sequence; then it uses the SS2D module to encode this sequence; then it uses a 1×1 convolution to reduce the dimension of each word in the sequence to 1; then it uses the sigmoid function to map each word to the (0, 1) interval, thereby obtaining the weight of each channel of the input feature map; finally, it multiplies each channel of the input feature map by the corresponding weight.
[0034] like Figure 5 As shown, the fusion process of the C3K2-SSMSCA module for the C3K2 module, SMSA module, and SSMCA module is as follows: First, the C3K2 module is used for encoding; then the SMSA module and SSMCA module are executed in parallel, and their results are concatenated in the channel dimension; then 3×3 convolution is used for encoding; finally, 1×1 convolution is used to adjust the number of channels.
[0035] Step 3: Deploy the trained model onto the target hardware.
[0036] Step 4: For each new printed circuit board image, preprocessing is performed first, including image scaling, boundary padding, and pixel normalization. Then, the image is input into the trained model for defect detection to obtain the detection results, including the type, location, and bounding box of each defect. The detection results are then saved.
[0037] The implementation system of the above-mentioned deep learning-based printed circuit board defect detection method includes: The acquisition module is used to acquire images of printed circuit boards.
[0038] The preprocessing module is used to preprocess the printed circuit board image.
[0039] The inference module is used to perform defect detection on the pre-processed printed circuit board image using a pre-trained improved YOLOv12 printed circuit board defect detection model, and obtain the detection results, including the type, location and bounding box of each defect.
[0040] The storage module is used to store the original printed circuit board images and defect detection results.
[0041] To verify the advantages of the proposed method, experiments were conducted to compare the accuracy of the proposed method with the YOLOv12 method and the YOLO-EMAC method in printed circuit board defect detection. A miniaturized version of the model was used for each method. The mean accuracy (AP@0.5:0.95) and the mean mean accuracy (mAP@0.5:0.95) at an intersection-to-union (IoU) threshold of 0.5 to 0.95 (step size 0.05) were used as performance metrics. Experiments were conducted on the DeepPCB dataset, with defect types including missing vias, mouse bite marks, open circuits, short circuits, burrs, and excess copper. The DeepPCB dataset contains 1500 images, with 1050 in the training set, 150 in the validation set, and 300 in the test set. The experimental results on the test set were statistically analyzed. For model training, the batch size was set to 32, the number of training epochs to 300, the input image size (imgsz) to 640×640, the optimizer to stochastic gradient descent (SGD), the number of warmup epochs to 5, the image mosaic probability to 0.5, the image flip probability to 0.5, the target confidence threshold (conf) to 0.25, the intersection-over-union (IoU) threshold for non-maximum suppression to 0.45, and the image translation ratio (translate) to 0.2. All other parameters used their default values. For model testing, conf was set to 0.25 and IoU to 0.45. An NVIDIA A800 GPU was used for model training. The experimental results are shown in Table 1. The experimental results show that the method proposed in this invention has higher accuracy in detecting printed circuit board defects than the YOLOv12 method and the YOLO-EMAC method.
[0042]
Claims
1. A method for detecting defects in printed circuit boards based on deep learning, characterized in that, Includes the following steps: Industrial cameras are used to capture images of printed circuit boards, and the printed circuit board images are preprocessed. The pre-processed printed circuit board image is input into the pre-trained improved YOLOv12 printed circuit board defect detection model to obtain the detection results, including the type, location and bounding box of each defect, and the detection results are saved. The improvements to the YOLOv12 printed circuit board defect detection model are as follows: A new cross-stage fusion module NA2C2f for neighborhood and region integration is introduced into the network architecture of the YOLOv12 model. A new integrated module, C3K2-SSMSCA, based on the state-space model and the C3K2 module, is introduced into the network architecture of the YOLOv12 model.
2. The method for detecting defects in printed circuit boards based on deep learning according to claim 1, characterized in that, The NA2C2f module includes a new neighborhood and region-based multi-head self-attention module, NAMHSA.
3. The method for detecting defects in printed circuit boards based on deep learning according to claim 2, characterized in that, The NAMHSA module first uses the dynamic Tanh function DyT for processing; then it executes the neighborhood attention module and the region attention module with bottleneck structure in parallel, and concatenates their results in the channel dimension; then it uses 1×1 convolution and 3×3 convolution in parallel for feature extraction, and concatenates their results in the channel dimension, and then uses 1×1 convolution for feature fusion and channel number adjustment; finally, it performs residual connections. Then use the DyT function to process it; Then the MLP layer is executed; finally, the residual connection is executed.
4. The method for detecting defects in printed circuit boards based on deep learning according to claim 2, characterized in that, The NA2C2f module first uses a first 1×1 convolution to adjust the number of channels; then it extracts features by stacking NAMHSA modules, with each pair of NAMHSA modules forming a layer; then it concatenates the result of the first 1×1 convolution with the output of each NAMHSA layer in the channel dimension; finally, it uses a second 1×1 convolution to perform feature fusion and adjust the number of channels.
5. The method for detecting defects in printed circuit boards based on deep learning according to claim 1, characterized in that, The C3K2-SSMSCA module includes a new spatial attention module SSMSA based on a state-space model and a new channel attention module SSMCA based on a state-space model.
6. The method for detecting defects in printed circuit boards based on deep learning according to claim 5, characterized in that, The SSMSA module first encodes the input feature map using the two-dimensional selective scanning module SS2D; then it encodes it using 3×3 convolution and reduces the number of channels to 1 / 16 of the original; then it uses 1×1 convolution to reduce the number of channels to 1; then it uses the sigmoid function to map each pixel to the (0, 1) interval, thereby obtaining the weight of each pixel; finally, it multiplies each pixel of the input feature map by the corresponding weight.
7. The method for detecting defects in printed circuit boards based on deep learning according to claim 5, characterized in that, The SSMCA module first uses the Fast Spatial Pyramid Pooling (SPPF) module for feature extraction; then it uses the Adaptive Average Pooling (APS) module for dimensionality reduction in the spatial dimension; then it flattens the data matrix of each channel into a one-dimensional vector, treats this vector as a word, and uses the number of channels as the number of words, thus forming a word sequence; then it uses the SS2D module to encode this sequence. Then, a 1×1 convolution is used to reduce the dimension of each word in the sequence to 1; then, the sigmoid function is used to map each word to the (0, 1) interval, thereby obtaining the weight of each channel of the input feature map; finally, each channel of the input feature map is multiplied by the corresponding weight.
8. The method for detecting defects in printed circuit boards based on deep learning according to claim 5, characterized in that, The fusion process of the C3K2-SSMSCA module with the C3K2 module, SSMSA module, and SSMCA module is as follows: First, the C3K2 module is used for encoding; The SSMSA and SSMCA modules are then executed in parallel, and their results are concatenated along the channel dimension. 3×3 convolutions are then used for encoding, and finally 1×1 convolutions are used to adjust the number of channels.
9. A deep learning-based printed circuit board defect detection system, characterized in that, include: The acquisition module is used to acquire images of printed circuit boards; The preprocessing module is used to preprocess the printed circuit board image; The inference module is used to perform defect detection on the pre-processed printed circuit board image using a pre-trained improved YOLOv12 printed circuit board defect detection model, and obtain the detection results, including the type, location and bounding box of each defect. The improvements to the YOLOv12 printed circuit board defect detection model are as follows: A new cross-stage fusion module NA2C2f for neighborhood and region integration is introduced into the network architecture of the YOLOv12 model. A new integrated module, C3K2-SSMSCA, based on the state-space model and the C3K2 module, is introduced into the network architecture of the YOLOv12 model. The storage module is used to store the original printed circuit board images and defect detection results.