Steel defect detection method based on KDH-YOLOv7
Through the combination of K-means++ clustering algorithm and P-ELAN structure, the N-CIOU loss function is constructed, and the DyHead structure is introduced to improve the YOLOv7 network model, which solves the problems of low manual detection efficiency and insufficient model performance in steel defect detection, and realizes the More efficient detection accuracy and performance improvements.
Patent Information
- Application Number
- CN202411280670.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-17
AI Technical Summary
The existing steel defect detection technology has problems such as poor subjectivity, low efficiency, high resource consumption in artificial visual detection, and poor performance of YOLOv7 network model in target boundary details and small target detection.
The data set is processed using K-means++ clustering algorithm, the P-ELAN structure is introduced, the N-CIOU loss function is constructed, and the DyHead structure that integrates scale attention, spatial attention, and task attention is added, and the YOLOv7 network model is improved to KDH-YOLOv7 , improve the model's target detection head expression ability.
It significantly improves detection accuracy, reduces calculation costs, improves model detection performance, and enhances the detection ability of steel defects.
Smart Images

Figure CN119152190A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of steel material detection, and in particular to a steel material defect detection method based on KDH-YOLOv7. Background Art
[0002] Steel, as an important construction and manufacturing material, may be affected by various factors during the production process and produce surface defects, such as scratches, oxidation, stains, etc. These defects will not only affect the appearance of the product, but most importantly, affect its performance and durability. Defect detection technology is a key and challenging task in computer-aided industrial production. It can improve the safety and reliability of steel products and ensure the safety of life and property. In the past, defects on the surface of steel were detected through manual visual inspection. However, manual visual inspection has subjective differences and can easily cause operator fatigue, which greatly reduces the detection efficiency and poses a safety hazard. Due to the large-scale production of steel, detection requires a lot of time and human resources. Existing detection models also have certain limitations in efficiency, scope of application and automation.
[0003] Compared to some more complex object detection models, such as Faster R-CNN and SSD, the accuracy of the YOLOv7 network model may be slightly lower. It may perform poorly in the detection of details of object boundaries and small objects; due to the large network structure and high computing requirements of the YOLOv7 network model, the training time is longer and more computing resources are required; this may be a problem in some resource-limited environments. By improving the structure of the YOLOv7 network model, this problem can be effectively solved.
[0004] Therefore, the present invention provides a steel defect detection method based on KDH-YOLOv7. Summary of the invention
[0005] The invention discloses a steel defect detection method based on KDH-YOLOv7. The method can improve the detection accuracy by processing a data set through a K-means++ clustering algorithm. The method can reduce the calculation cost through a P-ELAN structure. The method can improve the model detection performance by constructing an N-CIOU loss function. The method can also generate a KDH-YOLOv7 network model by adding a DyHead structure integrating scale attention, space attention and task attention, and improve the YOLOv7 network model. The KDH-YOLOv7 network model can significantly improve the expression ability of the target detection head of the model.
[0006] The present invention provides a steel defect detection method based on KDH-YOLOv7, comprising:
[0007] Processing the acquired NEU-DET steel inspection data set to obtain a steel inspection data set to be used;
[0008] The K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set;
[0009] The obtained YOLOv7 network model is improved by improving the network head part, optimizing the loss function, and lightweighting the model. Training and evaluation are performed based on the steel inspection data set to be used to obtain the improved YOLOv7 network model.
[0010] The improved YOLOv7 network model is used to perform defect detection based on the target steel inspection dataset.
[0011] Furthermore, the obtained NEU-DET steel inspection data set is processed to obtain a steel inspection data set to be used, including:
[0012] The obtained NEU-DET steel inspection dataset is divided into a ratio of 8:1:1 to obtain a training sub-dataset, a validation sub-dataset, and a test sub-dataset, which are then summarized to generate a steel inspection dataset to be used.
[0013] Furthermore, the K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set, including:
[0014] The K-means++ clustering algorithm is used to locate a basic cluster center and several available cluster centers in the NEU-DET steel inspection data set, and the selection probability of each available cluster center is calculated according to the following formula;
[0015]
[0016] Among them, P(X i ) represents the probability of selecting the i-th available cluster center, D(X i ) represents the shortest distance between the i-th available cluster center and the basic cluster center, A represents the NEU-DET steel inspection dataset;
[0017] According to the selection probability of each available cluster center, the target cluster center that meets the preset selection probability standard is selected;
[0018] According to the center of the target cluster, the NEU-DET steel detection dataset is divided into several data clusters. The steel contours are drawn according to the data clusters, and after mapping the steel contours, the target steel detection dataset is obtained.
[0019] Furthermore, the obtained YOLOv7 network model is improved by improving the network head part, optimizing the loss function and lightweighting the model, including: improving the network head part, specifically:
[0020] The dynamic head framework is introduced in the head layer of the YOLOv7 network model. The dynamic head framework converts the attention function into three continuous attentions: scale-aware attention, space-aware attention, and task-aware attention, so that each attention only focuses on one perspective, as shown in the following formula:
[0021] W(F)=π C (π S (π L (F)·F)·F)·F
[0022] where F∈R L×S×C Represents the three-dimensional feature tensor, π L () represents scale-aware attention, π S () represents spatial perception attention, π C () indicates task-aware attention;
[0023] Use DCNv3 to replace DCNv2 in the dynamic head framework for convolution operations.
[0024] Furthermore, scale-aware attention fuses different features based on semantics, space-aware attention focuses on the discrimination ability of different spatial positions, and task-aware attention combines learning with the generalization of target representation; scale-aware attention, space-aware attention and task-aware attention are used to combine with the target detection head to predict image detection tasks.
[0025] Furthermore, the obtained YOLOv7 network model is improved in the network head part, optimized in the loss function, and lightweighted in the model, including: optimizing the loss function, specifically:
[0026] Based on the NWD loss function, the Wasserstein distance is introduced to optimize the CIOU loss function in the YOLOv7 network model to obtain the N-CIOU loss function, which is expressed as:
[0027]
[0028] L NWD =1-NWD(N a ,N b )
[0029] L N-CIOU =(1-ε)*L NWD +ε*L CIOU
[0030] Among them, W 2 2(N a , N b ) is the Wasserstein distance metric, C is a constant adjusted according to different data sets, and L NWD represents the NWD loss function, L N-CIOU represents the N-CIOU loss function, L CIOU represents the CIOU loss function, N a , N b The Gaussian distribution for bounding box modeling, exp represents an exponential function with the natural constant e as the base, and ε is a weight factor used to control the optimization ratio of the two types of loss functions, with a value of 0.5.
[0031] Furthermore, the obtained YOLOv7 network model is subjected to network head part improvement, loss function optimization and model lightweight processing, including: model lightweight processing, specifically:
[0032] A lightweight P-ELAN structure is constructed based on PCONV convolution to replace the convolution structure of the Backbone layer in the YOLOv7 network model.
[0033] Furthermore, training evaluation is performed based on the steel inspection dataset to be used, including:
[0034] Use the training sub-dataset and the validation sub-dataset to train the model;
[0035] The test sub-dataset is used to evaluate the model performance.
[0036] Furthermore, the improved YOLOv7 network model is used to perform defect detection based on the target steel inspection dataset, including:
[0037] Input the data in the target steel detection dataset into the backbone layer of the improved YOLOv7 network model;
[0038] Extract features through the P-ELAN structure and other modules of the backbone layer;
[0039] The extracted features are output as three layers of Feature Maps of different sizes at the Head layer;
[0040] For the Feature Map, heavy parameter convolution and dynamic head framework are used to perform classification, foreground and background classification, and bounding box task prediction to obtain defect detection results.
[0041] Furthermore, the improved YOLOv7 network model is used to perform defect detection based on the target steel inspection data set, which also includes setting the weight value of each defect type detection in the overall steel defect detection result according to the historical defect detection results, and improving the defect detection results according to the weight value. The specific steps are as follows:
[0042] Obtain historical defect detection results, and conduct combined analysis based on the historical defect detection results and the target steel inspection data set;
[0043] If the defect type of the target steel material inspection data set is a single defect or a combination of defects less than a set number threshold, the first defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results;
[0044] If the defect type of the target steel material inspection data set is a combination defect greater than a set quantity threshold, the second defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results;
[0045] Obtaining defect types of defect types, and obtaining a plurality of single defect detection accuracies corresponding to each defect type and a plurality of combined defect detection accuracies of each defect type combined with all other defect types according to the first defect detection accuracy and the second defect detection accuracy;
[0046] Based on the accumulation of single defect detection accuracy and multiple combined defect detection accuracy, an average defect detection accuracy for each defect type is obtained;
[0047] Based on the average defect detection accuracy of each defect type, a weight value of each defect type in the defect detection result is set;
[0048] The weight value is applied to the calculation of the detection accuracy of each defect type in the defect detection result.
[0049] The achievable beneficial effects of the above technical solution are: by using the K-means++ clustering algorithm to process the data set, the detection accuracy can be improved; the computational cost is reduced by the P-ELAN structure; the model detection performance is improved by constructing the N-CIOU loss function; by adding the DyHead structure that integrates scale attention, spatial attention, and task attention, the YOLOv7 network model is improved to generate the KDH-YOLOv7 network model, and the KDH-YOLOv7 network model can significantly improve the expression ability of the model's target detection head.
[0050] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description and the accompanying drawings.
[0051] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0053] Figure 1 Schematic diagram of the steps of a steel defect detection method based on KDH-YOLOv7 in an embodiment of the present invention;
[0054] Figure 2 Schematic diagram of the method steps for clustering the NEU-DET steel inspection data set using the K-means++ algorithm in an embodiment of the present invention;
[0055] Figure 3 is a schematic structural diagram of a dynamic head frame in an embodiment of the present invention;
[0056] Figure 4 It is a schematic diagram of the lightweight P-ELAN structure in an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0058] This embodiment provides a steel defect detection method based on KDH-YOLOv7. Figure 1 As shown, including:
[0059] Processing the acquired NEU-DET steel inspection data set to obtain a steel inspection data set to be used;
[0060] The K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set;
[0061] The obtained YOLOv7 network model is improved by improving the network head part, optimizing the loss function, and lightweighting the model. Training and evaluation are performed based on the steel inspection data set to be used to obtain the improved YOLOv7 network model.
[0062] The improved YOLOv7 network model is used to perform defect detection based on the target steel inspection dataset.
[0063] The working principle of the above technical solution is: in order to realize the steel defect detection method based on YOLOv7, the present invention first processes the acquired NEU-DET steel detection data set to obtain the stand-by steel detection data set; then uses the K-means++ algorithm to cluster the NEU-DET steel detection data set to obtain the target steel detection data set; then, the obtained YOLOv7 network model is improved by the network head part, the loss function is optimized, and the model is lightweight, and training and evaluation are performed based on the stand-by steel detection data set to obtain an improved YOLOv7 network model; finally, the improved YOLOv7 network model is used to perform defect detection based on the target steel detection data set.
[0064] The beneficial effects of the above technical solution are: by adopting the solution provided in this embodiment, the detection accuracy can be improved by processing the data set with the K-means++ clustering algorithm; the computational cost is reduced by the P-ELAN structure; the model detection performance is improved by constructing the N-CIOU loss function; and the expression ability of the target detection head of the model can be significantly improved by adding the DyHead structure that integrates scale attention, spatial attention, and task attention.
[0065] In one embodiment, the acquired NEU-DET steel material detection data set is processed to obtain a steel material detection data set to be used, including:
[0066] The obtained NEU-DET steel inspection dataset is divided into a ratio of 8:1:1 to obtain a training sub-dataset, a validation sub-dataset, and a test sub-dataset, which are then summarized to generate a steel inspection dataset to be used.
[0067] The working principle of the above technical solution is as follows: the NEU-DET steel inspection dataset is a steel surface defect dataset released by Northeastern University, which collects six typical surface defects of hot-rolled strip, including cracks, inclusions, spots, pockmarks, scales and scratches, and has 1,800 grayscale images, and each type of defect contains 300 samples; in order to process the acquired NEU-DET steel inspection dataset, the present invention divides the acquired NEU-DET steel inspection dataset in proportion according to a division ratio of 8:1:1 to obtain a training sub-dataset, a verification sub-dataset and a test sub-dataset, and summarizes them to generate a steel inspection dataset to be used.
[0068] The beneficial effect of the above technical solution is: by adopting the solution provided in this embodiment, by dividing the sub-data sets, a basis is laid for subsequent training, verification and testing work.
[0069] In one embodiment, Figure 2 As shown in the figure, the K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set, including:
[0070] The K-means++ clustering algorithm is used to locate a basic cluster center and several available cluster centers in the NEU-DET steel inspection data set, and the selection probability of each available cluster center is calculated according to the following formula;
[0071]
[0072] Among them, P(X i ) represents the probability of selecting the i-th available cluster center, D(X i ) represents the shortest distance between the i-th available cluster center and the basic cluster center, A represents the NEU-DET steel inspection dataset;
[0073] According to the selection probability of each available cluster center, the target cluster center that meets the preset selection probability standard is selected;
[0074] According to the center of the target cluster, the NEU-DET steel detection dataset is divided into several data clusters. The steel contours are drawn according to the data clusters, and after mapping the steel contours, the target steel detection dataset is obtained.
[0075] The working principle of the above technical solution is as follows: a suitable anchor frame is crucial to building a high-performance detection model. However, the anchor frame of YOLOv7 is only applicable to data sets of conventional size and is difficult to adapt to complex steel detection environments. The detection anchor frame is reconstructed using the K-means++ clustering algorithm, which can reduce the difference between the real frame and the preset frame, thereby improving the detection accuracy and reducing the probability of false detection and missed detection. The present invention first uses the K-means++ clustering algorithm to locate a basic cluster center and several available cluster centers in the NEU-DET steel detection data set, and calculates the selection probability of each available cluster center; then, according to the selection probability of each available cluster center, the target cluster center that meets the preset selection probability standard is screened; finally, according to the target cluster center, the NEU-DET steel detection data set is divided into several data clusters, the steel contour is drawn according to the data cluster, and the steel contour is mapped to obtain the target steel detection data set.
[0076] The beneficial effect of the above technical solution is: by adopting the solution provided in this embodiment, by using the K-means++ clustering algorithm to reconstruct the detection anchor frame, the difference between the real frame and the preset frame can be reduced, thereby improving the detection accuracy and reducing the probability of false detection and missed detection.
[0077] In one embodiment, the obtained YOLOv7 network model is subjected to network head part improvement, loss function optimization and model lightweight processing, including: performing network head part improvement, specifically:
[0078] The dynamic head framework is introduced in the head layer of the YOLOv7 network model. The dynamic head framework converts the attention function into three continuous attentions: scale-aware attention, space-aware attention, and task-aware attention, so that each attention only focuses on one perspective, as shown in the following formula:
[0079] W(F)=π C (π S (π L (F)·F)·F)·F
[0080] where F∈R L×S×C Represents the three-dimensional feature tensor, π L () represents scale-aware attention, π S () represents spatial perception attention, π C () indicates task-aware attention;
[0081] Use DCNv3 to replace DCNv2 in the dynamic head framework for convolution operations.
[0082] The working principle of the above technical solution is as follows: the head in target detection is mainly responsible for processing feature extraction and prediction, and due to the complexity of classification and positioning combination, various algorithms have been generated, which attempt to improve the performance in the detection part, but they lack a unified perspective to deal with the detection problem; in order to solve this problem, the present invention introduces a dynamic head framework in the head layer of the YOLOv7 network model; Figure 3 As shown, Feature Pyramid means feature pyramid; Scaleaware attention means scale attention mechanism; Spatial aware attention means spatial attention mechanism; Task aware attention means task attention mechanism; avg pool means average pooling layer; conv means convolution layer; relu means activation function; hard sigmoid means activation function; fc (full connection) means full connection layer; normalize means standardization layer; index means variable convolution (different sizes of convolution can be selected according to feature maps of different levels); dcnv3 means 3*3 convolution; offset refers to standard 3*3 convolution; sigmoid is the activation function;
[0083] The dynamic head framework proposed in the present invention converts the attention function into three continuous attentions: scale-aware attention, space-aware attention, and task-aware attention, so that each attention only focuses on one perspective. The expression of the dynamic head framework is:
[0084] W(F)=π C (π S (π L (F)·F)·F)·F
[0085] where F∈R L×S×C Represents the three-dimensional feature tensor, π L () represents scale-aware attention, π S () represents spatial perception attention, π C () represents task-aware attention; at the same time, DCNv3 is used to replace DCNv2 in the dynamic head framework for convolution operations; DCNv3 uses shared weights to reduce parameter and memory complexity, and introduces a multi-group mechanism, which can be coordinated with adaptive spatial aggregation to effectively improve feature diversity. The normalization mode is set to Softmax normalization for each sampling point, which not only makes the training process of large-scale models more stable, but also builds the connection relationship between all sampling points.
[0086] The beneficial effect of the above technical solution is: by adopting the solution provided in this embodiment and adding a dynamic head framework that integrates scale attention, spatial attention, and task attention, the expressive ability of the target detection head of the model can be significantly improved.
[0087] In one embodiment, scale-aware attention fuses different features based on semantics, spatial-aware attention focuses on the discrimination ability of different spatial positions, and task-aware attention combines learning with the generalization of target representation; scale-aware attention, spatial-aware attention, and task-aware attention are used in combination with the target detection head to predict image detection tasks.
[0088] The working principle of the above technical solution is: since different attention can only focus on one perspective and is accidental, the present invention proposes scale-aware attention, which is based on semantic fusion of different features, and its formula is as follows:
[0089]
[0090] Among them, π L (F) represents the hierarchical attention corresponding to the Fth feature, f() represents the linear function using 1x1 convolution, σ() is the hard-sigmoid function, S represents the spatial perception parameter of the feature in the dynamic head frame, and Q represents the channel perception parameter of the feature in the dynamic head frame;
[0091] The spatial perception attention proposed in the present invention focuses on the ability to distinguish different spatial positions, and its formula is as follows:
[0092]
[0093] Among them, π S (F) represents the spatial attention corresponding to the Fth feature, L represents the matrix column in the sparse matrix corresponding to the Fth feature, k represents the matrix row in the sparse matrix corresponding to the Fth feature, P k +Δp k represents the L-direction position offset of the non-zero element in the corresponding sparse matrix, W (l,k) represents the non-zero elements in the sparse matrix, Δm k It represents the k-direction offset of the non-zero element in the corresponding sparse matrix; sparse matrix represents a matrix with a small number of non-zero elements; L-direction position offset represents the L-direction distance between a non-zero element and the previous non-zero element; k-direction offset represents the k-direction distance between a non-zero element and the previous non-zero element;
[0094] Task-aware attention combines learning with generalization of target representations, and its formula is as follows:
[0095] π C (F)·F=max(α 1 (F)·F c +β 1 (F),α 2 (F)·F c +β 2 (F)
[0096] Among them, πC(F) represents the channel attention corresponding to the Fth feature, [α 1 ,α 2 ,β 1 ,β 2 ] T =θ(·) is a hyperfunction used to calculate the activation threshold corresponding to the Fth training feature map; θ(·) is a function used to learn to control the activation threshold, which is divided into four vectors in the formula and combined with the tensor respectively. The usage of θ(·) is similar to Dynamic ReLU. First, global pooling is performed on the L×S dimension, and then two fully connected layers and a normalization layer are used, and finally the output is normalized using the shifted sigmoid function;
[0097] Scale-aware attention, space-aware attention, and task-aware attention are used to combine with the object detection head to make predictions for image detection tasks.
[0098] The beneficial effect of the above technical solution is: by adopting the solution provided by this embodiment, by combining scale-aware attention, space-aware attention and task-aware attention with the target detection head, it is convenient to predict the image detection task more accurately and comprehensively.
[0099] In one embodiment, the obtained YOLOv7 network model is subjected to network head part improvement, loss function optimization and model lightweight processing, including: loss function optimization, specifically:
[0100] Based on the NWD loss function, the Wasserstein distance is introduced to optimize the CIOU loss function in the YOLOv7 network model to obtain the N-CIOU loss function, which is expressed as:
[0101]
[0102] L NWD =1-NWD(N a ,N b )
[0103] L N-CIOU =(1-ε)*L NWD +ε*L CIOU
[0104] in, is the Wasserstein distance metric, C is a constant adjusted according to different data sets, and L NWD represents the NWD loss function, L N-CIOU represents the N-CIOU loss function, L CIOU represents the CIOU loss function, N a , N b The Gaussian distribution for bounding box modeling, exp represents an exponential function with the natural constant e as the base, and ε is a weight factor used to control the optimization ratio of the two types of loss functions, with a value of 0.5.
[0105] The working principle of the above technical solution is: in order to improve the accuracy of the model in ensuring the type of surface defects, the present invention optimizes the loss function in the model. The loss function is a weighted sum of classification loss, confidence loss and bounding box regression loss. YOLOv7 uses CIOU as the bounding box regression loss. The present invention combines NWD to construct an N-CIOU loss function. By introducing the concept of Wasserstein distance, more information about the position and shape distribution between bounding boxes can be considered in the CIOU loss function, thereby improving the model detection performance.
[0106] The beneficial effect of the above technical solution is: by adopting the solution provided by this embodiment, the model detection performance can be improved by constructing the N-CIOU loss function.
[0107] In one embodiment, the obtained YOLOv7 network model is subjected to network head part improvement, loss function optimization and model lightweight processing, including: performing model lightweight processing,
[0108] Specifically:
[0109] A lightweight P-ELAN structure is constructed based on PCONV convolution to replace the convolution structure of the Backbone layer in the YOLOv7 network model.
[0110] The working principle of the above technical solution is as follows: In order to reduce the complexity of the model and realize the lightweight model, the present invention constructs a lightweight P-ELAN structure based on PCONV convolution, replacing the convolution structure of the Backbone layer in the YOLOv7 network model; Figure 4 As shown in the figure, the CBS module is a basic module of the YOLOv7 network model, which consists of three parts: Conv convolution layer, BN batch normalization layer and SiLU activation function layer; Cat represents the concatenation operation, which merges the two feature maps along the channel dimension to increase the receptive field and feature diversity of the network; PCONV represents partial convolution, which applies filters only on part of the input channel, while reducing redundant calculations and memory accesses, thereby extracting spatial features more efficiently.
[0111] The beneficial effects of the above technical solution are: by adopting the solution provided in this embodiment, a lightweight P-ELAN structure is constructed based on PCONV, and PCONV convolution can reduce computational redundancy and memory access, and only applies traditional convolution to some input channels for spatial feature extraction, while the remaining channels remain unchanged, thereby reducing the number of network parameters and the amount of calculation, and improving the network's reasoning speed.
[0112] In one embodiment, training evaluation is performed based on a steel material detection dataset to be used, including:
[0113] Use the training sub-dataset and the validation sub-dataset to train the model;
[0114] The test sub-dataset is used to evaluate the model performance.
[0115] The working principle of the above technical solution is: in order to realize the training evaluation of the model, the present invention uses the training sub-dataset and the verification sub-dataset to carry out the learning and training of the model; and uses the test sub-dataset to evaluate the model performance.
[0116] The beneficial effect of the above technical solution is: by adopting the solution provided in this embodiment, through training evaluation, the necessary conditions are provided for the function detection and subsequent use of the model.
[0117] In one embodiment, defect detection is performed based on a target steel material inspection dataset using an improved YOLOv7 network model, including:
[0118] Input the data in the target steel detection dataset into the backbone layer of the improved YOLOv7 network model;
[0119] Extract features through the P-ELAN structure and other modules of the backbone layer;
[0120] The extracted features are output as three layers of Feature Maps of different sizes at the Head layer;
[0121] For the Feature Map, heavy parameter convolution and dynamic head framework are used to perform classification, foreground and background classification, and bounding box task prediction to obtain defect detection results.
[0122] The working principle of the above technical solution is: in the process of using the improved YOLOv7 network model, the data in the target steel inspection data set is first input into the backbone layer of the improved YOLOv7 network model; then the features are extracted through the P-ELAN structure and other modules of the backbone layer; finally, the extracted features are output as three layers of Feature Maps of different sizes in the Head layer; for the Feature Map, heavy parameter convolution and dynamic head framework are used to perform classification, foreground and background classification, and border task prediction to obtain the defect detection results.
[0123] The beneficial effect of the above technical solution is: by adopting the solution provided by this embodiment, the accuracy of defect detection is improved by using the improved YOLOv7 network model for defect detection.
[0124] In one embodiment, defect detection is performed based on a target steel material detection data set using an improved YOLOv7 network model, and also includes setting a weight value of each defect type detection in the overall steel material defect detection result according to historical defect detection results, and improving the defect detection result according to the weight value. The specific steps are:
[0125] Obtain historical defect detection results, and conduct combined analysis based on the historical defect detection results and the target steel inspection data set;
[0126] If the defect type of the target steel material inspection data set is a single defect or a combination of defects less than a set number threshold, the first defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results;
[0127] If the defect type of the target steel material inspection data set is a combination defect greater than a set quantity threshold, the second defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results;
[0128] Obtaining defect types of defect types, and obtaining a plurality of single defect detection accuracies corresponding to each defect type and a plurality of combined defect detection accuracies of each defect type combined with all other defect types according to the first defect detection accuracy and the second defect detection accuracy;
[0129] Based on the accumulation of single defect detection accuracy and multiple combined defect detection accuracy, an average defect detection accuracy for each defect type is obtained;
[0130] Based on the average defect detection accuracy of each defect type, a weight value of each defect type in the defect detection result is set;
[0131] The weight value is applied to the calculation of the detection accuracy of each defect type in the defect detection result.
[0132] The working principle of the above technical solution is: in order to achieve accurate analysis and judgment of defect detection results, the present invention also includes setting a weight value of each defect type detection in the overall defect detection result of steel according to the historical defect detection results, and improving the defect detection results according to the weight value. The specific steps are: firstly obtaining the historical defect detection results, and combining and analyzing the historical defect detection results with the target steel detection data set;
[0133] If the defect type of the target steel material inspection data set is a single defect or a combination of defects less than a set number threshold, the first defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results; if the defect type of the target steel material inspection data set is a combination of defects greater than a set number threshold, the second defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results;
[0134] Then, the defect type of the defect type is obtained, and based on the first defect detection accuracy and the second defect detection accuracy, a plurality of single defect detection accuracies corresponding to each defect type and a plurality of combined defect detection accuracies of each defect type combined with all other defect types are obtained; based on the accumulation and average of the single defect detection accuracy and the plurality of combined defect detection accuracies, an average defect detection accuracy of each defect type is obtained;
[0135] Finally, based on the size of the average defect detection accuracy of each defect type, a corresponding weight value of each defect type in the defect detection result is set; and the weight value is applied to the calculation of the detection accuracy of each defect type in the defect detection result.
[0136] The beneficial effect of the above technical solution is: by adopting the solution provided by this embodiment, a weight value is set according to the average defect detection accuracy of each defect type, and used to improve the defect detection result, the accuracy value of the defect detection result is further improved.
[0137] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A steel defect detection method based on KDH-YOLOv7, characterized in that: include: Processing the acquired NEU-DET steel inspection data set to obtain a steel inspection data set to be used; The K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set; The obtained YOLOv7 network model is improved by improving the network head part, optimizing the loss function, and lightweighting the model. Training and evaluation are performed based on the steel inspection data set to be used to obtain the improved YOLOv7 network model. The improved YOLOv7 network model is used to perform defect detection based on the target steel inspection dataset.
2. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: The obtained NEU-DET steel inspection data set is processed to obtain the steel inspection data set to be used, including: The obtained NEU-DET steel inspection dataset is divided into a ratio of 8:1:1 to obtain a training sub-dataset, a validation sub-dataset, and a test sub-dataset, which are then summarized to generate a steel inspection dataset to be used.
3. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: The K-means++ algorithm is used to cluster the NEU-DET steel inspection data set to obtain the target steel inspection data set, including: The K-means++ clustering algorithm is used to locate a basic cluster center and several available cluster centers in the NEU-DET steel inspection data set, and the selection probability of each available cluster center is calculated according to the following formula; Among them, P(X i ) represents the probability of selecting the i-th available cluster center, D(X i ) represents the shortest distance between the i-th available cluster center and the basic cluster center, A represents the NEU-DET steel inspection dataset; According to the selection probability of each available cluster center, the target cluster center that meets the preset selection probability standard is selected; According to the center of the target cluster, the NEU-DET steel detection dataset is divided into several data clusters. The steel contours are drawn according to the data clusters, and after mapping the steel contours, the target steel detection dataset is obtained.
4. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: For the obtained YOLOv7 network model, the network head part is improved, the loss function is optimized, and the model is lightweight, including: improving the network head part, specifically: The dynamic head framework is introduced in the head layer of the YOLOv7 network model. The dynamic head framework converts the attention function into three continuous attentions: scale-aware attention, space-aware attention, and task-aware attention, so that each attention only focuses on one perspective, as shown in the following formula: W(F)=π C (p S (p L (F)·F)·F)·F where F∈R L×S×C Represents the three-dimensional feature tensor, π L () represents scale-aware attention, π S () represents spatial perception attention, π C () indicates task-aware attention; Use DCNv3 to replace DCNv2 in the dynamic head framework for convolution operations.
5. A steel defect detection method based on KDH-YOLOv7 according to claim 4, characterized in that: Scale-aware attention fuses different features based on semantics, spatial-aware attention focuses on the discrimination ability of different spatial positions, and task-aware attention combines learning with the generalization of target representation; scale-aware attention, spatial-aware attention, and task-aware attention are used to combine with the target detection head to predict image detection tasks.
6. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: For the obtained YOLOv7 network model, the network head part is improved, the loss function is optimized, and the model is lightweight, including: loss function optimization, specifically: Based on the NWD loss function, the Wasserstein distance is introduced to optimize the CIOU loss function in the YOLOv7 network model to obtain the N-CIOU loss function, which is expressed as: L NWD =1-NWD(N a ,OF b ) L N-CIOU =(1-e)*L NWD +e*L CIOU in, is the Wasserstein distance metric, C is a constant adjusted according to different data sets, and L NWD represents the NWD loss function, L N-CIOU represents the N-CIOU loss function, L CIOU represents the CIOU loss function, N a ,N b The Gaussian distribution model for modeling the bounding box, exp represents an exponential function with the natural constant e as the base, and ε is a weight factor used to control the optimization ratio of the two types of loss functions, with a value of 0.
5.
7. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: For the obtained YOLOv7 network model, the network head part is improved, the loss function is optimized, and the model is lightweight, including: lightweight model processing, specifically: A lightweight P-ELAN structure is constructed based on PCONV convolution to replace the convolution structure of the Backbone layer in the YOLOv7 network model.
8. A steel defect detection method based on KDH-YOLOv7 according to claim 2, characterized in that: The training and evaluation are carried out based on the steel inspection dataset to be used, including: Use the training sub-dataset and the validation sub-dataset to train the model; The test sub-dataset is used to evaluate the model performance.
9. A steel defect detection method based on KDH-YOLOv7 according to claim 7, characterized in that: Using the improved YOLOv7 network model, defect detection is performed based on the target steel inspection dataset, including: Input the data in the target steel detection dataset into the backbone layer of the improved YOLOv7 network model; Extract features through the P-ELAN structure and other modules of the backbone layer; The extracted features are output as three layers of Feature Maps of different sizes at the Head layer; For the Feature Map, heavy parameter convolution and dynamic head framework are used to perform classification, foreground and background classification, and bounding box task prediction to obtain defect detection results.
10. A steel defect detection method based on KDH-YOLOv7 according to claim 1, characterized in that: Using the improved YOLOv7 network model, defect detection is performed based on the target steel inspection data set. It also includes setting the weight value of each defect type detection in the overall steel defect detection result according to the historical defect detection results, and improving the defect detection results according to the weight value. The specific steps are as follows: Obtain historical defect detection results, and conduct combined analysis based on the historical defect detection results and the target steel inspection data set; If the defect type of the target steel material inspection data set is a single defect or a combination of defects less than a set number threshold, the first defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results; If the defect type of the target steel material inspection data set is a combination defect greater than a set quantity threshold, the second defect detection accuracy is obtained by analysis based on the corresponding historical defect detection results; Obtaining defect types of defect types, and obtaining a plurality of single defect detection accuracies corresponding to each defect type and a plurality of combined defect detection accuracies of each defect type combined with all other defect types according to the first defect detection accuracy and the second defect detection accuracy; Based on the accumulation of single defect detection accuracy and multiple combined defect detection accuracy, an average defect detection accuracy for each defect type is obtained; Based on the average defect detection accuracy of each defect type, a weight value of each defect type in the defect detection result is set; The weight value is applied to the calculation of the detection accuracy of each defect type in the defect detection result.
