PCB surface defect detection method and device based on YOLOv3 algorithm
By combining the batch normalization layer and the convolution layer in the YOLOv3 algorithm, using GIoU and K-means++ clustering algorithms to perform multi-scale training, the problem of insufficient PCB surface defect detection efficiency and accuracy in the existing technology is solved, and the problem is achieved Efficient and accurate detection results.
Patent Information
- Application Number
- CN202011542008.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-23
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2040-12-23
AI Technical Summary
Existing deep learning algorithms are difficult to meet the efficiency and accuracy requirements of printed circuit board (PCB) surface defect detection. Traditional methods have low accuracy, insufficient generalization capabilities, poor robustness, and are difficult to be compatible with multiple PCB design rules and defect types.
Adopt a network structure based on the YOLOv3 algorithm, combine the batch normalization layer and the convolution layer, use GIoU to determine the network loss function and performance evaluation index, determine the anchor box through the K-means++ clustering algorithm, and conduct multi-scale training to establish an efficient PCB surface defect detection model.
It improves the detection efficiency and accuracy of the model, enhances the detection ability of small defect targets, and achieves high efficiency and high precision in PCB surface defect detection, which is suitable for industrial production environments.
Smart Images

Figure CN112669275B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target data detection, and in particular to a PCB surface defect detection method and device based on a YOLOv3 algorithm. Background Art
[0002] At present, printed circuit board (PCB) surface defect detection mainly faces the following challenges and difficulties: first, there are many types of PCBs available on the market, and the PCB design rules are different; second, the types of PCB defects and functional designs are complex and diverse; third, the PCB defect detection industry lacks a large number of PCB defect samples, resulting in unbalanced data used in traditional methods. PCB surface defect detection mainly includes two parts: welding seam defect detection and component detection. Traditional manual visual inspection methods and machine vision inspection methods based on image processing have problems such as low accuracy, insufficient generalization ability and poor robustness, and it is difficult to achieve compatibility with multiple PCB surface defect detections, which has become increasingly unable to meet the needs of industrial production. Therefore, it is of great practical significance to design an efficient and accurate machine vision circuit board inspection system equipped with an industrial camera to replace human eye detection.
[0003] In recent years, although the automatic optical inspection (AOI) system has replaced most of the manual inspection technologies, improved the inspection accuracy, reduced the inspection cost, and has the advantages of being more convenient and efficient than manual inspection, its false detection rate and missed detection rate are still too high. Moreover, the detection effect is easily affected by factors such as image illumination, occlusion, and angle changes. At the same time, the detection algorithm also has problems such as poor noise resistance, long calculation time, and poor real-time detection performance. The six common defects in welding seam defect detection in actual industrial scenarios are: missing holes, mouse-type erosion, open circuits, short circuits, burrs, and copper slag.
[0004] Printed circuit board (PCB) defect detection methods have mainly experienced the development and changes of traditional artificial vision detection methods, machine vision detection methods based on image processing, and current target detection methods based on deep learning. Some new detection methods have also emerged, such as automated X-ray detection, laser detection systems, etc., but they all have disadvantages such as slow detection speed, high failure rate, and high cost. Traditional target detection technology is generally divided into three steps: first, use sliding windows of different scales to determine the candidate (to be detected) area; then extract visual features related to the candidate area, such as Haar features or HOG features, and finally train the classifier for regional classification. Traditional target detection methods also have inherent disadvantages: (1) The region selection algorithm based on sliding windows has low correlation, high time complexity, and a large number of redundant windows; (2) The manually designed function relies on a lot of prior knowledge, is highly subjective, and the three-step detection process is complicated and cumbersome; (3) The traditional target detection method is slow and cannot meet the real-time detection requirements of industrial production. The traditional target detection process is as follows Figure 1 shown.
[0005] At present, the mainstream object detection methods are mainly based on deep learning models. Object detection methods based on deep learning are mainly divided into two categories: two-stage object detection methods and one-stage object detection methods. The two-stage object detection method is mainly divided into two steps: the first step is to extract proposal boxes from the image, remove some background proposal boxes, and perform position correction at the same time; the second step is to test and classify each proposal box and correct its position. Therefore, the candidate region-based method is also called a two-stage object detection method. Although the performance of the two-stage object detection method is relatively high, the detection speed is still far behind that of real-time detection. Typical algorithms include R-CNN, SPP-Net, Fast R-CNN, Faster R-CNN, etc.; one-stage object detection combines these two processes together to better meet the requirements of real-time detection. In the one-stage object detection method, the proposal box is no longer used for "rough detection + refinement", but the "anchor point + classification refinement" operation framework is adopted, that is, the feedforward network is only calculated once. With this method, the detection speed is significantly improved. Typical algorithms include SSD, RetinaNet, YOLO, etc. Deep learning methods have the advantages of automated feature extraction and end-to-end control. However, due to the local functional characteristics of CNN, existing deep learning algorithms are difficult to meet the requirements of efficiency and accuracy for PCB surface defect detection. Summary of the invention
[0006] An embodiment of the present invention provides a PCB surface defect detection method based on the YOLOv3 algorithm, which is used to improve the efficiency and accuracy of PCB surface defect detection. The method includes:
[0007] Establishing a network structure of a YOLOv3 algorithm, wherein a batch normalization layer of the network structure is combined with a convolutional layer;
[0008] Determine the network loss function and performance evaluation index of the YOLOv3 algorithm based on GIoU;
[0009] According to the K-means++ clustering algorithm, the anchor frame of the PCB surface defect sample data set is determined;
[0010] According to the network structure of the YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set, a PCB surface defect detection model based on the YOLOv3 algorithm is established;
[0011] According to the PCB surface defect sample dataset, multi-scale training is performed on the PCB surface defect detection model based on the YOLOv3 algorithm;
[0012] The image data of the PCB to be inspected is input into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and the location information of the surface defects of the PCB to be inspected is output.
[0013] The embodiment of the present invention provides a PCB surface defect detection device based on the YOLOv3 algorithm, which is used to improve the efficiency and accuracy of PCB surface defect detection. The device includes:
[0014] A network structure building module, used to build a network structure of the YOLOv3 algorithm, wherein a batch normalization layer of the network structure is combined with a convolutional layer;
[0015] The network loss function determination module is used to determine the network loss function and performance evaluation index of the YOLOv3 algorithm based on GIoU;
[0016] An anchor frame determination module, used to determine the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm;
[0017] The PCB surface defect detection model building module is used to build a PCB surface defect detection model based on the YOLOv3 algorithm according to the network structure of the YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set;
[0018] PCB surface defect detection model training module, used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample data set;
[0019] The PCB surface defect detection module is used to input the image data of the PCB to be detected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and output the location information of the surface defects of the PCB to be detected.
[0020] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned PCB surface defect detection method based on the YOLOv3 algorithm is implemented.
[0021] An embodiment of the present invention also provides a computer-readable storage medium, which stores a method for executing the above-mentioned PCB surface defect detection method based on the YOLOv3 algorithm.
[0022] The embodiment of the present invention establishes a network structure of a YOLOv3 algorithm, and combines a batch normalization layer with a convolution layer of the network structure, thereby improving the forward reasoning speed of the model and reducing the training time of a PCB surface defect sample data set of the model; determining a network loss function and a performance evaluation index of the YOLOv3 algorithm according to GIoU, thereby solving the problem of inconsistency between the network loss function and the performance evaluation index in the existing YOLOv3 algorithm, and improving the detection accuracy of the model for medium and small defect targets of the PCB based on GIoU; determining an anchor frame of a PCB surface defect sample data set according to a K-means++ clustering algorithm, thereby improving the accuracy of the anchor frame; performing multi-scale training on a PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample data set, thereby enhancing the robustness of the model in detecting images of different resolutions; inputting image data of a PCB to be detected into a trained PCB surface defect detection model based on the YOLOv3 algorithm, and outputting position information of the PCB surface defect to be detected; and then realizing efficient and high-precision detection of PCB surface defects based on the trained PCB surface defect detection model based on the YOLOv3 algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0024] Figure 1 Schematic diagram of the traditional target detection process;
[0025] Figure 2Schematic diagram of the process of a PCB surface defect detection method based on the YOLOv3 algorithm in an embodiment of the present invention;
[0026] Figure 3 A schematic diagram of the network structure of the YOLOv3 algorithm in an embodiment of the present invention;
[0027] Figure 4 Schematic diagram of using IoU as a performance evaluation indicator in an embodiment of the present invention;
[0028] Figure 5 Schematic diagram of a multi-scale training process in an embodiment of the present invention;
[0029] Figure 6 A schematic diagram of resource utilization of a server in an embodiment of the present invention;
[0030] Figure 7 Schematic diagram of the average loss function curve of the model during the training process in an embodiment of the present invention;
[0031] Figure 8 Schematic diagram of the average intersection-over-union ratio curve of the model during the training process in an embodiment of the present invention;
[0032] Fig. 9 A schematic diagram showing the comparison test results between the improved YOLOv3 according to the embodiment of the present invention and the existing YOLOv3;
[0033] Fig.10 A schematic diagram of comparative analysis of mAP performance indicators in test results of different image sizes between the improved YOLOv3 of an embodiment of the present invention and the existing YOLOv3;
[0034] Fig.11 Schematic diagram of the structure of a PCB surface defect detection device based on the YOLOv3 algorithm in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0036] In order to solve the technical problem that the existing deep learning algorithm is difficult to meet the requirements of PCB surface defect detection efficiency and accuracy, the embodiment of the present invention provides a PCB surface defect detection method based on the YOLOv3 algorithm, which is used to improve the efficiency and accuracy of PCB surface defect detection. Figure 2 FIG. 1 is a schematic diagram of a PCB surface defect detection method based on the YOLOv3 algorithm in an embodiment of the present invention. Figure 2 As shown, the method includes:
[0037] Step 201: Establishing a network structure of the YOLOv3 algorithm, wherein a batch normalization layer of the network structure is combined with a convolutional layer;
[0038] Step 202: Determine the network loss function and performance evaluation index of the YOLOv3 algorithm according to GIoU;
[0039] Step 203: determining the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm;
[0040] Step 204: establishing a PCB surface defect detection model based on the YOLOv3 algorithm according to the network structure of the YOLOv3 algorithm, the network loss function and the performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set;
[0041] Step 205: performing multi-scale training on a PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample dataset;
[0042] Step 206: input the image data of the PCB to be inspected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and output the position information of the surface defects of the PCB to be inspected.
[0043] In one embodiment, in step 201, the network structure of the YOLOv3 algorithm uses Darknet-53 as a feature extractor.
[0044] In the specific implementation, the feature extraction backbone network of YOLOv3 refers to the network structure design of SSD and ResNet, that is, Darknet-53 is used instead of Darknet-19 as the feature extractor. Darknet-53 is mainly composed of 3×3 and 1×1 filters, with residual connections, such as the residual network in ResNet. There are no pooling layers and fully connected layers in the network structure of the entire YOLOv3 algorithm. During the forward propagation algorithm, the size change of the tensor is achieved by changing the stride of the convolution kernel. For example, Stride (stride) = 2 is equivalent to reducing the side length of the image by half.
[0045] The performance comparison between Darknet-53 and Resnet-101, Resnet-152 and Darknet-19 networks is shown in Table 1.
[0046] Table 1 Comparison of characteristic network performance
[0047]
[0048] As can be seen from Table 1, compared with Resnet-101, Resnet-152, and Darknet-19, the Top-1, Top-5, and floating-point operations per second accuracy of the Darknet-53 network have been improved, which can achieve better real-time detection and accuracy requirements.
[0049] YOLOv3 first extracts the features of the input image through the feature extraction network to obtain a feature map of a certain size, such as 13×13 (equivalent to the size of a 416×416 image), and then divides the input image into 13×13 grid cells. Among them, the center coordinates of the target are located in the grid cells, and the target is predicted through the grid cells. Each grid cell predicts 3 bounding boxes with a fixed number. The predicted output feature map has two dimensions, which is the dimension of the extracted features, such as 13×13, and the other dimension (depth) is B×(5+C). Among them, B represents the number of bounding boxes predicted by each grid cell. The schematic diagram of the network structure of the YOLOv3 algorithm is shown in the figure. Figure 3 shown.
[0050] YOLOv3 has made great improvements in the overall network structure, mainly in the following aspects: (1) Category prediction: using multi-label classification, multiple independent logistic classifiers replace the Softmax function to calculate the possibility of a specific input label. (2) Bounding box prediction and cost function operation: using logistic regression to predict the objective score of each bounding box, changing the way the cost function is calculated. (3) Multi-scale fusion prediction: fusion prediction from three different scales (similar to FPN). (4) Feature extraction: using the Darknet-53 network instead of Darknet-19 as the feature extractor.
[0051] Based on the above design and improvement ideas, YOLOv3 has better detection effect on small defect targets than YOLOv2, and is more suitable for the detection of PCB surface defect targets. Compared with other target detection algorithms, YOLOv3 has achieved better optimization in detection speed and accuracy, and can be better applied in industrial scenarios. The performance comparison of YOLOv3 and other networks is shown in Table 2.
[0052] Table 2 Performance comparison between YOLOv3 and other networks
[0053]
[0054] In one embodiment, in step 201, establishing a network structure of the YOLOv3 algorithm includes: combining a batch normalization layer and a convolutional layer of the network structure in the following manner:
[0055]
[0056] in,
[0057] In the formula, x out is the output result of the batch normalization layer combined with the convolutional layer, x i is the output result of each layer after combination, n is the number of layers, γ is the scale factor, μ is the average value, σ 2 is the variance, β is the offset before combination, β′ is the offset after combination, w i is the weight parameter before combining, w i ′ is the combined weight parameter.
[0058] In specific implementation, when the neural network trains the network model, the BN (batch normalization) layer can accelerate network fusion and effectively control overfitting. It is usually placed after the convolution layer and before the activation layer. At the same time, after the BN layer normalizes the data, it can effectively solve the problems of gradient disappearance and gradient explosion. Although the BN layer plays a positive role in training, it increases the amount of calculation during network forward reasoning, affects the performance of the model, and occupies more memory or video memory space. Since there are a large number of image PCB defect data sets in the training set, the ability to effectively reduce training time plays a vital role in the rapid fusion of the model.
[0059] The calculation formulas of the BN layer and convolution layer in the existing YOLOv3 algorithm are as follows:
[0060]
[0061] In the formula, x out is the result of BN layer operation, x conv is the result of the convolutional layer operation before the BN layer, x conv As shown below:
[0062]
[0063] In the embodiment of the present invention, the operation formula after the BN layer and the convolution layer are combined is shown in formula (1). The derivation process of formula (1) is described below:
[0064]
[0065]
[0066] Substituting the combined weight parameter formula and the combined offset formula into formula (5), we can obtain the operation formula (1) after combining the BN layer and the convolution layer.
[0067] At this point, the only parameter left in the weight file is the weight parameter w iThe combined parameters need to be written into a new weight file. Experiments show that the present invention combines the BN layer and the convolution layer together, effectively improving the model performance, increasing the forward reasoning speed and accelerating the model training process.
[0068] In one embodiment, in step 202, the network loss function and performance evaluation index of the YOLOv3 algorithm are determined according to GIoU, including:
[0069] Determine GIoU based on the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box;
[0070] Determine GIoU as the performance evaluation indicator of the YOLOv3 algorithm;
[0071] Based on GIoU, determine the network loss function of the YOLOv3 algorithm.
[0072] In one embodiment, the GIoU is determined according to the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box, including: determining the GIoU in the following manner:
[0073]
[0074] Where A is the predicted box, B is the actual box, and C is the minimum convex set of the predicted box and the actual box.
[0075] In one embodiment, based on GIoU, determining the network loss function of the YOLOv3 algorithm includes: determining the network loss function of the YOLOv3 algorithm in the following manner:
[0076] L GIoU =1-GIoU (7)
[0077] Where, L GIoU is the network loss function of the YOLOv3 algorithm.
[0078] In specific implementation, YOLOv3 introduces the mean square error (MSE) loss function in the target frame to coordinate the regression calculation process, and uses cross entropy as the loss function for category and confidence. However, the MSE loss function is very sensitive to the target scale, and the target scale has a greater impact on the accuracy of regression calculation.
[0079] Due to the intersection-over-union ratio of the IoU calculation model, IoU can better reflect the quality of the regression frame, and the calculation of IoU is robust in terms of target scale. Therefore, in the embodiment of the present invention, IoU is considered to be used instead of MSE to return the target frame calculation. After a lot of experimental research, the inventor found that using IoU as the loss function for regression calculation is an improvement compared to the result of MSE calculation. The schematic diagram of IoU used as a performance evaluation indicator is shown in Figure 4 shown.
[0080] However, if IoU is directly used as a criterion for evaluating model performance, when the predicted frame and the real-time frame do not overlap, the corresponding IoU is zero no matter how far the distance between the two is. The temporal model cannot measure the distance between the predicted frame and the real-time frame. Therefore, an embodiment of the present invention proposes to measure the degree of fit between the predicted frame and the original labeled frame based on GIoU. For the predicted frame A and the actual frame B, the minimum convex set C (including the minimum bounding box of A and B) can be calculated. Through the minimum convex set, GIoU can be calculated. The calculation formulas of IoU and GIoU are shown in formula (6). The numerator of the negative part of the GIoU formula in formula (6) belongs to part of the minimum convex set and does not include A or B. GIoU is similar to IoU. GIoU is used as a distance evaluation metric, and its loss function L GIoU The calculation of is shown in formula (7).
[0081] According to the calculation formula of GIoU, it can be seen that GIoU is always less than or equal to IoU. From the calculation formula of IoU, it can be concluded that 0≤IoU≤1, and from the calculation formula of GIoU, it can be concluded that -1≤GIoU≤1, that is, only when the predicted frame GIoU=1, it completely overlaps with the real-time frame. And when the IoU between the predicted frame and the real-time frame is zero, GIoU is converted into formula (8):
[0082] GIoU=-1+(A∪B) / C (8)
[0083] At this time, the farther the predicted frame is from the real-time frame, the closer GIoU is to -1, while A∪B remains unchanged. In order to optimize GIoU, C must be gradually reduced, that is, the predicted frame is getting closer and closer to the real-time frame.
[0084] In one embodiment, in step 203, determining the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm includes:
[0085] Randomly select a point from the PCB surface defect sample data point set as the cluster center;
[0086] Repeat the following steps until a preset number of cluster centers are selected: for each point in the PCB surface defect sample data point set, calculate the distance from each point to the cluster center closest to the point; based on the distance from each point to the cluster center closest to the point, determine the point whose distance to the cluster center is greater than a preset threshold as a new cluster center;
[0087] According to the preset number of cluster centers, the anchor frame of the PCB surface defect sample data set is determined based on the K-means++ clustering algorithm.
[0088] In specific implementation, YOLOv3 introduced the idea of anchor boxes in Faster R-CNN. The K-means clustering algorithm used in YOLOv3 obtained 9 anchor boxes based on the statistics of a specific data set. Selecting appropriate anchor points can speed up the fusion of the network and reduce errors. However, the traditional K-means clustering algorithm randomly selects k data points as the initial cluster centroid. This random method is prone to obtaining a local optimal solution rather than a global optimal solution.
[0089] Therefore, in order to obtain a larger intersection-over-union (IoU) between the anchor frame and the adjacent real-time frame and avoid the influence of the traditional K-means clustering, the embodiment of the present invention uses the K-means++ clustering algorithm to make the initial cluster center as non-randomly generated as possible, and optimizes the original algorithm. The specific process of the K-means++ clustering algorithm is shown in Table 3 below.
[0090] Table 3 Specific process of K-means++ clustering algorithm
[0091]
[0092] The embodiment of the present invention uses the K-means++ clustering algorithm to obtain 9 anchor frames in the constructed PCB target detection database. Through comparative detection, a group of anchor points are finally selected: (5,6), (25,10), (20,34), (35,79), (52,43), (59,115), (115,90), (156,197), (372,326), and divided into three proportional feature maps.
[0093] During specific implementation, in step 204, based on the network structure of the aforementioned YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set, an initial model of the PCB surface defect detection model based on the YOLOv3 algorithm can be established, and then the initial model needs to be trained based on the PCB surface defect sample data set.
[0094] In one embodiment, step 205: performing multi-scale training on a PCB surface defect detection model based on the YOLOv3 algorithm according to a PCB surface defect sample dataset, including:
[0095] The image size of the PCB surface defect sample dataset is divided into multiple image scales;
[0096] According to various image scales, the transfer learning method is used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm.
[0097] In practice, YOLOv3 uses a convolutional neural network to extract features and does not use a fully connected layer to get predictions. Therefore, during training, the network does not have to fix the size of the input image.
[0098] Since the improved network consists of 4 residual modules and a densely connected dense block, and the minimum image size is 1 / 32 of the input image, the image size must be a multiple of 32 when changing. Therefore, the image size of the training set is divided into multiple image scales, namely {320, 352, ..., 608}. During the training process, 10 scales are randomly selected for training in each iteration, such as Figure 5 As shown in the figure, experiments have proved that the model trained with the multi-scale training strategy has good robustness and can accept input images of any size, which helps to improve the network performance evaluation indicators of the model.
[0099] Finally, in step 206, the image data of the PCB to be inspected can be input into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and the location information of the surface defects of the PCB to be inspected can be output.
[0100] A specific example is given below to facilitate understanding of how to implement the present invention.
[0101] Step 1: Dataset Source and Generation
[0102] For deep learning target detection, the source and generation of experimental data sets are two very important steps. The accuracy of the original data labels directly affects the effectiveness of training and the accuracy of inspection. Therefore, in this specific embodiment, the data set has a total of 693 images, involving six common defect types: missing holes, mouse-type corrosion, open circuits, short circuits, burrs, and copper slag.
[0103] In this specific embodiment, the data set first adopts the standard VOC2007 data set format, but the amount of data in the original data set is relatively small, which easily leads to overfitting during the training process. Therefore, this specific embodiment adopts two data optimization processing methods to increase the richness and diversity of the data set. First, an offline data optimization method is adopted, including cropping the image size, rotating the image, adjusting the contrast and increasing the noise of the image. Secondly, an online data optimization method is used, which is mainly used for random translation and horizontal flipping of training images. 80% of the photos are randomly selected as the training set, and the remaining 20% are used as the test data set.
[0104] Step 2: Building the experimental environment
[0105] In this specific embodiment, the training experimental environment is constructed on a cloud server, and the files and data are configured locally and then uploaded to the cloud server for model training. The software and hardware configuration of the cloud server is shown in Table 4 below.
[0106] Table 4 Cloud server software and hardware configuration
[0107]
[0108] During model training, the server resource utilization is as follows: Figure 6 As shown, Figure 6 A screenshot of server resource usage over a certain period of time, mainly including comparative analysis of CPU, memory, and GPU usage.
[0109] Step 3: Establish and train a PCB surface defect detection model based on the YOLOv3 algorithm
[0110] This specific embodiment adopts the idea of transfer learning, which is based on the trained network model and transfers parameters and knowledge on this basis. This method requires only a small amount of computing resource cost and training time to achieve new task support.
[0111] First, the entire network model is based on the open source deep learning framework Darknet provided by the official website, using the improved YOLOv3 network model and combined with the idea of transfer learning for training. Secondly, during the training process, dynamic monitoring is adopted to save the training logs and weight files from time to time. According to the script program and data visualization ideas, the loss function curve and IoU curve are drawn according to the saved training log files. Finally, according to the loss function and IoU information, the entire network parameters are fine-tuned and optimized, and combined with the early termination strategy, the optimal weight file is saved as a prediction model for PCB defect detection. The parameter configuration of training initialization is shown in Table 5.
[0112] Table 5 Initialization parameters of network training
[0113]
[0114] The changing trend of the average loss function and the average intersection-over-combination ratio of the model during training is as follows: Figure 7 and Figure 8 As shown, as shown. Figure 7 As shown in the figure, at the beginning of training, the loss function value is about 2.8. As the number of training times increases, the loss value begins to decrease, and then the trend gradually stabilizes. After about 20,000 iterations, when the loss value fluctuates around 0.1, the model can be saved.
[0115] like Figure 8As shown in the figure, the average IoU at the beginning of training is about 0.2. As the number of training iterations increases, the average IoU gradually increases, and the detection accuracy of the surface model begins to gradually improve. When the number of iterations reaches about 900, the average IoU can reach about 50%. The weight file generated by the training is called to perform the first test on the test image. The first test effect is described as follows: the model training is underfitting, that is, there is still room for improvement. The network has not yet modeled all the relevant patterns in the training data, and the test results are prone to problems such as low accuracy and missed detection.
[0116] Step 4: Experimental results and performance comparison analysis
[0117] The model evaluation metric selected in this specific embodiment is mAP (which refers to the average of various average precisions). In target detection, mAP is a common indicator for measuring detection accuracy. It refers to the average of various AP (average precision). The larger the mAP value, the better the performance of the entire model and the higher the recognition accuracy. AP refers to the average precision of a single category, which is used to measure how well the model can identify defects in a certain category. The AP used in this specific embodiment defaults to AP50, which refers to the average accuracy of single category recognition under the premise that the IoU between the predicted box and the original labeled box is greater than 50%.
[0118] In this specific embodiment, the comparison test results of the improved YOLOv3 of the embodiment of the present invention and the existing YOLOv3 are as follows: Fig. 9 As shown in the figure. Experiments show that the improved YOLOv3 algorithm model has higher detection accuracy than the existing YOLOv3 algorithm model, and the mAP value has increased by 7.89%. Secondly, the improved YOLOv3 algorithm model improves the detection accuracy of small defect targets and enhances the reliability of the model.
[0119] The embodiment of the present invention combines the convolution layer with the batch normalization layer (BN). This specific embodiment randomly selects 2,000 images from the test set for prediction on the GPU, and calculates the average prediction time. The experimental results before and after the improvement are shown in Table 6. The experiment proves that the network model constructed by combining the convolution layer and the BN layer in the embodiment of the present invention reduces the forward reasoning time by 7.89%. This shows that the combination of the convolution layer and the BN layer can shorten the forward reasoning time of the model, reduce the memory and video memory space occupied, and does not cause performance loss.
[0120] Table 6 Performance comparison analysis before and after combining the convolution layer and batch normalization layer (BN)
[0121]
[0122] The embodiment of the present invention proposes a multi-scale training method. This specific embodiment selects four scales (320×320, 416×416, 512×512, 608×608) of images to perform performance analysis on the test data set. Fig.10 This paper compares the mAP performance indicators of the improved YOLOv3 and the existing YOLOv3 in the test results of different image sizes. The experimental results show that the improved YOLOv3 model based on multi-scale training in the embodiment of the present invention has higher detection accuracy than the existing YOLOv3 model. The mAP value increased by 4.67% on average, and the applicability of the model to different input images was also improved, effectively improving the detection effect of images with different resolutions.
[0123] In order to verify the detection effect on the same data set, this specific embodiment compares and analyzes the mAP parameters per second of SSD, Faster R-CNN, the existing YOLOv3 model and the improved YOLOv3 model in the embodiment of the present invention, and the number of recognized frames is used as an evaluation metric for the detection effect. The experimental results are shown in Table 7.
[0124] Table 7 Comparative analysis of detection performance of different models
[0125]
[0126] It can be seen from Table 7 that among the four models compared in the above table, Faster R-CNN has the highest recognition accuracy, but the slowest detection speed. Although the recognition accuracy of the improved YOLOv3 model is lower than that of the Faster R-CNN model, its detection speed is 147.5 times higher than that of the Faster R-CNN model. Compared with the SSD model and the YOLOv3 model, the mAP and recognition frame rate of the improved YOLOv3 model have been improved to a certain extent. Therefore, it can be seen that the improved YOLOv3 model of the embodiment of the present invention takes into account both the detection accuracy and the detection rate, and can effectively complete the PCB surface defect detection task.
[0127] Based on the same inventive concept, a PCB surface defect detection device based on the YOLOv3 algorithm is also provided in an embodiment of the present invention, such as the following embodiment. Since the principle of solving the problem by the PCB surface defect detection device based on the YOLOv3 algorithm is similar to that of the PCB surface defect detection method based on the YOLOv3 algorithm, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.
[0128] Fig.11 FIG. 1 is a schematic diagram of the structure of a PCB surface defect detection device based on the YOLOv3 algorithm in an embodiment of the present invention. Fig.11 As shown, the device comprises:
[0129] The network structure establishment module 01 is used to establish the network structure of the YOLOv3 algorithm, wherein the batch normalization layer of the network structure is combined with the convolution layer;
[0130] A network loss function determination module 02 is used to determine the network loss function and performance evaluation index of the YOLOv3 algorithm according to GIoU;
[0131] Anchor frame determination module 03, used to determine the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm;
[0132] PCB surface defect detection model establishment module 04 is used to establish a PCB surface defect detection model based on the YOLOv3 algorithm according to the network structure of the YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set;
[0133] PCB surface defect detection model training module 05, used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample data set;
[0134] The PCB surface defect detection module 06 is used to input the image data of the PCB to be detected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and output the position information of the surface defects of the PCB to be detected.
[0135] In one embodiment, the network structure establishment module 01 is specifically used to combine the batch normalization layer and the convolution layer of the network structure in the following manner:
[0136]
[0137] in,
[0138] In the formula, x out is the output result of the batch normalization layer combined with the convolutional layer, x i is the output result of each layer after combination, n is the number of layers, γ is the scale factor, μ is the average value, σ 2 is the variance, β is the offset before combination, β′ is the offset after combination, w i is the weight parameter before combining, w i ′ is the combined weight parameter.
[0139] In one embodiment, the network structure of the YOLOv3 algorithm uses Darknet-53 as a feature extractor.
[0140] In one embodiment, the network loss function determination module 02 is specifically used for:
[0141] Determine GIoU based on the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box;
[0142] Determine GIoU as the performance evaluation indicator of the YOLOv3 algorithm;
[0143] Based on GIoU, determine the network loss function of the YOLOv3 algorithm.
[0144] In one embodiment, the network loss function determination module 02 is further used to determine the GIoU in the following manner:
[0145]
[0146] Where A is the predicted box, B is the actual box, and C is the minimum convex set of the predicted box and the actual box.
[0147] In one embodiment, the network loss function determination module 02 is further used to determine the network loss function of the YOLOv3 algorithm in the following manner:
[0148] L GIoU =1-GIoU;
[0149] Where, L GIoU is the network loss function of the YOLOv3 algorithm.
[0150] In one embodiment, the anchor frame determination module 03 is specifically used to:
[0151] Randomly select a point from the PCB surface defect sample data point set as the cluster center;
[0152] Repeat the following steps until a preset number of cluster centers are selected: for each point in the PCB surface defect sample data point set, calculate the distance from each point to the cluster center closest to the point; based on the distance from each point to the cluster center closest to the point, determine the point whose distance to the cluster center is greater than a preset threshold as a new cluster center;
[0153] According to the preset number of cluster centers, the anchor frame of the PCB surface defect sample data set is determined based on the K-means++ clustering algorithm.
[0154] In one embodiment, the PCB surface defect detection model training module 04 is specifically used for:
[0155] The image size of the PCB surface defect sample dataset is divided into multiple image scales;
[0156] According to various image scales, the transfer learning method is used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm.
[0157] An embodiment of the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned PCB surface defect detection method based on the YOLOv3 algorithm is implemented.
[0158] An embodiment of the present invention also provides a computer-readable storage medium, which stores a method for executing the above-mentioned PCB surface defect detection method based on the YOLOv3 algorithm.
[0159] In summary, the embodiment of the present invention establishes a network structure of the YOLOv3 algorithm, and combines a batch normalization layer with a convolutional layer of the network structure, thereby improving the forward reasoning speed of the model and reducing the training time of the PCB surface defect sample data set of the model; determining the network loss function and performance evaluation index of the YOLOv3 algorithm according to GIoU, thereby solving the problem of inconsistency between the network loss function and the performance evaluation index in the existing YOLOv3 algorithm, and improving the detection accuracy of the model for medium and small defect targets of PCB based on GIoU; determining the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm, thereby improving the accuracy of the anchor frame; performing multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample data set, thereby enhancing the robustness of the model in detecting images of different resolutions; inputting the image data of the PCB to be detected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and outputting the position information of the PCB surface defect to be detected, thereby realizing efficient and high-precision detection of PCB surface defects based on the trained PCB surface defect detection model based on the YOLOv3 algorithm.
[0160] In addition, the embodiment of the present invention uses open data sets and transfer learning, machine learning and data visualization ideas to closely combine academic research and engineering applications. From the perspective of the specific project process of PCB surface defect detection, a series of processes in target detection are systematically explained, including project preliminary research, algorithm selection, data set download and packaging, experimental environment construction, model training, model testing, model optimization, etc., effectively completing the PCB surface defect detection task.
[0161] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0162] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0163] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0164] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0165] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A PCB surface defect detection method based on YOLOv3 algorithm, characterized in that: include: Establishing a network structure of a YOLOv3 algorithm, wherein a batch normalization layer of the network structure is combined with a convolutional layer; Determine the network loss function and performance evaluation index of the YOLOv3 algorithm based on GIoU; According to the K-means++ clustering algorithm, the anchor frame of the PCB surface defect sample data set is determined; According to the network structure of the YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set, a PCB surface defect detection model based on the YOLOv3 algorithm is established; According to the PCB surface defect sample dataset, multi-scale training is performed on the PCB surface defect detection model based on the YOLOv3 algorithm; Input the image data of the PCB to be inspected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and output the location information of the surface defects of the PCB to be inspected; Among them, the network structure of the YOLOv3 algorithm is established, including: combining the batch normalization layer and the convolution layer of the network structure in the following manner: in, In the formula, x out is the output result of the batch normalization layer combined with the convolutional layer, x i is the output result of each layer after combination, n is the number of layers, γ is the scale factor, μ is the average value, σ 2 is the variance, β is the offset before combination, β′ is the offset after combination, and w i is the weight parameter before combining, w i ′ is the weight parameter after combination; The network loss function and performance evaluation indicators of the YOLOv3 algorithm are determined based on GIoU, including: Determine GIoU based on the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box; Determine GIoU as the performance evaluation indicator of the YOLOv3 algorithm; Based on GIoU, determine the network loss function of the YOLOv3 algorithm; Wherein, determining GIoU according to the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box includes: determining GIoU in the following manner: In the formula, A is the predicted box, B is the actual box, and C is the minimum convex set of the predicted box and the actual box; Wherein, based on GIoU, determining the network loss function of the YOLOv3 algorithm includes: determining the network loss function of the YOLOv3 algorithm in the following manner: L GIoU =1-GIoU; Where, L GIoU It is the network loss function of the YOLOv3 algorithm.
2. The method according to claim 1, characterized in that The network structure of the YOLOv3 algorithm uses Darknet-53 as a feature extractor.
3. The method according to claim 1, characterized in that According to the K-means++ clustering algorithm, the anchor frame of the PCB surface defect sample data set is determined, including: Randomly select a point from the PCB surface defect sample data point set as the cluster center; Repeat the following steps until a preset number of cluster centers are selected: for each point in the PCB surface defect sample data point set, calculate the distance from each point to the cluster center closest to the point; based on the distance from each point to the cluster center closest to the point, determine the point whose distance to the cluster center is greater than a preset threshold as a new cluster center; According to the preset number of cluster centers, the anchor frame of the PCB surface defect sample data set is determined based on the K-means++ clustering algorithm.
4. The method according to claim 1, characterized in that According to the PCB surface defect sample dataset, the PCB surface defect detection model based on the YOLOv3 algorithm is trained at multiple scales, including: The image size of the PCB surface defect sample dataset is divided into multiple image scales; According to various image scales, the transfer learning method is used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm.
5. A PCB surface defect detection device based on YOLOv3 algorithm, characterized in that: include: A network structure building module, used to build a network structure of the YOLOv3 algorithm, wherein a batch normalization layer of the network structure is combined with a convolutional layer; The network loss function determination module is used to determine the network loss function and performance evaluation index of the YOLOv3 algorithm based on GIoU; An anchor frame determination module, used to determine the anchor frame of the PCB surface defect sample data set according to the K-means++ clustering algorithm; The PCB surface defect detection model building module is used to build a PCB surface defect detection model based on the YOLOv3 algorithm according to the network structure of the YOLOv3 algorithm, the network loss function and performance evaluation index of the YOLOv3 algorithm, and the anchor frame of the PCB surface defect sample data set; PCB surface defect detection model training module, used to perform multi-scale training on the PCB surface defect detection model based on the YOLOv3 algorithm according to the PCB surface defect sample data set; PCB surface defect detection module, used to input the image data of the PCB to be detected into the trained PCB surface defect detection model based on the YOLOv3 algorithm, and output the location information of the surface defects of the PCB to be detected; The network structure building module is specifically used to combine the batch normalization layer and the convolution layer of the network structure in the following manner: in, In the formula, x out is the output result of the batch normalization layer combined with the convolutional layer, x i is the output result of each layer after combination, n is the number of layers, γ is the scale factor, μ is the average value, σ 2 is the variance, β is the offset before combination, β′ is the offset after combination, w i is the weight parameter before combining, w i ′ is the weight parameter after combination; The network loss function determination module is specifically used for: Determine GIoU based on the predicted box, the actual box, and the minimum convex set of the predicted box and the actual box; Determine GIoU as the performance evaluation indicator of the YOLOv3 algorithm; Based on GIoU, determine the network loss function of the YOLOv3 algorithm; The network loss function determination module is further used to determine the GIoU as follows: In the formula, A is the predicted box, B is the actual box, and C is the minimum convex set of the predicted box and the actual box; The network loss function determination module is further used to determine the network loss function of the YOLOv3 algorithm as follows: L GIoU =1-GIoU; Where, L GIoU It is the network loss function of the YOLOv3 algorithm.
6. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
