A PCB defect detection method for improving a YOLOv12 network architecture

By introducing the SCSA attention mechanism and P2 detection head into the YOLOv12 network, and replacing SiLU with the GeLU activation function, the problem of insufficient identification of minute defects in PCB defect detection by the YOLOv12 model is solved, thereby improving detection accuracy and stability.

CN122434892APending Publication Date: 2026-07-21UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
UNIV OF ELECTRONICS SCI & TECH OF CHINA
Filing Date
2026-04-30
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

The existing YOLOv12 model has insufficient ability to identify small defects in PCB defect detection, does not make full use of shallow features, and has limited detection accuracy in complex backgrounds.

Method used

The SCSA attention mechanism is introduced into the YOLOv12 network, a P2 detector head is added, and the SiLU activation function is replaced with the GeLU activation function to enhance the model's ability to perceive small defect targets and its nonlinear expression ability.

Benefits of technology

It improves the model's ability to detect small defects, reduces the false negative rate, and enhances detection accuracy and stability in complex backgrounds.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122434892A_ABST
    Figure CN122434892A_ABST
Patent Text Reader

Abstract

The application discloses a PCB defect detection method for improving YOLOv12 network architecture and belongs to the technical field of PCB defect detection. In view of the problems that the existing YOLOv12 model has insufficient shallow feature extraction, defect details are easy to be lost and the detection precision is limited under a complex background in PCB micro defect detection, the YOLOv12 network structure is improved. The method comprises the following steps: constructing a PCB defect dataset and completing preprocessing; introducing an SCSA attention mechanism into the YOLOv12 network to enhance the feature extraction capability of key defect areas; additionally adding a P2 detection head to improve the detection effect of micro target defects; replacing the original SiLU activation function with a GeLU activation function to enhance the nonlinear expression capability and training stability of the network; training and detecting PCB defect images by using the improved network model to realize the recognition of multiple types of PCB defects. Compared with the original YOLOv12 model, the improved method can effectively improve the PCB defect detection performance. The method has the advantages of high detection precision, strong micro defect recognition capability and good complex background adaptability and can be applied to automatic quality detection in PCB intelligent manufacturing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of PCB defect detection technology, and in particular to a PCB defect detection method with an improved YOLOv12 network architecture. Background Technology

[0002] Printed Circuit Boards (PCBs) are fundamental components in electronic products, enabling electrical connections between electronic components. Their manufacturing quality directly impacts the performance and reliability of electronic devices. During PCB production, factors such as materials, processes, and environment often result in surface defects like missing holes, rodent bites, open circuits, short circuits, burrs, and stray copper. Failure to detect and address these defects promptly can lead to malfunctions in circuitry, thereby affecting product quality and operational safety.

[0003] Traditional PCB defect detection methods mainly rely on manual visual inspection or image processing-based detection algorithms. Manual visual inspection is inefficient, highly subjective, and unstable, making it difficult to meet the demands of modern electronics manufacturing for high-efficiency and high-precision inspection. While traditional machine vision-based methods have improved detection efficiency to some extent, they often suffer from insufficient robustness and limited feature extraction capabilities in scenarios with complex backgrounds, minute defects, and multiple types of defects coexisting.

[0004] With the development of deep learning technology, object detection methods based on convolutional neural networks have been widely applied in the field of industrial vision inspection. Among them, the YOLO series models have shown good application prospects in PCB defect detection due to their advantages of fast detection speed and end-to-end structure. YOLOv12, as an object detection network, has strong real-time detection capabilities, but it still has certain limitations in PCB scenarios: on the one hand, PCB defects are usually small in size and have fine textures, and the original network does not make sufficient use of shallow fine-grained features, which can easily lead to missed detection of small defects; on the other hand, complex backgrounds and multi-scale targets can also affect the model's effective representation of key defect areas, thus limiting further improvement in detection accuracy.

[0005] Therefore, it is necessary to propose an improved YOLOv12 network architecture method for PCB micro-defect detection tasks to enhance the model's ability to represent defect regions in small targets and complex backgrounds, thereby improving the accuracy and practicality of PCB defect detection. Summary of the Invention

[0006] To address the aforementioned shortcomings of existing technologies, the present invention aims to provide an improved PCB defect detection method based on the YOLOv12 network architecture, thereby solving the technical problems of insufficient ability to identify minute defect targets, inadequate utilization of shallow features, and limited detection accuracy in complex backgrounds in the existing YOLOv12 model during PCB defect detection.

[0007] To achieve the above objectives, the present invention adopts the following technical solution:

[0008] A PCB defect detection method with improved YOLOv12 network architecture includes the following steps:

[0009] S1. Obtain a PCB defect image dataset and preprocess the dataset to construct a data sample set for model training, validation and testing;

[0010] S2, An improved model is built based on the YOLOv12 network. The SCSA attention mechanism is introduced into the YOLOv12 network structure to enhance the network's ability to extract feature information of PCB defect areas.

[0011] S3, A P2 detection head is added to the YOLOv12 network to improve the model's ability to perceive and detect small defect targets;

[0012] S4, replace the SiLU activation function in the YOLOv12 network with the GeLU activation function to improve the nonlinear expression ability and training stability of the network;

[0013] S5. The improved YOLOv12 network is used to train the PCB defect images to obtain the PCB defect detection model.

[0014] S6: Input the PCB image to be detected into the trained PCB defect detection model, and output defect category information and defect location information.

[0015] Furthermore, the PCB defects include, but are not limited to, one or more of the following: missing holes, rodent bites, open circuits, short circuits, burrs, and stray copper.

[0016] Furthermore, the dataset preprocessing includes image annotation, data partitioning, and data organization before model training. Preferably, the dataset can be divided into a training set, a validation set, and a test set; in some embodiments, the training set, validation set, and test set are divided in an 8:1:1 ratio, but are not limited to this ratio.

[0017] Furthermore, the SCSA attention mechanism can be embedded in at least one location within the YOLOv12 network's backbone and / or neck feature fusion network to enhance the model's feature representation capabilities in both spatial and channel dimensions. As a preferred embodiment, the SCSA attention mechanism can be embedded simultaneously at key locations in both the backbone and neck to improve the feature response capability to PCB defect areas.

[0018] Furthermore, the P2 detection head is used to introduce shallow, high-resolution feature information to enhance the model's ability to identify minute defects. Optionally, while adding the P2 detection head, the original detection head structure can also be adaptively adjusted to reduce the impact of redundant scale features on PCB defect detection tasks.

[0019] Furthermore, the GeLU activation function is used to replace the SiLU activation function in the YOLOv12 network, thereby improving the network's ability to fit complex feature distributions and enhancing the model's expressive power. Preferably, the GeLU activation function works in conjunction with the SCSA attention mechanism and the P2 detection head to further improve PCB defect detection performance.

[0020] Furthermore, the model training can be performed iteratively under preset training parameters until the model converges. Optionally, the training parameters include, but are not limited to, the number of training epochs, learning rate, scaling parameters, batch processing parameters, and hardware environment parameters. Beneficial effects

[0021] Compared with the prior art, the present invention has at least the following beneficial effects:

[0022] (1) By introducing the SCSA attention mechanism into the YOLOv12 network, the model’s ability to focus on key areas of PCB defects is enhanced, and the feature extraction effect under complex backgrounds is improved.

[0023] (2) By adding the P2 detection head, shallow high-resolution feature information is introduced, which improves the model's ability to detect small defect targets and reduces the false negative rate;

[0024] (3) By replacing the SiLU activation function with the GeLU activation function, the nonlinear expression ability of the network is enhanced, and the model training stability and detection accuracy are improved;

[0025] (4) By combining and optimizing the network structure, the present invention can better adapt to PCB defect detection tasks, and has the advantages of high detection accuracy, strong ability to identify small defects and good ability to adapt to complex backgrounds. It can be applied to automated quality inspection scenarios in PCB intelligent manufacturing. Attached Figure Description

[0026] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings.

[0027] Figure 1 This is a schematic diagram of the entire process of adding an attention mechanism to the YOLOv12 algorithm for PCB defect detection.

[0028] Figure 2It is a PCB defect dataset that systematically covers six common defect types.

[0029] Figure 3 This is the overall architecture diagram of the SCSA attention mechanism.

[0030] Figure 4 This is a schematic diagram of the network structure with the SCSA attention mechanism added to the backbone of the YOLOv12 model.

[0031] Figure 5 This is a schematic diagram of the network structure with the SCSA attention mechanism added to the Neck of the YOLOv12 model.

[0032] Figure 6 This is a schematic diagram of the network structure with the SCSA attention mechanism added to the Backbone and Neck of the YOLOv12 model. Detailed Implementation

[0033] The technical solution of the present invention will be further described below with reference to the accompanying drawings. It should be noted that the following specific embodiments are only used to explain the present invention and are not intended to limit the scope of protection of the present invention. For those skilled in the art, equivalent substitutions, modifications, or improvements made without departing from the spirit and substance of the present invention should all fall within the scope of protection of the present invention.

[0034] like Figure 1 As shown, this invention provides a PCB defect detection method with an improved YOLOv12 network architecture, comprising: acquiring PCB defect image data and constructing a dataset; constructing an improved PCB defect detection network based on the YOLOv12 target detection network; training the improved PCB defect detection network using the dataset to obtain a trained PCB defect detection model; inputting the PCB image to be detected into the trained PCB defect detection model, and outputting the category information and location information of the PCB defect.

[0035] First, PCB defect image data is acquired, and the images are labeled, organized, and segmented to construct a dataset for training, validation, and testing. For example... Figure 2 As shown, the PCB defects include, but are not limited to, missing vias, rodent bites, open circuits, short circuits, burrs, and stray copper. Preferably, the dataset is divided into a training set, a validation set, and a test set; in some embodiments, the training set, validation set, and test set are divided in an 8:1:1 ratio, but are not limited to this ratio.

[0036] Based on this, an improved model is constructed using the YOLOv12 object detection network. The improvements mainly include: introducing the SCSA attention mechanism into the network, adding a P2 detection head to the detection head structure, and replacing the SiLU activation function with the GeLU activation function.

[0037] like Figure 3 As shown, the SCSA attention mechanism is used to enhance the network's ability to represent the spatial and channel features of key areas of PCB defects, thereby reducing the impact of complex backgrounds and irrelevant textures on the detection results. As a preferred technical solution, the SCSA attention mechanism can be set at at least one location in the Backbone and / or Neck of the YOLOv12 target detection network.

[0038] like Figure 4 As shown, in some implementations, the SCSA attention mechanism is set in the backbone, and a P2 detection head is added to the detection head structure to enhance the response capability of the feature extraction stage to the defect area, while preserving shallow high-resolution detail information.

[0039] like Figure 5 As shown, in some implementations, the SCSA attention mechanism is set in the Neck, and a P2 detection head is added to enhance the ability to characterize defect regions during multi-scale feature fusion.

[0040] like Figure 6 As shown, in some other implementations, the SCSA attention mechanism is set in both the Backbone and Neck, and a P2 detection head is added to jointly improve the detection capability of PCB defect targets during the feature extraction and feature fusion stages.

[0041] Furthermore, the P2 detection head is connected to the shallow feature map to introduce high-resolution feature information and improve the detection capability for minute defects. Since PCB defects are usually small in size and have weak edge details, the addition of the P2 detection head can more effectively preserve shallow detail information and reduce the risk of missing minute defects.

[0042] Furthermore, the SiLU activation function in the convolutional part of the YOLOv12 object detection network is replaced with the GeLU activation function to improve the network's ability to express nonlinear features and its training stability. Preferably, the GeLU activation function replacement is used in conjunction with the SCSA attention mechanism and the P2 detection head to further improve PCB defect detection performance.

[0043] After improving the network structure, the improved network is trained using the constructed dataset. Specifically, the training set is input into the improved PCB defect detection network, and the category and location prediction results are obtained through forward propagation. Then, the model parameters are updated through backpropagation, and the training process is monitored and parameters are adjusted using a validation set. As a preferred technical solution, training is iterated under preset training parameters until the model converges. In some implementations, training is deployed on the AutoDL platform, with 200 training epochs, an initial learning rate of 0.01, and a composite scaling configuration adapted to the YOLOv12 network, where scale=n. The experimental hardware environment consists of an NVIDIA RTX 4090 graphics card and a 16 vCPU Intel Xeon Platinum 8352V processor. It should be noted that the above training parameters and hardware environment are merely examples and do not constitute a limitation of the present invention.

[0044] To verify the effectiveness of the technical solution of this invention, a comparative experiment was conducted on the original YOLOv12 model and different improvement methods using a PCB defect dataset. The evaluation metric was mAP@0.5. Experimental results show that the mAP@0.5 of the original YOLOv12 model is 78.7%. When the SCSA attention mechanism is introduced and a P2 detector head is added, if SCSA is set on the Neck, the mAP@0.5 is 88.2%; if SCSA is set on the Backbone, the mAP@0.5 is 87.9%; if SCSA is set on both the Neck and Backbone, the mAP@0.5 is 88.5%. Based on this, further replacing the SiLU activation function with the GeLU activation function improves the model's mAP@0.5 to 90.2%.

[0045] Table 1. Experimental results of the original YOLOv12 and different improvement methods.

[0046] Original YOLOv12 78.7% SCSA embedded Neck+P2 detection head 88.2% SCSA embedded BackBone+P2 detection head SCSA embedded Neck+BackBone+P2 detection head 87.9%88.5% Replace the SiLu function with the GeLu function. 90.2%

[0047] The experimental results above show that, compared with the original YOLOv12 model, the improved scheme proposed in this invention can significantly improve the PCB defect detection performance. Furthermore, after introducing the SCSA attention mechanism and adding the P2 detection head, the model's ability to detect minute defects is significantly enhanced. Preferably, after further replacing the SiLU activation function with the GeLU activation function, the model's mAP@0.5 reaches 90.2%, indicating that the combined optimization scheme of the SCSA attention mechanism, P2 detection head, and GeLU activation function replacement proposed in this invention can effectively enhance the model's ability to represent minute PCB defects and complex background features, thereby further improving detection accuracy. It should be understood that the above experimental results are from embodiments obtained under specific datasets, training parameters, and experimental environments, and are used to illustrate the effectiveness of the technical solution of this invention, but should not be construed as the sole limitation on the technical effects of this invention.

[0048] After training, the improved YOLOv12 model can be deployed in an automatic PCB surface defect detection task. When an image of a PCB to be detected is input, the model can output defect category, location, and confidence information, enabling rapid identification of multiple types of PCB defects. Optionally, the method of this invention can also be applied to other industrial vision inspection scenarios with requirements for detecting small targets, and is not limited to PCB surface defect detection. As a preferred technical solution, this invention is particularly suitable for automated quality inspection scenarios with a high proportion of small defect targets, complex background textures, and high requirements for detection accuracy and real-time performance.

[0049] All features disclosed in this specification, or steps in all disclosed methods or processes, may be combined in any way, except for mutually exclusive features and / or steps. Any feature disclosed in this specification (including any appended claims and abstract) may be replaced by other equivalent or similar features unless specifically stated otherwise. That is, unless specifically stated otherwise, each feature is merely one example of a series of equivalent or similar features.

[0050] This invention is not limited to the specific embodiments described above. The invention extends to any new feature or combination disclosed in this specification, as well as any new method or process step or combination disclosed herein.

Claims

1. A PCB defect detection method, characterized in that, Includes the following steps: Acquire PCB defect image data, and construct a dataset for model training and defect detection based on the PCB defect image data; A PCB defect detection network is constructed based on the YOLOv12 target detection network, and the YOLOv12 target detection network is improved. The improvement includes: introducing the SCSA attention mechanism into the YOLOv12 target detection network, adding a P2 detection head for small defect detection in the detection head structure, and replacing the SiLU activation function in the YOLOv12 target detection network with the GeLU activation function. The improved PCB defect detection network was trained using the dataset to obtain the trained PCB defect detection model. The PCB image to be detected is input into the trained PCB defect detection model, which outputs the category and location information of the PCB defect.

2. The PCB defect detection method according to claim 1, characterized in that: The SCSA attention mechanism is set in the backbone feature extraction part and / or feature fusion part of the YOLOv12 target detection network to enhance the network's ability to represent spatial feature information and channel feature information of PCB defect areas.

3. The PCB defect detection method according to claim 1, characterized in that: The P2 detection head is connected to the shallow feature map of the network to introduce high-resolution feature information, and together with other scale detection heads, it forms a multi-scale detection structure to improve the detection capability of small-sized PCB defects.

4. The PCB defect detection method according to claim 1, characterized in that: The GeLU activation function is used to replace the SiLU activation function in the YOLOv12 target detection network to improve the network's nonlinear representation of PCB defect features and training stability.

5. The PCB defect detection method according to claim 1, characterized in that: The PCB defects include, but are not limited to, one or more of the following: missing holes, rodent bites, open circuits, short circuits, burrs, and stray copper. The PCB defect detection method is used for the detection of minute defect targets and the detection of PCB surface defects under complex background conditions.