A metal surface defect detection method based on improved YOLOv3

By improving the YOLOv3 algorithm, using K-means++ clustering, path aggregation network and ResBlock structure, combined with the DIOU loss function, the problem of poor detection of small targets and targets with unobvious features in metal surface defect detection is solved, achieving high accuracy and speed. detection effect.

CN113920400BInactive Publication Date: 2024-09-06LIAONING TECHNICAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111199291.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-14
Publication Date
2024-09-06
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing metal surface defect detection methods have shortcomings in detection accuracy and speed. In particular, they have poor detection results for small targets and targets with unobvious features, and their robustness is low, making it difficult to adapt to environmental changes.

Method used

Improve the YOLOv3 algorithm, generate more accurate a priori boxes through the K-means++ clustering algorithm, introduce the path aggregation network and ResBlock structure to enhance feature extraction capabilities, and use the DIOU loss function to optimize bounding box regression.

Benefits of technology

It has significantly improved the accuracy and speed of metal surface defect detection, with mAP reaching 72.83%, which is better than the single YOLOv3 and other mainstream target detection models, and can effectively detect small targets and defects with unclear features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113920400B
    Figure CN113920400B
Patent Text Reader

Abstract

The present invention discloses a metal surface defect detection method based on improved YOLOv3. Firstly, a K‑means++ clustering algorithm is used to cluster the parameters of the real frame, and a priori frame with a higher average intersection-over-union ratio than the real frame is obtained to improve the convergence speed of the algorithm; then, the feature pyramid (FPN) structure in the YOLOv3 algorithm is improved, a path aggregation network is introduced into the FPN structure, and a ResBlock structure is proposed to replace the convolution structure in the FPN, so as to enhance the feature extraction ability of the algorithm and improve the detection ability of small targets and targets with unclear features; finally, the DIOU loss function is used to optimize the bounding box regression, improve the positioning accuracy of the bounding box, and further improve the detection effect of the YOLOv3 model. The experimental results on the NEU‑DET dataset show that the proposed algorithm can effectively improve the accuracy of metal surface defect detection, and the mAP reaches 72.83%, which is 8.00% higher than the single YOLOv3 algorithm, and is better than other mainstream target detection models.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of mechanical processing technology, and in particular to a metal surface defect detection method based on improved YOLOv3. Background Art

[0002] During the mechanical processing, the metal surface will inevitably be damaged due to the influence of processing tools or operations, resulting in a series of defects such as cracks and plaques. The surface defects of the metal will seriously affect the quality and appearance of related products, thereby damaging the interests of the enterprise. Therefore, effective detection of defects on the metal surface can timely discover defective products, improve product utilization, and ensure product quality, which plays an important role in the development of the enterprise. Traditional manual visual inspection is easily affected by human subjective judgment, and there are problems such as unstable detection accuracy and low efficiency. Therefore, how to accurately and efficiently detect metal surface defects has become one of the hot research issues in recent years.

[0003] Early metal surface defect detection methods are mainly divided into traditional image processing methods and machine learning methods based on manually extracted features. Traditional image processing methods use the properties reflected by local anomalies to perform defect detection and segmentation, such as edge detection, template matching and other algorithms; machine learning-based methods first extract input image features using methods such as LBP and HOG, design feature vectors that describe defect information, and then input the feature vectors into a pre-trained classifier model to determine whether the input image contains defects. Although these methods have promoted the development of defect detection technology, these methods are usually only applicable to specific scenarios, lack adaptability to environmental changes, and have low robustness.

[0004] With the widespread application of deep learning in the field of computer vision, deep learning methods have gradually replaced traditional machine vision for metal surface defect detection. Deep learning detection algorithms are mainly divided into single-stage algorithms represented by YOLO, SSD and other algorithms and two-stage algorithms represented by R-CNN. The two-stage algorithm first uses a region selection network to extract features and generate candidate boxes, and then uses another convolutional neural network to classify and regress the candidate boxes. The two-stage algorithm has high detection accuracy, but the detection speed is slow and it is difficult to achieve real-time detection; the single-stage algorithm converts the detection problem from a classification problem to a regression problem, and only uses a convolutional neural network for feature extraction and candidate box classification and regression. It is an end-to-end target detection algorithm. The single-stage algorithm has a faster detection speed, but the detection accuracy is usually not as high as the two-stage algorithm.

[0005] Therefore, there is an urgent need for a metal surface defect detection method with faster detection speed and higher detection accuracy. Summary of the invention

[0006] In view of this, the present invention provides a metal surface defect detection method based on improved YOLOv3, by improving the YOLOv3 algorithm, while retaining the faster detection speed advantage of the YOLOv3 algorithm, further improving the accuracy of metal surface defect detection.

[0007] To this end, the present invention provides the following technical solutions:

[0008] The present invention provides a metal surface defect detection method based on improved YOLOv3, the method comprising:

[0009] S1. Acquire an image of the metal surface defect to be detected;

[0010] S2, performing image preprocessing on the image of the metal surface defect to be detected;

[0011] S3: Input the image after image preprocessing into the trained metal surface defect detection model to obtain the metal surface defect detection result; the metal surface defect detection model is based on the improved YOLOv3 model; in the improved YOLOv3 model, after the feature pyramid network transfers and fuses the deep feature information from top to bottom by upsampling, a path aggregation network is introduced, and a bottom-up feature pyramid structure is added behind the feature pyramid network layer. In addition to using the fused feature map for prediction, a downsampling branch is added to fuse the shallow feature map and the deep feature map again; the 5 consecutive CBL structures in the feature pyramid network are reintegrated using the residual structure, Add operation and Concat operation, and the information is superimposed by the Add operation to increase the amount of information describing the image features without changing the image dimension; the feature map obtained by the Add operation and the feature map of the jump connection are stacked by the Concat operation, and the features describing the image itself are increased by stacking the dimensions; the feature map passing through a CBL structure is used as the output of the residual structure.

[0012] Furthermore, the image preprocessing includes:

[0013] Resize the image to fit the input image size of the metal surface defect detection model.

[0014] Furthermore, the image preprocessing also includes: randomly performing flipping and color gamut transformation operations on the image with a probability of 0.5.

[0015] Furthermore, the improved YOLOv3 adopts the DIOU loss function to optimize the bounding box regression.

[0016] Furthermore, the improved YOLOv3 adopts a K-means++ clustering algorithm to cluster the parameters of the true box to obtain a priori box with a higher average intersection-over-union ratio with the true box.

[0017] Advantages and positive effects of the present invention:

[0018] The invention discloses a metal surface defect detection method based on improved YOLOv3. YOLOv3 is improved. First, the K-means++ clustering algorithm is used to cluster the parameters of the real frame, and a priori frame with a higher average intersection-over-union ratio with the real frame is obtained to improve the convergence speed of the algorithm; then the feature pyramid (FPN) structure in the YOLOv3 algorithm is improved, a path aggregation network is introduced into the FPN structure, and a ResBlock structure is proposed to replace the convolution structure in the FPN, so as to enhance the feature extraction ability of the algorithm and improve the detection ability of small targets and targets with unclear features; finally, the DIOU loss function is used to optimize the bounding box regression, improve the positioning accuracy of the bounding box, and further improve the detection effect of the YOLOv3 model. The experimental results on the NEU-DET data set show that the method provided by the invention can effectively improve the metal surface defect detection accuracy, and the mAP reaches 72.83%, which is 8.00% higher than the single YOLOv3, and is better than other mainstream target detection models. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0020] Figure 1 This is a flow chart of a metal surface defect detection method based on YOLOv3 in an embodiment of the present invention;

[0021] Figure 2 Schematic diagram of the original YOLOv3 network structure;

[0022] Figure 3 Schematic diagram of the residual structure in the original YOLOv3 network;

[0023] Figure 4 Schematic diagram of the improved YOLOv3 network structure in an embodiment of the present invention;

[0024] Figure 5 Schematic diagram of the ResBlock structure in the improved YOLOv3 network in an embodiment of the present invention;

[0025] Figure 6 The predicted box and the real box have the same L2 distance but different IOU;

[0026] Figure 7Schematic diagram of DIOU in an embodiment of the present invention;

[0027] Figure 8 Schematic diagram of the NEU-DET dataset;

[0028] Fig. 9 It is the loss function value curve of YOLOv3 and improved YOLOv3;

[0029] Fig.10 Comparison of PR curves of YOLOv3 and improved YOLOv3 for each defect category;

[0030] Fig.11 Comparison of the average precision values ​​of YOLOv3 and improved YOLOv3. DETAILED DESCRIPTION

[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0032] like Figure 1 It shows a flow chart of a metal surface defect detection method based on improved YOLOv3 provided in an embodiment of the present invention, the method comprising:

[0033] S1. Acquire an image of the metal surface defect to be detected;

[0034] Among them, metal surface defects mainly include the following six categories: crazing, inclusions, patches, pitted surface, rolled-in scale, and scratches.

[0035] The image of metal surface defects to be detected includes one or more of the above metal surface defects.

[0036] S2, performing image preprocessing on the image of the metal surface defect to be detected;

[0037] Among them, image preprocessing includes: adjusting the image size to adapt to the input image size of the metal surface defect detection model. For example, if the initial pixel of the image is 200×200, the image size is adjusted to 416×416, which is adapted to the input image size of the YOLOv3 model.

[0038] In order to enhance the processing effect of the metal surface defect detection model, the image preprocessing also includes: randomly flipping the image with a probability of 0.5 and performing color gamut transformation operations.

[0039] S3: Input the image after image preprocessing into the trained metal surface defect detection model to obtain the metal surface defect detection result.

[0040] Among them, the metal surface defect detection model in the embodiment of the present invention is based on the improved YOLOv3 model.

[0041] YOLOv3 is an end-to-end real-time target detection algorithm. The network structure is as follows Figure 2 As shown in the figure, it mainly consists of three parts: Darknet-53 feature extraction network, FPN and multi-scale prediction layer. Among them:

[0042] Darknet-53 integrates the residual structure of ResNet (Residual Network), which is composed of a CBL structure and 5 residual structures. The CBL structure is composed of a convolutional layer, a batch normalization layer, and an activation function layer in series; the 5 residual structures are composed of different numbers of residual blocks (1, 2, 8, 8, 4), and N residual blocks are composed of a CBL structure and N residual units in series, such as Figure 3 (a) Each residual unit is composed of the input of the previous layer and the output of the previous layer through two CBL structures through the Add operation, as shown in Figure 3 (b) Each residual structure compresses the input feature map size to half of its original size. Figure 2 In the figure, the input image is 416×416×3, and the feature map sizes of the five residual structures are 208×208×64, 104×104×128, 52×52×256, 26×26×512, and 13×13×1024. The output feature maps of the last three residual structures will be used as the input of FPN.

[0043] FPN includes three prediction branch structures, which provide feature information for the detection of large targets, medium targets, and small targets respectively. It uses the CBL structure and upsampling layer through the top-down feature flow to fuse the strong semantic information contained in the deep feature branch with the shallow feature branch, providing stronger semantic feature information for the shallow feature branch.

[0044] The multi-scale prediction layer yolo head structure consists of a CBL structure and a 1×1 convolutional layer, which reduces the dimension of the input feature map to a fixed number of channels to produce the final output.

[0045] YOLOv3 uses a 416×416 image as input. After passing through the feature extraction network, the image is divided into S×S grids. By using the K-means clustering algorithm to generate a priori boxes for the data set, each grid will eventually preset 3 sets of prior boxes at 3 different scales. Then each prediction feature layer needs to predict N×N×[S×(4+1+C)] parameters, where N represents the scale size; S represents the number of scales predicted for each grid; 4+1+C parameters are predicted for each scale, including 4 offset parameters for each predicted bounding box; 1 confidence score, the confidence of the current grid is 0 when it does not contain the target, and the confidence becomes the IOU value of the predicted box and the true box when it contains the target; C category scores, the category with the highest score is the target category. Then, by setting a threshold for the confidence, the prediction boxes with low scores are excluded, and finally, the redundant prediction boxes are filtered out by non-maximum suppression (NMS) to obtain the final network prediction result.

[0046] In order to improve the detection accuracy of YOLOv3 in detecting metal surface defects, the following improvements are proposed to the YOLOv3 algorithm in the embodiment of the present invention: first, the K-means++ clustering algorithm is used to obtain a priori boxes with a higher average intersection-over-union ratio, thereby improving the convergence speed of the target detection algorithm; then, the FPN is improved by introducing the PANet and ResBlock structures, thereby enhancing the feature extraction capability of the algorithm and improving the detection capability of small targets and targets with unclear features; finally, the CIOU loss function is used to optimize the bounding box regression, thereby improving the accuracy of the positioning bounding box and further improving the detection effect of the YOLOv3 model.

[0047] For ease of understanding, the improvements made to the YOLOv3 algorithm in the embodiments of the present invention are specifically described below:

[0048] (1) Improve the prior box generation method: use K-means++ clustering algorithm

[0049] The original YOLOv3 algorithm uses the K-means clustering algorithm to cluster the true bounding box size and determine the highest priority box size to improve the overlap rate between the prior box and the true box.

[0050] Since the K-means clustering algorithm is sensitive to the selection of initial cluster centers, different initial cluster centers will produce different clustering results, and there will also be large differences between different results, resulting in the final prior frame being inaccurate. To address this phenomenon, the K-means++ clustering algorithm is adopted in the embodiment of the present invention to replace the cluster center selection method of the K-means algorithm: first, the data mean is used as the first cluster center, and then K-1 points in the data that are farthest from the first cluster center are selected as the remaining cluster centers. After obtaining K initial cluster centers, the K-means algorithm is used for clustering.

[0051] The K-means algorithm divides samples by using Euclidean distance as a similarity measurement method. Using Euclidean distance as a distance measurement method will cause a larger error in a large bounding box than a small bounding box, thereby deviating from the clustering result. Since the significance of clustering is to determine more accurate prior frame parameters so that the prior frame and the true frame have a higher average intersection-over-union ratio, the intersection-over-union ratio is used as a new judgment standard. The final distance measurement formula in the embodiment of the present invention is shown in formula (1):

[0052]

[0053]

[0054] Among them, box represents the true bounding box parameters, centroid represents the cluster center, IOU represents the intersection-over-union ratio of the predicted box A and the true box B. The larger the IOU, the smaller the distance.

[0055] Since the anchor box size of the original YOLO algorithm is generated by clustering the COCO dataset, the target category and size of this dataset are quite different from those of the NEU-DET dataset. Therefore, the Kmeans++ algorithm is used to generate a priori boxes for the NEU-DET dataset with an input resolution of 416×416. The sizes of the 9 anchor boxes generated are (33,349), (37,73), (50,147), (79,391), (96,81), (119,150), (162,258), (293,122), and (333,399), and the average intersection-over-union ratio is increased to 69.03%, which is 2.68% higher than the result obtained by K-means.

[0056] (2) Improve the network structure

[0057] In the embodiment of the present invention, further optimization and improvement are made to the FPN structure of YOLOv3, and the FPN structure is combined with the path aggregation network. Path aggregation mainly considers the importance of shallow feature information of the network. Since shallow features are mostly edge shape and other features, they are very important for accurate detection. The improved YOLOv3 network structure is as follows Figure 4 As shown in the figure, after the model transfers and fuses the deep feature information from top to bottom through FPN by upsampling, it introduces a path aggregation network and adds a bottom-up feature pyramid structure behind the FPN layer. In addition to using the fused 52×52 scale feature map for prediction, it adds a downsampling branch and fuses the shallow feature map with the deep feature map again. With this combined operation, the FPN layer transfers strong semantic features from top to bottom, while the feature pyramid transfers strong positioning features from bottom to top. The strong semantic features and strong positioning features are combined in pairs, and parameters of different detection layers are aggregated from different backbone layers.

[0058] In addition, a ResBlock structure is proposed in the embodiment of the present invention to replace the five consecutive CBL structures in the original model. The original model uses five consecutive CBL structures, and extracts features by alternating 1×1 and 3×3 convolutions. In order to enhance the feature extraction effect, the five consecutive CBL structures are re-integrated using residual structures, Add operations, and Concat operations, such as Figure 5 As shown in the figure, first, the Add operation can be used to superimpose information and increase the amount of information describing the image features without changing the image dimension; then, the feature map obtained by the Add operation and the feature map of the jump connection are stacked together through the Concat operation, and the features describing the image itself are increased by stacking the dimensions; finally, the feature map that has passed through a CBL structure is used as the output of the ResBlock structure.

[0059] (3) Improve the loss function

[0060] The loss function is the basis for judging the difference between the predicted value and the true value, and plays a vital role in the performance of the deep learning algorithm. Only by using a loss function that is more suitable for the detection principle of the YOLOv3 algorithm can better detection results be achieved.

[0061] The loss function of the original YOLOv3 model consists of the weighted sum of three parts: bounding box regression loss, confidence loss, and classification loss, namely:

[0062] L=L coord +L conf +L cla (3)

[0063] The bounding box regression loss consists of two parts: the center point coordinate loss and the width and height size loss, which are calculated using the mean square error function; the confidence loss is obtained by summing the confidence loss of the target detection box and the confidence loss of the non-target detection box, which is calculated using the cross entropy function; the category loss is calculated using the Sigmoid activation function. The loss function calculation formula is shown in formula (4):

[0064]

[0065] where λ coord , noobj is the balance coefficient, the total number of grids is S 2 Each grid generates B candidate boxes, and finally gets S*S*B bounding boxes. Indicates whether the jth anchor box of the i-th grid is "responsible" for this target. If so, then Otherwise, it is 0. The definition of "responsible" is: when the IOU between the B anchor boxes of the i-th grid and the real bounding box of the target is the largest among all the anchor boxes and the real bounding box, the anchor box is said to be "responsible" for the target. i , Y i , W i , H i Represent the horizontal and vertical coordinates of the center of the real bounding box and the width and height of the box, respectively. Represents the value of the corresponding predicted bounding box; and C i Represent the confidence of the predicted box and the true box respectively; and p i (c) Represents the category probability values ​​of the predicted box and the true box respectively.

[0066] The polynomial in formula (4) contains 5 sub-terms. The first term represents the loss of the center coordinate of the prediction box; the second term is the loss of the width and height of the prediction box; the third term is the confidence loss of the prediction box containing the target; the fourth term is the confidence loss of the prediction box excluding the target; and the last term is the category probability value loss. The squared error is used in the bounding box regression loss to reduce the impact of the excessive proportion of the prediction box loss value. At the same time, since the bounding box regression loss value of the small target is small, (2-W i ×H i ) equation to adjust the weights and increase the loss of small object bounding box regression.

[0067] From formula (4), we can see that the original YOLOv3 uses the mean square error loss function for prediction box regression. However, the mean square error loss function treats the coordinates of the center point of the bounding box and the width and height information as independent variables, ignoring the overall connection between these four parameters. Therefore, it cannot well reflect the IOU value of the predicted box and the true box, thereby reducing the efficiency of target positioning. Figure 6 The IOU comparison is when the L2 norm of the distance between the predicted box and the real box corner coordinates is the same, where the solid box represents the real box and the dotted box represents the predicted box. Figure 6 It can be seen that the two boxes with the same L2 distance have very different IOU values.

[0068] Since YOLOv3 needs to obtain a prediction box with a larger IOU value as the final result, IOU is used to measure the bounding box regression loss. However, IOU cannot accurately reflect the overlap between two boxes. When IOU is equal, the overlap between the two boxes may be different, so IOU cannot be directly used as a bounding box regression loss function. In view of this situation, the DIOU loss function is used as a new bounding box regression loss function. The DIOU diagram is shown below: Figure 7As shown, d represents the distance between the center points of the two candidate boxes, and c represents the diagonal distance of the minimum closure area that can contain both the predicted box and the real box.

[0069] The calculation formula of DIOU is shown in formula (5):

[0070]

[0071] Among them, b and b gt denote the center points of the predicted box and the true box respectively, and ρ denotes the Euclidean distance. When the two bounding boxes completely overlap, L DIoU = 0, when the two bounding boxes are far apart, L DIoU It is close to 2, so DIoU can well reflect the overlap degree of two bounding boxes. The loss function of DIOU is shown in formula (6):

[0072] L DIoU =1-DIoU (6)

[0073] DIoU takes into account the overlapping area and center point distance of the bounding box. When the predicted box and the real box do not intersect, it can still provide the correct moving direction for the predicted box, making the predicted box regression more accurate. Since DIoU directly calculates the distance between the two boxes, it can also increase the prediction box regression speed.

[0074] In the specific implementation, the metal surface defect detection model needs to be trained in advance. The training process is as follows:

[0075] First, obtain a metal surface defect dataset, such as the NEU-DET steel surface defect dataset. Adjust the size of each image in the dataset to a size that is compatible with the yolov3 model (416×416). To enhance the model training effect, each image is randomly flipped and the color gamut is transformed with a probability of 0.5. The dataset is divided into a training set and a test set in proportion.

[0076] Then, the training set was used to train the metal surface defect detection model. Adam was used as the optimizer for network training, and the batch size was set to 8. After 250 epochs, the initial learning rate was set to 1e-2. The piecewise constant decay strategy was adopted, the step size was set to 2, and the decay rate was set to 0.96. Finally, the learning rate was reduced to 1e-6.

[0077] The metal surface defect detection method based on improved YOLOv3 in the embodiment of the present invention improves YOLOv3. First, the K-means++ clustering algorithm is used to cluster the real frame parameters to obtain a priori frame with a higher average intersection-over-union ratio with the real frame to improve the convergence speed of the algorithm; then the feature pyramid (FPN) structure in the YOLOv3 algorithm is improved, a path aggregation network is introduced into the FPN structure, and a ResBlock structure is proposed to replace the convolution structure in the FPN, so as to enhance the feature extraction capability of the algorithm and improve the detection capability of small targets and targets with unclear features; finally, the DIOU loss function is used to optimize the bounding box regression, improve the positioning accuracy of the bounding box, and further improve the detection effect of the YOLOv3 model. This method can effectively improve the accuracy of metal surface defect detection.

[0078] In order to verify the effectiveness of the metal surface defect detection method based on improved YOLOv3 provided by the present invention, the present invention conducted the following experiments:

[0079] Experimental platform: The experiment is based on the Windows 10 operating system. The workstation is configured with an Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz, 32G running memory, and an Nvidia RTX 3070 graphics card with 8G video memory. Pytorch 1.7 is used as the deep learning framework, and CUDA 11.0 and Cudnn 8.0.5 are used for GPU accelerated model training.

[0080] Dataset: The experiment uses the NEU-DET steel surface defect dataset, which has 6 types of defects, namely crazing, inclusions, patches, pitted surface, rolled-in scale, and scratches, with 300 images for each type of defect. Since the initial pixel of the image is 200×200, in order to adapt to the input image size of the YOLO model, the 1800 images in the dataset are resized to 416×416. In order to enhance the model training effect, each image is randomly flipped and color gamut transformed with a probability of 0.5. The dataset is divided into training set and test set in a ratio of 8:2, and then the training set is divided into training set and validation set in a ratio of 9:1. Finally, 1296 training images, 144 validation images and 360 test images are obtained. The NEU-DET dataset is as follows Figure 8 shown.

[0081] Model training: Since the NEU-DET dataset is quite different from the dataset used for pre-training weights, the experiment does not load pre-training weights for training. Adam is used as the optimizer for network training, and the batch size is set to 8. After 250 epochs, the initial learning rate is set to 1e-2, and the piecewise constant decay strategy is adopted. The step size is set to 2 and the decay rate is 0.96, and the learning rate is finally reduced to 1e-6.

[0082] Fig. 9 Loss curves for YOLOv3 and improved versions ( Fig. 9 The left picture is the YOLOv3 model loss function value curve. Fig. 9 The right figure is the loss function value curve of the improved YOLOv3 model), with the horizontal axis being the epoch value and the vertical axis being the loss value. Since the model does not load the pre-trained weights for training, the initial loss value is relatively high. The initial loss value of the YOLOv3 model reaches 198.56; the initial loss value of the improved YOLOv3 model reaches 171.38. In order to make the curve fluctuation of the loss function value clearer and more intuitive, the loss function value curve is drawn from the second epoch. The loss of the second epoch of the YOLOv3 model is 46.39. After 250 epochs of training, it finally converges to 13.65; the loss of the second epoch of the improved YOLOv3 model is 26.92. After 250 epochs of training, it finally converges to 13.01. It can be seen that the convergence speed of the loss value of the improved algorithm is significantly accelerated, which proves the effectiveness of the algorithm improvement.

[0083] Evaluation indicators: The experiment uses mAP (mean Average Precision) to test the effectiveness of the improved model. mAP is the most important and commonly used evaluation indicator in the target detection algorithm, and is one of the best criteria for measuring the comprehensive performance of the model. AP (Average Precision) can be obtained by calculating the accuracy P (Precision) and the recall R (Recall), and then the AP is averaged by the number of categories to get the final mAP. The calculation formulas of P, R, AP, and mAP are shown in equations (7)-(10):

[0084]

[0085]

[0086]

[0087]

[0088] Where TP represents the number of correctly predicted targets; FN represents the number of unpredicted targets; FP represents the number of incorrectly predicted targets; AP is the average accuracy of each category; and N is the total number of categories in the dataset.

[0089] Compared with the YOLOv3 algorithm, the detection accuracy of the algorithm of the present invention for each defect category is improved, which proves the effectiveness of the improvement.

[0090] Experimental results analysis:

[0091] (1) Longitudinal comparative experiment and result analysis:

[0092] The original YOLOv3 and the improved YOLOv3 of the present invention are used to predict the test set respectively and the visual prediction results of the six defect categories are compared with the true label values. Fig.10 As shown (the first row represents the true label value, the second row represents the prediction result of the original YOLOv3, and the third row represents the prediction result of the improved YOLOv3 of the present invention). By comparison, it can be seen that the algorithm of the present invention can detect more targets than YOLOv3, and the size and position of the prediction box are closer to the true box. In the detection of these 6 defect categories, the detection effect of the algorithm of the present invention is better than that of YOLOv3, which proves that the improved algorithm can effectively improve the recall rate, improve the regression effect of the prediction box, and make the prediction box closer to the true box.

[0093] Fig.11 The AP value comparison of the original algorithm and the improved algorithm for different categories is listed. It can be seen from the figure that the model proposed by the present invention has a certain degree of improvement in all categories compared with the original model. At the same time, for the three defect categories of crazing, inclusion and scratches, the accuracy of the improved algorithm is more obvious, which is increased by 17%, 7% and 8% respectively. Fig.11 From the visual inspection image, the features of crazing defects are not obvious, while inclusion and scraches defects have more small targets. The algorithm of the present invention significantly improves the detection accuracy of the above defects, and the detection effect of the visual inspection image is also significantly improved, which proves the effectiveness of the algorithm of the present invention in detecting small targets and defects with unclear features.

[0094] In order to further analyze the impact of various improvements on the YOLOv3 algorithm, an ablation experiment was conducted. The algorithm of the present invention was divided into 4 groups for training and testing. The first group was the YOLOv3 algorithm, and the fourth group was the algorithm of the present invention. The improved methods proposed by the present invention were added to groups 2-4 in sequence. The experimental results are shown in Table 1.

[0095] Table 1

[0096]

[0097] As can be seen from Table 1, the prior box of group A using K-means++ clustering has a higher average intersection-over-union ratio, and the mAP is slightly improved compared to the original algorithm; compared with group A and group B, it can be seen that after improving the feature extraction effect of the FPN structure enhancement model, the mAP has been significantly improved. Although the addition of the PANet structure will introduce some parameters and cause the FPS to decrease, considering the obvious improvement in accuracy, the improvement is worthwhile. Finally, compared with the algorithm of the present invention, after using DIOU as the bounding box regression loss, the mAP also has a higher improvement, and finally reaches 72.83%.

[0098] In summary, the ablation experiment proves that the improvement methods proposed by the present invention for YOLOv3 are effective, that is, the detection accuracy is effectively improved while minimizing the FPS loss.

[0099] (2) Horizontal comparison experiment and result analysis

[0100] The present invention also compares the detection effects of the improved YOLOv3 algorithm with other excellent target detection algorithms in the application of metal surface defect detection. The results are shown in Table 2. It can be seen that the mAP of the improved YOLOv3 algorithm reaches 72.83%, which is 8.00% higher than that of the original YOLOv3 algorithm, and the AP values ​​of the six defects are all improved; compared with the single-stage target detection algorithms SSD and DSSD, the mAP is 11.06% and 6.64% higher respectively, and the detection speed is much faster than DSSD, with a real-time detection effect; compared with the two-stage detection algorithm Faster R-CNN, the mAP is 4.38% higher. In terms of FPS, although it has declined compared with the original algorithm, it can still perform real-time detection at a relatively high FPS. Compared with the mainstream target detection algorithms Mobilenetv3-YOLOv4 and EfficientDet D6 in the past two years, the algorithm of the present invention is comparable to the former in FPS and has a mAP 2.00% higher. Although the mAP of the latter is 3.49% higher than that of the algorithm of the present invention, due to the huge network structure of EfficientDet D6, its real-time performance is extremely low, with an FPS of only 2.90, and it is unable to achieve real-time industrial detection.

[0101] In summary, the comprehensive detection performance of the algorithm of the present invention is optimal and meets the higher detection requirements of metal surface defect detection.

[0102] Table 2

[0103]

[0104] In order to solve the problems of poor small target detection effect and missed detection of targets with unclear features in metal surface defect detection, the present invention proposes an improved YOLOv3 metal surface defect detection algorithm. First, a priori frame with a higher average intersection-over-union ratio is obtained through K-means++ clustering; secondly, a path aggregation network is introduced after the FPN structure and 5 consecutive convolution blocks are replaced with a ResBlock structure to enhance the algorithm feature extraction effect; finally, DIOU is used as a new bounding box regression loss to optimize the bounding box regression effect. The final experimental results show that the improved algorithm has a certain degree of improvement compared with the original YOLOv3 and other mainstream target detection algorithms, and can meet the further accuracy requirements of metal surface defect detection. In future research, the detection speed will be balanced while further improving the detection accuracy of the model to meet the real-time detection needs.

[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A metal surface defect detection method based on improved YOLOv3, characterized in that: The method comprises: S1. Acquire an image of the metal surface defect to be detected; S2, performing image preprocessing on the image of the metal surface defect to be detected; S3: Input the image after image preprocessing into the trained metal surface defect detection model to obtain the metal surface defect detection result; the metal surface defect detection model is based on the improved YOLOv3 model; in the improved YOLOv3 model, the feature pyramid network transfers and fuses the deep feature information from top to bottom by upsampling, introduces the path aggregation network, adds a bottom-up feature pyramid structure behind the feature pyramid network layer, and adds a downsampling branch to the fused feature map in addition to prediction, and fuses the shallow feature map and the deep feature map again; the 5 consecutive CBL structures in the feature pyramid network are reintegrated using the residual structure, Add operation and Concat operation, firstly, the information is superimposed by the Add operation to increase the amount of information describing the image features without changing the image dimension, and then the feature map obtained by the Add operation and the feature map of the jump connection are stacked by the Concat operation, and the features describing the image itself are increased by stacking the dimensions, and finally the feature map passing through a CBL structure is used as the output of the residual structure; Among them, the CBL structure is composed of a convolutional layer, a batch normalization layer, and an activation function layer in series; the five residual structures are respectively composed of different numbers of residual blocks, and N residual blocks are composed of a CBL structure and N residual units in series; the five consecutive CBL structures in the feature pyramid network are reintegrated using the residual structure, Add operation, and Concat operation, including: the input end, the first CBL, the second CBL, and the third CBL are connected in sequence, the output of the first CBL and the output of the third CBL are skipped, and the output of the third CBL is used as the input of the Add operation together, the fourth CBL is connected to the input end, the output of the fourth CBL and the output of the Add operation are used as the input of the Concat operation together, and the output of the Concat operation is used as the input of the fifth CBL; The improved YOLOv3 adopts the DIOU loss function to optimize the bounding box regression; the improved YOLOv3 adopts the K-means++ clustering algorithm to cluster the parameters of the real box to obtain a priori box with a higher average intersection-over-union ratio with the real box.

2. According to a metal surface defect detection method based on improved YOLOv3 according to claim 1, it is characterized in that: The image preprocessing comprises: Resize the image to fit the input image size of the metal surface defect detection model.

3. A metal surface defect detection method based on improved YOLOv3 according to claim 2, characterized in that: The image preprocessing also includes: The image is randomly flipped and the color gamut is transformed with a probability of 0.5.