Printed circuit board surface defect detection method based on improved YOLOv8

By introducing deformable multi-head attention, lightweight dynamic upsampling, hierarchical routing guidance attention mechanism and improved downsampling HDS fusion into the YOLOv8 algorithm, an improved YOLOv8 network is built, which solves the problems of low efficiency and insufficient accuracy of PCB surface defect detection in the prior art, and achieves fast and accurate defect detection and improved automation level.

CN120182676APending Publication Date: 2025-06-20SHANGHAI UNIV OF ENG SCI
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510234578.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

The prior art has problems such as low efficiency, large error, and high labor intensity in surface defect detection of printed circuit boards (PCBs). Especially when dealing with small target defects and complex backgrounds, Faster R-CNN is slow and YOLOv8 is low.

Method used

The YOLOv8 algorithm introduces deformable multi-head attention feature extraction fusion, lightweight dynamic upsampling, hierarchical routing guidance attention mechanism, and improved downsampling HDS fusion to build an improved YOLOv8 network for rapid and accurate detection of PCB surface defects.

Benefits of technology

It realizes rapid and accurate detection of PCB surface defects, reduces manual inspection costs, improves the automation level of the production line, and thus improves the quality control capabilities of PCB production.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120182676A_ABST
    Figure CN120182676A_ABST
Patent Text Reader

Abstract

The invention discloses a printed circuit board surface defect detection method based on improved YOLOv8, and belongs to the technical field of defect detection and image processing. Comprising the following steps: acquiring a public data set, constructing an improved YOLOv8 network, and modifying a C2f module by adopting deformable multi-head attention; an attention mechanism module BLRA is added behind the last module SPPF in the backbone and then output is carried out; a traditional up-sampling module is replaced with lightweight dynamic up-sampling DySample; and replacing the last three Conv modules in the backbone and the Conv module in the Neck with a lightweight down-sampling HDS module, carrying out target detection by using the trained improved YOLO v8 network, and outputting a target detection result. According to the invention, by improving the YOLOv8 network, rapid and accurate detection of PCB surface defects is realized, so that the quality control capability of PCB production is 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 defect detection and image processing, and particularly relates to a method for detecting surface defects of printed circuit boards based on improved YOLOv8. Background Art

[0002] With the rapid development of electronic products, printed circuit boards (PCBs), as the core components of electronic devices, their production quality is crucial to the performance and stability of the entire product. In the process of PCB manufacturing, the detection of surface defects is a key link to ensure product quality. Traditional methods for detecting surface defects of PCBs mostly rely on manual inspection or automated equipment based on simple image processing, which have problems such as low efficiency, large errors, and high labor intensity.

[0003] In recent years, with the development of deep learning technology, it has achieved remarkable results in the fields of image classification and object detection, and has become one of the main methods in defect detection. Faster R-CNN is a region-based object detection method. First, it extracts feature maps through a deep convolutional neural network (CNN), then uses a region proposal network (RPN) to generate candidate boxes, then classifies and regresses the bounding boxes of the candidate boxes, and finally removes duplicate detection boxes through non-maximum suppression (NMS) to output the accurate defect positions. YOLOv8, on the other hand, uses an end-to-end convolutional neural network, directly divides the input image into multiple grids, and each grid simultaneously predicts the category, bounding box, and confidence of the defect, removes the redundant boxes through non-maximum suppression, and finally outputs the detection results. In comparison, Faster R-CNN pays more attention to accuracy, while YOLOv8 performs better in terms of detection speed and real-time performance.

[0004] However, Faster R-CNN and YOLOv8 each have certain limitations in PCB defect detection. Although Faster R-CNN has an advantage in accuracy, its speed is slow. This is mainly because it uses a Region Proposal Network (RPN) to generate candidate regions, resulting in a large computational overhead and making it difficult to meet the real-time requirements. In addition, Faster R-CNN has a weak detection ability for small target defects. Especially when dealing with high-noise or complex backgrounds, it is prone to missed detections. Its computational resource consumption is high, especially when processing high-resolution images, which requires strong hardware support, limiting its application in the production environment. Although YOLOv8 has an advantage in detection speed, its accuracy is often low when dealing with small target defects. Especially for small or blurred defects, there may be missed detections or false detections. The fully convolutional network structure of YOLOv8 makes its performance inferior to some refined detection methods in complex backgrounds. Other circuit components, reflected light, or texture noise on the PCB surface may interfere with the detection process. In addition, when multiple defects appear simultaneously, YOLOv8 may have problems such as overlapping detection frames and label confusion, thus affecting the detection accuracy. In real-time detection scenarios, YOLOv8 may face the balance problem between accuracy and speed. Especially when dealing with complex or high-resolution images, more computational resources may be required to maintain high accuracy. Summary of the Invention

[0005] Aiming at the defects of the prior art, the present invention introduces deformable multi-head attention feature extraction and fusion, lightweight dynamic upsampling, hierarchical routing guided attention mechanism, and improved downsampling HDS fusion into the YOLOv8 algorithm to achieve fast and accurate detection of PCB surface defects, reduce the cost of manual detection, improve the automation level of the production line, and thus enhance the quality control ability of PCB production.

[0006] To achieve the above object, the present invention provides a method for detecting surface defects of printed circuit boards based on improved YOLOv8, including the following steps:

[0007] (1) Obtain a public dataset and perform preprocessing;

[0008] (2) Based on YOLOv8, construct an improved YOLOv8 network, including:

[0009] Use deformable multi-head attention to improve the last C2f module in the backbone and the last two C2f modules in the Neck;

[0010] Add an attention mechanism module BLRA after the last module SPPF in the backbone and then output;

[0011] Replace the traditional upsampling module in the Neck with a lightweight dynamic upsampling DySample;

[0012] Replace the last three Conv modules in the backbone and the Conv module in the Neck with a lightweight downsampling HDS module to achieve downsampling;

[0013] (3) Train the improved YOLOv8 network using the preprocessed public dataset to obtain a trained improved YOLO v8 network;

[0014] (4) Use the trained improved YOLO v8 network for object detection and output the object detection results.

[0015] Furthermore, the preprocessing includes random brightness adjustment, adding Gaussian noise, random scaling, and random rotation to expand the dataset.

[0016] Furthermore, the specific implementation of improving the C2f module in the backbone using deformable multi-head attention is as follows: Introduce a deformable multi-head attention DMHA module after 2 Conv modules in the Bottleneck module of the original C2f module.

[0017] Furthermore, the lightweight downsampling HDS module is specifically as follows: It includes two processing paths. One path reduces the dimension through two consecutive convolutional layers, and the other path extracts features through a consecutive pooling layer and convolutional layer. Finally, the outputs of the two paths are concatenated as the final output.

[0018] Furthermore, in the improved YOLOv8 network, use the NWD loss function weighted in combination with the WIOU loss function to replace the original CIOU loss function;

[0019] L NWD-WIOU =(1 - w n )L NWD + W n L WIOU

[0020] Where: L NWD-WIOU is the loss function of the improved YOLOv8 network, L NWD is the NWD loss function, L WIOU is the WIOU loss function, and w n is the weighting coefficient.

[0021] The present invention also provides a printed circuit board surface defect detection system based on the improved YOLOv8. The printed circuit board surface defect detection method based on the improved YOLOv8 includes:

[0022] A data acquisition module, which is used to obtain a public dataset and perform preprocessing;

[0023] A network modeling module, which is used to build an improved YOLOv8 network based on YOLOv8, including:

[0024] Using deformable multi-head attention to improve the last C2f module in the backbone and the last two C2f modules in the Neck;

[0025] Introducing an attention mechanism module BLRA after the last module SPPF in the backbone and then outputting;

[0026] Using lightweight dynamic upsampling DySample to replace the traditional upsampling module in the Neck;

[0027] Using a lightweight downsampling HDS module to replace the last three Conv modules in the backbone and the Conv module in the Neck to achieve downsampling;

[0028] A network training module, which is used to train the improved YOLOv8 network with the preprocessed public dataset to obtain a trained improved YOLO v8 network;

[0029] A detection module, which is used to perform target detection with the trained improved YOLOv network and output target detection results.

[0030] The present invention also provides a computer-readable storage medium storing a computer program, characterized in that when the computer program is executed by a processor, the method for detecting surface defects of a printed circuit board based on improved YOLOv8 as described above is implemented.

[0031] The present invention also provides an electronic device, including a memory and a processor, where the memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to execute the method for detecting surface defects of a printed circuit board based on improved YOLOv8 as described above.

[0032] Advantages of the present invention:

[0033] 1. Based on the YOLOv8 architecture, by using the C2f_DA module to replace the traditional C2f module, the present invention can flexibly allocate weights to features, significantly improving the detection ability for subtle defects on the surface of printed circuit boards. Secondly, through lightweight dynamic upsampling, the detailed reconstruction of the feature map is realized, enhancing the perception ability of target defects. Furthermore, by adding a hierarchical routing guided attention module, the feature fusion and multi-scale perception ability are improved. Finally, by improving downsampling, information loss can be reduced, the feature expression ability can be enhanced, and the balance of accuracy, speed and computing resources can be further achieved.

[0034] 2. In the defect detection task, the improved YOLOv8 has relatively low parameter quantity (Params) and floating-point operation quantity (FLOPS), and can achieve efficient detection performance in different software and hardware environments, with high real-time performance and accuracy. It effectively improves production efficiency and product quality, and provides a more reliable quality control solution for industrial manufacturing. Description of the Drawings

[0035] Figure 1 It is a schematic flow diagram of the printed circuit board surface defect detection method based on the improved YOLOv8 in the embodiment of the present invention.

[0036] Figure 2 It is a schematic diagram of the improved YOLOv8 network structure in the embodiment of the present invention.

[0037] Figure 3 It is a schematic diagram of the original YOLOv8 network structure in the embodiment of the present invention.

[0038] Figure 4 It is a schematic diagram of the improved C2f module (C2f_DA) structure introducing deformable multi-head attention in the embodiment of the present invention.

[0039] Figure 5 It is a schematic diagram of the lightweight dynamic upsampling DySample structure in the embodiment of the present invention.

[0040] Figure 6 It is a schematic diagram of the BLRA attention mechanism structure in the embodiment of the present invention.

[0041] Figure 7 It is a schematic diagram of the downsampling HDS structure in the embodiment of the present invention.

[0042] Figure 8 It is a detection result diagram using the improved YOLOv8 network. Detailed Embodiment

[0043] The present invention will be further explained below in conjunction with the drawings and embodiments.

[0044] As Figure 1 shown, the embodiment of the present invention provides a printed circuit board surface defect detection method based on the improved YOLOv8, including the following steps:

[0045] S101. Obtain a public dataset and perform preprocessing.

[0046] The present invention uses the publicly available dataset PKU-HRI, which contains six typical surface defects of PCBs, namely missing hole, mouse bite, open circuit, short, spur, and spurious copper.

[0047] The dataset contains 693 images, which are expanded to 6,237 images through image preprocessing methods such as random brightness adjustment, adding Gaussian noise, random scaling, and random rotation. These methods can simulate images under different conditions, increase the diversity of data, and enhance the robustness of the model. The dataset is divided into a training set, a validation set, and a test set according to a ratio of 7:2:1.

[0048] S102: Based on YOLOv8, construct an improved YOLOv8 network.

[0049] As Figure 2 shown, the embodiment of the present invention constructs an improved YOLOv8 network based on the YOLOv8 network for defect detection.

[0050] The improved YOLOv8 network, like the YOLOv8 network (as Figure 3 shown), includes BackBone, Neck, and Head. The main improvement points are as follows:

[0051] (1) Use deformable multi-head attention to improve the last C2f module in the backbone and the last two C2f modules in the Neck.

[0052] The traditional C2f module extracts key information in the image through channel and spatial context fusion, but this method often cannot flexibly handle local changes and detailed features in the image. To overcome the above problems, the improved YOLOv8 network introduces deformable multi-head attention (DMHA) to improve C2f. As Figure 4 shown, that is, in the Bottleneck module of the original C2f module, a deformable multi-head attention DMHA module is introduced after 2 Conv modules, thus obtaining C2f_DA to enhance the expression ability of the C2f module in the network.

[0053] First, generate reference points from the input feature map and adjust their positions according to the downsampling factor to ensure coverage of the entire feature map. Use a lightweight offset generation network to predict the offsets for each reference point to adapt to local feature variations. Then, sample features from the deformed positions through bilinear interpolation to ensure a larger receptive field and information coverage. For each sampled point, calculate its deformed key and value and convert them to a high-dimensional representation through a linear mapping.

[0054] Next, use deformable multi-head attention to perform dot product calculations on the deformed key and query vectors to obtain attention weights and aggregate the weighted values. Finally, concatenate the outputs of each head and perform a linear transformation through a projection matrix to obtain the final output representation.

[0055] Different from traditional self-attention mechanisms, DMHA enables the network to dynamically adjust its attention to different regions of the image according to local changes in the image by introducing the idea of deformable sampling. Especially for regions with detailed information or large variations, it can more precisely capture the key information in these regions.

[0056] The advantage of DMHA lies in its ability to adaptively and selectively focus on key regions of the image during the feature extraction process, rather than uniformly scanning the entire image. This mechanism dynamically selects the regions to be focused on by introducing deformable sampling, thus not only capturing local details but also effectively handling problems such as geometric transformations and scale changes in the image. In this way, the network can flexibly and precisely model objects with complex structures and achieve better performance in different tasks.

[0057] In addition, DMHA reduces the computational complexity through deformable sampling of local regions. Compared with traditional global attention mechanisms, DMHA only calculates the local regions relevant to the task, thus significantly reducing the computational amount and memory consumption. In the case of high-resolution images or when dealing with a large amount of input data, this optimization is particularly important, which can significantly improve the efficiency and inference speed of the network while ensuring detection accuracy.

[0058] After introducing DMHA, the C2f module can better handle local changes and detailed features in the image. Especially when facing complex backgrounds or changing object shapes, it can more accurately identify and locate targets. This improvement not only enhances the network's feature extraction ability but also strengthens the model's robustness in various complex scenarios, enabling it to better adapt to various tasks.

[0059] (2) Add an attention mechanism module BLRA after the last module SPPF in the backbone and then output.

[0060] In industrial production, the defects of PCB bare boards usually appear as small targets. When performing defect detection, different detection heads are often designed for targets of different scales in order to process small, medium, and large-scale targets separately. However, for small targets, if the same weights are assigned to these three different-scale targets, it will lead to unnecessary computational overhead, thus reducing the detection efficiency. To address this problem, the improved YOLOv8 network introduces an attention mechanism module BLRA (BiLevel Routing Attention) after the last module SPPF in the backbone.

[0061] As Figure 5 shown, BLRA is divided into two stages, and the intermediate feature map X ∈ R H×W×C is used as the input and passes through these two stages in sequence to infer the correlation of the divided regions.

[0062] In the first stage, first, the feature map is used as the input, and three tensors Q, K, and V are obtained through linear mapping. Then the feature map is divided into multiple coarse-grained blocks, and self-attention calculations are performed on these coarse-grained blocks. The regional-level Q r , K r are respectively obtained by using the regional average values on Q and K within each coarse-grained block. Through Q r and K r , the adjacency matrix A r of the affinity map of non-overlapping regions in the feature map is calculated. A r is used to measure the correlation degree, that is, the correlation, between different coarse-grained blocks (i.e., two regions) at the semantic level.

[0063] A r = Q r (K r ) T

[0064] Then, the indices of the top k elements with the largest correlation are found from the matrix A r to form the relationship index matrix I r :

[0065] I r = top(k)Index(A r )

[0066] In the second stage, based on the relationship index matrix obtained in the first stage Further perform fine-grained self-attention calculation on the feature map. Through sparsity operations, parts with low correlation to the target area are skipped, thus saving the number of parameters and computational volume and improving the speed of the model in processing the input PCB feature map. Finally, in order to more effectively extract the contour features of the detection target, the attention mechanism focuses on the most relevant key-value pairs, ensuring that the model can focus on the main content of the target and improving the detection accuracy. Specifically as follows:

[0067] Use the token-to-token attention mechanism and obtain the key tensor K r through the relationship index matrix I g and the value tensor V g :

[0068] K g = gather(K, I r )

[0069] V g = gather(V, I r )

[0070] For the obtained K g and V g use the attention mechanism and combine with the query tensor Q to obtain the output tensor O:

[0071] O = Attention(Q, K g , V g ) + LCE(V)

[0072] where: LCE(V) is the local context enhancement function, which can be parameterized through depth convolution, thus enabling a fine-grained Token-to-Token (T2T) attention mechanism.

[0073] (3) Replace the traditional upsampling method in Neck with the lightweight dynamic upsampling DySample.

[0074] As Figure 6 shown, the DySample (Dynamic Sample) module is an efficient and lightweight upsampling technique. Through a point-based sampling strategy, from a learning perspective, it directly performs upsampling without relying on dynamic convolution or additional sub-networks. This method effectively preserves the details and defect features in the upsampling process, thus significantly improving the detection accuracy and efficiency.

[0075] The grid sampling function grid_sample takes in a feature map X of shape C×H1×W1 and a set of sampling coordinates S of shape 2×H2×W2, samples X using bilinear interpolation according to the positions specified in S, and outputs a new feature map X′ of size C×H2×W2. The specific process is as follows:

[0076] X′ = grid_sample(X, S)

[0077] Given the upsampling scale factor of S and a feature map X of size C×H×W, a linear layer is used to generate an offset P of size 2S 2 ×H×W, which is then converted to a size of 2×sh×sw through a pixel rearrangement operation, where s represents the scale of the upsampling factor, and h and w are the height and width of the target size. The number of input and output channels of the linear layer are C and 2S respectively 2 . Through an addition operation, the sampling set s is the sum of the offset P and the original sampling grid G, that is:

[0078] P = linear(X)

[0079] S = G + P

[0080] To enhance the flexibility of the offset, an adaptive range factor can be generated point - by - point by linearly projecting the input feature map. The key to this process is to generate an adaptive offset for each position, enabling the upsampling process to adjust the sampling points according to the features at different positions, thereby improving the accuracy and flexibility of upsampling. Therefore, the formula can also be re - expressed as:

[0081] P = 0.5 * sigmoid(linear2(X)) * linear1(X)

[0082] Where: linear1 and linear2 refer to two linear layers respectively. linear2 is responsible for generating the dynamic range factor, generating a point - by - point dynamic adjustment factor through linear projection, which is used to adjust the amplitude of the offset. To ensure that the generated factor is within a reasonable range, the Sigmoid function and a static factor of 0.5 are used to limit the output within the interval [0, 0.5] centered around 0.25. linear1 is another linear layer directly used to generate the offset. The generated offset is multiplied by the dynamic range factor output by linear2 to obtain the final offset P. This design enables the model not only to generate offsets but also to dynamically adjust the range of the offsets, thereby improving the flexibility of the model. In this way, the model can more precisely control the offset of each point during upsampling, reducing the boundary jagged effect and detail blurring problems caused by overlapping sampling, and thus improving the quality of image reconstruction and feature retention.

[0083] (4) Replace the last three Conv modules in the backbone and the Conv module in the Neck with lightweight downsampling HDS modules to achieve downsampling.

[0084] HDS (Hybrid DownSampling) aims to optimize the feature retention ability and computational efficiency during the downsampling process. Generally, the downsampling operation causes a reduction in the spatial dimension, inevitably losing some detailed information, which is particularly challenging when dealing with high-resolution images. To address this issue, the HDS module adopts a multi-path parallel processing strategy, integrating the advantages of convolutional layers and pooling layers, enabling the downsampling process to not only effectively compress the spatial dimension but also maximize the retention of key information, thus maintaining a high feature expression ability while ensuring the dimensionality reduction efficiency.

[0085] As Figure 7 shown, the lightweight downsampling HDS module specifically includes: two processing paths, one for dimensionality reduction through two consecutively connected convolutional layers, and the other for feature extraction through a consecutively connected pooling layer and convolutional layer. Finally, the outputs of the two paths are concatenated as the final output.

[0086] Through this parallel processing method, HDS can more fully extract key information from the input data and fuse the results of the two paths, thus balancing the relationship between feature retention and spatial compression during the downsampling process. This method not only improves the downsampling efficiency but also enables the model to better capture detailed information and global features when dealing with high-resolution images or complex vision tasks.

[0087] Therefore, the HDS module is a refined downsampling strategy, especially in the processing of high-resolution images and complex vision tasks, which can significantly improve the performance of the model. In scenarios with limited computational resources, HDS provides strong support for the efficient operation of the model by optimizing the computational amount and enhancing the feature expression ability.

[0088] The improved YOLOv8 network replaces the C2f module in the original backbone with the C2f_DA module, enhancing the network's ability to extract PCB surface defect features; uses the lightweight dynamic upsampling DySample to replace the traditional upsampling method in the Neck, which can achieve more accurate feature recovery, improve the model's accuracy, reduce the computational load, and enhance the generalization ability; integrates BLRA into the PCB defect detection model, improving the feature fusion and multi-scale perception ability, effectively enhancing the model's accuracy, robustness, and efficiency. Especially when dealing with complex PCB defects, it can significantly improve the detection performance; uses the lightweight downsampling HDS module to replace the downsampling module in the original model, which can reduce information loss, enhance the feature expression ability, and further balance accuracy, speed, and computational resources.

[0089] S103. Train the improved YOLOv8 network using the preprocessed public dataset to obtain a trained improved YOLOv8 network.

[0090] The original YOLOv8 uses the CIOU loss function, which performs poorly on smaller defects and does not consider the balance of easy and hard samples. To address the above problems, the present invention chooses to replace the original CIOU loss function with the NWD loss function weighted and combined with the WIOU function (abbreviated as NWD-WIOU).

[0091] IOU is mainly used to measure the overlap degree between the predicted bounding box and the ground truth bounding box, and is one of the key indicators for evaluating the model's performance. When used for low-pixel targets, IOU has obvious drawbacks. For low-pixel defects with a slight position shift, the IOU value will drop significantly, being overly sensitive to position deviations. However, the NWD metric has unique advantages and can properly handle the overlap problem caused by the aggregation of low-pixel defects. The calculation process of the NWD loss function is as follows: After quadratic modeling of the Gaussian distribution of the bounding box, the second-order Wasserstein distance between two two-dimensional Gaussian distributions μ1 = N(m1, ∑1) and μ2 = N(m2, ∑2) is defined as:

[0092]

[0093] After simplification, it can be written as:

[0094]

[0095] Where: ||·|| represents the Frobenius norm.

[0096] In addition, for the Gaussian distributions N a and N b , It is a distance metric and cannot be directly used as a similarity measure. Therefore, its exponential normalization is performed to obtain a new metric called the normalized Wasserstein distance, which simplifies to:

[0097]

[0098] where: c is a constant.

[0099] Therefore, the NWD loss function is:

[0100] L NWD = 1 - NWD(N a , N b ).

[0101] The CIOU function has certain limitations. It does not consider the problem of uneven distribution of easy and difficult samples in the samples. Therefore, the present invention introduces the WIOU loss function to solve this problem. This loss function adopts a dynamic non-monotonic focusing gradient gain allocation method. The calculation process of WIOU can be expressed as

[0102] L WIOU = R WIOU L IOU

[0103]

[0104] where: L IOU is the value of the ordinary loss function, and R WIOU represents the penalty term of this function. When R WIOU is in the interval [1, e), it increases L IOU of the ordinary anchor box. When L IOU is in the interval [0.1], it decreases R WIOU of the high-quality anchor box. (x, y) is the true position of the target box, and (x gt , y gt ) is the corresponding position of the predicted box. H g and W g represent the height and width of the smallest bounding box formed by the target box and the predicted box.

[0105] Finally, the improved YOLOv8 network loss function is:

[0106] L NWD-WIOU = (1 - w n )L NWD + w n L WIOU

[0107] where: w n refers to the weighting coefficient, which is used to control the proportion of the two types of loss functions. w nThe larger it is, the smaller the proportion of the NWD loss function. The weighting coefficients used for different datasets vary. Generally speaking, if the proportion of small targets in the dataset is relatively high, the appropriate weighting coefficient value will be relatively small; conversely, a larger weighting coefficient value should be selected.

[0108] In the embodiments of the present invention, the improved YOLOv8 network is trained using the NWD-WiseIou loss function and the SGD optimizer on the training set. The trained model is verified using the test set.

[0109] The evaluation metrics include accuracy, recall, frames per second, floating-point operation count, etc., to comprehensively evaluate the performance of the model. Finally, the improved YOLOv8 network is compared and tested with existing mainstream network models on the same validation set, as Figure 8 shown. The results are listed in the following table.

[0110] Table 1

[0111]

[0112] As can be seen from Table 1, the improved YOLOv8 network (ours) has achieved good results compared with other network models.

[0113] S104. Use the trained improved YOLOv8 network for target detection and output the target detection results.

[0114] The embodiments of the present invention also provide a printed circuit board surface defect detection system based on the improved YOLOv8, including:

[0115] A data acquisition module for acquiring a public dataset and performing preprocessing;

[0116] A network modeling module for constructing an improved YOLOv8 network based on YOLOv8, including:

[0117] Use deformable multi-head attention to improve the last C2f module in the backbone and the last two C2f modules in the Neck.

[0118] Add an attention mechanism module BLRA after the last module SPPF in the backbone and then output.

[0119] Use lightweight dynamic upsampling DySample to replace the traditional upsampling module in the Neck.

[0120] Use a lightweight downsampling HDS module to replace the last three Conv modules in the backbone and the Conv module in the Neck to achieve downsampling.

[0121] A network training module, configured to train the improved YOLO network using the preprocessed public dataset to obtain a trained improved YOLO network.

[0122] A detection module, configured to perform object detection using the trained improved YOLO network and output the object detection result.

[0123] An embodiment of the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the above-mentioned printed circuit board surface defect detection method based on improved YOLOv8.

[0124] An electronic device according to an embodiment of the present invention includes a memory and a processor. The memory stores a computer program, which, when executed by the processor, implements the above-mentioned printed circuit board surface defect detection method based on improved YOLOv8.

[0125] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can be made, and these improvements and modifications should also be regarded as the protection scope of the present invention.

Claims

1. A printed circuit board surface defect detection method based on improved YOLOv8, characterized in that: The steps include: (1) Obtain public datasets and perform preprocessing; (2) Based on YOLOv8, an improved YOLOv8 network is constructed, including: Use deformable multi-head attention to improve the last C2f module in backbone and the last two C2f modules in Neck; Add the attention mechanism module BLRA after the last module SPPF in the backbone and then output it; The lightweight dynamic upsampling DySample is used to replace the traditional upsampling module in Neck; the lightweight downsampling HDS module is used to replace the last three Conv modules in backbone and the Conv module in Neck to achieve downsampling; (3) using the preprocessed public data set to train the improved YOLOv8 network to obtain a trained improved YOLOv8 network; (4) Use the trained improved YOLOv8 network to perform target detection and output the target detection results.

2. The printed circuit board surface defect detection method based on improved YOLOv8 according to claim 1, characterized in that: The preprocessing includes random brightness adjustment, adding Gaussian noise, random scaling and random rotation to expand the data set.

3. The printed circuit board surface defect detection method based on improved YOLOv8 according to claim 1, characterized in that: The method of improving the C2f module in the backbone by using deformable multi-head attention is specifically as follows: a deformable multi-head attention DMHA module is introduced after two Conv modules in the Bottleneck module in the original C2f module.

4. The printed circuit board surface defect detection method based on improved YOLOv8 according to claim 1, characterized in that: The lightweight downsampling HDS module specifically includes two processing paths, one for dimensionality reduction through two sequentially connected convolutional layers, and the other for feature extraction through sequentially connected pooling layers and convolutional layers, and finally the two outputs are spliced ​​as the final output.

5. The printed circuit board surface defect detection method based on improved YOLOv8 according to claim 1, characterized in that: In the improved YOLOv8 network, the original CIOU loss function is replaced by the weighted NWD loss function combined with the WIOU loss function; L NWD-WIOU =(1-w n )L NWD +w n L WIOU Where: L NWD-WIOU is the loss function of the improved YOLOv8 network, L NWD is the NWD loss function, L WIOU is the WIOU loss function, w n Refers to the weighting coefficient.

6. A printed circuit board surface defect detection system based on improved YOLOv8, based on the printed circuit board surface defect detection method based on improved YOLOv8 according to any one of claims 1 to 5, characterized in that: include: Data collection module, used to obtain public data sets and perform preprocessing; The network modeling module is used to build an improved YOLOv8 network based on YOLOv8, including: Use deformable multi-head attention to improve the last C2f module in backbone and the last two C2f modules in Neck; Add the attention mechanism module BLRA after the last module SPPF in the backbone and then output it; The lightweight dynamic upsampling DySample is used to replace the traditional upsampling module in Neck; the lightweight downsampling HDS module is used to replace the last three Conv modules in backbone and the Conv module in Neck to achieve downsampling; A network training module, used to train the improved YOLOv8 network using the preprocessed public data set to obtain a trained improved YOLO v8 network; The detection module is used to perform target detection using the trained improved YOLO v8 network and output the target detection results.

7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the printed circuit board surface defect detection method based on improved YOLOv8 is implemented as described in any one of claims 1 to 5.

8. An electronic device, comprising a memory and a processor, characterized in that: The memory stores a computer program, and when the computer program is executed by the processor, the processor executes the printed circuit board surface defect detection method based on improved YOLOv8 as described in any one of claims 1 to 5.

Citation Information

Cited By

  • Novel PCB surface defect detection method

    CN121304543A