Hot-rolled steel strip surface defect detection method based on improved YOLOv5s network
By improving the YOLOv5s network structure, adopting AFPN and GIoU loss functions, and using the EffectiveSE module, the detection of surface defects in hot-rolled steel strip was optimized, improving detection performance and reducing computational burden, thus achieving more efficient detection results.
Patent Information
- Application Number
- CN202311105750.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-30
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2043-08-30
AI Technical Summary
The existing YOLOv5s network model has insufficient detection performance in the detection of surface defects in hot-rolled steel strip, especially in the detection of small targets, and the computational cost and parameter count are large.
The YOLOv5s network model was improved by changing the neck structure to an AFPN structure, using GIoU as the loss function, and adding an EffectiveSE convolutional neural network structure module in layer 23 to optimize the model's feature fusion and loss calculation.
It improves the model's performance in detecting small targets, reduces the number of model parameters and computational cost, shortens inference time, and improves detection efficiency.
Smart Images

Figure CN117132827B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The patent technology belongs to the technical field of target detection, and particularly relates to a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s model. BACKGROUND
[0002] As the main development material of modern industrial technology, steel is widely used in the fields of construction industry, marine engineering and aerospace engineering with the continuous improvement of industrial production capacity, and the quality of steel is also becoming more and more strict. However, due to the technical limitations of steel production, various surface defects such as scratches, cracks and concave surfaces may occur in the production process. These surface defects of steel not only affect the appearance of the product, but also reduce the wear resistance, toughness and other properties of the steel, and shorten the service life of the steel. Therefore, it is an important problem for modern steel producers to analyze and understand how to improve the quality of the surface of the steel.
[0003] In recent years, with the rapid development of machine vision algorithm, the vision-based automatic detection technology using cameras to obtain images has been widely used in surface defect detection. These algorithms can be roughly divided into three categories: traditional methods based on image structure features, machine learning methods based on statistical features and deep learning methods based on convolutional neural networks.
[0004] The defect detection method based on deep learning will become the main direction of future defect detection development. Although the target detection algorithm has made great progress, there are still many challenges in the implementation of the defect detection algorithm in the current actual production process, and there are still many problems to be solved.
[0005] The research on surface defect detection can be roughly divided into machine vision-based detection, x-ray detection, ultrasonic detection, infrared detection, eddy current detection and manual detection. In recent years, deep learning technology has made explosive development, and it is more accurate and robust compared with other detection methods. It plays an important role in improving product quality. The research on product defect recognition algorithm based on machine vision plays a key role in the development of intelligent production line, and is also an important step towards the intelligentization of industrial manufacturing. Therefore, the research on product defect detection using machine vision algorithm has important practical significance, and plays an important theoretical significance and practical value in realizing the intelligent manufacturing of industrial products. SUMMARY
[0006] The purpose of the present application is to improve the performance of the original yolov5s network model in detecting small targets, especially in detecting surface defects of hot-rolled steel strips. The present application provides a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network, which reduces the parameter quantity and calculation quantity of the model and shortens the inference time of the model.
[0007] The method is realized by using the technical scheme described below:
[0008] A hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network, the specific steps are as follows:
[0009] Step 1, make and divide the data set:
[0010] Get the open source data set of the surface defect database released by Northeastern University (NEU). First, make the data set into yolo format suitable for training YOLOv5 network model. Second, divide the data set into training set and validation set.
[0011] Step 2, model improvement:
[0012] Build the network structure model of the original YOLOv5s, based on the YOLOv5s network model, change the original structure of the neck part to AFPN structure, select GIoU as the loss function, and add EffectiveSE convolutional neural network structure module.
[0013] Step 3, train the model:
[0014] Use the training set of the surface defect data set divided in step 1, input into the network structure model of YOLOv5s before and after improvement built in step 2, and train by GPU to get the hot-rolled steel strip surface defect detection model.
[0015] Step 4, hot-rolled steel strip surface defect detection:
[0016] The validation set is input into the hot-rolled steel strip surface defect detection model trained in step 3, the test results are used to evaluate the model and obtain the trained model, the hot-rolled steel strip surface image to be detected is input into the trained model and the detection result is output.
[0017] Step 1 specifically includes:
[0018] Step 1.1, get the open source data set. Get the open source data set of the surface defect database released by Northeastern University (NEU) on the Northeastern University website, which collects six typical defects of hot-rolled steel strip surface, including scratches (Sc), inclusions (In), pitting surface (PS), cracking (Cr), patches (Pa) and rolled oxide skin (RS). The images in the data set are processed by grayscale, the original resolution is 200x200 pixels, there are 300 defect samples of each kind, a total of 1800 images. In the defect label of each picture, the yellow box indicates the position of the frame, and the green label is the class score.
[0019] Step 1.2, the open source data set in step 1.1 is divided and made into yolo format suitable for training of YOLOv5 target detection model. First, randomly divide the open source data set in step 1.1 into 80% training set and 20% validation set. Secondly, create a dataset folder under the data directory in the YOLOv5 folder, and the subfolder images stores the source picture data set of training and validation, and the subfolder labels stores the label data files of training and validation, which are train.txt and val.txt two files, respectively, storing the names (without suffix.jpg) of training set and validation set pictures.
[0020] Step 2 specifically includes:
[0021] Step 2.1, configure the deep learning environment and build the original YOLOv5s model. When configuring the environment required by yolov5s, the operating system used is Windows 10, the framework used is pytorch, the environment management used is anaconda, and the IDE used is pycharm. Download the yolov5 source code by entering its open source website and manually download zip or git clone remote repository. The code downloaded by the invention is version 5.7 of YOLOv5, and the requirements.txt file in the code folder describes the installation package required by the model.
[0022] Step 2.2, convert the structure of the neck part of the original model to AFPN structure. AFPN (progressive feature pyramid network) makes it easy to fuse direct features across non-adjacent levels, preventing loss and degradation of feature information during transmission and interaction. In order to eliminate the information conflict between features at different levels, adaptive spatial fusion is added in the process of multi-level feature fusion. The validation set and test set of MS COCO 2017 are used to conduct multiple experiments on AFPN, and the results show that compared with other feature pyramid networks, this method has more outstanding computing efficiency and stronger competitiveness.
[0023] In the process of multi-level feature fusion, because ASFF gives different spatial weights to features at different levels, the importance of key layers is enhanced, and the influence of information contradiction between different targets is reduced. For example, 3-level feature fusion:
[0024] x ij n→l represents the feature vector from Level n to Level l at position (i,j).y ij l represents the result feature vector, which is obtained by multi-level feature adaptive spatial fusion, through x ij1→l , x ij 2→l , x ij 3→l Linear combination of eigenvectors, as follows:
[0025]
[0026] wherein, represents the spatial weight of the feature distribution of the 3 levels at Level l, limited to
[0027] Step 2.3, select GIoU as the loss function. GIoU is a term added after IoU, which calculates the minimum circumscribed rectangle of the predicted box (A) and the real box (B), thereby representing the distance between the two boxes, solving the problem that the gradient is zero when the intersection of the two targets does not exist. The formula is:
[0028]
[0029]
[0030] wherein, C is the area of the minimum rectangle circumscribed by the two boxes A and B.
[0031] When IOU = 0:
[0032]
[0033] When IOU = 0, it means that there is no intersection between the A box and the B box, and the greater the distance between the A box and the B box, the more the value of GIOU tends to -1; when the A box and the B box coincide, GIOU = 1. Therefore, the value range of GIOU is (-1, 1].
[0034] When the loss function is GIOU:
[0035] L GIoU = 1-GIoU (5)
[0036] When there is no intersection between the A box and the B box, A∪B does not change. At this time, maximizing GIoU is to minimize C, which helps to continuously reduce the distance between the A box and the B box.
[0037] Step 2.4, add the EffectiveSE convolutional neural network structure module to the 23rd layer of the YOLOv5s network structure. EffectiveSE is a network structure composed of multiple modules, and its most core module is the "channel attention module", which is composed of a Squeeze part and an Excitation part. The Squeeze part is a global average pooling layer, which mainly compresses the feature map of each channel into a scalar. The Excitation part is an MLP (Multi-Layer Perceptron), which mainly learns the channel weight and multiplies it with the original feature map to obtain the weighted feature map.
[0038] eSE (Effective SE) only uses one FC layer with a C channel, thereby maintaining channel information and improving performance. The eSE process is defined as:
[0039] A eSE (X div ) =σ(W C (F gap (X div ))) (6)
[0040]
[0041] wherein, is a diversified feature map obtained through the 1x1conv operation of the OSA module. As a kind of channel attention feature descriptor, it is applied to the diversified feature Figure X div , making the diversified feature more informative. Finally, when using residual connection, the input feature map is added to the refined feature map X refine in the order of elements.
[0042] Step 3 specifically includes:
[0043] Step 3.1, configure the yaml file. First, configure the first yaml file, the configuration of the YOLOv5s model before and after improvement is the same. Copy the voc.yaml file to hg.yaml file, put it in the yolov5-master / data folder. Among them, the path is the location of the dataset dataset; train is the location of the training set; val is the location of the evaluation set; names is the name of the class in the data set, since the data label is the yolo format class, so only numbers, so you need to do a mapping record here, the data set of the present invention exists 6 categories, respectively Sc, In, PS, Cr, Pa and RS. Then, configure the second yaml file, which is located in the models folder, the original YOLOv5s model only needs to modify the nc in yolov5s.yaml file to 6; The improved YOLOv5s model copies the original yolov5s.yaml file to yolov5s_AFPN.yaml file, in addition to modifying nc in yolov5s.yaml file to 6, yolov5s_AFPN.yaml file needs to be configured according to the improvement of step 2.
[0044] Step 3.2, train the improved YOLOv5s network model. Here you need to download the pre-training weight yolov5s.pt from the yolov5 open source website first, then modify the configuration of weights in the train.py file to yolov5s.pt, modify the cfg to yolov5s_AFPN.yaml file in the models folder, modify the data to hg.yaml file in the data folder, modify the loss_category loss function class to GIoU, modify the epochs training round to 200, modify the batch-size to 16, modify the imgsz to 640, modify the workers to 16, modify the name of the training result folder to exp. After modification, use the training set of the surface defect data set divided in step 1 to start training.
[0045] Step 4 specifically includes:
[0046] Step 4.1, hot-rolled steel strip surface defect detection: after the model training of step 3 is completed, the modified model will automatically use the validation set of the surface defect data set divided in step 1 to detect, so as to obtain the result. The test results are shown in Table 1:
[0047] Table 1 Comparison of yolov5 network model before and after improvement
[0048]
[0049] F1_curve: represents the correlation between F1 score and confidence, where the x-axis is confidence. F1 score is a classification metric as the harmonic mean of precision and recall, with a value range of (0, 1), and the higher the score value, the better. Its formula is:
[0050]
[0051] Precision = TP / (TP+FP) (9)
[0052] Recall = TP / (TP+FN) (10)
[0053] F1 = 2*(Precision*Recall) / (Precision+Recall) (11)
[0054] P_curve: represents the correlation between accuracy and confidence, where the x-axis is confidence. When the value of confidence is larger, the value of accuracy will also increase.
[0055] R_curve: represents the correlation between recall and confidence.
[0056] PR_curve: represents the correlation between precision and recall, where P is precision and R is recall. The area surrounded by the P-R curve is the average precision (AP). The higher the value of AP, the better the performance of the model.
[0057] According to the test results, the values of P_curve, R_curve and F1_curve are improved, the values of individual classes of PR_curve are improved, the values of individual classes are decreased, but the value of mAP@0.5 is improved. In addition, the FLOPs(G) of the original model is 15.8 and the param(M) is 7.026307; the FLOPs(G) of the improved model is 11.6 and the param(M) is 4.786384. The parameter amount and the calculation amount of the model are reduced. Therefore, it is judged that the improved YOLOv5s model is better than the original model. BRIEF DESCRIPTION OF DRAWINGS
[0058] Figure 1 : The application is based on the flow diagram of hot rolled steel strip surface defect detection based on improved YOLOv5s network.
[0059] Figure 2 : The application is based on the network model architecture diagram after improvement.
[0060] Figure 3The application improves the architecture diagram of AFPN related to the YOLOv5s network model.
[0061] Figure 4 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0062] Figure 5 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0063] Figure 6 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0064] Figure 7 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0065] Figure 8 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0066] Figure 9 The application improves the architecture diagram of eSE related to the YOLOv5s network model.
[0067] Figure 10 The application improves the architecture diagram of eSE related to the YOLOv5s network model. DETAILED DESCRIPTION
[0068] The following is a further detailed description of a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network using specific embodiments and accompanying drawings. In addition, the technical features contained in the different embodiments of the application described below can be combined with each other without conflict. And, the specific embodiments are intended to interpret the application, not to limit the application.
[0069] As Figures 1-10 shown, a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network The purpose of this method is to improve the performance of the original yolov5s network model for small target detection, especially for hot-rolled steel strip surface defect detection, to provide a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network, which reduces the parameter amount and calculation amount of the model, and shortens the inference time of the model. The implementation of a hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network specifically includes:
[0070] Step 1, making and dividing the data set:
[0071] Step 1.1, obtain the open source data set. Obtain the open source data set of the surface defect database published by Northeastern University (NEU) on the official website of Northeastern University, which collects six typical defects of hot-rolled steel strip surface, including scratches (Sc), inclusions (In), pitting surface (PS), cracking (Cr), patches (Pa) and rolling scale (RS). The images in the data set are processed by grayscale, and the original resolution is 200x200 pixels. There are 300 defect samples of each kind, a total of 1800 images. In the defect annotation of each picture, the yellow box indicates the position of the frame, and the green label is the class score.
[0072] Step 1.2, divide and make the open source data set in step 1.1 into yolo format suitable for YOLOv5 target detection model training. First, randomly divide the open source data set in step 1.1 into 80% training set and 20% validation set. Secondly, create a dataset folder under the data directory in the YOLOv5 folder, and store the training and validation source picture data set in the images subfolder, and store the training and validation label data file in the labels subfolder, which are train.txt and val.txt two files, respectively. Store the names of the training set and validation set pictures (without suffix.jpg).
[0073] Step 2, model improvement:
[0074] Step 2.1, configure the deep learning environment and build the original YOLOv5s model. When configuring the environment required by yolov5s, the operating system used is Windows 10, the framework used is pytorch, the environment management used is anaconda, and the IDE used is pycharm. Download the yolov5 source code by entering its open source website and manually download zip or git clone remote repository. The code downloaded by the invention is version 5.7 of YOLOv5, and the requirements.txt file in the code folder describes the installation package required by the model.
[0075] Step 2.2, convert the structure of the neck part of the original model to the AFPN structure. As shown in Figure 3 The architecture diagram of AFPN is shown. AFPN (Asymmetric Feature Pyramid Network) makes it easy to fuse direct features across non-adjacent levels, preventing loss and degradation of feature information during transmission and interaction. To eliminate the information conflict of features between different levels, adaptive spatial fusion is added during the operation of multi-level feature fusion. A number of experiments on AFPN were conducted using the validation set and test set of MS COCO 2017, and the results showed that this method is more efficient and competitive than other feature pyramid networks.
[0076] Among them, in the process of multi-level feature fusion, because the spatial weights given to features of different levels by ASFF are different, the importance of key layers is enhanced, and the influence of information contradiction between different targets is reduced. For example, 3-level feature fusion:
[0077] x ij n→l x ij l x ij 1→l x ij 2→l x ij 3→l Linear combination of feature vectors, as follows:
[0078]
[0079] Among them, x
[0080] Step 2.3, select GIoU as the loss function. GIoU is a term added after IoU, which calculates the minimum circumscribed rectangle of the predicted box (A) and the real box (B), thereby representing the distance between the two boxes, solving the problem of zero gradient when the intersection of the two targets does not exist, the formula is:
[0081]
[0082]
[0083] Among them, C is the area of the smallest rectangle circumscribing the two boxes A and B.
[0084] When IOU = 0:
[0085]
[0086] When IOU = 0, it means that boxes A and B do not overlap. In this case, the greater the distance between boxes A and B, the closer the value of GIOU is to -1. When boxes A and B overlap, GIOU = 1. Therefore, the value range of GIOU is (-1, 1).
[0087] When the loss function is GIOU:
[0088] L GIoU =1-GIoU (5)
[0089] When boxes A and B have no intersection, A∪B remains unchanged. In this case, maximizing GIoU is equivalent to minimizing C, which helps to continuously reduce the distance between boxes A and B.
[0090] Step 2.4: Add the EffectiveSE convolutional neural network module to layer 23 of the YOLOv5s network structure. EffectiveSE is a network structure composed of multiple modules, the core of which is the "channel attention module," which consists of a Squeeze part and an Excitation part. The Squeeze part acts as a global average pooling layer, and its main function is to compress the feature maps of each channel into a scalar. The Excitation part acts as an MLP (Multilayer Perceptron), and its main function is to learn the weights of each channel and multiply them with the original feature maps to obtain weighted feature maps.
[0091] eSE (Effective SE) uses only one FC layer, which has a C channel, thus preserving channel information and improving performance. For example... Figure 4 The diagram shown is an architecture diagram of eSE. The eSE process is defined as follows:
[0092] A eSE (X div ) = σ(W C (F gap (X div (6)
[0093]
[0094] in, It is a diverse feature map, obtained through the 1×1 conv operation of the OSA module. It is applied as a channel attention feature descriptor to diverse features Figure X divThe diversified features are more informative. Finally, when using the residual connection, the input feature map is added to the refined feature map X refine in the middle.
[0095] Step 3, training the model:
[0096] The training set of the surface defect data set divided in step 1 is input into the network structure model of the improved YOLOv5s before and after the improvement in step 2, and trained by GPU to obtain the hot-rolled steel strip surface defect detection model.
[0097] Step 3.1, configure the yaml file. First, configure the first yaml file, the configuration of the improved YOLOv5s model before and after the improvement is the same. Copy the voc.yaml file to hg.yaml file, and place it in the yolov5-master / data folder. Among them, the path is the location of the dataset dataset; train is the location of the training set; val is the location of the evaluation set; names is the name of the category in the data set, since the data label is the yolo format category, so only numbers are needed, therefore, a mapping record is needed here, the present invention data set exists 6 categories, respectively Sc, In, PS, Cr, Pa and RS. Then, configure the second yaml file, which is located in the models folder, the original YOLOv5s model only needs to modify the nc in the yolov5s.yaml file to 6; the improved YOLOv5s model copies the original yolov5s.yaml file to yolov5s_AFPN.yaml file, in addition to modifying the nc in the yolov5s.yaml file to 6, it also needs to configure the yolov5s_AFPN.yaml file according to the improvement of the yolov5s model in step 2.
[0098] Step 3.2, training the YOLOv5s network model before and after the improvement. Here, the pre-trained weight yolov5s.pt needs to be downloaded from the yolov5 open source website first, then the configuration of weights in the train.py file is modified to yolov5s.pt, the configuration of cfg is modified to yolov5s_AFPN.yaml file in the models folder, the configuration of data is modified to hg.yaml file in the data folder, the loss category loss function class is set to GIoU, the training round number epochs is set to 200, the batch-size is set to 16, the imgsz is set to 640, the workers is set to 16, and the name of the training result folder is set to exp. After the modification, the training of the training set of the surface defect data set divided in step 1 is started. For example Figure 8The graph of the model training process results before and after improvement is shown.
[0099] Step 4, hot-rolled steel strip surface defect detection:
[0100] The verification set is input into the hot-rolled steel strip surface defect detection model trained in step 3, the test results are used to evaluate the model and obtain the trained model, the hot-rolled steel strip surface image to be detected is input into the trained model and the detection result is output.
[0101] After the model training in step 3 is completed, the verification set of the surface defect data set divided in step 1 will be automatically used to detect the modified model, so as to obtain the result. The training result is shown in Table 1:
[0102] Table 1 Comparison of yolov5 network model before and after improvement
[0103]
[0104] F1_curve: represents the correlation between F1 score and confidence, where the x-axis is the confidence. F1 score is a classification measure as the harmonic mean function of precision and recall, with a value range of (0, 1), and the higher the score value, the better. For example, Figure 5 The graph of the model test result F1_curve before and after improvement is shown. Its formula is:
[0105]
[0106] Precision (precision) = TP / (TP+FP) (9)
[0107] Recall (Recall) = TP / (TP+FN) (10)
[0108] F1 = 2*(precision*recall) / (precision+recall) (11)
[0109] P_curve: represents the correlation between accuracy and confidence, where the x-axis is the confidence. When the value of the confidence is larger, the value of the accuracy will also increase. For example, Figure 6 The graph of the model test result P_curve before and after improvement is shown.
[0110] PR_curve: represents the correlation between precision and recall, where P is precision and R is recall. The area surrounded by the P-R curve is the average precision (AP). The higher the value of AP, the better the performance of the model. For example, Figure 7Fig. 3 shows a curve diagram of the model test results R_curve before and after improvement.
[0111] R_curve: indicates the correlation between recall rate and confidence. As shown in Fig. 3, the original model has a better correlation between recall rate and confidence than the improved model. Figure 9 Fig. 4 shows a curve diagram of the model test results PR_curve before and after improvement.
[0112] According to the test results, the values of P_curve, R_curve and F1_curve are improved, the values of individual classes of PR_curve are improved, the values of individual classes are decreased, but the value of mAP@0.5 is improved. In addition, the FLOPs(G) of the original model is 15.8 and the param(M) is 7.026307; the FLOPs(G) of the improved model is 11.6 and the param(M) is 4.786384. The parameter amount and the calculation amount of the model are reduced. Therefore, it is judged that the improved YOLOv5s model is better than the original model.
Claims
1. A hot-rolled steel strip surface defect detection method based on an improved YOLOv5s network, characterized by comprising the following steps: Step 1, making and dividing the data set: Obtain the open source data set of the surface defect database published by Northeastern University. First, make the data set into a yolo format suitable for training the YOLOv5 network model. Second, divide the data set into a training set and a validation set. Step 2, model improvement: Build the network structure model of the original YOLOv5s, change the original structure of the neck part to AFPN structure, select GIoU as the loss function, and add the EffectiveSE convolutional neural network structure module to the 23rd layer of the YOLOv5s network structure. Step 3, training the model: Use the training set divided in step 1 as input to the network structure model of the improved YOLOv5s in step 2, and train it through GPU to obtain a hot-rolled steel strip surface defect detection model. Step 4, hot-rolled steel strip surface defect detection: Input the validation set into the hot-rolled steel strip surface defect detection model trained in step 3, evaluate the model using the test results, and obtain the trained model. Input the hot-rolled steel strip surface image to be detected into the trained model and output the detection result.
2. The hot-rolled steel strip surface defect detection method based on the improved YOLOv5s network according to claim 1, characterized in that, Step 1 specifically includes: Step 1.1, obtaining the open source data set, obtaining the open source data set of the surface defect database published by Northeastern University on the Northeastern University website, which collects six typical defects of hot-rolled steel strip surface, including scratches Sc, inclusions In, pitting surface PS, cracking Cr, plaque Pa and rolling oxide skin RS. The images in the data set are grayed, the original resolution is 200x200 pixels, there are 300 defect samples of each type, a total of 1800 images, and in the defect label of each picture, the yellow box indicates the position of the frame, and the green label is the class score. Step 1.2, divide and make the open source data set in step 1.1 into a yolo format suitable for training the YOLOv5 target detection model. First, randomly divide the open source data set in step 1.1 into 80% training set and 20% validation set. Second, create a dataset folder under the data directory in the YOLOv5 folder, and store the source picture data set of the training and validation in the images subfolder, and store the label data file of the training and validation in the labels subfolder, which are train.txt and val.txt two files, respectively. Store the names of the training set and validation set pictures.
3. The hot-rolled steel strip surface defect detection method based on the improved YOLOv5s network according to claim 1, characterized in that, Step 2 specifically includes: Step 2.1, configure the deep learning environment, build the original YOLOv5s model, configure the environment required by yolov5s, the operating system used is Windows10, the framework used is pytorch, the environment management used is anaconda, the IDE used is pycharm, download the yolov5 source code is to enter its open source website, manually download zip or git clone remote repository, the downloaded code is the 5.7 version of YOLOv5, the requirements.txt file in the code folder describes the installation package required by the model; Step 2.2, convert the structure of the neck part of the original model to AFPN structure, AFPN structure makes it easy to fuse direct features across non-adjacent levels, prevents loss and degradation of feature information during transmission and interaction, to eliminate the information conflict between features at different levels, adaptive spatial fusion is added in the process of multi-level feature fusion, Among them, in the process of multi-level feature fusion, because ASFF gives different spatial weights to features at different levels, the importance of key layers is enhanced, and the influence of information contradiction between different targets is reduced, 3 Level feature fusion: characteristic vector of position (i,j) from Level n to Level l, resultant characteristic vector, which is obtained by multi-level characteristic adaptive spatial fusion, through , , linear combination of characteristic vectors, as follows: (1) wherein , , denotes the spatial weight of the feature assignment of 3 Levels at Level l, restricted to ; Step 2.3, select GIoU as the loss function, GIoU adds an item after IoU, so as to calculate the minimum circumscribed rectangle of the predicted box A and the real box B, so as to represent the distance between the two boxes, solve the problem of zero gradient when the intersection of two targets does not exist, the formula is: (2) (3) Where C is the minimum rectangle area circumscribed by A and B two boxes, When Time: (4) When , it indicates that there is no intersection between the A frame and the B frame, at this time, the larger the distance between the A frame and the B frame, the more the value of the GIOU tends to -1; when the A frame and the B frame coincide, Therefore, the GIOU value range is (-1, 1], When the loss function is GIOU: (5) When there is no intersection between A and B, No change, at this time, the GIoU is maximized, that is, C is minimized, which helps to constantly reduce the distance between A and B. Step 2.4, EffectiveSE is a network structure composed of multiple modules, the most core module is "channel attention module", which is composed of Squeeze part and Excitation part, Squeeze part as a global average pooling layer, the main role is to compress the feature map of each channel into a scalar, Excitation part as MLP, the main role is to learn the channel weight, multiply it with the original feature map, and get the weighted feature map, eSE only uses one FC layer, which has a C channel, so as to maintain channel information and improve performance, the eSE process is defined as: (6) (7) wherein, is a diversified feature map which is obtained by the operation of the OSA module , is applied to the diversified feature map as a channel attention feature descriptor, making the diversified feature more informative, and finally, when using residual connection, the input feature map is added to the refined feature map in the order of elements. 4. The hot-rolled steel strip surface defect detection method based on the improved YOLOv5s network according to claim 1, characterized in that, Step 3 includes: Step 3.1, configure the yaml file, first, configure the first yaml file, the configuration of the YOLOv5s model before and after improvement is the same, copy the voc.yaml file to hg.yaml file, put it in the yolov5-master / data folder, where path is the location of the dataset dataset; train is the location of the training set; val is the location of the evaluation set; names is the name of the class in the data set, since the data label is yolo format class, so only numbers, so you need to do a mapping record here, there are 6 categories in the data set, respectively Sc, In, PS, Cr, Pa and RS, then, configure the second yaml file, which is located in the models folder, the original YOLOv5s model only needs to modify nc to 6 in yolov5s.yaml file; The improved YOLOv5s model copies the original yolov5s.yaml file to yolov5s_AFPN.yaml file, in addition to modifying nc to 6 in yolov5s.yaml file, yolov5s_AFPN.yaml file needs to be configured according to the improvement of yolov5s model in step 2; Step 3.2, train the improved YOLOv5s network model before and after, first download the pre-training weight yolov5s.pt from the yolov5 open source website, then modify the configuration of weights to yolov5s.pt in train.py file, modify cfg to yolov5s_AFPN.yaml file in models folder, modify data to hg.yaml file in data folder, modify loss_category loss function class to GIoU, modify epochs training rounds to 200, modify batch-size to 16, modify imgsz to 640, modify workers to 16, modify name to exp, modify the name of the training result folder, after modification, use the training set of the surface defect data set divided in step 1 to start training.
5. The hot-rolled steel strip surface defect detection method based on the improved YOLOv5s network according to claim 1, characterized in that, Step 4 specifically includes: Step 4.1, hot-rolled steel strip surface defect detection: after the model training of step 3 is completed, the modified model will automatically use the validation set of the surface defect data set divided in step 1 to detect the training result, in which: F1_curve: indicates the correlation between F1 score and confidence, where the x-axis is the confidence, F1 score is a classification measure, which is the harmonic mean function of precision and recall, the value range is (0, 1), the higher the score value, the better, its formula is: (8) Precision = TP / (TP+FP) (9) Recall = TP / (TP+FN) (10) (11) P_curve: indicates the correlation between accuracy and confidence, where the x-axis is the confidence, when the value of the confidence is larger, the value of the accuracy will also increase, PR_curve: represents the correlation between precision and recall, where P is precision and R is recall, the area surrounded by the P-R curve is the average precision, the higher the value of AP, the better the performance of the model, R_curve: represents the correlation between recall and confidence.
Citation Information
Patent Citations
Gear defect detection method
CN115880244A
System, device, process and method of measuring food, food consumption and food waste
US20220270238A1