PCB surface defect detection method based on improved YOLOv11
By improving the YOLOv11 algorithm, combined with the E-CBAM attention mechanism, CBS, SPP and detection head design, the problem that traditional detection methods are difficult to accurately detect small defects is solved, and efficient and accurate detection of surface defects of PCB boards is achieved, reducing production costs and time.
Patent Information
- Application Number
- CN202510194709.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-10
AI Technical Summary
Traditional manual visual inspection methods have high subjectivity and low efficiency, making it difficult to accurately detect minor defects of PCB boards, such as short circuits, open circuits, rat bites, burrs, fake copper and leaky holes, which can easily lead to false detection and missed inspection, increasing production costs and time.
Based on the improved YOLOv11 algorithm, the PCB board surface defect detection method is used to create defect image data sets, image processing, use the K-means++ algorithm to improve anchor box generation and build an improved YOLOv11 model, and the E-CBAM attention mechanism module, CBS replacement Conv, SPP replacement SPPF, and increase detection head and fusion feature information to improve detection accuracy and efficiency.
It improves the accuracy and efficiency of PCB board surface defect detection, reduces model size and calculation amount, reduces hardware requirements, saves production costs and time, and avoids complex steps of human operation.
Smart Images

Figure CN120125533A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of PCB board detection, and specifically relates to a method for detecting surface defects of PCB boards based on improved YOLOv11. Background Art
[0002] With the continuous development of technology, the electronics industry has entered a period of rapid growth. As an important carrier of electronic components, the quality of PCB boards will directly affect the working efficiency of electronic circuits and also have a great impact on the entire production cycle and service life of products. Therefore, the detection of surface defects of PCB boards has become an inevitable task.
[0003] Traditional detection is carried out by manual visual inspection. Manual visual inspection has high subjectivity and low efficiency, and it is impossible to accurately detect tiny defects such as short circuits, open circuits, mouse bites, burrs, false copper, and leakage holes, which easily leads to misdetection and missed detection events, resulting in a large waste of production costs and time.
[0004] With the development of deep learning technology, the application of deep learning technology in the field of industrial detection has gradually become a hot topic. Compared with traditional detection methods, using deep learning technology for defect detection will undoubtedly greatly improve the detection efficiency and accuracy, avoid the complex steps of manual operation, and reduce production costs.
[0005] Among deep learning algorithm models, traditional algorithm models are large in volume and difficult to deploy, and have low detection accuracy for small targets in complex backgrounds, leaving much room for improvement. Summary of the Invention
[0006] Object of the Invention: The object of the present invention is to provide a method for detecting surface defects of PCB boards based on improved YOLOv11 on the basis of the YOLOv11 algorithm.
[0007] Technical Solution: The method for detecting surface defects of PCB boards based on improved YOLOv11 of the present invention includes the following steps:
[0008] Make a defect image dataset of PCB boards;
[0009] Perform image processing on the dataset to enrich the sample capacity and construct a complete dataset required for model training;
[0010] Use the K-means++ algorithm to improve the generation method of anchor boxes;
[0011] Build an improved YOLOv11 model, and train the improved YOLOv11 model using the complete dataset to obtain the trained improved YOLOv11 model; the improved YOLOv11 model includes: replacing the C3K2 module in the 7th layer of the original Backbone network structure with the E-CBAM attention mechanism module; replacing Conv with CBS and SPPF with SPP in the Backbone network structure; on the basis of the original Neck network, adding new convolutional layers CBS, Concat, and C3K2, and fusing the feature information of the 14th layer and the 25th layer of the network structure as the input feature information of the 26th layer; in the Prediction network structure, adding a detection head Detect;
[0012] Detect and recognize the defect image data of the PCB board based on the trained improved YOLOv11 model.
[0013] Furthermore, the image defects in the PCB board defect image dataset include short circuits, open circuits, mouse bites, burrs, false copper, and leakage holes of the PCB board.
[0014] Furthermore, perform image processing on the collected dataset, including: cropping, translation, changing brightness, adding noise, and rotating the angle.
[0015] Furthermore, the generation method of the anchor box is as follows:
[0016] (1) Randomly select the width and height values of a true box according to the complete dataset category as the first anchor box;
[0017] (2) Calculate the shortest distance between each sample and the current existing clustering center, and calculate the probability of each sample being selected as the clustering center according to the shortest distance, and select the minimum IOU of the true box and the existing anchor box as the next true anchor box;
[0018] (3) Repeat step (2), select n anchor boxes, calculate the width and height of the true box according to different clustering centers to obtain the optimal anchor box, repeat this step until the change range of the width and height drops to the lowest, then obtain the anchor box with the smallest error value.
[0019] Furthermore, the E-CBAM attention mechanism module includes a channel attention module CAM and an improved spatial attention module E-SAM. The input information is first weighted by the channel attention module CAM, and the weighted result is weighted again by the improved spatial attention module E-SAM to obtain the result;
[0020] The improved spatial attention module includes: taking the channel attention feature map information output by the channel attention module CAM module as input data; performing global max pooling and global average pooling based on the channel on the channel attention feature map information, and then performing a concatenation operation on these two results based on the channel; passing through 4 convolutions with a kernel size of 3×3 to reduce the dimension to 1 channel; and then passing through the sigmoid activation function to generate a spatial attention weight matrix; finally, multiplying the spatial attention weight matrix and the channel attention feature map information to obtain the finally generated spatial attention feature map.
[0021] Furthermore, in the Neck network, the feature information of the 5th layer of the network structure is fused with the feature information of the 16th layer as the input information of the 17th layer; the feature information of the 7th layer is fused with the feature information of the 13th layer and then fused with the 19th layer information as the input information of the 20th layer; the output feature of the 11th layer is fused with the output feature of the 22nd layer as the input feature information of the 23rd layer; the output feature of the 14th layer is fused with the output feature of the 25th layer as the input feature information of the 26th layer.
[0022] Furthermore, in the Prediction network structure, a detection head Detect is added, including:
[0023] The output information of the 17th layer of the Neck network structure is input into the first detection head Detect; the output information of the 20th layer is input into the second detection head Detect; the output feature information of the 23rd layer is input into the third detection head Detect; the output feature information of the 26th layer is input into the fourth detection head Detect; the feature information output by the first detection head, the second detection head, the third detection head, and the fourth detection head is fused as the output of the entire improved YOLOv11 model.
[0024] The system corresponding to the method includes:
[0025] A dataset production unit for producing a defect image dataset of PCB boards; and performing image processing on the dataset to enrich the sample capacity and construct a complete dataset required for model training;
[0026] An anchor box generation unit for improving the generation method of anchor boxes using the K-means++ algorithm;
[0027] The model construction and training unit is used to construct an improved YOLOv11 model and train the improved YOLOv11 model with a complete dataset to obtain a trained improved YOLOv11 model. The improved YOLOv11 model includes: replacing the original C3K2 module in the 7th layer with an E-CBAM attention mechanism module in the Backbone network structure; replacing Conv with CBS and SPPF with SPP in the Backbone network structure; based on the original Neck network, adding new convolutional layers CBS, Concat, and C3K2, and fusing the feature information of the 14th layer and the 25th layer of the network structure as the input feature information of the 26th layer; in the Prediction network structure, adding a detection head Detect.
[0028] The detection unit is used to detect and identify the defective image data of the PCB board based on the trained improved YOLOv11 model.
[0029] An electronic device for storing and executing the method includes a memory and a processor, where:
[0030] The memory is used to store a computer program that can run on the processor;
[0031] The processor is used to execute the steps of the PCB board surface defect detection method based on the improved YOLOv11 when running the computer program.
[0032] A storage medium for storing and executing the method, where a computer program is stored on the storage medium, and when the computer program is executed by at least one processor, the steps of the PCB board surface defect detection based on the improved YOLOv11 are realized.
[0033] Beneficial effects: Compared with the prior art, the significant technical effects of the present invention are: (1) By adding an E-CBAM module on the basis of the Backbone network structure, the feature extraction ability of the network is improved while redundant calculations are reduced, and the detection performance of the model is enhanced; (2) After replacing Conv with CBS and SPPF with SPP in the Backbone network, the model size is reduced and the detection efficiency of the model is improved; (3) Adding CBS, Concat, and C3K2 modules in the Neck network, thereby adding a new detection end in the original Prediction network; (4) By adding a new detection end on the basis of the original Prediction network and using the K-means++ algorithm to improve the generation method of anchor boxes, the detection scale is enhanced and the neglect of low-level semantic information is avoided; (5) By optimizing the network structure of YOLOv11, the computational amount of the overall model is reduced, and the requirement of the training model for hardware is also reduced, effectively saving production costs and production efficiency. Brief Description of the Drawings
[0034] Figure 1 is the flow chart of the method of the present invention;
[0035] Figure 2 is the schematic diagram of the E-CBAM structure;
[0036] Figure 3 is the schematic diagram of the improved spatial attention module structure;
[0037] Figure 4 is the schematic diagram of the improved YOLOV11 network structure. Detailed Description of the Invention
[0038] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0039] As Figure 1 shown, based on the YOLOv11 algorithm, the present invention proposes a method for detecting surface defects of PCB boards based on improved YOLOv11, including the following steps:
[0040] S1. Collect defect image data of PCB boards. This data set includes micro-defect images such as short circuits, open circuits, mouse bites, burrs, false copper, and leakage holes of PCB boards.
[0041] S2. Process the collected data set through methods such as cropping, translation, changing brightness, adding noise, rotating angles, etc. to enrich the sample capacity and construct a complete data set required for model training.
[0042] S3. Use the K-means++ algorithm to improve the generation method of anchor boxes and enhance low-level semantic information. Compared with the traditional K-means algorithm, the K-means++ algorithm uses IOU(box, cluster), that is, the ratio of the intersection to the union of the real box and the clustering center, to calculate the distance between the sample and the clustering center, so as to control the error of different-sized bounding boxes. The formula is as follows:
[0043] DiStance(box, cluster) = 1 - IOU(box, cluster)(1)
[0044] Among them, DiStance(box, cluster) is the distance between the sample and the cluster center, box represents the set of true boxes, cluster represents the set of cluster centers, and IOU(box, cluster) represents the ratio of the intersection to the union of the true box and the cluster center. The higher the value of IOU(box, cluster), the closer the true box is to the cluster center, and the higher the correlation. The method for initializing the cluster center is to select k cluster centers one by one, and the sample points farther away from other cluster centers are more likely to be selected as the next cluster center. The calculation formula of the present invention is as follows:
[0045]
[0046] Among them, α is the complete data set, and the shortest distance between each sample and the existing cluster center is represented by D(X), and P(X) is the probability that the sample X becomes the next cluster center. The specific generation method of the anchor box is as follows:
[0047] (1) Randomly select the width and height values of a true box as the first anchor box according to the categories of the provided complete data set. Here, the categories of the complete data set include short circuits, open circuits, mouse bites, burrs, false copper, leakage holes, etc. of the PCB board.
[0048] (2) Obtain the shortest distance between each sample and the existing cluster center according to formula (1), and use this shortest distance value as the input value of D(X) in formula (2) to calculate the probability that each sample is selected as the cluster center, and select the minimum IOU between the true box and the existing anchor box as the next true anchor box.
[0049] (3) Repeat step (2), select n anchor boxes, calculate the width and height of the true box according to different cluster centers to obtain the optimal anchor box, and repeat this step until the change range of the width and height drops to the lowest, then the anchor box with the smallest error value is obtained.
[0050] S4. Construct an improved YOLOv11 model, and use the complete data set to train the improved YOLOv11 model to obtain the trained improved YOLOv11 model.
[0051] The improved YOLOv11 model described in the present invention is improved based on the YOLOv11 algorithm model;
[0052] 1. Incorporate a new attention mechanism E-CBAM into the original network structure, and add new convolutional layers CBS, Concat, and C3K2 to the Neck network to improve the model's network feature extraction ability, reduce redundant calculations, and enhance the detection performance of the algorithm model;
[0053] 2. Optimize the YOLOv11 network structure to reduce the computational complexity of the overall model and also lower the hardware requirements for training the model;
[0054] 3. Improve the defect detection efficiency of the PCB board, improve the defect detection accuracy, and enhance the production quality of the PCB board by adopting the improved YOLOv11 algorithm.
[0055] The specific improvements are as follows:
[0056] (1) In the Backbone network structure, use the E-CBAM attention mechanism module to replace the original C3K2 module in the seventh layer; adopt the measure of fusing the E-CBAM attention mechanism to improve the network feature extraction ability, reduce redundant calculations, and enhance the model detection performance.
[0057] The E-CBAM attention mechanism is an efficient attention mechanism module proposed in the present invention. It is jointly composed of two sub-modules: the channel attention module CAM (Channel Attention Module) and the optimized and improved spatial attention module E-SAM (Efficient Spatial Attention Module). The overall structure is as Figure 2 shown.
[0058] From Figure 2 it can be seen that the input information is first weighted by the channel attention module CAM, and the weighted result is weighted again by the improved spatial attention module E-SAM to obtain the result.
[0059] The structure of the improved spatial attention module is as Figure 3 shown. The main work of the improved spatial attention module includes: using the channel attention feature map information output by the channel attention module CAM as the input data (Channel Input Feature). Perform global maxpooling and global average pooling processing on the channel attention feature map information based on the channel, and then perform a concat operation on these two results based on the channel. After 4 convolutions with a kernel size of 3×3, the dimension is reduced to 1 channel. Then, through the sigmoid activation function, a spatial attention weight matrix is generated. Finally, multiply the spatial attention weight matrix by the input data of the improved spatial attention module, Channel Input feature (i.e., the channel attention feature map information) to obtain the finally generated spatial attention feature map.
[0060] The overall expression formulas are shown in (3) and (4):
[0061]
[0062] Among them, F s is the spatial attention feature map, and M + (F c ) is the spatial attention weight matrix, and F c is the channel attention feature map, σ is the activation function, and f / × / is a convolution operation with a convolution kernel size of 3x3. AugPool is average pooling, and MaxPool is max pooling. is the global average pooling feature, is the global max pooling feature.
[0063] By improving the convolution structure of spatial attention, using consecutive 3×3 convolution kernels reduces the computational complexity of the model based on the original algorithm. Through the multi-layer stacking of small convolution kernels, while deepening the network structure, the network capacity and complexity are enhanced.
[0064] (2) In the Backbone network structure, replace Conv with CBS and SPPF with SPP; reduce the model size and improve the model detection efficiency.
[0065] (3) Based on the original Neck network, the present invention adds new convolution layers CBS, Concat, and C3K2, and fuses the feature information of the 14th layer and the 25th layer of the network structure as the input feature information of the 26th layer.
[0066] In the Neck network, fuse the feature information of the 5th layer and the 16th layer of the network structure as the input information of the 17th layer; fuse the feature information of the 7th layer and the 13th layer and then fuse it with the 19th layer information as the input information of the 20th layer; fuse the output features of the 11th layer and the 22nd layer as the input feature information of the 23rd layer; fuse the output features of the 14th layer and the 25th layer as the input feature information of the 26th layer. Compared with the initial algorithm, the utilization of feature information is further enhanced, and the expression ability of feature information is strengthened.
[0067] (4) In the Prediction network structure, a detection head Detect is added. The output information of the 17th layer of the Neck network structure is input into the first detection head Detect; the output information of the 20th layer is input into the second detection head Detect; the output feature information of the 23rd layer is input into the third detection head Detect; the output feature information of the 26th layer is input into the fourth detection head Detect; the feature information output by the first, second, third, and fourth detection heads is fused as the output of the entire improved YOLOv11 model. Compared with the initial algorithm, the improved YOLOv11 model further enhances the utilization of feature information and strengthens the expression ability of feature information.
[0068] The structure of the improved YOLOv11 model is as Figure 4 shown.
[0069] The improved YOLOv11 model is trained using the complete dataset in step S2 and the anchor boxes generated in step S3 to obtain the trained improved YOLOv11 model.
[0070] S5. Detect and identify the defect image data of the PCB board based on the trained improved YOLOv11 model.
[0071] The present invention also provides a PCB board surface defect detection system based on the improved YOLOv11, including:
[0072] A dataset production unit, which is used to collect the defect image dataset of the PCB board; and by performing image processing on the collected dataset, enriching the sample capacity, and constructing the complete dataset required for model training;
[0073] An anchor box generation unit, which is used to improve the generation method of anchor boxes using the K-means++ algorithm;
[0074] A model construction and training unit, which is used to construct the improved YOLOv11 model and train the improved YOLOv11 model using the complete dataset to obtain the trained improved YOLOv11 model; the improved YOLOv11 model includes: replacing the original C3K2 module in the 7th layer with the E-CBAM attention mechanism module in the Backbone network structure; replacing Conv with CBS and SPPF with SPP in the Backbone network structure; on the basis of the original backbone network, by adding new convolutional layers CBS, Concat, C3K2, and fusing the feature information of the 14th layer and the 25th layer of the network structure as the input feature information of the 26th layer; in the Prediction network structure, a detection head Detect is added;
[0075] The detection unit is used to detect and identify the defective image data of the PCB board based on the trained improved YOLOv11 model.
[0076] The present invention also provides an electronic device for storing and executing the method, including a memory and a processor, wherein:
[0077] The memory is used to store a computer program that can run on the processor;
[0078] The processor is used to execute the steps of the PCB board surface defect detection method based on the improved YOLOv11 when running the computer program.
[0079] The present invention also provides a storage medium for storing and executing the method. A computer program is stored on the storage medium, and when the computer program is executed by at least one processor, the steps of the PCB board surface defect detection based on the improved YOLOv11 are implemented.
[0080] Experimental verification:
[0081] 1. Data augmentation is performed on the collected PCB board picture information by means of cropping, translation, changing brightness, adding noise, rotating the angle, etc. to enrich the sample capacity.
[0082] 2. Improve the original detection box model, and finally use clustering analysis to obtain the optimal 12 anchor box parameters with different proportion sizes to avoid the problem of slow convergence speed.
[0083] 3. Add a detection end. The new detection end further strengthens the extraction of feature information, further fuses the shallow features to obtain richer and more efficient semantic information, and further broadens the receptive field by adding a CBS module to obtain more useful feature information, thereby effectively improving the model detection accuracy.
[0084] 4. Improve the original network structure, fuse the E-CBAM attention mechanism. At the detection end, the feature information of the 5th layer of the network structure is fused with the feature information of the 16th layer as the input information of the 17th layer, the feature information of the 7th layer is fused with the feature information of the 13th layer and fused with the 19th layer information as the input information of the 20th layer, the output feature of the 11th layer is fused with the output feature of the 22nd layer as the input feature information of the 23rd layer, and the output feature of the 14th layer is fused with the output feature of the 25th layer as the input feature information of the 26th layer. Compared with the initial algorithm, the improved algorithm structure further enhances the utilization of feature information and strengthens the expression ability of feature information.
Claims
1. A PCB board surface defect detection method based on improved YOLOv11, characterized in that: The following steps are involved: Create a defect image dataset of PCB boards; Perform image processing on the data set to enrich the sample capacity and build a complete data set required for model training; Use K-means++ algorithm to improve the generation method of anchor boxes; An improved YOLOv11 model is constructed, and the improved YOLOv11 model is trained using a complete data set to obtain a trained improved YOLOv11 model; the improved YOLOv11 model includes: using an E-CBAM attention mechanism module in the Backbone network structure to replace the original C3K2 module in the 7th layer; In the Backbone network structure, Conv is replaced by CBS, and SPPF is replaced by SPP. On the basis of the original Neck network, new convolutional layers CBS, Concat, and C3K2 are added, and the feature information of the 14th layer of the network structure is fused with the feature information of the 25th layer as the input feature information of the 26th layer. In the Prediction network structure, the detection head Detect is added. Based on the trained improved YOLOv11 model, the defective image data of PCB boards is detected and identified.
2. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: The image defects in the defect image dataset of PCB boards include short circuits, open circuits, mouse bites, burrs, false copper and leaks on PCB boards.
3. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: The collected data sets are processed by image processing, including cropping, translation, brightness change, noise addition and rotation angle.
4. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: The anchor box is generated as follows: (1) Randomly select the width and height of a real box as the first anchor box according to the category of the complete dataset; (2) Calculate the shortest distance between each sample and the current cluster center, and calculate the probability of each sample being selected as the cluster center based on the shortest distance, and select the smallest IOU between the true box and the existing anchor box as the next true anchor box; (3) Repeat step (2) and select n anchor frames. Calculate the width and height of the real frame according to the different cluster centers to obtain the optimal anchor frame. Repeat this step until the change in width and height is minimized, and then obtain the anchor frame with the smallest error value.
5. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: The E-CBAM attention mechanism module includes a channel attention module CAM and an improved spatial attention module E-SAM. The input information is first weighted by the channel attention module CAM, and the weighted result is weighted again by the improved spatial attention module E-SAM to obtain the result; The improved spatial attention module includes: taking the channel attention feature map information output by the channel attention module CAM module as input data; The channel attention feature map information is processed by global max pooling and global average pooling based on the channel, and then the two results are concat-operated based on the channel; after 4 convolutions with a kernel size of 3×3, the dimension is reduced to 1 channel; the spatial attention weight matrix is generated by the activation function sigmoid; finally, the spatial attention weight matrix is multiplied by the channel attention feature map information to obtain the final generated spatial attention feature map.
6. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: In the Neck network, the 5th layer feature information of the network structure is fused with the 16th layer feature information as the 17th layer input information; the 7th layer feature information is fused with the 13th layer feature information and the 19th layer information as the 20th layer information input; the output features of the 11th layer are fused with the output features of the 22nd layer as the input feature information of the 23rd layer; the output features of the 14th layer are fused with the output features of the 25th layer as the input feature information of the 26th layer.
7. The PCB surface defect detection method based on improved YOLOv11 according to claim 1, characterized in that: In the Prediction network structure, the detection head Detect is added, including: The output information of the 17th layer of the Neck network structure is input into the first detection head Detect; the output information of the 20th layer is input into the second detection head Detect; the output feature information of the 23rd layer is input into the third detection head Detect; the output feature information of the 26th layer is input into the fourth detection head Detect; the feature information output by the first detection head, the second detection head, the third detection head and the fourth detection head is fused as the output of the entire improved YOLOv11 model.
8. A PCB board surface defect detection system based on improved YOLOv11, characterized in that: include: A data set making unit, used for making a defect image data set of a PCB board; The dataset is processed to enrich the sample capacity and build a complete dataset required for model training. Anchor box generation unit, used to improve the generation method of anchor boxes using K-means++ algorithm; The model building and training unit is used to build an improved YOLOv11 model, and use a complete data set to train the improved YOLOv11 model to obtain a trained improved YOLOv11 model; the improved YOLOv11 model includes: using the E-CBAM attention mechanism module to replace the original C3K2 module of the 7th layer in the Backbone network structure; replacing Conv with CBS and SPPF with SPP in the Backbone network structure; on the basis of the original Neck network, by adding new convolutional layers CBS, Concat, and C3K2, and merging the feature information of the 14th layer of the network structure with the feature information of the 25th layer as the input feature information of the 26th layer; in the Prediction network structure, adding a detection head Detect; The detection unit is used to detect and identify defect image data of the PCB board based on the trained improved YOLOv11 model.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein: A memory for storing computer programs that can be run on the processor; A processor is used to execute the steps of the PCB board surface defect detection method based on improved YOLOv11 as described in any one of claims 1 to 7 when running the computer program.
10. A storage medium, characterized in that: The storage medium stores a computer program, which, when executed by at least one processor, implements the steps of PCB board surface defect detection based on improved YOLOv11 as described in any one of claims 1 to 7.
Citation Information
Cited By
Industrial connector assembly state detection method based on lightweight target detection network
CN121033617A
Novel PCB surface defect detection method
CN121304543A