PCB small target defect detection method based on improved YOLOv8s
By improving the YOLOv8s network model, it solves the problems of low efficiency and high missed detection rate of traditional PCB defect detection methods, achieves efficient detection of small target defects, improves detection accuracy and speed, and is suitable for the needs of modern production lines.
Patent Information
- Application Number
- CN202410746698.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-09-03
AI Technical Summary
Traditional PCB defect detection methods have low efficiency and high miss detection rate, making it difficult to meet the strict requirements of modern production lines. In particular, the detection performance of small target defects is low.
Improve the YOLOv8s network model by adding a small target detection layer, introducing optional dilated convolution and attention fusion modules, designing a flexible spatial pyramid pooling layer, combining deformable convolution and spatial information enhancement modules, and improving the neck structure and Loss function to improve detection accuracy and efficiency of small targets.
Real-time and efficient detection of PCB small target defects on embedded devices is achieved, significantly improving detection accuracy and speed, and meeting the detection needs of modern production lines.
Smart Images

Figure CN118587188A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image classification, and in particular to a PCB small target defect detection method based on improved YOLOv8s. Background Art
[0002] With the miniaturization and high integration of electronic products, PCB defect detection faces greater challenges. Small target defects such as welding problems and short circuits are crucial to the reliability of electronic products, so it is particularly important to accurately detect these defects. Traditional PCB defect detection methods have limitations such as low efficiency, high missed detection rate, and strong subjectivity, which make it difficult to meet the strict requirements of modern production lines. To overcome these problems, automated detection methods based on computer vision are widely used. Their non-contact, high adaptability and versatility make them a hot technology in the current defect detection field.
[0003] Early PCB defect detection relied on image processing and feature extraction algorithms, such as edge detection and shape recognition. However, with the introduction of deep learning, detection methods are divided into two categories: methods based on traditional deep learning models (such as CNN) and methods based on target detection models. Methods based on traditional deep learning models mainly use convolutional neural networks and other methods for feature extraction and defect classification. Another method is to use target detection models, such as the YOLO series, Faster R-CNN, etc. These models can detect the location and category of defects at the same time, with higher detection accuracy and efficiency. However, these networks have high requirements on device computing power and low detection performance for small targets, so it is necessary to improve them. Summary of the invention
[0004] The purpose of the present invention is to provide a PCB small target defect detection method based on improved YOLOv8s to solve the problems raised in the above background technology.
[0005] To achieve the above-mentioned purpose, the present invention provides the following technical solutions: inputting an image training data set into an improved Yolov8s network model for training to obtain a target detection model; collecting real-time PCB image information by a camera and sending it to a defect recognition unit; the defect recognition unit includes a target detection module to obtain a PCB small target defect position recognition result, and the recognition process is performed on the trained improved Yolov8s network model.
[0006] The improved Yolov8s network model training method specifically includes: after the training set images are subjected to data enhancement operation, they are input into the improved Yolov8s network for training, so as to obtain a target detection model.
[0007] The improved Yolov8s network implementation method specifically includes: firstly, adding a small target detection layer and a small object detection head to improve the detection effect of small targets; secondly, introducing the selective dilated convolution (S-Conv) and the convolution and attention fusion module (CAFM) in the backbone network to achieve effective fusion of features of various scales by expanding the receptive field and enhancing the feature representation ability; at the same time, designing a flexible and efficient spatial pyramid pooling layer, combining deformable convolution and spatial information enhancement modules, to improve the model's representation ability and detection accuracy of target features; in addition, the neck structure is improved through the information aggregation-distribution mechanism. Finally, VFWD-CIoU is used to replace the original loss function to improve the detection performance of dense small targets.
[0008] The PCB small target defect recognition scheme specifically includes: collecting PCB image information by a camera, inputting it into a small target defect recognition unit, processing it by a trained improved Yolov8s model and outputting a recognition result.
[0009] The small target defect recognition unit specifically includes a target detection module, which is composed of a trained improved Yolov8s network model, and the output is the location of the PCB small target defect and the probability of whether it is detected as a PCB small target defect.
[0010] Compared with the prior art, the beneficial effects of the present invention are: adding a small target detection layer and adding a small object detection head to improve the detection effect of small targets; secondly, introducing a selective dilated convolution (S-Conv) and a convolution and attention fusion module (CAFM) in the backbone network, by expanding the receptive field and enhancing the feature representation ability, the effective fusion of features of various scales is achieved; at the same time, a flexible and efficient spatial pyramid pooling layer is designed, combined with a deformable convolution and a spatial information enhancement module, to improve the model's representation ability and detection accuracy of target features; in addition, the neck structure is improved through an information aggregation-distribution mechanism; finally, the loss function is improved, and VFWD-CIoU is used to replace the original loss function to improve the detection performance of dense small targets. The improved method of the present invention effectively solves the deficiencies in the prior art and realizes real-time and efficient detection of small target defects on PCBs on embedded devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 It is a schematic diagram of the functional modules of the present invention.
[0012] Figure 2 This is the improved YOLOv8 network structure diagram of the present invention
[0013] Figure 3 Optional dilated convolutional structure for use in the present invention.
[0014] Figure 4 This is a structural diagram of the CAFM used in the present invention.
[0015] Figure 5 Schematic diagram comparing the SPPF modules before and after the improvement of the present invention.
[0016] Figure 6 This is a diagram showing the detection results of the improved Yolov8s model of the present invention. Specific implementation methods
[0018] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0019] The invention provides a PCB small target defect detection method based on improved YOLOv8s. The method comprises the following steps: inputting an image training data set into an improved Yolov8s network model for training to obtain a target detection model; collecting real-time PCB board picture information by a camera and sending the information to a defect detection unit; the defect detection and recognition unit comprises a target detection module, and outputs a PCB small target defect position and a recognition result, wherein the recognition process is performed on the trained improved Yolov8s network model.
[0020] According to the classification of the training data set, the recognition types can be divided into several categories that are the same as the classification of the training data set. For example, the recognition types are divided into solder joint leakage, mouse bite, open circuit, short circuit, burr and excess copper.
[0021] The improved Yolov8s network model is implemented as follows: an image of size 640×640×3 is input, and after the improved backbone network extracts features, four feature maps of different sizes are sent to the Neck feature fusion network. The Neck network contains an improved spatial pyramid pooling layer, and uses deformable convolution and spatial information enhancement modules to improve the model's ability to characterize target features and detection accuracy. In addition, the neck structure is improved through an information aggregation-distribution mechanism. After feature fusion, the image is input into the improved Yolov8s network for classification, the classification result of the target detection module is obtained, and the detection result is displayed in the UI interface.
[0022] The improvement method of the Yolov8s network is as follows: the feature map fusion technology is introduced. This technology combines shallow detail information with deep semantic information by splicing feature maps of different levels to construct a more comprehensive and rich feature representation. Secondly, a special small object detection head is designed according to the characteristics of small targets. This detection head is located at the top of the entire target detection network and is directly connected to the neck network to ensure that the fused feature information can be fully utilized. The newly designed small object detection head corresponds to a 160×160 detection feature map, which means that it can handle smaller target areas. With this design, the model can more accurately detect small targets larger than 4×4 pixels and accurately predict their position and size. The new small target detection head will work together with the other three detection heads to provide the model with all-round, multi-scale feature information to assist the model in completing the final detection task.
[0023] The improvement method of the YOLOv8s network is as follows: the C2f module in the backbone is transformed with optional dilated convolution to obtain a new module ASC2f, which replaces the original C2f module in the backbone. Compared with the original C2f module, an optional parameter is introduced to control the expansion rate in the convolution operation, so that the network can select the appropriate expansion rate according to the characteristics of the input data, thereby obtaining better performance. At the same time, the number of network parameters and the amount of calculation are reduced, and the efficiency of the model is improved. Secondly, by expanding the receptive field, it helps the model to obtain a wider range of spatial information, better understand the entire PCB image, obtain better feature information, and improve the effect of target detection.
[0024] The improvement method of the YOLOv8s network is as follows: the convolution and attention fusion module CAFM is introduced. CAFM can extract features of different scales by designing a multi-scale feedforward network, thereby improving the detection performance of small targets. By placing it after the backbone and before the detect, the ability to extract global and local features is enhanced, which effectively improves the detection performance of small targets. The enhanced feature expression enables the model to automatically learn and strengthen important features, thereby improving the model's ability to understand and utilize data.
[0025] The YOLOv8s network is improved by combining deformable convolution and spatial information enhancement modules to improve SPPF, and aggregating features at different scales through multi-scale maximum pooling operations; then, the aggregated feature map is input into the deformable convolution layer to obtain a feature representation with an adaptive receptive field; then, the output of the deformable convolution is sent to the spatial information enhancement module to further enhance the spatial information of the feature map; finally, the enhanced features are fused through the convolution layer, and the size of the feature vector finally output by the backbone part of the model is adjusted. The introduction of the two modules makes it possible to effectively improve the feature extraction capability of the SPPF module without significantly increasing the number of model parameters. The deformable convolution enables the model to adapt to targets of different scales and shapes more accurately; and the spatial information enhancement module further enhances the spatial information of the feature map, making the model more accurate and reliable in distinguishing and locating targets.
[0026] The improvement method of the YOLOv8s network is as follows: the loss function is replaced by VFWD-CIoU from CIoU Loss, and WD Loss provides a metric value WD_IoU to measure the similarity between the predicted box and the true box. Then, the IoU part in CIoU Loss is replaced by WD_IoU, and the classification loss is processed in combination with Varifocal Loss. By combining WD Loss and Varifocal Loss to improve CIoU Loss, the performance of the target detection algorithm is further improved. The specific implementation formulas are as follows:
[0027]
[0028] Among them, α is a positive weight coefficient used to balance the impact of center point distance and aspect ratio difference, ρ 2 (C A ,C B ) is the square of the Euclidean distance between the center points of the bounding boxes A and B, d 2 is the square of the diagonal length of the smallest enclosing rectangle containing bounding boxes A and B, v is used to measure the aspect ratio, d is the distance measure between the two boxes, D max is the maximum possible value of this distance metric.
[0029] The following Table 1 shows the mAP@0.5, Precision, Recall and detection speed of Faster R-CNN, Yolov4, Yolov5s, YOLOv7, YOLOv7-tiny, Yolov8 and the improved Yolov8s provided in this embodiment in a GPU environment in an example, where the data set used for training and testing is a PCB defect data set provided by the Intelligent Robot Open Laboratory of Peking University.
[0030] Table 1:
[0031]
[0032] From Table 1, we can see that the improved YOLOv8 shows excellent performance in PCB small target defect detection. The improved YOLOv8 reaches 99.1% in the mAP@0.5 index, which is a significant improvement compared with the original YOLOv8. This shows that the model can more accurately identify defects and give accurate bounding boxes in PCB small target defect detection. The improved model reaches 53.9 in FPS, which is slightly lower than 57.8 of YOLOv7-tiny, but it is significantly improved compared with the original YOLOv8. This means that the model performs well in real-time and can quickly process and detect input images. By optimizing the model structure and parameters, the improved YOLOv8 achieves a reduction in model size and parameter quantity while maintaining high accuracy. This makes the model easier to deploy to edge devices or embedded systems, meeting the requirements of model size and computing resources in practical applications.
[0033] Figure 1 It is a schematic diagram of the functional modules of the present invention, which specifically includes: a camera collects PCB board image data, and the collected data is input into a PCB small target defect detection and identification unit; the PCB small target defect detection and identification unit includes a target detection module; the data is processed by an improved Yolov8s model to obtain a result.
[0034] Figure 2 The improved Yolov8s network structure diagram for the present invention is as follows: an image of size 640×640×3 is input, and after the features are extracted by the improved backbone network, four feature maps of different sizes are output and sent to the Neck feature fusion network. The Neck feature fusion network uses deformable convolution and spatial information enhancement modules to design a more flexible and effective spatial pyramid pooling layer to improve the model's ability to characterize target features and detection accuracy. At the same time, the information aggregation-distribution mechanism is integrated to improve the neck structure. A special small object detection head is designed. This detection head is located at the top of the entire target detection network and is directly connected to the neck network. Finally, the 4 layers of feature maps are passed through the four detection heads respectively for prediction.
[0035] Figure 3The optional atrous convolution structure used in the present invention is specifically as follows: by introducing an optional parameter to control the expansion rate in the convolution operation, the network can select a suitable expansion rate according to the characteristics of the input data, thereby obtaining better performance. At the same time, the network parameters and the amount of calculation are reduced, and the efficiency of the model is improved. Secondly, by expanding the receptive field, it helps the model to obtain more extensive spatial information and better understand the entire PCB image. The C2f module in the backbone is transformed with the optional atrous convolution to obtain a new module ASC2f, which replaces the original C2f module in the backbone, obtains better feature information, and improves the effect of target detection.
[0036] Figure 4 This is the CAFM structure diagram used in the present invention. Specifically, CAFM is introduced in YOLOv8 and placed after backbone and before detect to enhance the ability to extract global and local features, effectively improve the performance of small target detection, and enhance feature expression so that the model can automatically learn and strengthen important features, thereby improving the model's ability to understand and utilize data. For PCB small target detection, due to the small size of the target, CAFM can extract features of different scales by designing a multi-scale feedforward network, thereby improving the detection performance of small targets.
[0037] Figure 5 The schematic diagram of the comparison of the SPPF module before and after the improvement of the present invention. Specifically: first, the features are aggregated at different scales through multi-scale maximum pooling operations; then, the aggregated feature map is input into the deformable convolution layer to obtain a feature representation with an adaptive receptive field; then, the output of the deformable convolution is sent to the spatial information enhancement module to further enhance the spatial information of the feature map; finally, the enhanced features are fused through the convolution layer, and the size of the feature vector finally output by the Backbone part of the model is adjusted. The introduction of the two modules makes it possible to effectively improve the feature extraction capability of the SPPF module without significantly increasing the number of model parameters. The deformable convolution enables the model to adapt to targets of different scales and shapes more accurately; and the spatial information enhancement module further enhances the spatial information of the feature map, making the model more accurate and reliable in distinguishing and locating targets.
[0038] Figure 6 This is the effect diagram of the detection results of the improved Yolov8s model of the present invention. Specifically, it shows the performance of the improved YOLOv8s algorithm in processing six different defects: solder joint leakage, mouse bite, open circuit, short circuit, burr and excess copper.
[0039] Although the present invention has been disclosed as above in terms of preferred embodiments, they are not intended to limit the present invention. Anyone skilled in the art can make various changes or modifications without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection defined by the claims of this application.
Claims
1. A PCB small target defect detection method based on improved YOLOv8s, characterized by: The following steps are involved: Step 1: Use an image acquisition device to collect PCB board image data; Step 2: Divide the collected images into training sets and test sets in proportion, input the training data set into the improved Yolov8s network model for training, and obtain the target detection model; Step 3: The camera collects real-time PCB image information and sends it to the PCB small target defect recognition unit; Step 4: The recognition process is performed on the trained improved Yolov8s network model, and the detection results are displayed in real time on the UI interface.
2. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: The improved Yolov8s model training method adds a small target detection layer, combines the shallow detail feature map with the deep semantic feature map through feature fusion technology, and adds a small object detection head to enhance the perception ability of small targets.
3. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: The improved Yolov8s network introduces optional atrous convolution to improve the C2f module in the backbone network, designs a new module ASC2f to replace the C2f in the backbone, expands the receptive field, improves the feature representation capability and enhances the fusion of features of various scales, and introduces CAFM at the same time. By placing it after the backbone and before detect, the detection performance of small targets is improved.
4. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: In the SPPF module, all ordinary convolutional layers are replaced with deformable convolutional layers, and a spatial information enhancement module is added after the convolution operation to enhance the spatial information of the feature map through context aggregation.
5. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: In the neck structure, the information aggregation-distribution mechanism is integrated to achieve the aggregation and distribution of multi-scale features by building a GD module. At the same time, the number of layers of the neck structure is increased to introduce a new small target detection head.
6. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: The loss function of bounding box regression of the original model is replaced by VFWD-CIoU to improve the detection effect of dense small objects.
7. A PCB small target defect detection method based on improved YOLOv8s according to claim 1, characterized in that: The real-time PCB small target defect recognition method is as follows: a camera collects PCB image information, inputs it into a PCB small target defect recognition unit, and processes it with a trained improved Yolov8s model to output a recognition result.
Citation Information
Patent Citations
PCB small target defect detection method and system based on improved YOLOv5
CN115359016A
PCB defect detection and identification method based on YOLO-SEE
CN117372339A
PCB bare board defect detection method based on improved YOLOv8 neural network
CN118071733A
Textile materials with two tone effect used for skin layer of shoes and methods for manufacturing the same
KR1020250040195A
Cited By
Power transmission line multi-defect detection method and system based on improved YOLOv8s
CN119559479A
A method and system for detecting multiple defects in transmission lines based on improved YOLOv8s
CN119559479B
System and method for detecting internal defects of basin-type insulator based on pulse infrared thermal waves
CN119643638A
Construction method and detection method of insulator defect detection model based on CDC-YOLOv8, equipment and storage medium
CN119741584A
A construction and detection method, device and storage medium of an insulator defect detection model based on CDC-YOLOv8
CN119741584B
