A strip steel surface defect detection method based on improved YOLOv5 network

By introducing a channel space attention module into the YOLOv5 network, integrating shallow and deep features and enhancing attention operations, the problem of feature extraction difficulties in detecting weak defects on the strip surface is solved, and higher detection accuracy and real-time performance are achieved.

CN114663346BActive Publication Date: 2025-04-15HEBEI UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210113743.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-30
Publication Date
2025-04-15
Estimated Expiration
2042-01-30

AI Technical Summary

Technical Problem

When detecting weak and slight defects on the surface of strip steel, it is difficult to effectively extract features, resulting in poor detection results and cannot meet the real-time and accuracy requirements of actual industrial production.

Method used

A strip surface defect detection method based on improved YOLOv5 network is designed. By introducing a channel space attention module (CSA module) into the YOLOv5 network, shallow features are fused with deep features, and target information extraction is enhanced through attention calculation to suppress background information.

Benefits of technology

The accuracy of identification of defects of different types and similar structural structures has been improved, the real-time detection and positioning capabilities of strip surface defects have been enhanced, and the real-time and accuracy requirements of industrial production have been met, and the detection accuracy and efficiency have been significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114663346B_ABST
    Figure CN114663346B_ABST
Patent Text Reader

Abstract

The present invention discloses a strip surface defect detection method based on an improved YOLOv5 network. The detection method is based on the YOLOv5 network model and adds a self-designed channel space attention module to improve the detection accuracy and solve the problem of feature extraction in complex scenes and backgrounds. The detection method of the present invention gives full play to the advantages of deep learning methods in extracting features, and can learn simple shallow features from a large number of data sets without relying on artificial feature engineering, and then gradually learn more complex and abstract deep features. It has better performance, higher defect type recognition accuracy, and high precision and recall rate of lithium battery defects, and fast recognition speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of industrial defect detection, and in particular relates to a strip surface defect detection method based on a YOLOv5 network of a spatial channel attention module. Background Art

[0002] Strip steel is one of the important raw materials for steel. It is widely used in machinery manufacturing, aerospace and transportation, and plays an important role in various production and life. However, in the production process of strip steel, due to the limitations of industrial technology and the influence of production process, various defects such as surface oil spots, almond-shaped defects, white spots and scratches may appear on the surface of the strip steel. These defects will greatly affect the corrosion resistance and service life of the strip steel. The existing defect detection methods mainly use manual naked eye detection, which has low detection efficiency, high labor intensity and high production cost, and can no longer meet the needs of strip steel surface defect detection.

[0003] Deep learning automatically extracts and learns defect features through convolutional neural networks without the need for artificial feature factor design. Therefore, deep neural networks have the characteristics of strong learning ability and high robustness, and have gradually become the mainstream method for strip surface defect detection. Weng Yushang et al. (Weng Yushang, Xiao Jinqiu, Xia Yu. Strip surface defect detection based on improved Mask R-CNN algorithm [J / OL]. Computer Engineering and Applications: 1-12 [2021-06-24].) proposed an improved mask region convolutional neural network (Mask R-CNN) algorithm, and used the k-means II clustering algorithm to improve the region proposal network (RPN) anchor frame generation method. Li Weigang et al. (Li Weigang, Ye Xin, Zhao Yuntao, Wang Wenbo. Strip surface defect detection based on improved YOLOv3 algorithm [J]. Journal of Electronics, 2020) proposed a YOLOV3 algorithm framework that integrates shallow features and deep features. The average accuracy of the improved YOLOv3 algorithm on the Northeastern University strip steel data set reached 80%. However, when faced with faint and tiny strip defects, due to the strong coupling between the background and foreground and the small defect area, the deep learning model cannot extract features well, resulting in poor model detection effect. Summary of the invention

[0004] In view of the shortcomings of the prior art, the technical problem that the present invention intends to solve is to provide a strip surface defect detection method based on an improved YOLOv5 network, which can perform real-time detection and defect location of common different types of strip surface defects, improve the accuracy of identifying defects of different types and similar structures, and meet the real-time and accuracy requirements of actual strip industrial production.

[0005] The technical solution adopted by the present invention to solve the above technical problem is: designing a strip surface defect detection method based on an improved YOLOv5 network, characterized in that the method comprises the following steps:

[0006] Step 1: Obtaining image dataset

[0007] 1.1 Use industrial cameras to collect images of the strip surface and screen out images containing defects; when the defect types in the screened defect images cover the types of known strip surface defects, a defect image set is formed;

[0008] 1.2 Normalize the size of the defect image set, and then use Labelimg software to manually annotate the images in the defect image set so that each defect image has a label with the defect type and defect location coordinates;

[0009] 1.3 Randomly divide at least 60% of the labeled defect image set into the training set, and the rest into the verification set;

[0010] Step 2: Construct and improve the YOLOv5 network model

[0011] The improved YOLOv5 network model is based on the YOLOv5 network model, in which a CSA module is serially connected between the three CSP23_ modules of PAN and the three conv modules of the classification and positioning parts of the network model;

[0012] The CSA module consists of a channel attention module and a spatial attention module. The two modules are connected in series, and the output of the channel attention module is the input of the spatial attention module.

[0013] The feature map F1 output by the CSP23_ module is input into the CSA module and first processed by the channel attention module. The channel attention module first processes the input feature F1 through global maximum pooling and global average pooling based on depth and width respectively to obtain two 1×1×C feature maps; then, the two 1×1×C feature maps are respectively processed by a fast one-dimensional convolution with a convolution kernel size of k, and then the results of the two fast one-dimensional convolutions are added and then processed by the activation function sigmoid to obtain the channel attention; the channel attention is multiplied by the original feature F1 to re-weight the feature to obtain the weighted feature F2;

[0014] The feature F2 output by the channel attention module is input to the spatial attention module. The spatial attention module performs global maximum pooling and global average pooling on the feature F2 to obtain two H×W×1 feature maps. Then, the two H×W×1 feature maps are concatenated based on the channel. The result of the concatenation operation is convolved with a convolution kernel of 7×7 to reduce the dimension to a one-dimensional vector, i.e., H×W×1. The spatial attention weight is then generated by the activation function sigmoid. Finally, the spatial attention weight is multiplied by the input feature F2 to obtain the output feature F3 of the spatial attention module. Feature F3 is the output of the CSA module and the input of the conv module of the classification and positioning part of the network model.

[0015] Step 3: Train and improve the YOLOv5 network model

[0016] 3.1 Image dataset preprocessing

[0017] The training set is preprocessed using Mosaic data augmentation;

[0018] 3.2 Parameter settings

[0019] Initialize all weight values, bias values, batch normalization scale factor values, set the network's initial learning rate and batch_size, and input the initialized parameter data into the network; dynamically adjust the learning rate and number of iterations according to the changes in training loss to update the parameters of the entire network; the training is divided into two stages. The first stage is the first 100 cycles at the beginning of training, and the initial learning rate is fixed to 0.001 to speed up convergence; the second stage refers to the training cycle after 100 cycles, and the initial learning rate is set to 0.0001;

[0020] 3.3 Network model training

[0021] The preprocessed training set is input into the improved YOLOv5 network model after the initialization parameters are set in the second step for feature extraction. The K-means clustering method is used to automatically generate anchor boxes for the training set images. The size of the anchor box is used as the prior box, and the bounding box is obtained by bounding box regression prediction. Then the bounding box is classified using the logistic classifier to obtain the defect category classification probability corresponding to each bounding box. Then the defect category classification probabilities of all bounding boxes are sorted by the non-maximum suppression method, and the defect category corresponding to each bounding box is determined to obtain the predicted value. The predicted value includes defect category and defect location information, and the non-maximum suppression threshold is 0.5. Then the loss value between the predicted value and the true value is calculated by the loss function GIOU. Back propagation is performed according to the training loss value to update the parameters of the backbone network and the classification regression network until the loss value meets the preset value and the training of the network model parameters is completed.

[0022] 3.4 Network model testing

[0023] Input the validation set into the network model that has completed parameter training in step 3.3 to obtain the tensor prediction value of the validation set; compare its tensor prediction value with the annotation information to test the reliability of the network model; use AP to evaluate the network model. When AP is not less than 85%, the network model is tested to be reliable;

[0024] Step 4: Strip surface defect detection

[0025] The surface image of the strip to be inspected is subjected to the same size normalization operation as in step 1.2 of the first step, and then input into the network model tested as reliable in the third step to obtain the defect tensor information of the surface image of the strip to be inspected, including the defect location, defect category and confidence.

[0026] Compared with the prior art, the beneficial effects of the present invention are as follows: the detection method of the present invention is based on the YOLOv5 network model, and a self-designed channel space attention module is added; the channel space attention module first fuses the shallow features with the deep features and then performs the attention operation. In this way, since the deep layer contains more high-level semantic information and less background information, the target information after the fusion of the shallow features and the deep features is strengthened, and the network can pay more attention to the target defects and suppress the background information when performing the attention operation, so as to better guide the multi-scale fusion, improve the detection accuracy, and solve the problem of feature extraction in complex scenes and backgrounds. The detection method of the present invention gives full play to the advantages of deep learning methods in extracting features, and can learn simple shallow features from a large number of data sets without relying on artificial feature engineering, and then gradually learn more complex and abstract deep features, with better performance, higher defect type recognition accuracy, and high precision and recall rate of lithium battery defects, and fast recognition speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 A schematic diagram of the structure and principle of a CSA module according to an embodiment of the detection method of the present invention.

[0028] Figure 2 A schematic diagram of the structure and principle of an improved YOLOv5 network model of an embodiment of the detection method of the present invention. DETAILED DESCRIPTION

[0029] The technical solution of the present application will be described clearly and completely below in conjunction with the accompanying drawings. 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 are within the scope of protection of this application.

[0030] The present invention provides a strip steel surface defect detection method based on an improved YOLOv5 network (hereinafter referred to as the detection method, see Figure 1-2 ), the detection method comprises the following steps:

[0031] Step 1: Obtaining image dataset

[0032] 1.1 Use industrial cameras to collect images of the strip surface and screen out images containing defects; when the defect types in the screened defect images cover the types of known strip surface defects, a defect image set is formed;

[0033] 1.2 Normalize the size of the defect image set (in this embodiment, scale it to 608*608 pixels), and then use Labelimg software to manually annotate the images in the defect image set so that each defect image has a label of defect type and defect location coordinates;

[0034] 1.3 Randomly divide no less than 60% of the labeled defect image set into a training set, and the rest into a validation set; this implementation is 4:1, that is, the training set is 80% and the remaining 20% ​​is the validation set.

[0035] Step 2: Construct and improve the YOLOv5 network model

[0036] The improved YOLOv5 network model is based on the YOLOv5 network model. A CSA (channel spatial attention) module is connected in series between the three CSP23_ (cross-stage local network, CSP23_5, CSP23_4, CSP23_3) modules of PAN (pixel aggregation network) and the three conv (convolution) modules of the classification and positioning part of the network model.

[0037] The CSA module consists of a channel attention module and a spatial attention module. The two modules are connected in series, and the output of the channel attention module is the input of the spatial attention module.

[0038] The feature map F1 (C×W×H) output by the CSP23_ module is input into the CSA module and first processed by the channel attention module. The channel attention module firstly processes the input feature F1 (C×W×H) through the global maximum pooling (MaxPool) and global average pooling (AvgPool) based on depth and width, respectively, to obtain two C×1×1 feature maps. Then, the two C×1×1 feature maps are processed by a fast one-dimensional convolution (Conv1d) with a convolution kernel size of k, and then the results of the two fast one-dimensional convolutions are added and processed by the activation function sigmoid to obtain the channel attention; the channel attention is multiplied by the original feature F1 to re-weight the feature to obtain the weighted feature F2.

[0039] The kernel size k of the fast one-dimensional convolution represents the coverage of local cross-channel interactions, that is, how many close neighbors participate in the attention prediction of the one-dimensional channel. The coverage of the interaction (that is, the kernel size k) is proportional to the channel dimension, and the specific calculation formula is:

[0040]

[0041] Among them, C represents the number of feature channels, β=2 and b=1 represent two hyperparameters.

[0042] The feature F2 output by the channel attention module is input to the spatial attention module. The spatial attention module performs global maximum pooling (Max Pool) and global average pooling (Mean Pool) on the feature F2 to obtain two 1×W×H feature maps; then the two 1×W×H feature maps are concatenated (Concat) based on the channel, and the result of the concatenation operation is reduced to a one-dimensional vector, i.e., 1×W×H, through a convolution operation with a convolution kernel of 7×7, and then the spatial attention weight is generated through the activation function sigmoid. Finally, the spatial attention weight is multiplied by the input feature F2 to obtain the output feature F3 of the spatial attention module. Feature F3 is the output of the CSA module and also the input of the conv module of the classification and positioning part of the network model.

[0043] Step 3: Train and improve the YOLOv5 network model

[0044] 3.1 Image dataset preprocessing

[0045] The training set is preprocessed using Mosaic data augmentation;

[0046] 3.2 Parameter settings

[0047] Initialize all weight values, bias values, batch normalization scale factor values, set the network's initial learning rate and batch_size, and input the initialized parameter data into the network; dynamically adjust the learning rate and number of iterations according to changes in training loss to update the parameters of the entire network; the training is divided into two stages. The first stage is the first 100 cycles at the beginning of training, and the initial learning rate is fixed to 0.001 to speed up convergence; the second stage refers to the training cycle after 100 cycles, and the initial learning rate is set to 0.0001.

[0048] 3.3 Network model training

[0049] The preprocessed training set is input into the improved YOLOv5 network model after the initialization parameters are set in the second step for feature extraction. The K-means clustering method is used to automatically generate anchor frames for the training set images. The size of the anchor frame (the size of the anchor frame will be scaled proportionally according to the image scaling size) is used as the prior frame, and the bounding box is obtained by bounding box regression prediction; then the bounding box is classified using a logistic classifier to obtain the defect category classification probability corresponding to each bounding box; then the defect category classification probabilities of all bounding boxes are sorted by the non-maximum suppression method (NMS), the defect category corresponding to each bounding box is determined, and the predicted value is obtained; the predicted value includes defect category and defect location information, and the non-maximum suppression threshold is 0.5; then the loss value between the predicted value and the true value is calculated by the loss function GIOU; back propagation is performed according to the training loss value, and the parameters of the backbone network and the classification regression network are updated until the loss value meets the preset value and the training of the network model parameters is completed;

[0050] 3.4 Network model testing

[0051] Input the validation set into the network model that has completed parameter training in step 3.3 to obtain the tensor prediction value of the validation set; compare its tensor prediction value with the annotation information to test the reliability of the network model; use AP to evaluate the network model. When AP is not less than 85%, the network model is tested to be reliable.

[0052] Step 4: Strip surface defect detection

[0053] The surface image of the strip to be inspected is subjected to the same size normalization operation as in step 1.2 of the first step, and then input into the network model tested as reliable in the third step to obtain the defect tensor information of the surface image of the strip to be inspected, including the defect location, defect category and confidence (the maximum probability of defect category classification).

[0054] The YOLOv5 model uses Mosaic data enhancement on the input image to enrich the image content and improve the detection effect of shallow smoke or small smoke areas.

[0055] Mosaic data enhancement has the following characteristics:

[0056] First, a batch of images (batch refers to Batch, batch refers to Batch size, which is a hyperparameter of the model, and batch is equal to 32 in this embodiment) is taken from the training sample set; secondly, 4 images are randomly selected from the batch of images, and the four images are randomly operated by color gamut change, reduction, inversion and / or cropping, and at least one operation is performed on each image; then the 4 images are arranged in four directions of upper left, lower left, upper right and lower right, and then spliced ​​to obtain a new image, and the size of the new image is the same as the size of the original image without operation, which is 608×608×3; repeat the above operation, and set the number of cycles equal to Batch size.

[0057] The Focus module connects three groups of CBL (convolution layer-batch normalization-activation function Leaky Relu, CBL) convolution structures and a cross-stage local network CSP1_X module, and then connects a pooling network SPP module to form a feature extraction network; the image is sliced ​​by using the Focus module, and then sent to the structure composed of CBL convolution structure and CSP1_X module after passing through the Focus module, and then the low-level features and high-level features are fused through the SPP module.

[0058] The Focus module has the following features:

[0059] First, the original image of size 608×608×3 is marked with four numbers 1, 2, 3, and 4. Then, the pixels with the same number are combined into four parts of size 304×304×3. Then, these four parts are spliced ​​in the depth direction according to the size of the numbers into a feature map of 304×304×12, and then connected to a CBL convolution structure.

[0060] The characteristics of the CBL convolution structure contained in the Focus module are: the number of convolution kernels in the convolution layer (convolution, conv) is 64, the size is 3×3, and the stride is 1.

[0061] The CSP1_X module has the following features:

[0062] X represents the number of residual structures, and other structures are the same except for the number of residual structures.

[0063] Taking the CSP1_3 module as an example, the CSP1_3 module first performs a CBL convolution operation on the input feature map; then it is sent to three residual structures, and then the feature map after the residual structure is convolved, and the new feature map obtained by direct convolution with the input feature map is concat in the depth direction; finally, it is input into the next module through batch normalization, activation function Leakyrelu and a layer of CBL convolution structure.

[0064] The convolution layer conv of the CBL convolution structure that directly convolves the input feature map in the CSP1_X module is the same as the convolution layer conv in the last CBL convolution structure in the CSP1_X module. The relevant dimensions of the convolution layer conv are: the convolution kernel size is 1×1, and the stride is 1.

[0065] Feature reprocessing network design: The feature pyramid FPN and pixel aggregation network PAN structures are adopted, where the FPN structure is composed of two groups of CSP2_3 modules, CBL convolution structure and up sample structure in series; PAN includes two CBL convolution structures to downsample the data.

[0066] The output of each upsampling structure in FPN is concatenated with the output feature maps of the CSP1_9-1 and CSP1_9-2 modules in the feature extraction network in the depth direction. At the same time, the output of each CBL convolution structure in FPN is concatenated with the feature maps of the corresponding size of the CBL convolution structure in PAN in the depth direction. A CSP2_3 module and an SPP module are added to the PAN structure each time after the CBL convolution structure. A CSP2_3 module and an SPP module are also added before the first CBL convolution structure of the PAN structure. Neither the CSP2_3 nor the SPP modules change the size of the feature map. The output of the CSP2_3-3 module in Neck is 76×76, and then it is connected to the CBL convolution structure to change the image size to 38×38. The output of the CSP2_3-4 module is connected to the input of the CBL convolution structure to change the image to 19×19.

[0067] FPN includes two CBL convolution structures, but the CBL here are all convolutions with a step size of 1, which has no effect on the size of the feature map. It is the upsampling in FPN that changes the size of the feature map and learns multi-scale target information.

[0068] The cross-stage partial network CSP2_3 module has the following characteristics:

[0069] The module structure is the same as the structure after the add fusion process is deleted in each residual structure of the CSP1_3 module. The CSP2_3 module includes an initial CBL convolution structure and a final CBL convolution structure, multiple repeating units, a 1×1 convolution layer connected to a 3×3 convolution layer through batch normalization and activation function Leaky relu, and the 3×3 convolution layer is connected to batch normalization and activation function Leaky relu to form a repeating unit. There are three repeating units. The input of the first repeating unit is connected to the output of the initial CBL convolution structure. The outputs of the three repeating units connected in series are connected to a convolution layer. The output of the convolution layer is concatenated with the original input after passing through a convolution layer, and then connected to the final CBL convolution structure through batch normalization and activation function Leaky relu.

[0070] The CBL convolution structure in FPN has the following characteristics: the convolution kernel size is 1×1 and the step size is 1.

[0071] The CBL convolution structure in PAN has the following characteristics: the convolution kernel size is 3×3 and the stride is 2.

[0072] The SPP module consists of four parallel pooling layers with maximum pooling kernel sizes of 1×1, 5×5, 9×9, and 13×13, respectively. The SPP module itself contains two layers of CBL convolutional structures at the beginning and end.

[0073] The output of the YOLOv5 model inherits the idea of ​​YOLOv3 and uses three scale feature maps for detection, with feature map sizes of 19×19, 38×38, and 76×76. A corresponding number of anchor boxes are assigned to each scale after each added SPP module, and 9 anchor boxes are generated for each pixel in the feature map. The optimal box is selected through weighted non-maximum suppression, and GIOU is returned to the network as the loss function to train the parameters.

[0074] This example was completed on the Centos7.9.2 platform and implemented using Python programming. The computer performance for testing and training the network model was: Tesla v100, Intel Xeon(R)Gold 6271c CPU @2.6GHz; the framework used was the pytorch deep learning framework. The learning rate of the YOLOv5 model was selected as λ=0.01, and the number of training steps was 500.

[0075] This embodiment uses AP (Average Precision) and mAP (mean Average Precision) for evaluation. In target detection, each category corresponds to an accuracy rate and a recall rate. Common evaluation indicators in recent years are AP and mAP. AP is the area under the accuracy (precision)-recall rate (recall) curve. The PR curve is drawn with Precision as the y-axis and Recall as the x-axis. The quality of the model is mainly determined by the size of the area under the curve. mAP is the average AP of multiple categories.

[0076]

[0077]

[0078] Among them, TP is the number of positive examples correctly classified as positive examples, FP is the number of positive examples incorrectly classified as negative examples, and FN is the number of negative examples classified as positive examples.

[0079] The calculation method of AP is:

[0080]

[0081] Among them, p represents precision and r represents recall.

[0082] In actual statistical situations, precision and recall are not continuous curves, but independent finite values. Therefore, they are discretely counted during the calculation process:

[0083]

[0084] Where N is the total number of images in the test data set, p(k) is the accuracy of the model in recognizing k images, and Δr(k) represents the change in recall rate when the model recognizes k images to k-1 images.

[0085] In target detection, the degree of overlap between the predicted marker box and the target's true marker box is usually used to determine whether the model has correctly detected the target. The overlap is also called IOU (Intersection Over Union). The IoU threshold is generally set to 0.5. If the IoU calculated by the model is greater than 0.5, then the target is correctly detected. The IoU diagram is shown in the figure.

[0086] The calculation formula is:

[0087]

[0088] Among them, A∩B represents the overlapping area of ​​the prediction box and the target box, and A∪B represents the union area of ​​the prediction box and the target box.

[0089] In this embodiment, experiments are conducted on a total of four defect images, namely, block defects, scratches, oil spots and white spots on the surface of the steel strip. The recognition accuracy of white spots is about 87%, and the recognition rates of all other defects are above 90%. The recognition rates of block defects and oil spots, two defects with similar structures, are relatively high, indicating that the detection method of the present invention has high discrimination and detection accuracy for these two types of similar defects.

[0090] Any matters not described in the present invention are applicable to the prior art.

Claims

1. A strip steel surface defect detection method based on an improved YOLOv5 network, characterized in that the detection method comprises the following steps: Step 1: Obtaining image dataset 1.1 Use industrial cameras to collect images of the strip surface and screen out images containing defects; when the defect types in the screened defect images cover the types of known strip surface defects, a defect image set is formed; 1.2 Normalize the size of the defect image set, and then use Labelimg software to manually annotate the images in the defect image set so that each defect image has a label with the defect type and defect location coordinates; 1.3 Randomly divide at least 60% of the labeled defect image set into the training set, and the rest into the verification set; Step 2: Construct and improve the YOLOv5 network model The improved YOLOv5 network model is based on the YOLOv5 network model, in which a CSA module is serially connected between the three CSP23_ modules of PAN and the three conv modules of the classification and positioning parts of the network model; The CSA module consists of a channel attention module and a spatial attention module. The two modules are connected in series, and the output of the channel attention module is the input of the spatial attention module. The feature map F1 output by the CSP23_ module is input into the CSA module and first processed by the channel attention module. The channel attention module first processes the input feature F1 through global maximum pooling and global average pooling based on depth and width respectively to obtain two C×1×1 feature maps; then, the two C×1×1 feature maps are respectively processed by a fast one-dimensional convolution with a convolution kernel size of k, and then the results of the two fast one-dimensional convolutions are added and processed by the activation function sigmoid to obtain the channel attention; the channel attention is multiplied by the original feature F1 to re-weight the feature to obtain the weighted feature F2; The feature F2 output by the channel attention module is input into the spatial attention module. The spatial attention module performs global maximum pooling and global average pooling on the feature F2 to obtain two 1×W×H feature maps. Then, these two 1×W×H feature maps are concatenated based on the channel, and the result of the concatenation operation is convolved with a convolution kernel of 7×7 to reduce the dimension to a one-dimensional vector, i.e., 1×W×H. The spatial attention weight is then generated by the activation function sigmoid. Finally, the spatial attention weight is multiplied by the input feature F2 to obtain the output feature F3 of the spatial attention module. Feature F3 is the output of the CSA module and the input of the conv module of the classification and positioning part of the network model. Step 3: Train and improve the YOLOv5 network model 3.1 Image dataset preprocessing The training set is preprocessed using Mosaic data augmentation; 3.2 Parameter settings Initialize all weight values, bias values, batch normalization scale factor values, set the network's initial learning rate and batch_size, and input the initialized parameter data into the network; dynamically adjust the learning rate and number of iterations according to changes in training loss to update the parameters of the entire network; The training is divided into two stages. The first stage is the first 100 cycles at the beginning of training, and the initial learning rate is fixed to 0.001 to speed up convergence. The second stage refers to the training cycle after 100 cycles, and the initial learning rate is set to 0.0001. 3.3 Network model training The preprocessed training set is input into the improved YOLOv5 network model after the initialization parameters are set in the second step for feature extraction. The anchor box is automatically generated for the training set image using the K-means clustering method. The size of the anchor box is used as the prior box, and the bounding box is obtained by bounding box regression prediction. Then the bounding box is classified using the logistic classifier to obtain the defect category classification probability corresponding to each bounding box. Then, the defect category classification probabilities of all bounding boxes are sorted by the non-maximum suppression method, and the defect category corresponding to each bounding box is determined to obtain the predicted value; the predicted value includes the defect category and defect location information, and the non-maximum suppression threshold is 0.5; then the loss value between the predicted value and the true value is calculated by the loss function GIOU; back propagation is performed according to the training loss value to update the parameters of the backbone network and the classification regression network until the loss value meets the preset value and the training of the network model parameters is completed; 3.4 Network model testing Input the validation set into the network model that has completed parameter training in step 3.3 to obtain the tensor prediction value of the validation set; compare its tensor prediction value with the annotation information to test the reliability of the network model; use AP to evaluate the network model. When AP is not less than 85%, the network model is tested to be reliable; Step 4: Strip surface defect detection The surface image of the strip to be inspected is subjected to the same size normalization operation as in step 1.2 of the first step, and then input into the network model tested as reliable in the third step to obtain the defect tensor information of the surface image of the strip to be inspected, including the defect location, defect category and confidence.

2. The method for detecting surface defects of strip steel based on an improved YOLOv5 network according to claim 1, characterized in that: The kernel size k of the fast one-dimensional convolution in the channel attention module represents the coverage of local cross-channel interactions, that is, how many close neighbors participate in the attention prediction of the one-dimensional channel; the coverage k of the interaction is proportional to the channel dimension, and the specific calculation formula is: Among them, C represents the number of feature channels, β=2 and b=1 represent two hyperparameters.

3. The method for detecting surface defects of strip steel based on an improved YOLOv5 network according to claim 1, characterized in that: In step 1.2 of the first step, the size normalization operation is to scale the image to 608*608 pixels.

4. The method for detecting surface defects of strip steel based on an improved YOLOv5 network according to claim 1, characterized in that: In step 1.3 of the first step, the training set is 80% and the remaining 20% ​​is the validation set.

Citation Information

Patent Citations

  • Insulator defect detection method based on improved YOLOv5 convolutional neural network

    CN112819804A

  • Yolov3 strip steel surface defect detection and classification method introducing attention mechanism

    CN112884709A