PCB defect detection method and system based on improved Yolov8 model and storage medium

By improving the Yolov8 model, including deleting the P5 large object detection layer, adding the P2 small object detection layer and edge enhancement module, replacing the C2F module with CODF module, and using the SIOU loss function, the existing PCB defect detection method has solved the low detection accuracy of the existing PCB defect detection method. and slow speed problems achieve more efficient and accurate defect detection.

CN119399115APending Publication Date: 2025-02-07GUANGDONG UNIV OF TECH +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411370503.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

The existing PCB defect detection methods based on deep learning have problems such as low detection accuracy, large model size, and slow detection speed, which are difficult to meet the efficient and accurate detection standards of modern industries.

Method used

By improving the Yolov8 model, it includes deleting the P5 large object detection layer in the backbone network and the head network, adding the P2 small object detection layer and edge enhancement module, replacing the C2F module in the neck network as a CODF module, and losing CIOU The function is replaced by the SIOU loss function.

Benefits of technology

It improves the accuracy and speed of PCB defect detection, enhances the model's feature extraction ability for small targets and complex backgrounds, and improves the detection accuracy and convergence speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119399115A_ABST
    Figure CN119399115A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of PCB defect detection, and discloses a PCB defect detection method and system based on an improved Yolov8 model and a storage medium, and the method comprises the steps: obtaining a PCB defect data set, carrying out the preprocessing of the PCB defect data set, and dividing the preprocessed PCB defect data set into a training set and a test set according to a proportion; constructing a defect detection model based on the improved Yolov8; training the defect detection model by using the training set to obtain a trained defect detection model, and testing the performance of the trained defect detection model by using the test set; and inputting a to-be-detected PCB image into the trained defect detection model to obtain a detection result. According to the method, the Yolov8 model is improved, so that the PCB defect detection precision and the PCB defect detection speed can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of PCB defect detection, and in particular to a PCB defect detection method, system and storage medium based on an improved Yolov8 model. Background Art

[0002] Printed Circuit Board (PCB) is an important electronic component and the core carrier for interconnecting electronic components. During the manufacturing process, various process steps such as negligence in the wiring stage, poor welding and improper etching solution ratio may cause surface defects of printed circuit boards. Among them, the most common types of defects such as short circuit, open circuit, rat bite, open circuit, missing hole and excess copper will affect the performance and stability of electronic products, and may even cause safety hazards. In addition, with the continuous improvement of market demand and modern process manufacturing level, PCB is constantly developing in the direction of lightness, thinness and high density. Therefore, quality control inspection of printed circuit boards is an important guarantee for improving the performance, reliability, safety and economic benefits of electronic equipment.

[0003] Research on PCB defect detection has been carried out for many years. In the past, people used inefficient traditional contact detection methods, such as manual visual inspection and electrical inspection, which are difficult to meet the current manufacturing standards of modern industry. With the development of computer vision technology, many researchers have applied machine vision methods to PCB defect detection. At present, PCB defect detection mainly uses automatic optical inspection (AOI) equipment, which is embedded with machine vision methods such as image registration. However, it has obvious limitations in terms of computational complexity, sensitivity to image changes, and feature extraction accuracy. In practical applications, various factors need to be weighed, which makes it increasingly difficult to adapt to efficient and accurate modern industrial inspection standards. In recent years, with the rapid development of deep learning technology, some deep learning-based detection models have been widely used in industrial product surface defect detection tasks, such as Faster RCNN and YOLO. By training a large number of PCB defect images, it can automatically mine and learn the feature representation of defects, and then automatically identify various types of PCB defects. At present, the PCB surface defect detection method based on deep learning has made some progress, but it still has many shortcomings, such as low detection accuracy, large model size, and slow detection speed. Summary of the invention

[0004] The purpose of the present invention is to overcome the problems existing in the prior art and provide a PCB defect detection method, system and storage medium based on an improved Yolov8 model. The present invention can improve the PCB defect detection accuracy and detection speed.

[0005] In a first aspect, the present invention provides a PCB defect detection method based on an improved Yolov8 model, comprising: Acquire a PCB defect data set, preprocess the PCB defect data set, and divide the preprocessed PCB defect data set into a training set and a test set in proportion; Build a defect detection model based on improved Yolov8; Using the training set to train the defect detection model to obtain a trained defect detection model, and using the test set to test the performance of the trained defect detection model; The PCB image to be inspected is input into the trained defect detection model to obtain the inspection result.

[0006] Furthermore, the preprocessing is random rotation, random brightness change and / or Gaussian blur, and the ratio is .

[0007] Furthermore, the defect detection model is constructed based on the improved Yolov8, wherein the improvement of the Yolov8 model specifically includes: deleting the P5 large target detection layer in the backbone network and the head network, adding a first module in the head network, and the first module is used to perceive small targets; adding a second module between the backbone network and the head network, and the second module is used to perform edge texture detail enhancement processing on the feature map extracted by the backbone network, and the second module includes at least two; using a third module to replace the C2F module in the neck network, and the third module is used to enhance the feature extraction capability of the neck network; replacing the CIOU loss function with the SIOU loss function.

[0008] Furthermore, the first module is a P2 small target detection layer; the second module is an edge enhancement module, which is based on central differential convolution; the third module is a CODF module, which is a fusion of a C2F module and a full-dimensional dynamic convolution.

[0009] Furthermore, the edge enhancement module includes a first branch, a second branch and a third branch in parallel, wherein the first branch includes a The convolution kernel and a The second branch consists of a central difference convolution kernel. One convolution kernel The third branch includes an operator for edge detection, a convolution kernel and a residual structure, the residual structure is the input of the third branch and the The convolution kernel outputs are connected and fused; after the input feature map is processed by the three branches, the processing results corresponding to each branch are fused and input into a A convolution kernel is used to obtain a convolution result, which is the input of the neck network.

[0010] Furthermore, the operator for edge detection is Operator.

[0011] Furthermore, the SIOU loss function is as follows:

[0012] in, is the distance loss, is shape loss, distance loss The calculation method is as follows:

[0013] Shape loss The calculation method is as follows:

[0014] in, , is the width and height of the prediction box; The loss is calculated as follows:

[0015] in, is the intersection of the predicted box and the true box, is the union of the predicted box and the true box.

[0016] Furthermore, in the test set used to test the performance of the trained defect detection model, the performance indicators used in the test include: accuracy , recall rate , mean average precision , Among them, the accuracy The calculation method is as follows:

[0017] Recall The calculation method is as follows:

[0018] Mean average precision The calculation method is as follows:

[0019] is a true positive, is a false positive. A false negative is the average precision of different categories in the dataset under different confidence thresholds, is the number of all categories in the dataset.

[0020] In a second aspect, the present invention further provides a PCB defect detection system based on an improved Yolov8 model, which is applied to the PCB defect detection method based on the improved Yolov8 model, and the system comprises: Preprocessing module: used for acquiring a PCB defect data set, preprocessing the PCB defect data set, and dividing the preprocessed PCB defect data set into a training set and a test set in proportion; Building module: used to build a defect detection model based on improved Yolov8; Training module: used to train the defect detection model using the training set to obtain the trained defect detection model, and use the test set to test the performance of the trained defect detection model; Detection module: used to input the PCB image to be detected into the trained defect detection model to obtain the detection result.

[0021] In a third aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer-stored program is executed by a processor, the PCB defect detection method based on the improved Yolov8 model is implemented.

[0022] Compared with the prior art, the present invention has the following beneficial effects: The invention improves the Yolov8 model, including: deleting the P5 large target detection layer in the backbone network and the head network, adding the P2 small target detection layer in the head network, the P2 small target detection layer can effectively improve the model's perception ability for small targets, thereby improving the detection accuracy; adding an edge enhancement module between the backbone network and the head network, the edge enhancement module can perform edge texture detail enhancement processing on the feature map extracted by the backbone network, and retain more tiny defect features, thereby further improving the detection accuracy; replacing the C2F module in the neck network with the CODF module, the CODF module is a fusion of the C2F module and the full-dimensional dynamic convolution, strengthening the network's key feature extraction ability for PCB surface defect targets under complex backgrounds, and further improving the defect detection accuracy; replacing the CIOU loss function with the SIOU loss function, thereby improving the detection accuracy and convergence speed of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 is a flow chart of a PCB defect detection method based on an improved Yolov8 model according to Embodiment 1 of the present invention; Figure 21 is a block diagram of a PCB defect detection system based on an improved Yolov8 model according to Embodiment 3 of the present invention; Figure 3 is a process diagram of improving the Yolov8 model in Example 1 of the present invention; Figure 4 is a structural diagram of the improved Yolov8 model according to Example 1 of the present invention; Figure 5 is a structural diagram of an edge enhancement module according to Embodiment 1 of the present invention; Figure 6 is a CODF module structure diagram of Example 1 of the present invention; Figure 7 This is a comparison diagram of the PR curves before and after the improvement of the Yolov8 model in Example 2 of the present invention, the left figure is before the improvement, and the right figure is after the improvement. DETAILED DESCRIPTION

[0024] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0025] Example 1 like Figure 1 As shown, a PCB defect detection method based on an improved Yolov8 model according to a preferred embodiment of the present invention includes: S1: obtaining a PCB defect data set, preprocessing the PCB defect data set, and dividing the preprocessed PCB defect data set into a training set and a test set in proportion; In an optional embodiment, a PCB defect dataset is obtained from a public PCB surface defect image dataset, the obtained PCB defect dataset is processed using preprocessing methods such as random rotation, random brightness change and / or Gaussian blur, and the preprocessed data is divided into a training set and a test set at a ratio of 9:1.

[0026] S2: Build a defect detection model based on improved Yolov8; In an optional embodiment, the improvement of the Yolov8 model specifically includes: Delete the P5 large target detection layer in the backbone network and the head network, and add a first module in the head network. The first module is used to perceive small targets. In this embodiment, the first module is the P2 small target detection layer. Specifically, the 20x20 large target detection layer is deleted in the backbone network, and only 4 downsampling operations are performed. At the same time, the 20x20 large target detection head is deleted, and a 160x160 small target detection head is added to adjust the network's perception of small targets on the PCB surface, which is conducive to improving detection accuracy and reducing redundant parameters and calculation bottlenecks. A second module is added between the backbone network and the head network. The second module is used to perform edge texture detail enhancement processing on the feature map extracted by the backbone network, and the second module includes at least two. In this embodiment, the second module is an edge enhancement module. The edge enhancement module is based on center difference convolution. Specifically, the center difference convolution block was originally proposed to be applied in the face liveness detection task and achieved better detection effect than ordinary convolution. The differential convolution has an additional center difference operation compared to ordinary convolution. Taking the center difference convolution with a kernel size of 3x3 as an example, the normal convolution obtains the result by sliding the sampling area on the feature map and multiplying it with the convolution kernel weight, while the center difference convolution first takes out the center point pixel value of the sampled feature map area, and then subtracts the pixel value of the surrounding area from the center point pixel value, and then multiplies it with the convolution kernel weight after subtraction to obtain the result. The center difference operation aggregates the intensity and gradient information, thereby better capturing the edge detail information in the feature map and enhancing the network's ability to capture fine-grained texture features. The center difference convolution block expression is:

[0027] The first term on the right side of the equation is the result of the ordinary convolution operation, and the second term is the result of the central difference convolution operation, where Represents the sampling feature map The pixel value of the center point, express Each pixel value in The relative position of is the convolution kernel weight parameter. Controls the contribution of differential convolution and ordinary convolution to the output result. In this embodiment, it is set to 0.7. The structure diagram of the edge enhancement module (EEM) is shown in Figure 5 The edge enhancement module includes a first branch, a second branch and a third branch in parallel, wherein the first branch includes a The convolution kernel and a The second branch consists of a central difference convolution kernel. One convolution kernel The third branch includes an operator for edge detection, a The convolution kernel and a residual structure, the operator used for edge detection in this embodiment is Operator, it is understandable that the operator can also be Operator, operator, the residual structure is the input of the third branch and The convolution kernel outputs are connected and fused; after the input feature map is processed by the three branches, the processing results corresponding to each branch are fused and input into a Convolution kernel, obtain the convolution result, and the convolution result is the input of the neck network.

[0028] The C2F module in the neck network is replaced by the third module, which is used to enhance the feature extraction capability of the neck network. In this embodiment, the third module is the CODF module, which is a fusion of the C2F module and the omni-dimensional dynamic Conv (ODConv). ODConv uses a multi-dimensional attention mechanism, which can improve the feature extraction capability of convolution by learning the complementary attention of the convolution kernel along four dimensions through a parallel strategy. CODF still retains the C2F structure, and replaces the ordinary convolution block in the Bottleneck in C2F with ODConv, avoiding the generation of redundant features, so that the network can effectively capture the feature information of small PCB targets under complex backgrounds. Its expression is:

[0029] in, Represents the convolution kernel The attention scalar, , , denote the attention scalars allocated along the convolution parameters, convolution kernel input channels, and output channels, respectively. Represents the multiplication operation between different dimensions of the convolution kernel space, Represents the convolution operation. The above improvements to the Yolov8 model can be referred to Figure 3 , the improved results are shown in Figure 4 .

[0030] Replace the CIOU loss function with the SIOU loss function.

[0031] The SIOU loss function is as follows:

[0032] in, is the distance loss, is shape loss, distance loss The calculation method is as follows:

[0033] in, The calculation method is as follows:

[0034] is the angle loss, The calculation method is as follows:

[0035] It is obtained by the distance between the center point of the predicted box and the center point of the real box and the height difference between the center point of the predicted box and the center point of the real box. , The calculation method is as follows:

[0036]

[0037] in, and The true box and the predicted box are coordinate, and The true box and the predicted box are coordinate, and is the width and height of the minimum bounding rectangle of the real box and the predicted box, shape loss The calculation method is as follows:

[0038] in, , is the width and height of the prediction box, and The definition is as follows:

[0039]

[0040] in, , , are the width and height of the predicted box and the real box respectively, Controls the focus on shape loss; The loss is calculated as follows:

[0041] in, is the intersection of the predicted box and the true box, is the union of the predicted box and the true box.

[0042] S3: Use the training set to train the defect detection model to obtain the trained defect detection model, and use the test set to test the performance of the trained defect detection model; In an optional embodiment, SGD is selected as the model optimizer, the number of training rounds epoch is set to 300, the initial learning rate lr0 is set to 0.01, the number of single batch samples batch_size is set to 8, num_workers is set to 4, the remaining parameters use the default values, and all images are scaled to 640 After the size of 640, it is input into the network for training to obtain the trained defect detection model. Then, the performance of the trained defect detection model is tested using the test set. The performance indicators used in the test include: accuracy , recall rate , mean average precision , Among them, the accuracy The calculation method is as follows:

[0043] Recall The calculation method is as follows:

[0044] Mean average precision The calculation method is as follows:

[0045] is a true positive, is a false positive. A false negative is the average precision of different categories in the dataset under different confidence thresholds, is the number of all categories in the dataset, The calculation method is as follows:

[0046] In addition, this embodiment may also use parameter quantity Param and detection speed FPS as additional indicators for measuring model performance.

[0047] S4: Input the PCB image to be inspected into the trained defect detection model to obtain the inspection result.

[0048] Example 2 In order to verify the performance of the model proposed in the present invention, this embodiment is based on a PCB defect detection method based on the improved Yolov8 model proposed in Example 1, and uses the same PCB data set as a training set and a test set to train and test the performance of other defect detection models and the performance of the improved Yolov8 model proposed in the present invention to verify the superiority of the model of the present invention. The defect detection models involved in the comparison include: Faster-RCNN, YoloX, Yolov5, Yolov8, and GCC-YOLO. Before the experiment, all models are set with the following parameters: SGD is selected as the model optimizer, the number of training rounds epoch is set to 300, the initial learning rate lr0 is set to 0.01, the number of single batch samples batch_size is set to 8, num_workers is set to 4, and the remaining parameters use the default values. All images are scaled to 640 After the size is 640, it is input into the network for training, and the test set is tested using the trained optimal weight file. The test results are recorded and saved, and the test results are evaluated. The model performance evaluation indicators use precision Precision, recall Recall, and average precision mAP. In addition, this embodiment also uses parameter size Param and detection speed FPS as additional performance evaluation indicators, as shown in the following table:

[0049] Among them, the performance comparison of the unimproved YOLOV8 and the improved YOLOV8 of the present invention is shown in the figure below: Figure 7 As shown in the above table and Figure 7 It can be seen that the improved Yolov8 model proposed in the present invention has superior performance.

[0050] Example 3 like Figure 2 As shown, a PCB defect detection system based on an improved Yolov8 model according to an embodiment of the present invention includes: Preprocessing module: used for acquiring a PCB defect data set, preprocessing the PCB defect data set, and dividing the preprocessed PCB defect data set into a training set and a test set in proportion; Building module: used to build a defect detection model based on improved Yolov8; Training module: used to train the defect detection model using the training set to obtain the trained defect detection model, and use the test set to test the performance of the trained defect detection model; Detection module: used to input the PCB image to be detected into the trained defect detection model to obtain the detection result.

[0051] It can be understood that the system of this embodiment corresponds to the method of the above-mentioned embodiment 1, and the options in the above-mentioned embodiment 1 are also applicable to this embodiment, so they will not be described repeatedly here.

[0052] Example 4 An embodiment of the present invention also provides a computer-readable storage medium, on which is stored a computer program for a PCB defect detection method based on an improved Yolov8 model. When the computer program for a PCB defect detection method based on an improved Yolov8 model is processed, the steps of the PCB defect detection method based on an improved Yolov8 model are implemented.

[0053] In summary, the embodiments of the present invention provide a PCB defect detection method, system and storage medium based on the improved Yolov8 model, which improves the Yolov8 model, including: deleting the P5 large target detection layer in the backbone network and the head network to reduce the calculation bottleneck and ensure the accuracy, adding the P2 small target detection layer in the head network, the P2 small target detection layer can effectively improve the model's perception ability for small targets, thereby improving the detection accuracy; adding an edge enhancement module between the backbone network and the head network, the edge enhancement module can perform edge texture detail enhancement processing on the feature map extracted by the backbone network, and retain more tiny defect features, further improving the detection accuracy; replacing the C2F module in the neck network with the CODF module, the CODF module is a fusion of the C2F module and the full-dimensional dynamic convolution, enhancing the network's ability to extract key features of PCB surface defect targets under complex backgrounds, and further improving the defect detection accuracy; replacing the CIOU loss function with the SIOU loss function, improving the detection accuracy and convergence speed of the model.

[0054] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and substitutions can be made without departing from the technical principles of the present invention. These improvements and substitutions should also be regarded as the scope of protection of the present invention.

Claims

1. A PCB defect detection method based on an improved Yolov8 model, characterized in that: The method comprises the following steps: Acquire a PCB defect data set, preprocess the PCB defect data set, and divide the preprocessed PCB defect data set into a training set and a test set in proportion; Build a defect detection model based on improved Yolov8; Using the training set to train the defect detection model to obtain a trained defect detection model, and using the test set to test the performance of the trained defect detection model; The PCB image to be inspected is input into the trained defect detection model to obtain the inspection result.

2. A PCB defect detection method based on an improved Yolov8 model according to claim 1, characterized in that: The preprocessing is random rotation, random brightness change and / or Gaussian blur, and the ratio is .

3. A PCB defect detection method based on an improved Yolov8 model according to claim 1, characterized in that: The defect detection model based on the improved Yolov8 is constructed, wherein the improvement of the Yolov8 model specifically includes: deleting the P5 large target detection layer in the backbone network and the head network, adding a first module in the head network, and the first module is used to perceive small targets; adding a second module between the backbone network and the head network, the second module is used to perform edge texture detail enhancement processing on the feature map extracted by the backbone network, and the second module includes at least two; using a third module to replace the C2F module in the neck network, the third module is used to enhance the feature extraction capability of the neck network; replacing the CIOU loss function with the SIOU loss function.

4. A PCB defect detection method based on an improved Yolov8 model according to claim 3, characterized in that: The first module is the P2 small target detection layer; the second module is an edge enhancement module, which is based on central differential convolution; the third module is a CODF module, which is a fusion of a C2F module and a full-dimensional dynamic convolution.

5. A PCB defect detection method based on an improved Yolov8 model according to claim 3, characterized in that: The edge enhancement module includes a first branch, a second branch and a third branch in parallel, wherein the first branch includes a The convolution kernel and a The second branch consists of a central difference convolution kernel. One convolution kernel The third branch includes an operator for edge detection, a convolution kernel and a residual structure, the residual structure is the input of the third branch and the The convolution kernel outputs are connected and fused; after the input feature map is processed by the three branches, the processing results corresponding to each branch are fused and input into a A convolution kernel is used to obtain a convolution result, which is the input of the neck network.

6. A PCB defect detection method based on an improved Yolov8 model according to claim 5, characterized in that: The operator used for edge detection is Operator.

7. A PCB defect detection method based on an improved Yolov8 model according to claim 3, characterized in that: The SIOU loss function is as follows: in, is the distance loss, is shape loss, distance loss The calculation method is as follows: Shape loss The calculation method is as follows: in, , is the width and height of the prediction box; The loss is calculated as follows: in, is the intersection of the predicted box and the true box, is the union of the predicted box and the true box.

8. A PCB defect detection method based on an improved Yolov8 model according to claim 1, characterized in that: In the test set used to test the performance of the trained defect detection model, the performance indicators used in the test include: accuracy , recall rate , mean average precision , Among them, the accuracy The calculation method is as follows: Recall The calculation method is as follows: Mean average precision The calculation method is as follows: is a true positive, is a false positive. A false negative is the average precision of different categories in the dataset under different confidence thresholds, is the number of all categories in the dataset.

9. A PCB defect detection system based on an improved Yolov8 model, applied to the PCB defect detection method based on an improved Yolov8 model as claimed in any one of claims 1 to 8, the system comprising: Preprocessing module: used for acquiring a PCB defect data set, preprocessing the PCB defect data set, and dividing the preprocessed PCB defect data set into a training set and a test set in proportion; Building module: used to build a defect detection model based on improved Yolov8; Training module: used to train the defect detection model using the training set to obtain the trained defect detection model, and use the test set to test the performance of the trained defect detection model; Detection module: used to input the PCB image to be detected into the trained defect detection model to obtain the detection result.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer stored program is executed by the processor, the PCB defect detection method based on the improved Yolov8 model described in any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Visual positioning method for UHPC highway guardrail center hole

    CN120726126A