PCB defect detection system and method based on improved YOLOv8

By introducing GSConv, VoVGSCSP and C2f_LSKA modules into the YOLOv8 network, the problems of low detection accuracy and slow speed in PCB defect detection are solved, and more efficient detection results are achieved.

CN120107232APending Publication Date: 2025-06-06SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510369684.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-27
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

The prior art has problems of low detection accuracy and slow detection speed in PCB defect detection, especially when dealing with scenarios with small defects on PCB boards, the difficulty of model detection increases.

Method used

In the YOLOv8 network model, the standard convolution in the backbone network is replaced as the lightweight convolution module GSConv, and VoVGSCSP and C2f_LSKA modules are introduced at the neck to improve detection accuracy and speed.

Benefits of technology

By improving the YOLOv8 network structure, the accuracy and detection speed of PCB defect detection are improved, and higher detection accuracy and faster inference speed are achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120107232A_ABST
    Figure CN120107232A_ABST
Patent Text Reader

Abstract

The invention discloses a PCB defect detection system and method based on improved YOLOv8, on the basis of a traditional YOLOv8 network model, a standard convolution Conv in a YOLOv8 backbone network is replaced with a convolution module GSConv, C2f modules on the twelfth layer and the eighteenth layer of the neck of the YOLOv8 are replaced with a VoVGSCSP module formed based on the GSConv, C2f modules on the fifteenth layer and the twenty-first layer of the neck are replaced with a C2fLSKA module, an LSKA module is introduced to replace Bottleneck of the C2f modules, and the C2fLSKA module is introduced to replace Bottleneck of the C2f modules. The improved YOLOv8 network model is formed, and the PCB defect detection precision and detection speed are improved by improving the YOLOv8 network structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of target detection, and mainly relates to a PCB defect detection system and method based on improved YOLOv8. Background Art

[0002] As an important component of electronic products, printed circuit boards (PCBs) are easily affected by various factors during the production process, such as mechanical friction, electrostatic interference, and chemical corrosion. These factors can easily lead to a series of defects in PCBs, such as missing holes, mouse bites, open circuits, short circuits, strays, fake copper, and broken holes, which seriously affect the quality and performance of PCBs. If these problems cannot be discovered and handled in time, they will directly affect the normal operation and service life of electronic equipment. 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.

[0003] 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, but they still have many shortcomings, such as low detection accuracy, large model size, slow detection speed, etc. In addition, the size of PCB defects on the entire PCB board is relatively small, which also increases the difficulty of the model to detect them. Summary of the invention

[0004] Aiming at the problems of low detection accuracy and slow detection speed in the prior art, the present invention proposes a PCB defect detection system and method based on improved YOLOv8. On the basis of the traditional YOLOv8 network model, the convolution module GSConv is used to replace the standard convolution Conv in the YOLOv8 backbone network, the VoVGSCSP module based on GSConv is used to replace the C2f modules of the 12th and 18th layers of the YOLOv8 neck, the C2f_LSKA module is used to replace the C2f modules of the 15th and 21st layers of the neck, and the LSKA module is introduced to replace the Bottleneck of the C2f module, thereby forming an improved YOLOv8 network model. By improving the YOLOv8 network structure, the accuracy and detection speed of PCB defect detection are improved.

[0005] In order to achieve the above-mentioned purpose, the technical scheme adopted by the present invention is: a PCB defect detection system based on improved YOLOv8, characterized in that: it at least includes an improved YOLOv8 network model, in which a convolution module GSConv is used to replace the standard convolution Conv in the YOLOv8 backbone network, a VoVGSCSP module based on GSConv is used to replace the C2f module of the 12th and 18th layers of the neck of YOLOv8, a C2f_LSKA module is used to replace the C2f module of the 15th and 21st layers of the neck, and an LSKA module is introduced to replace the Bottleneck of the C2f module.

[0006] As an improvement of the present invention, in the convolution module GSConv, a standard convolution SC and a depthwise separable convolution DSC are sequentially performed, and then the results of the two convolutions are spliced ​​together, and finally a shuffle operation is performed; the specific process is: first, the input feature map is downsampled by a standard convolution, and then a depthwise separable convolution is performed, and then the standard output information is spliced ​​with the output information of the depthwise separable convolution, and the order of the spliced ​​information is randomly disrupted and rearranged to achieve uniform exchange of feature information on different channels.

[0007] The VoVGSCSP module consists of a GSBottleneck module, a Conv module, and a Concat module. It captures local features in space by mapping input features into the network, and separates and fuses features by cross-stage partial connections. GSBottleneck is a bottleneck module based on GSConv, which consists of two GSConv layers. The first GSConv layer halves the number of input channels, and then outputs them after passing through the second GSConv layer. The cross-stage partial connection method is to divide the input feature map into two parts, one part is densely connected, and the other part is directly convolved, and then the outputs of the two parts are merged to form the final feature map. This method can enhance the learning ability of convolutional neural networks, reduce the reuse of gradient information between different layers, and improve the training efficiency of the model.

[0008] As an improvement of the present invention, the LSKA module adopts a large kernel attention LKA module and a CNN network architecture to decompose the two-dimensional convolution kernel of the deep convolution layer into cascaded horizontal and vertical 1-D kernels, solving the problems of LKA in computation and memory usage without losing performance. LKA uses larger convolution kernels to capture a wider range of contextual information. Large convolution kernels can provide a larger receptive field, which helps the network understand the global structure and patterns in the image. LSKA consists of deep convolution, deep dilated convolution and standard convolution, where both deep convolution and deep dilated convolution decompose the two-dimensional convolution kernel into cascaded one-dimensional convolution kernels. The deep dilated convolution is responsible for capturing the global spatial information of the deep convolution output, and then convolution is performed using a 1×1 convolution kernel to obtain an attention map. For a given input feature map F∈R C×H×W , where C is the number of input channels, H and W represent the height and width of the feature map respectively. The output of LSKA is:

[0009]

[0010] A C =W 1×1 *Z C

[0011]

[0012] in represents the output of the depthwise convolution, Z C is the output of the depthwise dilated convolution, Indicates the rounding down operation, A C is the attention map, F C is the input feature map, * and Represent convolution and Hadamard product respectively, output is the attention map A C And the input feature map F C The Hadamard product.

[0013] As another improvement of the present invention, the calculation method of the parameters Parameter and the calculation amount FLOPs of the LSKA module is as follows:

[0014]

[0015] Where k is the kernel size, d is the dilation rate, C is the number of input channels, H is the height of the feature map, and W is the width of the feature map. The first term in the Parameter formula represents the number of parameters for the depthwise convolution, the second term represents the number of parameters for the depthwise dilated convolution, and the third term represents the number of parameters for the 1×1 convolution. FLOPs is the same as above.

[0016] In order to achieve the above object, the present invention also adopts a technical solution: a PCB defect detection method based on an improved YOLOv8, comprising the following steps:

[0017] S1: Construct a PCB defect image dataset, expand the dataset through data enhancement method, and divide the expanded PCB defect image dataset into training set, validation set and test set in proportion;

[0018] S2: Build an improved YOLOv8 network model, in which the convolution module GSConv replaces the standard convolution Conv in the YOLOv8 backbone network, the feature fusion module VoVGSCSP replaces the C2f module at the 12th and 18th layers of the YOLOv8 neck, the C2f_LSKA module replaces the C2f module at the 15th and 21st layers of the neck, and the LSKA module replaces the Bottleneck in the C2f module;

[0019] S3: Input the training set in the PCB defect image dataset constructed in step S1 into the YOLOv8 network improved in step S2 for iterative training. After the training, best.pt and last.pt are obtained, where best.pt is the optimal weight obtained by iterative training. The quality of the best.pt model is verified by the validation set, and the evaluation index is obtained to evaluate the model.

[0020] S4: Set the model to predict mode, load the best.pt model obtained in step S3, input the image to be detected in the test set, and obtain the prediction result, thereby realizing the detection of PCB defects.

[0021] As an improvement of the present invention, the data enhancement method in step S1 at least includes cropping, flipping, rotating, color transformation and geometric transformation of the data, and the ratio of the training set, the validation set and the test set is 8:1:1.

[0022] As another improvement of the present invention, the evaluation indicators of step S3 include but are not limited to recall rate, precision rate, average precision rate mean, F1 score and frame rate.

[0023] The recall rate indicates the proportion of actually positive samples that are also recognized as positive samples by the classifier to all actually positive samples. The specific calculation method is:

[0024]

[0025] Among them, FN represents the number of samples that are actually positive but predicted to be negative, and TP represents the number of samples that are actually positive but predicted to be positive;

[0026] The precision rate indicates the proportion of positive samples that are actually positive samples and are also recognized as positive samples by the classifier to all positive samples recognized by the classifier, and is calculated by the following formula:

[0027]

[0028] Among them, FP represents the number of samples predicted to be positive when they are actually negative samples;

[0029] The mean average precision is the average of the AP values ​​of all categories, calculated by the following formula:

[0030]

[0031] Among them, AP represents the average precision of different categories in the data set at different confidence thresholds, n represents the number of defect categories, and i represents the i-th category;

[0032] The F1 score takes into account the recall rate and precision rate, and is the harmonic mean of the recall rate and precision rate. The value range of the F1 score is 0 to 1. The higher the F1 score, the better the performance of the model. It is calculated by the following formula:

[0033]

[0034] The frame rate indicates the number of images that the algorithm can process per second. The higher the frame rate value, the faster the algorithm has a processing speed. It is calculated by the following formula:

[0035]

[0036] Where N represents the number of images to be detected, and T represents the time used to detect all images to be detected.

[0037] Compared with the prior art, the present invention has the following beneficial effects: the present invention provides a PCB defect detection system and method based on improved YOLOv8, by replacing the convolution in the YOLOv8 backbone network with a lightweight convolution GSConv, the semantic information between channels is retained with lower time complexity; and a GSBottleneck bottleneck structure is formed based on GSConv, and the VoVGSCSP structure is composed of a GSBottleneck module, a Conv module and a Concat module, which is used to replace the C2f module at the neck of the original YOLOv8 network, which is equivalent to replacing the Bottleneck in C2f with the GSBottleneck in the VoVGSCSP structure, so that the model can improve the detection accuracy while reducing the reasoning time; by introducing the LSKA attention module, the C2f module is improved, that is, the Bottleneck module in C2f is replaced with LSKA, so as to reduce the redundant calculation of the model, maintain the detection accuracy of the model, and at the same time reduce the number of parameters of the model and improve the frame rate of the detection model. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a flowchart of the steps of the PCB defect detection method based on improved YOLOv8 of the present invention;

[0039] Figure 2 It is the structure diagram of GSConv and the structure diagram of VoVGSCSP, where:

[0040] Figure 2 (a) is the structural diagram of GSConv;

[0041] Figure 2 (b) is the structural diagram of VoVGSCSP;

[0042] Figure 3 is the structure diagram of LSKA and the structure diagram of C2f_LSKA, where

[0043] Figure 3 (a) is the structural diagram of LSKA;

[0044] Figure 3 (b) is the structural diagram of C2f_LSKA;

[0045] Figure 4 It is a schematic diagram of the network structure of the improved YOLOv8 of the present invention;

[0046] Figure 5 It is a comparison chart of the PR curves before and after the improvement of the YOLOv8 model in the test example of the present invention, where:

[0047] Figure 5 (a) is a schematic diagram of the PR curve before improvement;

[0048] Figure 5 (b) is a schematic diagram of the improved PR curve;

[0049] Figure 6 : is a graph showing the detection results of PCB defects by the improved YOLOv8 model in the test example of the present invention, wherein:

[0050] Figure 6 (a) is a schematic diagram of the detection results of the model for the hole defect;

[0051] Figure 6 (b) is a schematic diagram of the model's detection results for rat bite defects;

[0052] Figure 6 (c) is a schematic diagram of the detection results of the model for open circuit defects;

[0053] Figure 6 (d) is a schematic diagram of the detection results of the model for short circuit defects;

[0054] Figure 6 (e) is a schematic diagram of the detection results of the model for stray defects;

[0055] Figure 6 (f) is a schematic diagram of the model’s detection results for pseudo copper defects. DETAILED DESCRIPTION

[0056] The present invention will be further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention.

[0057] Example 1

[0058] The PCB defect detection system based on the improved YOLOv8 at least includes an improved YOLOv8 network model, such as Figure 4 As shown, in the network model, the convolution module GSConv is used to replace the standard convolution Conv in the YOLOv8 backbone network, the VoVGSCSP module based on GSConv is used to replace the C2f module at the 12th and 18th layers of the YOLOv8 neck, the C2f_LSKA module is used to replace the C2f module at the 15th and 21st layers of the neck, and the LSKA module is introduced to replace the Bottleneck of the C2f module.

[0059] In the YOLOv8 network, a lightweight convolution module GSConv is used to replace the Conv in the original backbone network, and the C2f modules in the 12th and 18th layers of the neck are replaced with VoVGSCSP modules, where GSConv uses the features generated by the standard convolution SC to penetrate into the features generated by the deep separable convolution DSC, and the SC information is fully mixed into the output of the DSC through a uniform mixing operation, thereby retaining the hidden connections between the features. VoVGSCSP captures local features in space by mapping the input features into the network, and separates and fuses features by connecting parts across stages, thereby reducing redundant calculations while maintaining the richness of feature representation and improving network efficiency.

[0060] The large separable attention module LSKA is introduced into the YOLOv8 model, and the C2f modules at the 15th and 21st layers of the neck are replaced with the C2f_LSKA module. The C2f_LSKA module replaces the original Bottleneck module in C2f with the LSKA module. First, the input feature map is processed by a convolution layer, and the number of channels of the output feature map is doubled. Then, the feature map is split into two layers. Figure 1 It is divided into two parts, one part enters the LSKA module, and the other part directly participates in the subsequent splicing. Finally, a convolution layer is used to compress the number of channels of the spliced ​​feature map to the required number of output channels.

[0061] Among them, LSKA is an attention module that establishes correlations and generates attention feature maps by using large kernel convolutions. It aims to solve the computational efficiency problem faced when using large kernel convolutions in visual attention networks. It decomposes the two-dimensional convolution kernel of the deep convolution layer into cascaded horizontal and vertical 1-D kernels, thereby achieving direct use of large kernels and reducing computational complexity and memory usage.

[0062] The system of this embodiment improves the accuracy and speed of PCB defect detection by improving the YOLOv8 network structure.

[0063] Example 2

[0064] PCB defect detection method based on improved YOLOv8, such as Figure 1 As shown, the specific steps include:

[0065] Step S1: construct a PCB defect dataset, expand the dataset using a data enhancement method, and divide the expanded PCB defect image dataset into a training set, a validation set, and a test set in proportion.

[0066] In order to prevent the model from overfitting, the data set is enhanced by cropping, flipping, rotating, color transformation, and geometric transformation. The open source PCB data set is selected and the data set is expanded from 1386 to 6237 by data enhancement. There are six types of defects, namely missing holes, rat bites, open circuits, short circuits, strays, and pseudo copper. Then the labeling tool Labelimg is used to annotate the images and divide them into training set, validation set, and test set in a ratio of 8:1:1.

[0067] Step S2: Build an improved YOLOv8 network model, use the lightweight convolution module GSConv to replace the standard convolution Conv in the YOLOv8 backbone network, and use the feature fusion module VoVGSCSP to replace the C2f module in the neck of YOLOv8; replace the remaining two C2f modules in the neck with the C2f_LSKA module, and use the LSKA module to replace the Bottleneck in C2f.

[0068] Build an improved YOLOv8 network model, such as Figure 4 As shown in Figure 1, the convolutional block at the 5th layer of the YOLOv8 network is replaced with a lightweight convolution GSConv, and the C2f at the 12th and 18th layers are replaced with VoVGSCSP. The structures of GSConv and VoVGSCSP are as follows: Figure 2 (a) and Figure 2 As shown in (b), GSConv first performs a standard convolution SC on the input, then a depth-separable convolution DSC, then concatenates the results of the two convolutions, and finally performs a shuffle operation to fully mix the information of SC and DSC, thereby retaining the hidden connections between features. The VoVGSCSP module consists of a GSBottleneck module, a Conv module, and a Concat module. GSBottleneck is a bottleneck module based on GSConv, and its computational cost is about 60% to 70% of that of a standard convolution, but its contribution to the model's learning ability is comparable to that of a standard convolution. Using the VOVGSCSP structure at the neck can further reduce the complexity of the computation and network structure while maintaining accuracy.

[0069] When the convolutional neural network transmits image information, it gradually converts spatial information to channels in the Backbone, and each time the spatial (width and height) compression and channel expansion of the feature map will lead to the loss of semantic information, while GSConv combines the advantages of SC and DSC to retain this information as much as possible. However, if GSConv is used in all stages of the model, the network layer of the model will be deeper, and the deeper the network layer, the greater the resistance to data flow and the increase in inference time. At the neck, the feature map becomes slender, that is, the channel dimension reaches the maximum and the width and height dimensions reach the minimum, and there is no need to convert spatial information to channels. Therefore, using VoVGSCSP at the neck can maintain the richness of feature representation while reducing redundant calculations and improving network efficiency. This module can efficiently fuse features from different levels and enhance feature expression capabilities, making the model more lightweight and suitable for real-time applications while maintaining high-precision detection and segmentation performance.

[0070] The large separable attention module LSKA is introduced into the improved YOLOv8 model, such as Figure 4 As shown in FIG. 1 , the C2f of the 15th and 21st layers in the improved YOLOv8 network is replaced by the C2f_LSKA module. The C2f_LSKA module replaces the Bottleneck in the C2f module with the LSKA module. The LSKA and C2f_LSKA structure diagrams are shown in FIG. Figure 3 (a) and Figure 3 (b) is shown. LSKA is an attention mechanism that uses large kernel convolution to establish correlation and generate attention feature maps. It aims to solve the computational efficiency problem faced when using large kernel convolution in visual attention networks. Visual attention combines the properties of self-attention modules and CNNs, and adopts large kernel attention (LKA) modules and CNN network architectures to achieve the long-range dependency of CNN and the spatial adaptability of self-attention modules. LKA uses larger convolution kernels to capture a wider range of contextual information. Large convolution kernels can provide a larger receptive field, which helps the network understand the global structure and patterns in the image.

[0071] LSKA decomposes the 2D convolution kernel of the deep convolution layer into cascaded horizontal and vertical 1-D kernels, solving the computational and memory usage problems of LKA without sacrificing performance. Figure 3 As shown in (a), for a given input feature map F∈R C ×H×W , where C is the number of input channels, H and W represent the height and width of the feature map respectively. The output of LSKA is

[0072]

[0073] A C =W 1×1 *ZC

[0074]

[0075] where * and represent convolution and Hadamard product respectively, Represents the output of the deep convolution, which consists of two cascaded 1D kernels of size 2d-1, capturing local spatial information and compensating for the grid effect of subsequent deep convolutions. C is the output of the depthwise dilated convolution, where Denotes the rounding down operation, and the depth dilated convolution is responsible for capturing the global spatial information of the depth convolution output. Then a 1×1 convolution kernel is used to perform convolution to obtain the attention map A. C Output is the attention map A C And the input feature map F C The Hadamard product.

[0076] The calculation method of the parameters and FLOPs of the LSKA module is as follows:

[0077]

[0078] Parameter quantity and computational complexity are important indicators for measuring deep learning algorithms. Parameter quantity is the number of parameters in the convolution kernel, which corresponds to the spatial complexity of the algorithm. Computational complexity is the number of floating-point operations of the convolutional neural network, which corresponds to the time complexity of the algorithm. Where k is the kernel size and d is the expansion rate. The calculation method for LKA parameters and FLOPs is as follows:

[0079]

[0080] It can be seen that LSKA saves 10% in the deep convolutional layer compared to LKA. parameters, saving in the dilated convolutional layer parameters, and again the amount of savings in FLOPs is the same as the number of parameters.

[0081] Step S3: Input the training set in the PCB defect image dataset into the network for iterative training, set the training parameters, obtain the optimal weight, and verify the quality of the model through the validation set, and evaluate the model according to the evaluation indicators.

[0082] Input the dataset constructed in step S1 into the network to start training, set the training parameters batch size to 16, the number of training rounds to 400, set the input image size to 640×640, use the trained optimal weight file to verify the model on the validation set, and evaluate the model according to the evaluation indicators. The evaluation indicators include recall rate, precision rate, average precision rate, F1 score and frame rate.

[0083] The recall rate indicates the proportion of actually positive samples that are also recognized as positive samples by the classifier to all actually positive samples, and is calculated by the following formula:

[0084]

[0085] The precision rate indicates the proportion of positive samples that are actually positive samples and are also recognized as positive samples by the classifier to all positive samples recognized by the classifier, and is calculated by the following formula:

[0086]

[0087] The mean average precision is the average of the AP values ​​of all categories, calculated by the following formula:

[0088]

[0089] The F1 score takes into account the recall rate and precision rate, and is the harmonic mean of the recall rate and precision rate. The value range of the F1 score is 0 to 1. The higher the F1 score, the better the performance of the model. It is calculated by the following formula:

[0090]

[0091] The frame rate indicates the number of images that the algorithm can process per second. The higher the frame rate value, the faster the algorithm has a processing speed. It is calculated by the following formula:

[0092]

[0093] FN represents the number of samples predicted as negative when they are actually positive, FP represents the number of samples predicted as positive when they are actually negative, TP represents the number of samples predicted as positive when they are actually positive, and TN represents the number of samples predicted as negative when they are actually negative. n represents the number of defect categories, i represents the i-th category, and AP represents the average precision of different categories in the data set at different confidence thresholds, that is, the area value obtained by integrating the precision-recall (PR) curve. F1 takes into account the recall rate and precision rate, and is the harmonic mean of the recall rate and precision rate. N represents the number of images to be detected, and T represents the time taken to detect all the images to be detected.

[0094] The mean average precision is one of the key indicators to measure the performance of the target detection algorithm. It takes into account the average detection accuracy of all categories. By calculating the accuracy of each category and taking the average, the mean average precision can fully reflect the detection performance of the algorithm in different categories. The higher the mean average precision, the more accurately the algorithm can identify the target object and the more stable it is in different categories. The F1 score ranges from 0 to 1. The higher the F1 score, the better the performance of the model. The frame rate indicates the number of images that the algorithm can process per second. The higher the frame rate value, the faster the algorithm has a processing speed and can process the input images in real time or near real time. In PCB defect detection, a high frame rate value can ensure the efficient operation of the production line and reduce waiting time and cost.

[0095] Step S4: Set the model to predict mode, load the optimal weight file obtained through training, input the image to be detected in the test set, and obtain the prediction result, thereby realizing the detection of PCB defects.

[0096] Set the YOLO model to Predict mode, which is used to use the trained model for prediction on the image to be detected. Load the optimal model weight file trained in step S3, batch input the images to be detected in the test set into the detection network, obtain the defect detection results through model prediction, and save the detection result image in the specified folder. The detection result image contains the prediction box, defect category and the confidence of each defect. The confidence indicates the degree of confidence of the model in the detection result, which is a value between 0 and 1. The closer to 1, the more accurate the position of the prediction box.

[0097] Test Case

[0098] The experimental environment of this test example is: CPU 13th Gen Intel(R)Core(TM)i5-13600K, GPU NVIDIA GeForce RTX 2080, Windows 11, Pytorch 2.3.1, CUDA 12.1.

[0099] The public PCB defect dataset PKU-Market-PCB is selected to verify the improved YOLOv8 model of the present invention. The dataset contains six defects: missing holes, rat bites, open circuits, short circuits, strays, and false copper. The dataset used in the experiment is a dataset that has been enhanced based on the public dataset, and is divided into a training set, a validation set, and a test set in a ratio of 8:1:1.

[0100] The basic model used in this test case is the YOLOv8n model with the smallest size and the least computational effort in the YOLOv8 series. The performance of the detection network is improved by modifying the algorithm model in the network structure and introducing lightweight convolution GSConv and C2f_LSKA structures. The experimental results are analyzed from the aspects of model accuracy and inference speed.

[0101] The model training parameters remained consistent during the experiment: batch was set to 16, epoch was set to 400, and the other parameters used the default values. All images were scaled to 640×640 and input into the network for training. The trained optimal model weight file was used to verify the validation set, and the evaluation indicators were obtained to evaluate the model performance. The model performance evaluation indicators use the mean average precision mAP, parameter Parameter, calculation GFLOPs, frame rate FPS and F1 score. Table 1 shows the indicators of the unimproved YOLOv8n model, the YOLOv8 improved model with only GSConv, and the YOLOv8 improved model with GSConv and C2f_LSKA on the PCB defect dataset.

[0102] Table 1 Evaluation indicators

[0103] Model mAP(%) Parameter GFLOPs FPS F1 YOLOv8n 97.3 3157200 8.9 173.15 0.96 YOLOv8n+GSConv 98.8 10527008 25.5 184.9 0.98 YOLOv8n+GSConv+C2f_LSKA 98.8 9826208 25.3 194.93 0.98

[0104] Among them, the PR curve comparison between the unimproved YOLOv8 and the improved YOLOv8 of the present invention is as follows: Figure 5 As shown in Table 1 and Figure 5 It can be seen that by improving the YOLOv8 model, the present invention can achieve a mAP value of 98.8% on the PCB defect data set, an FPS of 194.93 frames / second, and an F1 score of 0.98. Compared with the model before the improvement, the mAP is increased by 1.5%, the FPS is increased by 21.78 frames / second, and the F1 score is increased by 0.02. Compared with the basic model before the improvement, the improved method proposed in the present invention has higher detection accuracy for PCB defects and also improves the frame rate. This method takes into account the detection accuracy and detection speed of the model, indicating that the improved Yolov8 model proposed in the present invention has superior performance and provides a feasible solution for real-time PCB defect detection.

[0105] Use the trained model to make predictions on the images in the test set. Figure 6 The figure shows the prediction results of the improved YOLOv8 model for six defect images. The defect area in the image is outlined by the prediction box, and the defect type and confidence are marked. Different defect categories are distinguished by different colors. Figure 6 (a) to Figure 6(f) shows the detection results of six types of defects: missing_hole, mouse_bite, open_circuit, short, spur and spurious_copper. It can be seen that the defects in the image are all detected correctly, and the confidence level is more than 0.7, indicating that the model is highly confident about the detected targets.

[0106] In summary, the present invention introduces two structures, a lightweight convolution GSConv and a large separable kernel attention LSKA, to improve the YOLOv8 model. By replacing the standard convolution with GSConv in the backbone network, more hidden connections between features are retained, and the C2f module is replaced by the VoVGSCSP structure based on GSConv in the neck, so as to more efficiently fuse features from different levels. It can be seen that the detection accuracy of the model is improved through the improvement, and the reasoning speed of the model is improved at the same time; by introducing the LSKA module in the C2f module in the neck, while maintaining the accuracy, the number of parameters and the amount of calculation of the model are reduced, and the reasoning speed of the model is also improved. Therefore, the improved method for YOLOv8 described in the present invention is suitable for real-time and high-precision PCB defect detection.

[0107] It should be noted that the above content only illustrates the technical idea of ​​the present invention and cannot be used to limit the protection scope of the present invention. For ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications all fall within the protection scope of the claims of the present invention.

Claims

1. PCB defect detection system based on improved YOLOv8, characterized by: At least an improved YOLOv8 network model is included, in which the convolution module GSConv is used to replace the standard convolution Conv in the YOLOv8 backbone network, the VoVGSCSP module based on GSConv is used to replace the C2f module at the 12th and 18th layers of the YOLOv8 neck, the C2f_LSKA module is used to replace the C2f module at the 15th and 21st layers of the neck, and the LSKA module is introduced to replace the Bottleneck of the C2f module.

2. The PCB defect detection system based on improved YOLOv8 as claimed in claim 1, characterized in that: The convolution module GSConv includes at least one standard convolution SC and one depthwise separable convolution DSC; after the input feature map is sequentially subjected to a standard convolution downsampling and a depthwise separable convolution, the output information of the standard convolution is concatenated with the output information of the depthwise separable convolution, and the order of the concatenated information is randomly shuffled and rearranged; The VoVGSCSP module consists of a GSBottleneck module, a Conv module, and a Concat module, which captures local features in space by mapping input features to the network, and separates and fuses features by partially connecting across stages. The GSBottleneck module consists of two GSConv layers. The first GSConv layer halves the number of input channels and then outputs them through the second GSConv layer. The cross-stage partial connection divides the input feature map into two parts, one of which is densely connected and the other is directly convolved. The outputs of the two parts are merged to form the final feature map.

3. The PCB defect detection system based on improved YOLOv8 as claimed in claim 2, characterized in that: The LSKA module adopts the large kernel attention LKA module and the CNN network architecture to decompose the two-dimensional convolution kernel of the deep convolution layer into cascaded horizontal and vertical 1-D kernels; the LSKA module consists of deep convolution, deep dilated convolution and standard convolution, and the deep dilated convolution is responsible for capturing the global spatial information of the deep convolution output, and convolution is performed using a 1×1 convolution kernel to obtain an attention map; For a given input feature map F∈R C×H×W , where C is the number of input channels, H and W represent the height and width of the feature map respectively. The output of LSKA is: AND C =In 1×1 *WITH C in represents the output of the depthwise convolution, represents a convolution kernel with a channel number of C and a kernel size of (2d-1)×1, F C is the input feature map, Z C is the output of the depthwise dilated convolution, Indicates the rounding down operation, A C is the attention map, * and Represent convolution and Hadamard product respectively, output is the attention map A C And the input feature map F C The Hadamard product is , k is the kernel size, and d is the dilation rate.

4. The PCB defect detection system based on improved YOLOv8 as claimed in claim 3, characterized in that: The calculation method of the parameter quantity Parameter and the calculation quantity FLOPs of the LSKA module is as follows: Among them, the first item in Parameter and FLOPs represents the parameter amount and calculation amount of depth convolution, the second item represents the parameter amount and calculation amount of depth expansion convolution, and the third item represents the parameter amount and calculation amount of 1×1 convolution.

5. A PCB defect detection method based on improved YOLOv8 using the system as claimed in claim 1, characterized in that: The steps include: S1: Construct a PCB defect image dataset, expand the dataset through data enhancement method, and divide the expanded PCB defect image dataset into training set, validation set and test set in proportion; S2: Build an improved YOLOv8 network model, in which the convolution module GSConv replaces the standard convolution Conv in the YOLOv8 backbone network, the feature fusion module VoVGSCSP replaces the C2f module at the 12th and 18th layers of the YOLOv8 neck, the C2f_LSKA module replaces the C2f module at the 15th and 21st layers of the neck, and the LSKA module replaces the Bott leneck in the C2f module; S3: Input the training set in the PCB defect image dataset constructed in step S1 into the YOLOv8 network improved in step S2 for iterative training. After the training, the optimal weight best.pt of the model is obtained. The performance of the optimal weight best.pt model is verified by the validation set in step S1, and the optimal weight best.pt model is evaluated by the evaluation index. S4: Set the model to predict mode, load the optimal weight best.pt model obtained in step S3, input the image to be detected in the test set in step S1, obtain the prediction result, and complete the detection of PCB defects.

6. The PCB defect detection method based on improved YOLOv8 as claimed in claim 5, characterized in that: The data enhancement method in step S1 at least includes cropping, flipping, rotating, color transformation and geometric transformation of the data, and the ratio of the training set, the validation set and the test set is 8:1:

1.

7. The PCB defect detection method based on improved YOLOv8 as claimed in claim 5, characterized in that: The evaluation indicators of step S3 include but are not limited to recall rate, precision rate, average precision rate, F1 score and frame rate. The recall rate indicates the proportion of actually positive samples that are also recognized as positive samples by the classifier to all actually positive samples. The specific calculation method is: Among them, FN represents the number of samples that are actually positive but predicted to be negative, and TP represents the number of samples that are actually positive but predicted to be positive; The precision rate indicates the proportion of positive samples that are actually positive samples and are also recognized as positive samples by the classifier to all positive samples recognized by the classifier, and is calculated by the following formula: Among them, FP represents the number of samples predicted to be positive when they are actually negative samples; The mean average precision represents the average value of AP values ​​of all categories and is calculated by the following formula: Among them, AP represents the average precision of different categories in the data set at different confidence thresholds, n represents the number of defect categories, and i represents the i-th category; The F1 score represents the harmonic mean of recall and precision and is calculated using the following formula: The frame rate represents the number of images that the algorithm can process per second and is calculated using the following formula: Where N represents the number of images to be detected, and T represents the time used to detect all images to be detected.