Steel surface defect detection algorithm based on improved YOLOv5

By introducing the attention mechanism and improving the SPPF structure and loss function in YOLOv5, the problem that traditional detection methods are difficult to identify complex defects is solved, efficient and accurate steel surface defect detection is achieved, and detection accuracy and efficiency are improved.

CN118674697APending Publication Date: 2024-09-20UNIV OF ELECTRONICS SCI & TECH OF CHINA

Patent Information

Application Number
CN202410751850.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

Traditional steel surface defect detection methods are difficult to effectively identify and classify various complex defects, especially due to large differences within defect categories, small differences between categories, large scale contrast, and excessive background fusion, resulting in low detection accuracy and efficiency. .

Method used

Based on the improved YOLOv5 steel surface defect detection algorithm, the attention mechanism CBAM is introduced, the SPPF structure is improved, the Wise-IoU bounding box regression loss function is adopted, and the detection head is improved to form an efficient defect detection model.

Benefits of technology

The detection accuracy and efficiency are improved, with the mAP value reaching 80.6%, 4.8% higher than YOLOv5s, significantly reducing false detections and missed detections, and ensuring the accurate identification and classification of steel surface defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118674697A
    Figure CN118674697A
Patent Text Reader

Abstract

The invention discloses a steel surface defect detection algorithm based on improved YOLOv5, and the algorithm comprises the following steps: S1, obtaining a steel surface defect data set, carrying out the preprocessing of image data in the data set, and dividing the data set; s2, a CBAM attention mechanism is introduced into the YOLOv5 backbone network, an SPPF structure is improved, a detection head is improved, and a loss function is regressed by using a Wise-IoU bounding box; s3, training the improved YOLOv5 model by using the preprocessed data set to obtain an optimal weight file; and S4, loading the optimal model weight file, and carrying out defect identification on the steel surface image to be detected. The method can efficiently and accurately detect steel surface defects, improves the detection precision, and is suitable for quality control in industrial production.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the application field of industrial defect detection, and in particular to an improved steel surface defect detection algorithm based on YOLOv5. Background Art

[0002] In the steel production process, surface defect detection is a vital link. It not only directly affects the structural integrity and service life of steel, but also plays a key role in maintaining the stable operation of the production line and ensuring that the products meet industry standards and consumer expectations. Through accurate defect identification and classification, the production team can promptly discover and solve quality problems that arise in the production process, prevent defective steel from entering the market, and thus ensure the quality and performance of the final product. Therefore, the development of efficient and accurate steel surface defect detection methods is the focus of continuous research and technological innovation in the field of steel production.

[0003] The surface defects of steel have the characteristics of large intra-category differences, small inter-category differences, large contrast between different defect scales, and high degree of fusion with the background, which poses great challenges to traditional detection methods such as manual detection and photoelectric detection. In recent years, the rapid development of deep learning related theories has enabled end-to-end detection solutions to be realized, which can effectively overcome the limitations of traditional methods and improve the accuracy and efficiency of detection. Therefore, the present invention proposes a steel surface defect detection algorithm based on improved YOLOv5 in response to the actual needs of steel surface defect detection. Summary of the invention

[0004] The purpose of the present invention is to provide an improved steel surface defect detection algorithm based on YOLOv5, which introduces an attention mechanism, improves the SPPF structure, improves the detection head, and uses the Wise-IoU bounding box regression loss function as an evaluation indicator. The present invention has high detection accuracy and ensures good detection efficiency, providing important support for quality control of steel industry production.

[0005] The objective of the present invention is achieved through the following technical solution: an improved steel surface defect detection algorithm based on YOLOv5, comprising the following steps:

[0006] S1. Obtain a steel surface defect data set, perform preprocessing operations on image data in the data set, and divide the data set;

[0007] S2. Improve the YOLOv5 steel surface defect detection model to improve the performance of the model in the steel surface defect detection task;

[0008] S3, inputting the data set obtained in step 1 into the steel surface defect detection model of the improved YOLOv5 in step 2 for training, and obtaining the weight file with the best performance on the validation set;

[0009] S4, input the steel surface image to be tested, load the optimal model weights of step 3 to perform defect recognition, and output the final result of the steel surface defect image to be tested.

[0010] Furthermore, the step S1 includes the following sub-steps:

[0011] S11, selecting a public data set, and performing a Gaussian filtering image denoising operation on image data in the public data set of steel surface defects;

[0012] S12. Perform an image enhancement operation of adaptive grayscale equalization on the image data in the public dataset of steel surface defects.

[0013] S13, dividing the image data and label files of the data set into a training set, a validation set and a test set in a ratio of 8:1:1 for model training.

[0014] Furthermore, the step S2 includes the following sub-steps:

[0015] S21. Introduce the CBAM attention mechanism in the YOLOv5 backbone network. The CBAM module combines the two attention mechanisms of channel attention and spatial attention, which can comprehensively analyze and strengthen feature information, allowing the model to pay more attention to the key areas of the defect image and achieve efficient and accurate detection of defects.

[0016] S22. Replace the maximum pooling operation in the SPPF module with a soft pooling operation. At the same time, adjust the pooling kernel size in the module to 3×3, 5×5, and 9×9 to improve the responsiveness of the model to features of different scales. The improved SPPF module is named S-SPPF module.

[0017] S23. Replace the original coupled detection head of YOLOv5 with the decoupled detection head of YOLOX, and make further improvements by removing the 1×1 dimensionality reduction convolution layer and adjusting the detection head dimension according to the width coefficient of the backbone network and the neck; at the same time, simplify the two branches and reduce a 3×3CBS convolution module to avoid the increase in computational complexity and information loss caused by too many convolution layers. In addition, the SILU function in the original decoupled detection head CBS module is replaced by a simpler ELU activation function to form a CBE module. The improved decoupled detection head can alleviate the conflict between classification and positioning in target detection, and further improve the detection accuracy of steel surface defects;

[0018] S24. Replace the CIoU loss function of the YOLOV5 model with a Wise-IoU loss function that can balance data quality to reduce the penalty of low-quality data on network training. The specific formula of the Wise-IoU loss function is shown in formula (1)-formula (4):

[0019]

[0020] Among them, r is the gradient gain obtained by the prediction box; R WIoU is the geometric difference between the predicted box and the labeled box; is the loss value of the intersection-over-union ratio of the prediction box; x, y are the center coordinates of the prediction box; x gt ,y gt is the center coordinate of the annotation box; W g , H g is the width and height of the minimum enclosing box; β is the outlier degree of the predicted box; α and δ are hyperparameters; is the mean of the dynamic intersection-over-union loss of the prediction box.

[0021] Furthermore, the training process of the improved YOLOv5 steel surface defect detection model described in step S3 is as follows:

[0022] Use the steel surface defect dataset obtained in step 1 to train the improved YOLOv5 steel surface defect detection model. Set the relevant parameters for model training, select batch-size as 32, set the initial learning rate to 0.01, use the linear learning decay rate strategy for training, the weight decay parameter is 0.0005, and the momentum factor is set to 0.937; according to the YOLOv5 author's suggestion to train a smaller custom dataset, use the Adam optimizer, and train 200 rounds, of which the first 3 rounds use the warm-up method to preheat the learning rate. In addition, according to experience, set δ=3.0 and α=2.2 in Wise-IoU. After training, save the best performing model weights as the file best.pt for subsequent steel surface defect detection tasks.

[0023] Furthermore, the step S4 includes the following sub-steps:

[0024] S41. Input the image to be detected into the improved YOLOv5 steel surface defect detection model, load the pre-trained optimal weight file best.pt for detection, and the output image will mark the detected object category and its corresponding confidence.

[0025] S42. Verify the accuracy of the improved YOLOv5 steel surface defect detection model. When evaluating the model performance, AP (average precision) and mAP (average precision) are used as key indicators. The calculation method is shown in formula (5) and formula (6):

[0026]

[0027] Where N represents the number of samples, p(r i) means taking Recall values ​​at equal intervals, the accuracy rate under the i-th recall rate, AP(j) means the average precision of the j-th category recognition, and K means the total number of categories.

[0028] The beneficial effects of the present invention are as follows: a steel surface defect detection algorithm based on improved YOLOv5 is proposed, which solves the problem of unsatisfactory detection model performance caused by the characteristics of steel surface defects. The CBAM attention mechanism is introduced to focus on the defect area; the maximum pooling operation in the SPPF module is replaced with a soft pooling operation, and the pooling kernel size is adjusted, which effectively reduces the information loss of defects with high background fusion and tiny defects; the detection head is improved based on the decoupled structure, and the classification and positioning tasks are decomposed to alleviate the potential conflict between the two tasks; finally, Wise-IoU is used to replace the CIoU loss function in the original YOLOv5 network, which reduces the penalty of low-quality data on network training. The mAP value of the improved model for steel surface defect detection of the present invention reaches 80.6%, which is 4.8% higher than YOLOv5s, greatly reducing false detections and missed detections. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 This is a network structure diagram of steel surface defect detection based on improved YOLOv5 of the present invention;

[0030] Figure 2 This is a schematic diagram of the CBAM module in the present invention;

[0031] Figure 3 It is a schematic diagram of the S-SPPF module of the present invention;

[0032] Figure 4 Figure 1 is a structural diagram of the improved decoupling detection head of the present invention, wherein Figure (a) is the improved decoupling detection head structure, and Figure (b) is the CBE module structure;

[0033] Figure 5 Figure 2 is the detection result diagram, where Figure (a) is the original yolov5 detection result, and Figure (b) is the optimized model detection result. DETAILED DESCRIPTION

[0034] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.

[0035] S1. Obtain a steel surface defect data set, perform preprocessing operations on image data in the data set, and divide the data set;

[0036] The specific steps include:

[0037] S11. In the experiment, the present invention uses the NEU steel surface defect public dataset of Northeastern University, which contains six types in total: cracks (Cr), inclusions (In), patches (Pa), pits (Ps), scale indentations (Rs) and scratches (Sc). Each type of defect sample contains 300 images, all of which are grayscale images. First, the image data in the dataset is subjected to image denoising by Gaussian filtering;

[0038] S12, performing an image enhancement operation of adaptive grayscale equalization on the image data in the NEU data set;

[0039] S13, dividing the image data and label files of the data set into a training set, a validation set and a test set in a ratio of 8:1:1 for model training.

[0040] S2. Improve the YOLOv5 steel surface defect detection model to improve the performance of the model in the steel surface defect detection task. The improved model structure is shown in the figure below: Figure 1 ;

[0041] The specific steps include:

[0042] S21. Introduce the CBAM attention mechanism into the YOLOv5 backbone network. The CBAM module structure is as follows Figure 2 It combines the two attention mechanisms of channel attention and spatial attention, which can comprehensively analyze and enhance feature information, enable the model to pay more attention to the key areas of the defect image, and achieve efficient and accurate detection of defects.

[0043] S22. Replace the maximum pooling operation in the SPPF module with a soft pooling operation, and adjust the pooling kernel size in the module to 3×3, 5×5, and 9×9 to improve the responsiveness of the model to features of different scales. The improved SPPF module is named S-SPPF module, and its structure is as follows: Figure 3 .

[0044] S23, replace the original coupled detection head of YOLOv5 with the decoupled detection head of YOLOX, and make further improvements, remove the 1×1 dimensionality reduction convolution layer, and adjust the detection head dimension according to the width coefficient of the backbone network and the neck; at the same time, simplify the two branches and reduce a 3×3CBS convolution module to avoid the increase in calculation and information loss caused by too many convolution layers. In addition, the SILU function in the original decoupled detection head CBS module is replaced by a simpler ELU activation function to form a CBE module. The improved decoupled detection head structure is as follows Figure 4 (a), the CBE module structure is as follows Figure 4 (b) It can alleviate the conflict between classification and positioning in target detection and further improve the detection accuracy of steel surface defects;

[0045] S24. Replace the CIoU loss function of the YOLOV5 model with a Wise-IoU loss function that can balance data quality to reduce the penalty of low-quality data on network training. The specific formula of the Wise-IoU loss function is shown in formula (1)-formula (4):

[0046]

[0047] Among them, r is the gradient gain obtained by the prediction box; R WIoU is the geometric difference between the predicted box and the labeled box; is the loss value of the intersection-over-union ratio of the prediction box; x, y are the center coordinates of the prediction box; x gt ,y gt is the center coordinate of the annotation box; W g , H g is the width and height of the minimum enclosing box; β is the outlier degree of the predicted box; α and δ are hyperparameters; is the mean of the dynamic intersection-over-union loss of the prediction box.

[0048] S3, input the data set obtained in step 1 into the steel surface defect detection model of the improved YOLOv5 in step 2 for training, obtain the weight file with the best performance on the validation set, and save it as best.pt;

[0049] The specific experimental environment configuration for model training is shown in Table 1. The batch-size is 32, the initial learning rate is set to 0.01, the linear learning decay rate strategy is used for training, the weight decay parameter is 0.0005, and the momentum factor is set to 0.937. According to the YOLOv5 author's suggestion to train a smaller custom dataset, the Adam optimizer is used, and the number of training rounds is 200 rounds, of which the first 3 rounds use the warm-up method to preheat the learning rate. In addition, based on experience, δ=3.0 and α=2.2 in Wise-IoU are set.

[0050] Table 1 Experimental environment parameters

[0051]

[0052] S4, input the steel surface image to be tested, load the optimal model weights of step 3 to perform defect recognition, and output the final result of the steel surface defect image to be tested.

[0053] S41. Input the image to be detected into the improved YOLOv5 steel surface defect detection model, load the pre-trained optimal weight file best.pt for detection, and the output image will mark the detected object category and its corresponding confidence.

[0054] S42. The accuracy of the improved YOLOv5 steel surface defect detection model is verified. When evaluating the model performance, AP (average precision) and mAP (average precision) are used as key indicators. The calculation method is shown in formula (5) and formula (6):

[0055]

[0056] Where N represents the number of samples, p(r i ) means taking Recall values ​​at equal intervals, the accuracy rate under the i-th recall rate, AP(j) means the average precision of the j-th category recognition, and K means the total number of categories.

[0057] The comparative experimental results are shown in Table 2. It can be seen that the mAP value of the improved model is improved by 4.8% compared with YOLOv5s, and the AP values ​​of the six types of defects are all improved, indicating that the detection accuracy of the improved model is greatly improved.

[0058] Table 4-6 Comparison of mAP values ​​of different algorithm models

[0059]

[0060] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.

Claims

1. The steel surface defect detection algorithm based on improved YOLOv5 is characterized by: The following steps are involved: S1. Obtain a steel surface defect data set, perform preprocessing operations on image data in the data set, and divide the data set; S2. Improve the YOLOv5 steel surface defect detection model to improve the performance of the model in the steel surface defect detection task; S3, inputting the data set obtained in step 1 into the steel surface defect detection model of the improved YOLOv5 in step 2 for training, and obtaining the weight file with the best performance on the validation set; S4, input the steel surface image to be tested, load the optimal model weights of step 3 to perform defect recognition, and output the final result of the steel surface defect image to be tested.

2. The steel surface defect detection algorithm based on improved YOLOv5 according to claim 1, characterized in that: The step S1 comprises the following sub-steps: S11, performing a Gaussian filtering image denoising operation on the image data in the public dataset of steel surface defects; S12, performing an image enhancement operation of adaptive grayscale equalization on the image data in the public dataset of steel surface defects; S13, dividing the image data and label files of the dataset into a training set, a validation set and a test set in a ratio of 8:1:1 for model training.

3. The steel surface defect detection algorithm based on improved YOLOv5 according to claim 1, characterized in that: The step S2 comprises the following sub-steps: S21. Introduce the CBAM attention mechanism into the YOLOv5 backbone network, combining channel attention and spatial attention to enhance feature information and improve the model's ability to detect key areas of defective images; S22, replace the maximum pooling operation in the SPPF module with a soft pooling operation, and adjust the pooling kernel size in the module to improve the model's responsiveness to features of different scales; S23, replace the original coupled detection head of YOLOv5 with the improved decoupled detection head, remove the 1×1 dimensionality reduction convolution layer, adjust the detection head dimension, simplify the branch structure, and use the ELU activation function to replace the SILU function in the CBS module; S24. Replace the CIoU loss function of the YOLOv5 model with the Wise-IoU loss function to reduce the penalty of low-quality data on network training.

4. The steel surface defect detection algorithm based on improved YOLOv5 according to claim 1, characterized in that: The step S3 comprises the following sub-steps: Use the steel surface defect dataset obtained in step 1 to train the improved YOLOv5 steel surface defect detection model, set training parameters such as batch-size, initial learning rate, number of training rounds, and optimizer, and save the best performing model weights as the file best.pt.

5. The steel surface defect detection algorithm based on improved YOLOv5 according to claim 1, characterized in that: The step S4 comprises the following sub-steps: S41, inputting the image to be detected into the improved YOLOv5 steel surface defect detection model, loading the pre-trained optimal weight file for detection, and marking the detected object category and its corresponding confidence on the output image; S42. The accuracy of the improved YOLOv5 steel surface defect detection model was verified, and AP (average precision) and mAP (average precision) were used as key indicators to evaluate the model performance.

Citation Information

Patent Citations

  • MSRCP preprocessing algorithm and improved YOLOv5 fused foggy ship detection method

    CN115471741A

  • Forest fire detection method based on GS-YOLOv5

    CN116824340A

  • Remote sensing image target detection method, electronic equipment and storage medium

    CN117078916A

  • Steel surface defect detection and identification method based on improved YOLOv5s

    CN117422658A

  • Digital instrument identification method based on deep learning

    CN117765246A

Cited By

  • Electric control part appearance detection method and device based on deep learning

    CN120198439A

  • Method and device for appearance inspection of electronic control components based on deep learning

    CN120198439B

  • Industrial casting chilling block identification method based on improved YOLOv11 and double-flow network

    CN120877271A

  • Improved yolov11 and double-stream network-based industrial casting chill identification method

    CN120877271B