Surface defect open set detection method under small sample condition
Through the direction-aware meta-learning module, G-GSN feature extraction module and negative entropy loss function, the problem of identifying new types of defects in the industrial surface defect detection model under small sample conditions is solved, and efficient open set detection and closed set detection performance is achieved. Improved model reliability and detection efficiency.
Patent Information
- Application Number
- CN202410639509.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-03
AI Technical Summary
Under small sample conditions, industrial surface defect detection models have difficulty identifying new categories of defects and misclassifying them into known categories, reducing the reliability of the model, and existing open set detection methods perform poorly in small sample environments.
The direction-aware meta-learning module, G-GSN feature extraction module and open set classification loss function are used to divide small sample data into multiple tasks through meta-learning, use the coordinate attention mechanism to enhance feature representation capabilities, and design the Ghost Bottleneck structure to reduce computational complexity , and use the negative entropy loss function to improve the open set loss function to improve the detection ability of unknown categories.
Under small sample conditions, the model's recognition ability and detection efficiency of unknown category defects are significantly improved, and the open set detection performance is improved, proving its significant advantages under industrial small sample conditions, and performing well on closed set detection tasks.
Smart Images

Figure CN118587165A
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of industrial surface defect detection and deep learning technology, and in particular to an open set detection method for surface defects under small sample conditions. Background Art
[0002] Surface defects caused by the uncertainty of production process not only affect the appearance quality of the product, but also affect its mechanical function and may even cause the product to be scrapped. Therefore, industrial surface defect detection is of great significance to improve product quality and reduce costs.
[0003] Insufficient sample quantity in the industrial field is the key issue that leads to low accuracy of industrial surface defect detection models. Some scholars have conducted relevant research on this issue. For example, the article [Li X, Li L, Wang P, et al. You only train twice: A lighter and faster method for industrial weld defect detection based on dynamic kernel network [J]. Measurement, 2024, 231: 114642.] proposed an industrial small sample welding defect detection method, which adaptively adjusts its kernel function based on the dynamic kernel network and achieves efficient model learning and defect recognition through two training processes; the article [Shi Y, Wang H, **g C, et al. A Few-Shot Defect Detection Method for Transmission Lines Based on Meta-Attention and Feature Reconstruction [J]. Applied Sciences, 2023, 13 (10): 5896.] designs a new region proposal network, integrates support set features and query set features to focus on more detailed texture features, and achieves efficient detection under small samples; the article [Kang B, Liu Z, Wang X, et al. Few-shot object detection via feature reweighting [C] / / Proceedings of the IEEE / CVF international conference oncomputer vision.2019:8420-8429.] A meta-feature learner is introduced into the YOLOv2 model framework to realize an end-to-end training model under small samples. The above research has handled the small sample problem very well, but in the open set environment in the industrial field, new defect categories often appear. The above research cannot identify these new categories and will misclassify them into known categories, reducing the reliability of the model.
[0004] To enable the model to have open set detection capabilities, the key is to make the model reject unknown classes. For example, the article [Ye HJ, Hu H, Zhan DC, et al. Few-shot learning via embedding adaptation with set-to-set functions[C] / / Proceedings of the IEEE / CVF conference on computer vision and pattern recognition.2020:8808-8817.] emphasizes that known classes and unknown classes should not belong to the same embedding space, and proposes a method based on embedding adaptation. It adjusts the embedding representation between samples through set-to-set functions, so that similar samples are closer and heterogeneous samples are farther away, thereby enhancing the learning ability for unknown classes; the article [Esmaeilpour S, Shu L, Liu B. Open Set Recognition Via Augmentation-Based Similarity Learning[C] / / Conference on Lifelong Learning Agents.PMLR, 2022:875-885.] improves the detection of unknown classes by learning pairwise similarities in the training phase to distinguish known classes from pseudo-unknown classes; the article [Wang H, Pang G, Wang P, et al. Glocal energy-based learning for few-shot Open-set recognition[C] / / Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition.2023:7507-7516.] By combining category-level and pixel-level features to learn a global energy score, large energy scores are assigned to samples that deviate from known samples in category features or pixel features, and small energy scores are assigned in other cases, thereby improving the detection ability of unknown categories; Article [Jeong M, Choi S, Kim C. Few-shot open-set recognition by transformation consistency[C] / / Proceedingsof the IEEE / CVF Conference on Computer Vision and Pattern Recognition.2021:12566-12575.] proposed a SnaTCHer method, which detects unknown class samples that are significantly different from known classes by replacing the feature vector of the query sample with its corresponding class prototype and measuring the difference between the replaced prototype set and the original set using the transformation consistency principle. The above method enables the model to have good open set detection capabilities, but such models perform poorly under small sample conditions. Therefore, how to perform open set detection under small sample conditions for surface defect detection is still an important issue. . Summary of the invention
[0005] The purpose of the present invention is to provide an open set detection method for surface defects under small sample conditions, which includes a direction-aware meta-learning module, a G-GSN (GhostNet Global Spatial Network) feature extraction module and an open set classification loss function. Among them, the direction-aware meta-learning module uses meta-learning partitioning to divide the small sample data into multiple tasks, calculates and integrates the feature maps of meta-features in different directions for each task, and enhances the defect characterization capability of the support set meta-features, and enhances the generalization performance of the model using a small number of samples; the G-GSN feature extraction module generates additional feature maps with 1x1 point convolution, and then groups the input channels and performs convolution calculations within the groups, which reduces the computational complexity of the model while ensuring effective feature extraction, and reduces the impact of the direction-aware meta-learning module on the overall detection speed of the model; the open set classification loss function minimizes the negative entropy to make the unknown class deviate from the known class in the feature space, thereby improving the ability to identify unknown category defects in the open set scenario.
[0006] The technical solution adopted by the present invention is:
[0007] A surface defect open set detection method under small sample conditions comprises the following steps:
[0008] S1: Construct a method framework including a direction-aware meta-learning module, a G-GSN feature extraction module, and an open-set classification loss function;
[0009] S2: In the direction perception meta-learning module, the small sample data is first divided into multiple open set meta-tasks for model training and testing using the meta-learning N-way, K-shot (total number of task categories, number of samples in each category) task division method;
[0010] S3: In the direction-aware meta-learning module, a coordinate attention mechanism is added to calculate and integrate the feature maps of meta-features in different directions for each open-set meta-task, thus enhancing the defect representation capability of the support set meta-features;
[0011] S4: In the G-GSN feature extraction module, a large number of additional feature maps are first generated by using a simple linear transformation instead of the convolution operation in the feature extraction process. Then, the input channels are grouped and convolution calculations are performed within the groups, which reduces the computational complexity of the model while ensuring effective feature extraction.
[0012] S5: In the G-GSN feature extraction module, the Ghost Bottleneck structure is designed to reduce gradient damage, and the group shuffle convolution operation is used to evenly obtain multi-channel feature information, enhance the ability to capture small target defects, speed up the model in feature extraction, and improve detection efficiency;
[0013] S6: In the open set classification loss function, the key is to minimize the probability of known classes from the unknown class sample set. This is achieved by using the open set loss function OpL (Open set classification Loss) based on the improved cross entropy loss function to maximize the entropy of the known class probability, so that the model has the ability to recognize unknown classes.
[0014] Furthermore, in step S2, the small sample data is divided into multiple open set meta-tasks for model training and testing using a meta-learning task division method. The process includes the following steps:
[0015] 1-2) Divide the training task into meta-training sets and meta-test set
[0016] in, is the training set and test set of the i-th learning task; is the training set and test set of i test tasks; N s is the number of training sets, N t is the number of test sets.
[0017] 1-2) Divide the meta-training set MS into n task groups, Task1, Task2, ..., Task n For each task, N classes are randomly selected from the training set, with K samples in each class, as the training support set S for this group of tasks. train , the remaining samples are used as the training query set Q train .
[0018] 1-3) Compared with standard meta-learning, this paper expands the meta-test set MT(S, T) with unknown classes to make it have open set properties.
[0019] Furthermore, in step S3, a coordinate attention mechanism is added to the detector to calculate and integrate the feature maps of the meta-features in different directions for each open set meta-task, so that the model can fuse the meta-features of the support set to enhance the defect characterization capability. The process includes the following steps:
[0020] 2-1) Decompose channel attention into two parallel 1D feature encoding processes. These two processes aggregate the input features along the vertical and horizontal directions respectively to generate two independent direction-aware and position-aware feature maps. First, given the feature matrix, use the pooling kernels (H, 1) and (1, W) of 2 spatial dimensions to average pool each channel along the horizontal coordinate x and the vertical coordinate y and aggregate features along two directions to generate two direction-aware feature maps. The output of the cth channel at height h is expressed as:
[0021]
[0022] Where: W is the width of the feature map; x c (h,i) is the element of the feature map in channel c, height h and width i; is the average value of the cth channel at height h.
[0023] The output of the cth channel at width w is:
[0024]
[0025] Where: H is the height of the feature map; x c (j,w) is the element of the feature map in channel c, height j and width w; is the average value of the cth channel over width w.
[0026] 2-2) Then, connect them and feed them into the 1x1 convolution transformation function F1 to obtain:
[0027]
[0028] Where: [,] represents the concatenation operation along the spatial dimension; δ is the nonlinear activation function; f∈R C / r×(H+W) It is the intermediate feature map that encodes spatial information in the horizontal and vertical directions; r is the reduction ratio of the feature map channel.
[0029] 2-3) Then the feature map f after information interaction is restored along the spatial dimension into two independent tensors f h ∈R C / r×H×1 and f w ∈R C / r×1×W , and then through two more convolutions F h and F w f h and fw Transform and get the output:
[0030] g h =σ(F h (f h )),
[0031] g w =σ(F w (f w ))
[0032] Where: σ is the sigmoid function. The output is the channel attention weight g along the two spatial directions h and g w .
[0033] 2-4) Finally, the input x is reweighted to output the coordinate attention block y:
[0034]
[0035] Where: x c (i, j) is an element on the original feature map; c is the channel, i and j represent the row and column coordinates in the spatial dimension respectively; and Represents the attention weights along the height and width directions.
[0036] This encoding process enables the model to locate the specific location of defects more accurately and enhances the model's ability to recognize known defects.
[0037] Furthermore, in step S4, a large number of additional feature maps are generated by using a simple linear transformation instead of a convolution operation in the feature extraction process, and then the input channels are grouped and convolution calculations are performed within the groups, thereby reducing the amount of model calculations while ensuring effective feature extraction. The process includes the following steps:
[0038] 3-1) Use conventional convolution to obtain the intrinsic feature map Y'. The amount of computation in this part is approximately equal to:
[0039] Y'=X*f'
[0040] Where: * is the convolution operation; Y'∈R h’×w’×m is an intrinsic feature map with m channels; f'∈R c×k×k×m is the convolution kernel in this layer, h' and w' are the height and width of the output data respectively; k×k is the size of the convolution kernel, m≤n.
[0041] 3-2) Use the ∮ij operation to generate the Ghost feature map Yij for each channel of Y':
[0042] Where: y'i is the i-th intrinsic feature map in Y'; ∮i,j is the j-th (except the last) linear operation used to generate the j-th additional feature map Yij in the above function, that is, y'i can have one or more additional feature maps Yij; the last ∮i,j is the identity mapping used to retain the output after the identity mapping, where the linear operation ∮ occurs on each channel.
[0043] 3-3) The intrinsic feature map generated in the first step and the Ghost feature map obtained in the second step are concatenated to obtain the final result Output. Then the input channels are grouped and convolution calculations are performed within the groups to reduce the amount of model calculations while ensuring effective feature extraction.
[0044] Furthermore, in step S5, the GhostBottleneck structure is first designed to reduce gradient damage. The structure increases the number of channels by integrating multiple convolutional layers and residual connections and using two stacked ghost modules as expansion layers; the ReLU activation function is not used after the second Ghost module, and the feature response in the deep convolution output is retained; at the same time, when stride=2, the residual path is implemented by the downsampling layer and the deep convolution. After each layer, batch normalization (BN) and ReLU nonlinear activation functions are used to establish connections between Ghost modules and deepen the depth of the network through a large number of residual connections. As the depth of the network deepens, the number of model parameters increases dramatically, which not only increases the training time of the network, but also puts higher requirements on the computing equipment. Therefore, deep separable convolution is introduced between Ghost modules to balance the relationship between network depth and computing resources. Secondly, the group shuffle convolution operation is used to solve the problem of decreased feature extraction and fusion capabilities caused by using deep separable convolution, and evenly obtain multi-channel feature information. The structure includes the following steps:
[0045] 4-1) First, perform a downsampling operation on the input using ordinary convolution.
[0046] 4-2) Then use depthwise separable convolution.
[0047] 4-3) Finally, concatenate the results of the two convolution operations.
[0048] This makes the output of the depthwise convolution close to the output of the standard convolution, thus maintaining the information integrity of the standard convolution.
[0049] Furthermore, in step S6, the model is adapted to the open set scenario by minimizing the probability of known classes from the unknown class sample set, that is, using negative entropy as the loss function. The model is equipped with the ability to identify unknown classes by maximizing the entropy of the known class probability using the open set loss function OpL improved based on the cross entropy loss function. The loss design includes the following steps:
[0050] 5-1) Assume that the true distribution is Y and the predicted distribution is Y'. The task of the model is to minimize the difference between the true distribution Y and the predicted distribution Y', denoted as min(D kL (Y||Y')), where D kL (Y||Y') is the KL divergence. It is calculated as follows:
[0051]
[0052] 5-2) The calculation formula of cross entropy is:
[0053]
[0054] 5-3) The formula for information entropy is
[0055]
[0056] 5-4) Therefore, the calculation formula of KL divergence can be expressed as
[0057]
[0058] Among them, H(P) is the information entropy of the true distribution and is a constant. Therefore, the effect of minimizing the cross entropy is consistent with minimizing the KL divergence.
[0059] 5-5) Then by minimizing the negative entropy of the known category probability, that is, maximizing the entropy of the known category probability, based on the above formula
[0060] An improved open set loss is proposed as the loss function of this paper:
[0061]
[0062] Where: OpL represents the loss of samples from category k, Du[i] represents the set of unknown classes, k is a class in the unknown class set, and p(y=k|x) represents the probability that the model predicts that the sample belongs to category k given the input x. The lower the OpL value, the more certain the model's prediction on sample x is.
[0063] The beneficial effects of adopting the above technical solution are:
[0064] The purpose of the present invention is to provide a surface defect open set detection method under small sample conditions, such as Figure 1As shown in the figure, the method consists of three parts. The first part trains samples in a meta-task manner, and fuses the meta-features of the support set after coordinate attention enhancement to enhance the characterization ability of defects; the second part simplifies the convolution operation of the feature extraction process by designing a GhostBottleneck structure to achieve efficient feature extraction; the third part uses negative entropy to design an improved open set classification damage function OpL to enable the model to achieve open set detection.
[0065] The proposed method was experimented on the surface defect dataset of Northeastern University in open and closed set states. In the open set state of 5-shot and 10-shot, the proposed method MetaO (Metalearning with Open-set) achieved better detection results in the open set detection task than the other three comparison methods of F-CNN, FODNet, and RFDNet. In the 30-shot state, the proposed method was slightly inferior to the open set detection model RFDNet in natural scenes, which further proved the significant advantages of the proposed model under industrial small sample conditions. At the same time, the effectiveness of each module of the proposed method was proved through ablation experiments. Finally, a closed set experimental analysis was carried out to prove that the proposed model also has good performance in closed set detection tasks, which provides strong support for the application of open set detection of industrial surface defects under small sample conditions. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 Framework diagram of the open set detection method for surface defects under small sample conditions;
[0067] Figure 2 Open set meta-learning data partitioning method;
[0068] Figure 3 Coordinate attention structure diagram;
[0069] Figure 4 G-GSN network structure diagram;
[0070] Figure 5 GhostNet structure diagram;
[0071] Figure 6 GhostBottleneck residual structure diagram;
[0072] Figure 7 NEU-DET data graph;
[0073] Figure 8 Training data partition diagram;
[0074] Figure 95-shot model performance diagram;
[0075] Fig.10 Accuracy and speed scatter plot (5-shot);
[0076] Fig.11 Comparison of four models on FS-OD (10-shot);
[0077] Fig.12 grad_cam visualization of the feature map of the Mx layer;
[0078] Fig.13 Comparison chart of various models on the NEU-DET closed set. DETAILED DESCRIPTION
[0079] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0080] Based on the surface defect detection under small sample conditions, this paper takes deep learning technology as the carrier, and takes method perception meta-learning module, G-GSN feature extraction module and open set classification loss function as the main method framework, and proposes an open set detection method for surface defects under small sample conditions. Figure 1 As shown, the following steps are included:
[0081] S1: Construct a method framework including a direction-aware meta-learning module, a G-GSN feature extraction module, and an open-set classification loss function;
[0082] S2: In the direction perception meta-learning module, we first use the meta-learning N-way, K-shot task division method to divide the small sample data into multiple open set meta-tasks for model training and testing. The division is as follows: Figure 2 As shown;
[0083] The small sample data is divided into multiple open set meta-tasks for model training and testing using the meta-learning task division method. The process includes the following steps:
[0084] 1-1) Divide the training task into meta-training sets and meta-test set
[0085] in, is the training set and test set of the i-th learning task; is the training set and test set of i test tasks; N s is the number of training sets, N t is the number of test sets.
[0086] 1-2) Divide the meta-training set MS into n task groups, Task1, Task2, ..., Task n For each task, N classes are randomly selected from the training set, with K samples in each class, as the training support set S for this group of tasks. train , the remaining samples are used as the training query set Qtrain .
[0087] 1-3) Compared with standard meta-learning, this paper expands the meta-test set MT(S, T) with unknown classes to make it have open set properties.
[0088] S3: In the direction-aware meta-learning module, a coordinate attention mechanism is added to calculate and integrate the feature maps of meta-features in different directions for each open-set meta-task, thus enhancing the defect representation capability of the support set meta-features;
[0089] A coordinate attention mechanism is added to the detector to calculate and integrate the feature maps of meta-features in different directions for each open-set meta-task, so that the model can fuse the meta-features of the support set to enhance the characterization ability of defects. The process includes the following steps:
[0090] 2-1) Decompose channel attention into two parallel 1D feature encoding processes. These two processes aggregate the input features along the vertical and horizontal directions respectively to generate two independent direction-aware and position-aware feature maps. First, given the feature matrix, use the pooling kernels (H, 1) and (1, W) of 2 spatial dimensions to average pool each channel along the horizontal coordinate x and the vertical coordinate y and aggregate features along two directions to generate two direction-aware feature maps. The output of the cth channel at height h is expressed as:
[0091]
[0092] Where: W is the width of the feature map; x c (h,i) is the element of the feature map in channel c, height h and width i; is the average value of the cth channel at height h.
[0093] The output of the cth channel at width w is:
[0094]
[0095] Where: H is the width of the feature map; x c (j,w) is the element of the feature map in channel c, height j and width w; is the average value of the cth channel over width w.
[0096] 2-2) Then, connect them and feed them into the 1x1 convolution transformation function F1 to obtain:
[0097]
[0098] Where: [,] represents the concatenation operation along the spatial dimension; δ is the nonlinear activation function; f∈R C / r×(H+W)It is the intermediate feature map that encodes spatial information in the horizontal and vertical directions; r is the reduction ratio of the feature map channel.
[0099] 2-3) Then the feature map f after information interaction is restored along the spatial dimension into two independent tensors f h ∈R C / r×H×1 and f w ∈R C / r×1×W , and then through two more convolutions F h and F w f h and f w Transform and get the output:
[0100] g h =σ(F h (f h )),
[0101] g w =σ(F w (f w ))
[0102] Where: σ is the sigmoid function. The output is the channel attention weight g along the two spatial directions h and g w .
[0103] 2-4) Finally, the input x is reweighted to output the coordinate attention block y:
[0104]
[0105] Where: x c (i, j) is an element on the original feature map; c is the channel, i and j represent the row and column coordinates in the spatial dimension respectively; and Represents the attention weights along the height and width directions.
[0106] This encoding process enables the model to locate the specific location of defects more accurately and enhances the model's ability to recognize known defects.
[0107] S4: In the G-GSN feature extraction module, a large number of additional feature maps are first generated by using a simple linear transformation instead of the convolution operation in the feature extraction process. Then, the input channels are grouped and convolution calculations are performed within the groups, which reduces the computational complexity of the model while ensuring effective feature extraction.
[0108] A large number of additional feature maps are generated by using a simple linear transformation instead of convolution operation in the feature extraction process, and then the input channels are grouped and convolution calculations are performed within the groups, thereby reducing the amount of model calculation while ensuring effective feature extraction. The process includes the following steps:
[0109] 3-1) Use conventional convolution to obtain the intrinsic feature map Y'. The amount of computation in this part is approximately equal to:
[0110] Y'=X*f'
[0111] Where: * is the convolution operation; Y'∈R h’×w’×m is an intrinsic feature map with m channels; f'∈R c×k×k×m is the convolution kernel in this layer, h' and w' are the height and width of the output data respectively; k×k is the size of the convolution kernel, m≤n.
[0112] 3-2) Use the ∮ij operation to generate the Ghost feature map Yij for each channel of Y':
[0113]
[0114] Where: y'i is the i-th intrinsic feature map in Y'; ∮i,j is the j-th (except the last) linear operation used to generate the j-th additional feature map Yij in the above function, that is, y'i can have one or more additional feature maps Yij; the last ∮i,j is the identity mapping used to retain the output after the identity mapping, where the linear operation ∮ occurs on each channel.
[0115] 3-3) The intrinsic feature map generated in the first step and the Ghost feature map obtained in the second step are concatenated to obtain the final result Output. Then the input channels are grouped and convolution calculations are performed within the groups to reduce the amount of model calculations while ensuring effective feature extraction.
[0116] S5: In the G-GSN feature extraction module, the Ghost Bottleneck structure is designed to reduce gradient damage, and the group shuffle convolution operation is used to evenly obtain multi-channel feature information, enhance the ability to capture small target defects, speed up the model in feature extraction, and improve detection efficiency;
[0117] First, the Ghost Bottleneck structure is designed to reduce gradient damage. The structure increases the number of channels by integrating multiple convolutional layers and residual connections and using two stacked ghost modules as extension layers. After the second Ghost module, the ReLU activation function is not used to retain the feature response in the deep convolution output. At the same time, when stride=2, the residual path is implemented by the downsampling layer and the deep convolution. After each layer, batch normalization (BN) and ReLU nonlinear activation functions are used to establish connections between Ghost modules and deepen the depth of the network through a large number of residual connections. As the network depth increases, the number of model parameters increases dramatically, which not only increases the training time of the network, but also puts higher requirements on the computing equipment. Therefore, depth-wise separable convolution is introduced between Ghost modules to balance the relationship between network depth and computing resources. Secondly, the grouped shuffle convolution operation is used to solve the problem of decreased feature extraction and fusion capabilities caused by using depth-wise separable convolution, and evenly obtain multi-channel feature information. The structure includes the following steps:
[0118] 4-1) First, perform a downsampling operation on the input using ordinary convolution.
[0119] 4-2) Then use depthwise separable convolution.
[0120] 4-3) Finally, concatenate the results of the two convolution operations.
[0121] This makes the output of the depthwise convolution close to the output of the standard convolution, thus maintaining the information integrity of the standard convolution.
[0122] S6: In the open set classification loss function, the key is to minimize the probability of known classes from the unknown class sample set. This is achieved by using the open set loss function OpL, which is improved based on the cross entropy loss function, to maximize the entropy of the known class probability, so that the model has the ability to recognize unknown classes.
[0123] The model is adapted to the open set scenario by minimizing the probability of known classes from the unknown class sample set, that is, using negative entropy as the loss function. The model is equipped with the ability to identify unknown classes by maximizing the entropy of known class probabilities using the open set loss function OpL improved based on the cross entropy loss function. The loss design includes the following steps:
[0124] 5-1) Assume that the true distribution is Y and the predicted distribution is Y'. The task of the model is to minimize the difference between the true distribution Y and the predicted distribution Y', denoted as min(D kL (Y||Y')), where D kL (Y||Y') is the KL divergence. It is calculated as follows:
[0125]
[0126] 5-2) The calculation formula of cross entropy is:
[0127]
[0128] 5-3) The formula for information entropy is
[0129]
[0130] 5-4) Therefore, the calculation formula of KL divergence can be expressed as
[0131]
[0132] Among them, H(P) is the information entropy of the true distribution and is a constant. Therefore, the effect of minimizing the cross entropy is consistent with minimizing the KL divergence.
[0133] 5-5) Then by minimizing the negative entropy of the known category probability, that is, maximizing the entropy of the known category probability, based on the above formula
[0134] An improved open set loss is proposed as the loss function of this paper:
[0135]
[0136] Where: OpL represents the loss of samples from category k, Du[i] represents the set of unknown classes, k is a class in the unknown class set, and p(y=k|x) represents the probability that the model predicts that the sample belongs to category k given the input x. The lower the OpL value, the more certain the model's prediction on sample x is.
[0137] Based on the above steps, the present invention effectively solves the problem that it is difficult to effectively detect unknown classes in industrial surface defect detection under small sample conditions, and proposes an open set detection method for surface defects under small sample conditions. The method includes three parts. The first part trains samples in a meta-task manner, and fuses the meta-features of the support set after coordinate attention enhancement to enhance the characterization ability of defects; the second part simplifies the convolution operation of the feature extraction process by designing a GhostBottleneck structure to achieve efficient feature extraction; the third part uses negative entropy to design an improved open set classification damage function OpL to enable the model to achieve open set detection.
[0138] Experimental verification of the surface defect open set detection method under small sample conditions of the present invention:
[0139] 1. Test environment
[0140] Windows 11 system, CPU is Core(TM) i5-13400, graphics card is GeForce RGTX3060, 12G video memory, 32GB memory. The experimental software development uses python 3.8 version, pytorch 1.12.1 deep learning framework, Torch 1.12.1, torchvision 0.13.1.
[0141] 2. Test verification
[0142] Experimental results and analysis on the Northeastern University Surface Defect Detection Dataset (NEU-DET).
[0143] (1) Dataset description
[0144] Dataset: NEU-DET strip surface defect dataset, which collects six typical surface defects of hot-rolled steel strip, including rolling scale (RS), spot (Pa), crack (Cr), pit (PS), inclusion (In) and scratch (Sc). The database contains 1800 grayscale images, 300 samples for each defect, and the original resolution of each image is 200×200 pixels.
[0145] Existing studies on small sample steel surface defect detection divide the NEU-DET dataset into base classes C base (RS, In, Sc) and new class C novel (Cr, Pa, Ps). Base class data set D base Including training set D t base 720 images and validation set D v base 180 images, used for model pre-training and verification; new class dataset D novel Including training set D t novel 720 images and validation set D v novel 180 photos, fine-tuning stage from D t novel Randomly select k images of each category for training in D v novel Verify on.
[0146] In order to verify the open set detection performance under small sample conditions, this paper extracts and recombines the dataset according to the meta-learning task division method. base Further divided into support training set D s base and query training set D q base . Used for model pre-training and verification; in dividing new classes C novelWhen two categories are selected as the test support set, denoted as D s test The remaining categories N are regarded as unknown categories and are classified as the test query set, denoted as D q test The re-divided data is recorded as NEU-DET (FS-OD). s base+test Randomly select k images of each category for training in D q test The verification is performed on , where K can be 5, 10, or 30. The specific training data division is as follows Figure 8 shown.
[0147] (2) Implementation details and evaluation indicators
[0148] The model training process is as follows Fig. 9 As shown:
[0149] (1) D is used in the pre-training stage s base Conduct training, D q base Perform verification and obtain the pre-trained model;
[0150] (2) Randomly select the number of categories of two types of defects in the fine-tuning stage in the meta-test set MT(S, T), and the remaining category in the meta-test set is used as the unknown category unknown for verification;
[0151] (3) Freeze the backbone network of the pre-trained model and s base +D s test Fine-tune on D and use OpL as the loss function in the fine-tuning stage; q test The recognition performance of the model is verified on
[0152] The initial learning rate of the model is 0.01, and the learning rate reduction strategy uses cosine for update, with a decay exponent of 0.8. The model uses stochastic gradient descent (SGD) to update network parameters, with a weight decay value of 0.0005 and a momentum value of 0.937. The learning rate in the fine-tuning stage is 0.005, and other settings remain unchanged. The input image size is 640x640, the batch size is set to 16, the number of training iterations is 300, and an early stopping mechanism is introduced to prevent the model from overfitting. Mosaic enhancement strategy is used for image preprocessing.
[0153] To demonstrate the effectiveness of the proposed method, we use precision (P), recall (R), average precision (mAP), and average precision at a confidence level of 50-95% (AP@ 50-0.95) to verify the effectiveness of the model. The number of frames processed per second (FramesPerSecond, FPS) indicator is used for comparison to verify the detection speed of the model. The calculation formula is shown below.
[0154]
[0155]
[0156]
[0157] Among them, TP (TruePositive) indicates the number of positive samples that are correctly classified. FalseNegative (FP) indicates the number of negative samples that are incorrectly classified as positive samples. TN (TrueNegative) indicates the number of samples that are correctly classified as negative samples. FN (False Negative) is the number of positive samples that are incorrectly classified as negative samples. Precision is the accuracy rate, which indicates the proportion of true positive samples within the range of all samples judged as positive samples. Recall is the recall rate, which indicates the proportion of correctly identified samples among all positive samples. mAp refers to the average AP value of all categories of defects. AP refers to the area of the curve under the precision-recall curve. The formulas for AP and mAp are as follows. The higher the mAp value, the better the comprehensive detection performance of the model in all categories. The specific formula is as follows:
[0158]
[0159] Where N is the number of categories.
[0160] (3) Comparative experiment
[0161] In order to verify the surface defect open set detection performance of our method MetaO under small sample conditions, the open set detection performance of MetaO is evaluated in a zero-shot manner on the repartitioned NEU-DET (FS-OD) dataset. The open set detection model general basic detector FasterR-CNN is used as the baseline, denoted as F-CNN; and compared with the small sample industrial surface defect detection model FODNet, the threshold of its output score is set to distinguish unknown queries to adapt it to the open set detection task; finally, it is compared with the most advanced open set general detection model RFDNet in recent years. The experimental results are shown in Table 1.
[0162] Table 1 Comparison of detection results of various models in small sample open set scenario (%)
[0163]
[0164]
[0165] As can be seen from Table 1, the model in this paper shows good open set detection performance under various conditions (5-shot, 10-shot, 30-shot). Specifically, compared with the baseline F-CNN, MetaO's mAP increased by 4.9%, 7.74% and 8.33% in the three shot conditions respectively; compared with FODNet, MetaO's mAP increased by 3.38%, 5.73% and 7.06% respectively; it can be seen that the performance of the FODNet small sample model also decreased under the influence of unknown classes. Compared with RFDNet. MetaO's Map increased by 7.08% and 2.42% in the first two cases respectively. But it decreased by 1.62% compared with RFDNet in 30-shot. This shows that the general open set detection model usually has better detection performance when facing more sample data, but in the scenario of industrial few samples, the effect of MetaO in this paper is obviously better. In addition, the number of parameters of the MetaO model reached 2.1M, and the FPS was improved by 21.21 frames / s compared with FasterR-CNN, FODNet and RFDNet respectively. -1 , 7.47 frames / s -1 and 1.65 fps -1 . Fig.10 The performance of each model in the 5-shot case is shown, where the size of the circle represents the size of the model. It can be clearly seen from the figure that MetaO achieves open-set detection in the 5-shot case while ensuring a relatively fast detection speed, which fully demonstrates MetaO's superior real-time detection performance in the industrial small-sample open-set environment.
[0166] To further observe the model performance of MetaO, we take the 10-shot case as an example. Fig.11 The following graphs show the trends of the accuracy and loss of each model as the training rounds progress. Fig.11 As shown in (a), we can see that the accuracy of the F-CNN model stops increasing around 61 rounds, and the average accuracy reaches 44.36%. FODNet and RFDNet begin to converge around 50 and 41 rounds, and the average accuracy reaches 46.37% and 49.68% respectively. Compared with the other three models, MetaO reaches convergence around 36 rounds, and the average accuracy remains at 52.1%. Fig.11 It can be seen from (b) that the loss of MetaO converges faster than other models, indicating that MetaO has better detection performance in the open set detection task of small sample surface defects.
[0167] (4) Ablation experiment
[0168] In order to evaluate the impact of each module on the model performance, this section conducts ablation experiments in the open set state of the NEU-DET dataset. Non-GSN means that the model uses the original backbone network structure instead of the G-GSN network proposed in this paper, and other settings are consistent with MetaO; non-MC means that the model's original detector is used for detection instead of the direction-aware meta-learning module for detection, and other settings are consistent with MetaO; non-L means that the model uses the default classification loss function for loss calculation instead of the OpL loss function, and other settings are consistent with MetaO. The ablation results are shown in Table 2.
[0169]
[0170]
[0171] Table 2 Results of ablation experiments on NEU-DET (%)
[0172] From the results in Table 2, we can see that if the open set classification loss OpL is not used, the detection accuracy of the model under 5-shot, 10-shot and 30-shot conditions decreases by 8.17%, 2.26% and 3.02% respectively. The decrease is the largest in 5-shot, which shows that the OpL loss function can help the model handle open set detection tasks under small samples more effectively. By observing the model speed, we can see that when the direction-aware meta-learning module is not used, the model speed can reach 92.09 frames / s -1 After adding this module, the model speed dropped to 79.51 frames / s -1 , which shows that the design of the direction-aware meta-learning module has an impact on model reasoning. However, after adding the G-GSN lightweight backbone network designed in this paper, the model speed is increased to 86.21 frames / s. -1 , only dropped by 5.88 frames / s -1 This shows that the designed G-GSN effectively handles the problem of slower model inference speed caused by the direction-aware meta-learning module. It can be seen that the MetaO model proposed in this paper has better detection performance in the open set detection task of industrial surface defects under small sample conditions.
[0173] (5) Visualization Analysis
[0174] In order to better demonstrate MetaO’s ability to capture unknown defect features, the grad_cam feature map is visualized by the feature map of the first Mx layers of the network prediction head (the first few layers in the network, Mx), as shown in the figure: Fig.12 shown.
[0175] Fig.12From top to bottom are the original surface defect data images and the visualization results of each model network. Some defects are selected from the NEU-DET dataset for display. From left to right are inclusions, spots, and scratches. From top to bottom are the feature map visualization results of the original image, yolov8 network, and MetaO network in this paper. By analyzing the visualization results, it can be seen that the brightness of the feature map visualization defects in this paper is higher, the area is larger, and the overall uniformity is more uniform, which proves that the model in this paper captures the defect features more accurately; at the same time, the background part is cleaner, which shows that it has a stronger ability to suppress the background and is more conducive to capturing unknown defect features. In addition, the model in this paper pays attention to the possible locations of defects, such as the edge locations where scratches are prone to exist, and provides a more uniform global view. The above shows that the model in this paper can better aggregate defect features and achieve more accurate detection.
[0176] (6) Closed set experimental analysis
[0177] A good open-set defect detection model should not only improve the open-set defect detection capability, but also ensure that the model's closed-set defect detection capability does not decrease or even improves. Therefore, in order to prove that MetaO also has excellent detection capabilities in closed sets, this section conducts defect detection experiments in closed sets on the NEU-DET dataset. This section gives the experimental results of the proposed MetaO method in closed sets, and compares the accuracy with other methods while keeping the backbone network the same. To ensure that the experimental error is minimized, five experiments were conducted for each task and the average results were taken. After the average indicators of each task were statistically calculated, the overall average indicator was calculated. Compare with SSD, YOLO series and typical FasterR-CNN models in industrial scenarios. The following models are consistent with MetaO in the settings of hyperparameters such as input image size, number of training rounds, batch size, learning rate and image preprocessing strategy. The comparison results are shown in Table 3.
[0178] Table 3 Detection accuracy and speed of each model under closed set
[0179]
[0180] As can be seen from Table 3, the model in this paper has different levels of improvement compared with other methods under closed set tasks. The SSD model is based on multi-scale feature maps, and simultaneously performs target classification and bounding box regression through a single convolutional neural network. As a single-stage network, it has a faster inference speed. As shown in Table 3, the SSD model has a faster detection speed, but the detection performance is significantly worse than that of FasterRcnn. This may be because SSD skips the generation of region suggestions and directly predicts on different layers of the network, resulting in a certain loss in detection performance. The FasterRcnn model improves the detection performance by introducing a region extraction network for end-to-end detection. Compared with SSD, the overall mAP is increased by 10.46%, but the detection speed is reduced by 7.83 frames / s compared to SSD. -1 . It can be seen that it is difficult to balance between accuracy and speed. The Yolo series model converts the detection task into a regression task, and performs real-time detection by densely predicting bounding boxes and category information on the image. After continuous improvement, it has higher accuracy and speed, and is more suitable for industrial real-time defect detection. In general, the yolo series model has a significant improvement in accuracy and speed compared to SSD and FasterRcnn. It can be clearly seen from Table 3 that the model MetaO in this paper has improved mAP by 1.5% and FPS by 7.31 frames / s compared with yolov8, the best model among the above models. -1 , and it also has good detection effect in closed set.
[0181] To further observe the detection performance of the MetaO model under closed sets, Fig.13 The following graphs show the trends of accuracy and loss of each model under closed set with the number of training rounds. Fig.13 As shown in (c), we can see that MetaO maintains higher accuracy and good smoothness throughout the training process compared to other models, indicating that the model has good generalization ability. Fig.13 As can be seen in (d), the loss curve of MetaO is smoother and lower than that of other models, proving the accuracy of the model's prediction results.
[0182] 3. Conclusion
[0183] Aiming at the problem that it is difficult to effectively detect unknown classes in industrial surface defect detection under small sample conditions, a surface defect open set detection method under small sample conditions is proposed. The method consists of three parts. The first part trains samples in a meta-task manner, and after coordinate attention enhancement, the meta-features of the support set are fused to enhance the defect representation ability; the second part simplifies the convolution operation of the feature extraction process by designing a Ghost Bottleneck structure to achieve efficient feature extraction; the third part uses negative entropy to design an improved open set classification damage function OpL to enable the model to achieve open set detection. The experimental results show that under 5-shot and 10-shot conditions, MetaO achieves better results in open set detection tasks than the other three comparison methods. Under 30-shot conditions, the detection effect of this method is slightly inferior to that of the open set detection model RFDNet in natural scenes, which further proves the significant advantages of this model under industrial small sample conditions. At the same time, the effectiveness of each module of this method is proved by ablation experiments. Finally, a closed set experimental analysis is carried out, which proves that the model of this method also has good performance in closed set detection tasks, providing strong support for the application of open set detection of industrial surface defects under small sample conditions.
[0184] The above examples of the present invention are described in detail, but the content is only a preferred embodiment of the present invention and cannot be considered to limit the scope of implementation of the present invention. All equivalent changes and improvements made according to the scope of application of the present invention should still fall within the scope of the patent coverage of the present invention.
Claims
1. A surface defect open set detection method under small sample conditions, characterized by: Using deep learning technology to perform real-time and accurate open set detection of small sample surface defects includes the following steps: S1: Construct a method framework including a direction-aware meta-learning module, a G-GSN feature extraction module, and an open-set classification loss function; S2: In the direction perception meta-learning module, the meta-learning N-way and K-shot task division method is first used to divide the small sample data into multiple open set meta-tasks for model training and testing; S3: In the direction-aware meta-learning module, a coordinate attention mechanism is added to calculate and integrate the feature maps of meta-features in different directions for each open-set meta-task, thus enhancing the defect representation capability of the support set meta-features; S4: In the feature extraction module G-GSN, a large number of additional feature maps Ghost are first generated by using a simple linear transformation instead of the convolution operation in the feature extraction process. Then, the input channels are grouped and convolution calculations are performed within the groups, thereby reducing the amount of model calculation while ensuring effective feature extraction. S5: In G-GSN, the Ghost Bottleneck structure is designed according to the Ghost generation strategy to reduce gradient damage, and the group shuffle convolution operation is used to evenly obtain multi-channel feature information, enhance the ability to capture small target defects, speed up the model in feature extraction, and improve detection efficiency; S6: In the open set classification loss function, the key is to minimize the probability of known classes from the unknown class sample set. This is achieved by using the open set loss function OpL, which is improved based on the cross entropy loss function, to maximize the entropy of the known class probability, so that the model has the ability to recognize unknown classes.
2. The surface defect open set detection method under small sample conditions according to claim 1, characterized in that: Step S2: In the direction perception meta-learning module, the small sample data is divided into multiple open set meta-tasks for model training and testing using the meta-learning task division method. The process includes the following steps: 1-1) Divide the training task into meta-training sets and meta-test set in, is the training set and test set of the i-th learning task; is the training set and test set of i test tasks; N s is the number of training sets, N t is the number of test sets; 1-2) Divide the meta-training set MS into n task groups, Task1, Task2, ..., Task n For each task, N classes are randomly selected from the training set, with K samples in each class, as the training support set S for this group of tasks. train , the remaining samples are used as the training query set Q train ; 1-3) Compared with standard meta-learning, this paper expands the meta-test set MT(S, T) with unknown classes to make it have open set properties.
3. The surface defect open set detection method under small sample conditions according to claim 1, characterized in that: In the step S3, in the direction-aware meta-learning module, a coordinate attention mechanism is added to the detector to calculate and integrate the feature maps of the meta-features in different directions for each open-set meta-task, so that the model can fuse the meta-features of the support set to enhance the defect characterization capability. The process includes the following steps: 2-1) Decompose channel attention into two parallel 1D feature encoding processes. These two processes aggregate the input features along the vertical and horizontal directions respectively to generate two independent direction-aware and position-aware feature maps. First, given the feature matrix, use the pooling kernels (H, 1) and (1, W) of two spatial dimensions to average pool each channel along the horizontal coordinate x and the vertical coordinate y and aggregate features along two directions to generate two direction-aware feature maps. The outputs of the cth channel at height h are expressed as: Where: W is the width of the feature map; x c (h,i) is the element of the feature map in channel c, height h and width i; is the average value of the cth channel at height h, The output of the cth channel at width w is: Where: H is the height of the feature map; x c (j,w) is the element of the feature map in channel c, height j and width w; is the average value of the cth channel over width w; 2-2) Then, connect them and feed them into the 1x1 convolution transformation function F1 to obtain: Where: [,] represents the concatenation operation along the spatial dimension; δ is the nonlinear activation function; f∈R C / r×(H+W) is the intermediate feature map encoding spatial information in the horizontal and vertical directions; r is the reduction ratio of the feature map channel; 2-3) Then the feature map f after information interaction is restored along the spatial dimension into two independent tensors f h ∈R C / r×H×1 and f w ∈R C / r×1×W , and then through two more convolutions F h and F w f h and f w Transform and get the output: Where: σ is the sigmoid function, and the output is the channel attention weight g along the two spatial directions h and g w ; 2-4) Finally, the input x is reweighted to output the coordinate attention block y: Where: x c (i, j) is an element on the original feature map; c is the channel, i and j represent the row and column coordinates in the spatial dimension respectively; and Represents the attention weights along the height and width directions; This encoding process enables the model to more accurately locate the specific location of defects and enhance the model's recognition of known defects.
4. The surface defect open set detection method under small sample conditions according to claim 1, characterized in that: Step S4: In the G-GSN feature extraction module, a large number of additional feature maps are generated by using a simple linear transformation instead of a convolution operation in the feature extraction process, and then the input channels are grouped and convolution calculations are performed within the groups, thereby reducing the amount of model calculation while ensuring effective feature extraction. The process includes the following steps: 3-1) Use conventional convolution to obtain the intrinsic feature map Y'. The amount of computation in this part is approximately equal to: Y'=X*f' Where: * is the convolution operation; Y'∈R h’×w’×m is an intrinsic feature map with m channels; f'∈R c×k×k×m is the convolution kernel in this layer, h' and w' are the height and width of the output data respectively; k×k is the size of the convolution kernel, m≤n; 3-2) Use the ∮ij operation to generate the Ghost feature map Yij for each channel of Y': Where: y'i is the i-th intrinsic feature map in Y'; ∮i,j is the j-th linear operation used to generate the j-th additional feature map Yij in the above function, except for the last one, that is, y'i can have one or more additional feature maps Yij; the last ∮i,j is the identity mapping, which is used to retain the output after the identity mapping, where the linear operation ∮ occurs on each channel; 3-3) The intrinsic feature map generated in the first step and the Ghost feature map obtained in the second step are concatenated to obtain the final result Output. Then the input channels are grouped and convolution calculations are performed within the groups to reduce the amount of calculation of the model while ensuring effective feature extraction.
5. The surface defect open set detection method under small sample conditions according to claim 1, characterized in that: Step S5: In the G-GSN feature extraction module, a Ghost Bottleneck structure is first designed to reduce gradient damage. The structure increases the number of channels by integrating multiple convolutional layers and residual connections and using two stacked ghost modules as expansion layers. After the second Ghost module, the ReLU activation function is not used to retain the feature response in the deep convolution output. At the same time, when stride=2, the residual path is implemented by the downsampling layer and the deep convolution. After each layer, batch normalization and ReLU nonlinear activation functions are used to establish connections between Ghost modules and deepen the depth of the network through a large number of residual connections. Deep separable convolutions are introduced between Ghost modules to balance the relationship between network depth and computing resources. Secondly, group shuffle convolution operations are used to solve the problem of reduced feature extraction and fusion capabilities caused by using deep separable convolutions, and multi-channel feature information is evenly obtained. The structure includes the following steps: 4-1) First, perform a downsampling operation of ordinary convolution on the input; 4-2) Then use depth-wise separable convolution; 4-3) Finally, concatenate the results of the two convolution operations; The output of the depth convolution is made close to the output of the standard convolution, maintaining the information integrity of the standard convolution.
6. The surface defect open set detection method under small sample conditions according to claim 1, characterized in that: In step S6, in the open set classification loss function, the model is adapted to the open set scenario by minimizing the probability of known classes from the unknown class sample set, that is, using negative entropy as the loss function, and the model is equipped with the ability to identify unknown classes by maximizing the entropy of the known class probability by using the open set loss function OpL improved based on the cross entropy loss function. The loss design includes the following steps: 5-1) Assume that the true distribution is Y and the predicted distribution is Y'. The task of the model is to minimize the difference between the true distribution Y and the predicted distribution Y', denoted as min(D kL (Y||Y')), where D kL (Y||Y') is the KL divergence, which is calculated as follows: 5-2) The calculation formula of cross entropy is: 5-3) The formula for information entropy is 5-4) Therefore, the calculation formula of KL divergence can be expressed as Among them, H(P) is the information entropy of the true distribution and is a constant. Therefore, the effect of minimizing the cross entropy is consistent with minimizing the KL divergence. 5-5) Then by minimizing the negative entropy of the known category probability, that is, maximizing the entropy of the known category probability, an improved open set loss is proposed based on the above formula as the loss function of this paper: Where: OpL represents the loss of samples from category k, Du[i] represents the set of unknown classes, k is the category in the unknown class set, p(y=k|x) represents the probability that the model predicts that the sample belongs to category k given the input x. The lower the OpL value, the more certain the model's prediction on sample x is.
Citation Information
Patent Citations
Small sample target detection method based on coordinate attention group optimization
CN115019103A
Entropy perception element learning method for automatic target identification of open-set radar image
CN116310732A
Small sample open set identification method based on global-local energy collaborative representation
CN116563603A
Cited By
Welding defect identification method and platform for few samples
CN120912970A
A few-shot oriented welding defect recognition method and platform
CN120912970B
PCB defect detection and classification method based on deep learning
CN121169877A
