PCB bare board defect detection method based on improved YOLOv8 neural network
Patent Information
- Application Number
- CN202410411025.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-08
- Publication Date
- 2024-10-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the 5G era, the sophistication and layout complexity of PCB bare boards make traditional defect detection inefficient and less accurate. In particular, it is more difficult to detect defects with small feature scales. Existing deep learning methods still have insufficient accuracy and adaptability. Room for improvement.
Using the improved YOLOv8 neural network, by introducing the focus modulation module and the BEMA attention module, combined with the Inner-Shape-Iou loss function, the network's processing capabilities for images of different sizes and target positioning accuracy are improved, and the image contrast is enhanced through Gamma transformation to improve the model generalization ability and regression performance.
Significantly improved the accuracy and regression rate of PCB bare board defect detection. Compared with the original YOLOv8 model, the accuracy rate increased by 13.3%, the regression rate increased by 8.2%, map50 increased by 4%, and map50-95 increased by 15.7%. It is suitable for 5G PCB High-precision detection.
Smart Images

Figure CN118071733B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of PCB defect detection, and in particular relates to a PCB bare board defect detection method based on an improved YOLOv8 neural network. Background Art
[0002] In the manufacture of printed circuit boards, it is difficult to avoid defects in bare PCBs. Defective bare PCBs will affect their use. Therefore, it is crucial to perform defect detection before bare PCBs are put into use.
[0003] With the advancement of the 5G era and the continuous development of PCB bare boards, PCB bare boards are becoming more and more sophisticated, with dense layouts and complex circuits, which brings certain difficulties to defect detection. Defect detection of 5G PCB bare boards belongs to target detection and classification in the field of computer vision. Common defects mainly include 6 categories: burrs, residual copper, gaps, short circuits, open circuits, and holes. Traditional defect detection is mainly carried out by manual visual inspection. Long-term manual work will not only cause visual fatigue and easily produce errors, but also the efficiency of manual inspection is low, which is not suitable for large-scale PCB product production; in addition, for large-size PCBs, the acquisition camera has a limited field of view and cannot complete the complete image acquisition at one time. Therefore, it is necessary to collect block images with overlapping areas multiple times, and then stitch the images into a complete PCB image.
[0004] Defect detection based on computer vision is mainly divided into two directions. The first is based on traditional image processing methods, such as defect detection using template matching. Although this method is simple and intuitive, and has low detection costs, it is sensitive to rotation, scaling, deformation and noise of defects. If the target defect does not completely match the template, the detection performance may decrease. At the same time, when the layout in the PCB image is complex, it is difficult for template matching to detect all defects in the image. The second is a defect detection method based on deep learning. This method has certain robustness to deformation, noise and changes in illumination in PCB images. At the same time, in the face of different types of PCB defect detection problems, it can adapt to various scenarios by adjusting the network structure and training strategy, and has strong adaptability. Although the PCB defect detection method based on deep learning has certain advantages in the application of 5G PCB field, there is also room for improvement. Specifically, the 5G PCB has a denser circuit layout than the traditional PCB, and the feature scale on the circuit board is smaller, which makes the defect detection accuracy lower. Summary of the invention
[0005] The purpose of the present invention is to provide a PCB bare board defect detection method based on an improved YOLOv8 neural network. The method improves the accuracy and regression rate of PCB bare board defect detection after improving the traditional YOLOv8 neural network, and is suitable for defect detection and classification of PCB bare boards.
[0006] To achieve the above object, the present invention adopts the following technical solution:
[0007] A PCB bare board defect detection method based on an improved YOLOv8 neural network comprises the following steps:
[0008] Step 1: Obtain the block images of the PCB bare board, and stitch the block images into a complete PCB bare board image, and output the YOLO format dataset after preprocessing the PCB bare board image;
[0009] Step 2: Input the YOLO formatted data set into the trained improved Yolov8 neural network for PCB bare board defect detection and classification;
[0010] The improved Yolov8 neural network includes a backbone network, a neck network and a detection head network; the backbone network includes a first convolutional layer, a second convolutional layer, a first C2f module, a third convolutional layer, a second C2f module, a fourth convolutional layer, a third C2f module, a fifth convolutional layer, a fourth C2f module and a focus modulation module connected in sequence;
[0011] The neck network includes a first upsampling module, a first splicing module, a fifth C2f module, a second upsampling module, a second splicing module, a first BEMA module, a sixth convolutional layer, a third splicing module, a second BEMA module, a seventh convolutional layer, a fourth splicing module, and a third BEMA module; the focus modulation module is connected to the first upsampling module, the first splicing module splices the features output by the first upsampling module with the features output by the third C2f module and inputs them to the fifth C2f module and the second upsampling module, the features output by the second upsampling module and the features output by the second C2f module are spliced by the second splicing module and input to the first BEMA module and the sixth convolutional layer; the features output by the sixth convolutional layer and the features output by the fifth C2f module are spliced by the third splicing module and input to the second BEMA module and the seventh convolutional layer, the features output by the seventh convolutional layer and the features output by the focus modulation module are spliced by the fourth splicing module and input to the third BEMA module; the features output by the first BEMA module, the second BEMA module, and the third BEMA module are input to the detection head network;
[0012] The BEMA module includes a convolution module, a batch normalization module, an EMA attention module, a first convolution-normalization-activation module, a fifth splicing module, a random discarding module, a second convolution-normalization-activation module, and a sixth splicing module connected in sequence; the fifth splicing module is also connected to the EMA attention module, and the sixth splicing module is also connected to the convolution module;
[0013] The loss function of the detection head network adopts the Inner-Shape-Iou function, and the Inner-Shape-Iou function model is as follows:
[0014] L Iner-shape-Iou =1-IoU inner +distance shape +0.5Ω shape ;
[0015] Among them, L Inner-Shape-Iou is the loss function, IoU inner is the position information between the real bounding box and the predicted bounding box, distance shape It is the degree of deviation of the center point of the predicted bounding box relative to the center point of the true bounding box.
[0016] θ=4,Ω shape is the shape cost, w w is an indicator to measure the width difference between the predicted bounding box and the true bounding box; w h is an indicator to measure the height difference between the predicted bounding box and the true bounding box; θ is the weight of the shape cost; w and h are the width and height of the predicted bounding box;
[0017] hh and ww are the weight coefficients in the height direction and width direction respectively, and c is the weight coefficient of the predicted bounding box B and the real bounding box B gt The diagonal distance of the minimum enclosing bounding box between c ,y c ) is the center coordinate of the predicted bounding box B, is the ground-truth bounding box B gt The center point coordinates of
[0018]
[0019] inter is the intersection area of the two bounding boxes, is the length of the horizontal intersection of the two bounding boxes, that is, the smaller value of the right boundary of the two bounding boxes minus the larger value of the left boundary, is the length of the vertical intersection of the two bounding boxes, that is, the smaller value of the bottom boundaries of the two bounding boxes minus the larger value of the top boundaries;
[0020] union=(w gt ×h gt )×(ratio) 2 +(w×h)×(ratio) 2 -inter, ratio is the scale factor, w gt and h gt is the width and height of the real bounding box, w and h are the width and height of the predicted bounding box, ratio is the scale factor, ratio = 0.65.
[0021] Furthermore, the preprocessing in step 1 refers to first converting the PCB bare board image into a grayscale image, then performing a Gamma transformation on the grayscale image to achieve image enhancement; and finally converting it into a data set in a YOLO format.
[0022] Furthermore, small-size PCB bare board images are used to create training data sets and test data sets for training the improved YOLOv8 neural network.
[0023] The present invention adopts the focus modulation module FocalModulation suitable for small targets to replace the original SPPF module, introduces a branch structure in the EMA attention mechanism to form a new branch attention BEMA attention module, replaces the original C2f module, and comprehensively considers the position information Inner_IOU, distance information and shape relationship Shape_IOU of the defect detection boundary box to propose a new Inner-Shape-Iou loss function, so that the improved network can not only process input images of different sizes, but also more accurately locate the target in the image, improve the generalization ability of the model, and improve the regression performance of the model. The present invention can improve the regression rate of defect detection while ensuring the improvement of the accuracy of PCB bare board defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a brief schematic diagram of the process of the present invention.
[0025] Figure 2 It is a schematic diagram of the network structure of the present invention.
[0026] Figure 3 It is a schematic diagram of the BEMA module structure of the present invention.
[0027] Figure 4 It is a schematic diagram of PCB detection and classification of the present invention. DETAILED DESCRIPTION
[0028] like Figure 1 As shown, the present embodiment provides a PCB bare board defect detection method based on an improved YOLOv8 neural network, comprising the following steps:
[0029] Step 1: Get the block images of the PCB bare board, stitch the block images into a complete PCB bare board image, and preprocess the PCB bare board image. Preprocessing means first converting the PCB bare board image into a grayscale image, then performing Gamma transformation on the grayscale image to achieve image enhancement; finally, convert it into a YOLO format data set.
[0030] Gamma transformation enhances the contrast of images under different lighting conditions to facilitate more accurate labeling of various defects on bare PCB boards, and is also beneficial for subsequent neural network training.
[0031] Step 2: Input the YOLO format data set into the trained improved Yolov8 neural network for PCB bare board defect detection and classification.
[0032] This embodiment improves the Yolov8 neural network structure as follows Figure 2 As shown, it includes a backbone network, a neck network and a detection head network.
[0033] In this embodiment, the SPPF module in the backbone network is replaced with a focal modulation module, and the backbone network includes a first convolutional layer, a second convolutional layer, a first C2f module, a third convolutional layer, a second C2f module, a fourth convolutional layer, a third C2f module, a fifth convolutional layer, a fourth C2f module and a focal modulation module connected in sequence. In this embodiment, the original SPPF module is replaced with a FocalModulation module, so that the network can not only process input images of different sizes, but also more accurately identify and locate targets in the image.
[0034] In this embodiment, the last three C2f modules in the neck network are all replaced by BEMA modules. The neck network includes a first upsampling module, a first splicing module, a fifth C2f module, a second upsampling module, a second splicing module, a first BEMA module, a sixth convolutional layer, a third splicing module, a second BEMA module, a seventh convolutional layer, a fourth splicing module, and a third BEMA module; the focus modulation module is connected to the first upsampling module, the first splicing module splices the features output by the first upsampling module with the features output by the third C2f module and inputs them to the fifth C2f module and the second upsampling module, the features output by the second upsampling module and the features output by the second C2f module are spliced by the second splicing module and input to the first BEMA module and the sixth convolutional layer; the features output by the sixth convolutional layer and the features output by the fifth C2f module are spliced by the third splicing module and input to the second BEMA module and the seventh convolutional layer, the features output by the seventh convolutional layer and the features output by the focus modulation module are spliced by the fourth splicing module and input to the third BEMA module; the features output by the first BEMA module, the second BEMA module, and the third BEMA module are input to the detection head network.
[0035] The BEMA module structure of this embodiment is as follows Figure 3 As shown in the figure, a new branch attention BEMA is formed by introducing a branch structure into the EMA attention mechanism. The BEMA module includes a convolution module, a batch normalization module, an EMA attention module, a first convolution-normalization-activation module, a first splicing module, a random discard module, a second convolution-normalization-activation module, and a second splicing module connected in sequence; the first splicing module is also connected to the EMA attention module, and the second splicing module is also connected to the convolution module; the EMA attention module outputs component 1 and component 2 in a branch structure, component 2 is spliced with component 1 after the convolution-normalization-activation module, and the second convolution-normalization-activation module is spliced with the component of the convolution module for output, and the output of EMA after the first convolution-normalization-activation module is spliced with the output of EMA itself, which can integrate the characteristics of the two and enhance the diversity and representation ability of features. The BEMA module divides the output of the convolution module into two components. Through decomposition and reorganization, it can improve the network's perception of different features, and at the same time can help the network better capture local and global information in the data and improve the representation ability of features. The EMA attention mechanism module is introduced into the BEMA module, which enables the network to pay more attention to the features that have a greater impact on the task and improves the network's ability to process important features. The random dropout module is used for regularization, which can effectively reduce the risk of overfitting and improve the generalization ability of the model.
[0036] The network structure of the detection head network in this embodiment does not change, only the loss function in the network structure is changed. The loss function of this embodiment adopts the Inner-Shape-Iou function, and the Inner-Shape-Iou function model is as follows:
[0037] L Inner-Shape-Iou =1-IoU inner +distance shape +0.5Ω shape ;
[0038] Among them, L Inner-Shape-Iou is the loss function, IoU inner is the position information between the real bounding box and the predicted bounding box, distance shape It is the degree of deviation of the center point of the predicted bounding box relative to the center point of the true bounding box.
[0039] θ=4,Ω shape is the shape cost, w w is an indicator to measure the width difference between the predicted bounding box and the true bounding box; w his an indicator for measuring the height difference between the predicted bounding box and the true bounding box; θ is the weight of the shape cost, and the weight in this embodiment is 4.
[0040] hh and ww are the weight coefficients in the height direction and width direction respectively, and c is the weight coefficient of the predicted bounding box B and the real bounding box B gt The diagonal distance of the minimum enclosing bounding box between c ,y c ) is the center coordinate of the predicted bounding box B, is the ground-truth bounding box B gt The center point coordinates of
[0041]
[0042] inter is the intersection area of the two bounding boxes, is the length of the horizontal intersection of the two bounding boxes, that is, the smaller value of the right boundary of the two bounding boxes minus the larger value of the left boundary, is the length of the vertical intersection of the two bounding boxes, that is, the smaller value of the bottom boundaries of the two bounding boxes minus the larger value of the top boundaries;
[0043] union=(w gt ×h gt )×(ratio) 2 +(w×h)×(ratio) 2 -inter, ratio is the scale factor, w gt and h gt is the width and height of the real bounding box, w and h are the width and height of the predicted bounding box, ratio is the scale factor, ratio = 0.65.
[0044] The Inner-Shape-Iou loss function of this embodiment comprehensively considers the position information Inner_IOU, distance information and shape relationship of the bounding box, which can improve the generalization ability of the model and improve the regression performance of the model.
[0045] Since the number of PCB bare board samples is limited, this embodiment uses small-sized PCB bare board images to prepare training data sets and test data sets, and improves the Yolov8 neural network through small-sized PCB bare board images and their defect detection training.
[0046] The method of this embodiment and the traditional YOLOv8 neural network are used to compare the defects of 5G PCB bare boards. A camera is used to collect images of PCB bare boards, and the collection size is size=640 pixels×640 pixels. The PCB image resolution is 1917×1014 pixels. The LabelImg annotation tool is used to annotate the binary images of the PCB bare boards, and 6 types of defects are annotated, namely, open circuit, short circuit, notch, burr, residual copper, and hole. The corresponding category labels are: 0, 1, 2, 3, 4, 5, and the corresponding names are: open, short, mousebite, spur, copper, pin-hole, and the ratio of training set to verification set is 9:1; and the data set is saved in YOLO format; the detection network includes YOLOv8 original network, YOLOv8+EMA network, YOLOv8+FocalModulation network and the network model of this embodiment; this embodiment is YOLOv8+FocalModulation+BEMA; wherein the network setting parameters are shown in Table 1.
[0047] Table 1 Parameter unified configuration
[0048]
[0049] The device parameters used in this embodiment are as follows: processor: 12th Gen Intel(R)Core(TM)i9-12900HX 2.30GHz; GPU graphics card information: NVIDIAGeForce RTX 3080Ti Laptop GPU; Python interpreter information: Python3.9, Torch1.13.1; the network detection results are judged by accuracy, regression rate, map50 and map50-95, and the comparison of ablation experiment results is shown in Table 2.
[0050] Table 2 Network model detection results evaluation table
[0051]
[0052] The results show that the accuracy of the network model of this embodiment is improved by 13.3%, the regression rate is improved by 8.2%, the map50 is improved by 4%, and the map50-95 is improved by 15.7% compared with the original YOLOv8 model, proving that the improved YOLOv8 neural network in this application has improved the accuracy and regression rate of PCB bare board defect detection. The results of PCB bare board defect detection in this embodiment are as follows: Figure 4 shown.
[0053] The above description is only a preferred implementation manner of the present invention, but the protection scope of the present invention is not limited thereto, and any modification and replacement based on the technical solution and inventive concept provided by the present invention should be included in the protection scope of the present invention.
Claims
1. A PCB bare board defect detection method based on an improved YOLOv8 neural network, characterized in that: The steps include: Step 1: Obtain the block images of the PCB bare board, and stitch the block images into a complete PCB bare board image, and output the YOLO format dataset after preprocessing the PCB bare board image; Step 2: Input the YOLO formatted data set into the trained improved Yolov8 neural network for PCB bare board defect detection and classification; The improved Yolov8 neural network includes a backbone network, a neck network and a detection head network; the backbone network includes a first convolutional layer, a second convolutional layer, a first C2f module, a third convolutional layer, a second C2f module, a fourth convolutional layer, a third C2f module, a fifth convolutional layer, a fourth C2f module and a focus modulation module connected in sequence; The neck network includes a first upsampling module, a first splicing module, a fifth C2f module, a second upsampling module, a second splicing module, a first BEMA module, a sixth convolutional layer, a third splicing module, a second BEMA module, a seventh convolutional layer, a fourth splicing module, and a third BEMA module; the focus modulation module is connected to the first upsampling module, the first splicing module splices the features output by the first upsampling module with the features output by the third C2f module and inputs them to the fifth C2f module and the second upsampling module, the features output by the second upsampling module and the features output by the second C2f module are spliced by the second splicing module and input to the first BEMA module and the sixth convolutional layer; the features output by the sixth convolutional layer and the features output by the fifth C2f module are spliced by the third splicing module and input to the second BEMA module and the seventh convolutional layer, the features output by the seventh convolutional layer and the features output by the focus modulation module are spliced by the fourth splicing module and input to the third BEMA module; the features output by the first BEMA module, the second BEMA module, and the third BEMA module are input to the detection head network; The BEMA module includes a convolution module, a batch normalization module, an EMA attention module, a first convolution-normalization-activation module, a fifth splicing module, a random discarding module, a second convolution-normalization-activation module, and a sixth splicing module connected in sequence; the fifth splicing module is also connected to the EMA attention module, and the sixth splicing module is also connected to the convolution module; The loss function of the detection head network adopts the Inner-Shape-Iou function, and the Inner-Shape-Iou function model is as follows: LI nner-Shape-Iou =1-IoU inner +distance shape +0.5Ω shape ; Among them, L Inner-shape-Iou is the loss function, IoU inner is the position information between the real bounding box and the predicted bounding box, distance shape The degree of deviation of the center point of the predicted bounding box relative to the center point of the true bounding box; Ω shape is the shape cost, w w is an indicator to measure the width difference between the predicted bounding box and the true bounding box; w h is an indicator to measure the height difference between the predicted bounding box and the true bounding box; θ is the weight of the shape cost; w and h are the width and height of the predicted bounding box; hh and ww are the weight coefficients in the height direction and width direction respectively, and c is the weight coefficient of the predicted bounding box B and the real bounding box B gt The diagonal distance of the minimum enclosing bounding box between c ,y c ) is the center coordinate of the predicted bounding box B, is the ground-truth bounding box B gt The center point coordinates of inter is the intersection area of the two bounding boxes, is the length of the horizontal intersection of the two bounding boxes, that is, the smaller value of the right boundary of the two bounding boxes minus the larger value of the left boundary, is the length of the vertical intersection of the two bounding boxes, that is, the smaller value of the bottom boundaries of the two bounding boxes minus the larger value of the top boundaries; union=(w gt ×h gt )×(ratio) 2 +(w×h)×(ratio) 2 -inter, ratio is the scale factor, w gt and h gt is the width and height of the real bounding box, w and h are the width and height of the predicted bounding box, ratio is the scale factor, ratio = 0.
65.
2. A PCB bare board defect detection method based on an improved YOLOv8 neural network according to claim 1, characterized in that: The preprocessing described in step 1 refers to first converting the PCB bare board image into a grayscale image, then performing a Gamma transformation on the grayscale image to achieve image enhancement; and finally converting it into a YOLO format data set.
3. A PCB bare board defect detection method based on an improved YOLOv8 neural network according to claim 1, characterized in that: Small-size PCB bare board images are used to create training data sets and test data sets for training the improved YOLOv8 neural network.
Citation Information
Patent Citations
Small target detection method based on improved YOLOX model
CN115063672A
Insulator defect detection method based on improved YOLOv7
CN115731164A
Cited By
PCB bare board defect detection method and system based on improved YOLOv11 neural network
CN121074500A
