Industrial product surface defect anomaly detection method based on few samples
By constructing a local attention spatial transformation network based on double-layer convolution and combining Haar wavelet transform with convolution operation, efficient anomaly detection of surface defects of industrial products is achieved with a small number of samples, solving the accuracy problem in data-scarce scenarios and improving detection efficiency and accuracy.
Patent Information
- Application Number
- CN202510801325.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-16
- Publication Date
- 2025-09-19
AI Technical Summary
In industrial production, how to achieve accurate detection of product surface defects and anomalies with a small number of samples, especially to improve detection efficiency and accuracy in data-scarce scenarios.
A local attention space transformation network based on double-layer convolution is constructed. Through deep fusion of Haar wavelet transform and convolution operation, anomaly heat map is generated for anomaly detection. Weighted feature extraction using local attention map is used to achieve efficient anomaly localization.
It significantly improves the performance and efficiency of the detection network, can accurately identify anomalies under limited resources, expands the receptive field and captures low-frequency and high-frequency information, and improves the accuracy and robustness of detection.
Smart Images

Figure CN120672720A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial production detection automation, and in particular to a method for detecting surface defects and anomalies of industrial products based on a small amount of samples. Background Art
[0002] Anomaly detection technology plays a crucial role in the field of automated industrial production inspection. As a key branch of anomaly detection, it focuses on identifying and locating surface or internal flaws and defects in products during the production process. Specifically, it predicts whether a sample image or pixel is normal or abnormal. This technology is driving advancements in industrial surface defect detection. However, under industrial production conditions, the number of abnormal samples is extremely scarce due to the high quality control requirements of production lines. Therefore, collecting training sets of hundreds of industrial products is difficult and inefficient.
[0003] Therefore, many research efforts have turned their attention to small-sample anomaly detection. As the name suggests, small-sample anomaly detection methods leverage the characteristic information of a small number of normal samples to more accurately identify anomalous samples while reducing reliance on large amounts of labeled data. Small-sample anomaly detection technology has significant application value in data-scarce scenarios, improving detection efficiency and accuracy. Its strong adaptability provides new insights and approaches for the development of related fields. With the continuous advancement of technology, small-sample anomaly detection will play a vital role in even more areas.
[0004] How to accurately detect surface defects and anomalies of industrial products with a small number of samples is a hot topic and worthy of in-depth research. To this end, a method for detecting surface defects and anomalies of industrial products based on a small number of samples is proposed. Summary of the Invention
[0005] The technical problem to be solved by the present invention is: if accurate industrial product surface defect anomaly detection is achieved with a small number of samples, a method for industrial product surface defect anomaly detection based on a small number of samples is provided.
[0006] The present invention solves the above technical problems through the following technical solutions, which include the following steps:
[0007] S1: Sample data collection
[0008] Collect sample data to form a small number of sample data sets;
[0009] S2: Building an anomaly detection model
[0010] An anomaly detection model is constructed. The anomaly detection model includes three sequentially arranged local attention spatial transformation networks based on two-layer convolution with the same structure. After processing by the three local attention spatial transformation networks, the final output feature map is obtained. The Mahalanobis distance between the final output feature map and the normal sample feature library is calculated to generate an anomaly heat map. Anomaly detection is then performed using the anomaly heat map. The image-level anomaly score is the maximum value of the anomaly heat map. The pixel-level anomaly location is directly obtained by threshold segmentation of the anomaly heat map. The segmented area is the anomaly location.
[0011] The processing process of a single local attention space transformer network is as follows: the input image is processed using Haar wavelet transform, and the Haar wavelet transform is deeply integrated with the convolution operation to obtain the first intermediate feature map; the offset of the extracted first intermediate feature map is obtained by convolution operation and added to the initial sampling coordinates to generate new sampling coordinates, and then the convolution operation is applied to extract features to obtain the second intermediate feature map; the local importance of the second intermediate feature map is calculated to generate an attention map, and then the attention map is used to weight the input features to obtain the third intermediate feature map;
[0012] S3: Model training
[0013] The anomaly detection model is trained using a training set in a small number of sample data sets to obtain a trained anomaly detection model;
[0014] S4: Anomaly Detection
[0015] The test set in a small number of sample data sets is input into the trained anomaly detection model for anomaly detection and the anomaly detection results are output.
[0016] Furthermore, in step S1, a small number of sample data sets include multiple item categories, each category has a test set and a training set, the training set contains only normal images, and the test set contains abnormal images and normal images.
[0017] Furthermore, in step S2, the specific process of processing the input image X using Haar wavelet transform is as follows:
[0018] S211: Use one-dimensional Haar wavelet transform to perform channel-by-channel convolution on the input image in the width or height direction through a low-pass filter kernel and a normalized high-pass filter. Then downsample the convolution result with a stride of 2 to halve the spatial resolution.
[0019] S212: At the same time, two-dimensional Haar wavelet convolution transform is used for processing. In the two-dimensional Haar wavelet convolution transform, a low-pass filter f is used. LL , used to extract directional low-frequency details; and three high-pass filters fLH 、f HL and f HH , used to extract directional high-frequency details; the convolution kernel size of each filter in the two-dimensional Haar wavelet convolution transform is as follows:
[0020]
[0021] The input image is convolved with the above convolution kernel to obtain four frequency components:
[0022] [X LL X LH X HL X HH ]=Conv([f LL f LH f HL f HH ],X)
[0023] Among them, X LL Represents the low-frequency component, X LH 、X HL and X HH They represent the high-frequency components in the horizontal, vertical and diagonal directions respectively, and X represents the input image.
[0024] Furthermore, in step S2, the Haar wavelet transform is deeply integrated with the convolution operation to obtain the first intermediate feature map. The specific processing process is as follows:
[0025] S213: The low frequency component X among the four frequency components outputted from the previous stage is converted to (i-1) LL Decomposed into low frequency components step by step {X (i) LL} and high frequency components {X (i) H}, the specific formula is as follows:
[0026] X (i) LL ,X (i) H =WT(X (i-1) LL ),i=1,2,...,n
[0027] Among them, X (i) H Include X (i) LH 、X (i) HL and X (i) HH , WT represents wavelet transform;
[0028] S214: After each level of decomposition, the resolution of the low-frequency component is halved, but the original input area covered is doubled. The following convolution operation is performed independently on the sub-band after each level of decomposition:
[0029] Y (i) LL ,Y (i) H =Conv(W (i) ,(X (i) LL ,X (i) H ))
[0030] Among them, W (i) is the convolution kernel weight of the i-th level; Y (i) LL and Y (i) H They are the low-frequency feature map and high-frequency feature map after convolution respectively; Conv represents the convolution operation;
[0031] S215: In order to combine the outputs of different frequencies, the linear properties of the wavelet transform are used to merge the results of each layer step by step:
[0032] Z (i) =IWT(Y (i) LL +Z (i+1) ,Y (i) H )
[0033] Among them, Z (i) is the aggregate output starting from level i, i.e. the first intermediate feature map X 1 ; IWT stands for inverse wavelet transform.
[0034] Furthermore, in step S2, the second intermediate feature map X 2 The acquisition process is as follows:
[0035] S221: Obtain the first intermediate feature map X 1 Then, the offset ΔP is learned through convolution operation n , then the offset ΔP n Superimposed on the initial sampling coordinates, thereby generating new sampling coordinates corresponding to the convolution operation;
[0036] S222: Based on the new sampling coordinates, resampling and interpolation are used to obtain the features of the corresponding position of the input feature map, and then convolution is used to extract features to obtain the second intermediate feature map X 2 , the processing formula of the above process is as follows:
[0037]
[0038] Among them, P0 is the center position coordinate of the current convolution operation, P n is the relative position offset in the sampling grid R, and ΔP n is the learned offset, is the corresponding position P n The convolution weights, X 1 is the input feature map, that is, the first intermediate feature map, X 1 (P0+P n +ΔP n ) indicates that the input feature map is at position P0+P n +ΔP n , LDConv represents the convolution operation.
[0039] Furthermore, in step S2, the second intermediate feature map X 2 The specific process of calculating local importance, generating an attention map, and then using the attention map to weight the input features to obtain the third intermediate feature map is as follows:
[0040] S231: Generate an attention map by calculating the local importance of each pixel during downsampling;
[0041] S232: Use the attention map to weight the input features to obtain a third intermediate feature map.
[0042] Furthermore, in step S231, the local importance calculation formula is as follows:
[0043]
[0044] Where R is X 2 The neighborhood centered on X 2 is the second intermediate feature map, W k are learnable weights used to refine the importance of the measurements, It's X 2 The local importance of Represents the Softmax normalization operation to obtain the relative importance weight of each pixel.
[0045] Furthermore, in step S231, after calculating the local importance, the third intermediate feature map X is used 3 The first channel X [0] As a gating signal to calibrate the local importance, the specific formula is as follows:
[0046]
[0047] Among them, σ represents the Sigmoid activation function, represents bilinear interpolation, ⊙ represents element-by-element multiplication, X 3 is the third intermediate feature map, X 2 is the second intermediate feature map.
[0048] Compared with the prior art, the present invention has the following advantages:
[0049] 1. The present invention effectively increases the receptive field size of convolution, which avoids the problem of over-parameterization in the convolution process; at the same time, compared with traditional convolution, the use of wavelet convolution can capture both low-frequency and high-frequency information at the same time, improving robustness.
[0050] 2. The present invention makes it possible to extract features more accurately without being limited to a fixed sampling shape during the convolution process.
[0051] 3. The present invention achieves high-order information interaction through simple and efficient calculations, while maintaining the low-latency characteristics of first-order attention, significantly improving the performance and efficiency of the detection network. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 This is an overall flow chart of a method for detecting surface defects and anomalies of industrial products based on a small number of samples in an embodiment of the present invention;
[0053] Figure 2 Schematic diagram of the structure of the anomaly detection model in an embodiment of the present invention (only a single spatial transformation network is shown);
[0054] Figure 3 Schematic diagram of generating initial sampling coordinates in an embodiment of the present invention;
[0055] Figure 4 Schematic diagram of the overall process of step (2) in the embodiment of the present invention;
[0056] Figure 5 Schematic diagram of the overall process of step (3) in the embodiment of the present invention. DETAILED DESCRIPTION
[0057] The following is a detailed description of an embodiment of the present invention. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process. However, the protection scope of the present invention is not limited to the following embodiment.
[0058] like Figure 1 As shown, this embodiment provides a technical solution: a method for detecting surface defects and anomalies of industrial products based on a small number of samples, comprising the following steps:
[0059] Step 1: Collect a small amount of sample data
[0060] First, we collect a small dataset of samples. This dataset includes several common object categories. Each category has both a test set and a training set. Unlike datasets used in other anomaly detection methods, the training set contains only normal images, while the test set contains both normal and abnormal images.
[0061] Step 2: Build an anomaly detection model
[0062] like Figure 2 As shown in the figure, the anomaly detection model consists of three sequentially arranged, identically structured local attention spatial transformer networks based on two-layer convolution. In a single module, the processing steps are as follows:
[0063] Step (1): Use Haar wavelet transform to process the input image X, which can reduce the spatial resolution by half; then, deeply integrate Haar wavelet transform with convolution operation to further improve the feature extraction ability of the image and obtain feature map X 1 ;
[0064] Step (2): Then perform convolution operation on the extracted feature map X 1 Get the offset and add it to the initial sampling coordinates to generate new sampling coordinates, where the initial sampling coordinates are generated by the overall sampling network formed by the regular sampling network and the irregular sampling network; then, apply the convolution operation to extract features, thereby achieving effective processing and feature enhancement of the feature map, and obtain the feature map X 2 ;
[0065] Step (3): Finally, the feature map X output in the previous step 2 Calculate the local importance and generate an attention map, then use the attention map to weight the input features to enhance useful information and weaken useless information, and obtain the output feature map X 3 , which enables the anomaly detection model to run under limited resources.
[0066] After processing by the three spatial transformation networks described above, the final output feature map is obtained. The feature maps are output by the three spatial transformation networks, and the Mahalanobis distance between the test image features and the normal sample feature library is calculated to generate an anomaly heat map. The heat map represents the network combining the Mahalanobis distances of all pixel positions into a matrix to form an anomaly score map. Regions with higher color or brightness indicate larger Mahalanobis distances and higher levels of anomaly. The image-level anomaly score takes the maximum value of the anomaly heat map (anomaly score map). This score reflects the most significant deviation between the test image and the normal distribution. Pixel-level anomaly localization selects a threshold based on the distribution of normal samples. If a pixel in the image has a high anomaly score, then this location is a possible anomaly region.
[0067] Step 3: Perform anomaly detection
[0068] By selecting a test sample from a certain category and providing it with a support set of several normal samples, and comparing the registered features of the test image and the support images, anomalies can be directly identified and anomaly detection results can be output. By inputting these test sets into the trained anomaly detection model, the registered features of the test image and the support images can be compared to directly identify anomalies and output anomaly detection results.
[0069] In this embodiment, when evaluating the detection results, the area under the ROC curve (AUC) is used as an evaluation indicator to evaluate the performance of the anomaly detection model in anomaly detection.
[0070] In this embodiment, the anomaly detection results are visualized using T-SNE visualization technology.
[0071] Example 2
[0072] In this embodiment, the specific processing process in the anomaly detection model is further explained.
[0073] In step (1) of Example 1, the specific processing process is as follows:
[0074] For the input image X (two-dimensional image), Haar wavelet transform can be implemented efficiently through depth-wise separable convolution. Specifically, its one-dimensional Haar wavelet transform is implemented in the width or height direction of the input image X through a low-pass filter kernel. and normalized high-pass filter Perform channel-wise convolution ( and are key parameters for implementing Haar wavelet transform, which enable convolutional neural networks to effectively expand the receptive field and improve the response to low-frequency information). Secondly, the convolution result is downsampled with a step size of 2 to halve the spatial resolution. The two-dimensional Haar wavelet convolution transform uses a low-pass filter f LL , used to extract directional low-frequency details; and three high-pass filters f LH 、f HL and f HH , used to extract directional high-frequency details:
[0075]
[0076] By convolving the input image with these convolution kernels at the same time, four frequency components can be obtained:
[0077] [X LL X LH X HL X HH ]=Conv([fLL f LH f HL f HH ],X)
[0078] Among them, X LL represents the low-frequency component, and X LH 、X HL and X HH Represents the high-frequency components in the horizontal, vertical and diagonal directions respectively.
[0079] In the proposed process, we deeply fuse Haar wavelet transform with convolution operation. First, for the low-frequency component X among the four frequency components of the output of the previous stage, (i-1) LL Decomposed into low frequency components step by step {X (i) LL} and high frequency components {X (i) H}. This process is given by the following formula:
[0080] X (i) LL ,X (i) H =WT(X (i-1) LL ),i=1,2,...,n
[0081] Among them, X (i) H Contains X (i) LH 、X (i) HL and X (i) HH , X (i) LL It is the low-frequency component.
[0082] After each level of decomposition, the resolution of the low-frequency component is halved, but the original input area covered is doubled (the receptive field is expanded).
[0083] Perform small kernel convolution independently on each level of decomposed subband:
[0084] Y (i) LL ,Y (i) H =Conv(W (i) ,(X (i) LL ,X (i) H ))
[0085] Among them, W (i) is the convolution kernel weight of the i-th level; Y(i) LL and Y (i) H They are the low-frequency feature map and high-frequency feature map after convolution respectively; then, in order to combine the outputs of different frequencies, the linear property of wavelet transform IWT(X+Y)=IWT(X)+IWT(Y) is used to merge the results of each layer step by step:
[0086] Z (i) =IWT(Y (i) LL +Z (i+1) ,Y (i) H )
[0087] Among them, Z (i) is the aggregate output starting from level i, which is the sum of the two outputs generated by convolutions of different sizes. The final output Z (i) (Feature Map X 1 ) integrates multi-level receptive fields and multi-frequency features to achieve the complementarity of global and local information.
[0088] In general, the whole process is expressed by the following formula:
[0089] Z = IWT(Conv(W, WT(X)))
[0090] Where X is the input image tensor, and W is the weight tensor of a k×k depthwise separable convolution kernel with four times the input channels. By separating the convolution operations of different frequency components, the small kernel can cover a larger area of the original input, significantly expanding the receptive field relative to the input.
[0091] Although this method significantly expands the receptive field of convolution and improves the ability to extract low-frequency features through wavelet convolution transform, it is limited to a fixed wavelet decomposition pattern when dealing with drastic changes in target morphology or irregular structures. In addition, there is still room for improvement in the flexibility of the shape and size of the convolution kernel when deeply integrating the wavelet transform with the convolution layer. Moreover, the improvement in parameter efficiency depends on the cascade operation of multiple levels of transformation, which may introduce additional computational complexity. In order to further break through the boundaries of shape adaptability and parameter efficiency of convolution operations, the new method proposed below makes up for these shortcomings. It not only supports convolution kernels of arbitrary shapes and sizes, but also achieves a linear growth in the number of parameters.
[0092] In step (2) of Example 1, the specific processing process is as follows:
[0093] Input the feature map X generated in the previous step 1 Then, the offset ΔP is learned through convolution operation n , then the offset ΔP nSuperimposed on the initial sampling coordinates, new sampling coordinates corresponding to the convolution operation are generated. The new sampling coordinates are generated by the following steps:
[0094] First, a regular sampling network is generated for a convolution kernel of size N, and the initial sampling coordinates P of the convolution kernel are generated. n These coordinates can be regular or irregular, depending on the size and shape of the convolution kernel. This step determines the sampling location of the convolution operation on the feature map.
[0095] So for the input feature map X from the previous step 1 The benefit of this step is to generate diverse sample shapes for convolution at different positions in the feature map, thereby better capturing the diversity of local features. Finally, resampling and interpolation are used to obtain the features at the corresponding positions of the feature map, and then convolution is used to extract features to obtain the feature map X 2 For details, please see Figure 4 , the following is the specific formula expression of the whole process:
[0096]
[0097] Among them, P0 is the center position coordinate of the current convolution operation, P n is the relative position offset in the sampling grid R, and ΔP n is the learned offset, is the corresponding position P n The convolution weights, X 1 is the input feature map, X 1 (P0+P n +ΔP n ) indicates that the input feature map is at position P0+P n +ΔP n location.
[0098] In step (3) of Example 1, the specific processing process is as follows:
[0099] Feature map X output in the previous step 2 The attention map is generated by measuring the local importance of each pixel during downsampling. Its core is based on the input feature map X 2 The relative importance of information can be used to adaptively reduce useless information and enhance useful information.
[0100] The local importance calculation process is calculated by the following formula:
[0101]
[0102] Where R is X 2 The neighborhood centered on W kare learnable weights used to refine the importance of the measurements, It's X 2 The local importance of Represents the Softmax normalization operation to obtain the relative importance weight of each pixel, X i With X j Represents the eigenvalues of pixel positions i and j in the input feature map. It is a normalization step to ensure that in the region R k The sum of all weights in is 1.
[0103] In this process, SoftPool and 3×3 convolution are first used to calculate local importance, and then stride is used to reduce the amount of calculation and expand the receptive field. Secondly, the sigmoid function is used to convert the input features into values in the range of [0,1]. After that, bilinear is used for rescaling. The overall process is as follows Figure 5 shown.
[0104] At the same time, in order to calibrate the local importance and avoid artifacts caused by strided convolution and bilinear interpolation, a gating mechanism is used. This attention uses the feature map X 3 The first channel X 3 [0] As a gating signal, it calibrates the local importance. In general, its operation can be expressed as:
[0105]
[0106] Among them, σ represents the Sigmoid activation function, represents bilinear interpolation, ⊙ represents element-by-element multiplication, X 3 is the third intermediate feature map, X 2 is the second intermediate feature map. In this final process, the gating mechanism refines the local importance γ(X). In this way, the performance of the model is significantly improved while maintaining low latency, making it more suitable for running on resource-constrained devices.
[0107] As shown in Table 1, the 2-shot, 4-shot, and 8-shot results of each category of the MVTec-AD dataset using our method and their averages are shown. We will also show the results of the TDG and DiffNet models based on ResNet-18, and the results of each category are also shown. We reproduced RegAD *The results of the models are compared with those of the anomaly detection model (ours) of the present invention. The last row is the average result of all categories, and the best result is shown in bold. The results show that the average value of MVTec-AD dataset on 2-shot, 4-shot and 8-shot is 5.2%, 7% and 6.7% higher than that of DiffNet, and the average value on 2-shot, 4-shot and 8-shot is 1.3% higher than that of RegAD. * Increased by 1.2%, 0.7% and 0.3%.
[0108] Table 1 Results of MVTec-AD dataset when k=2, 4 and 8
[0109]
[0110] Although the embodiments of the present invention have been shown and described above, it will be understood that the above embodiments are illustrative and are not to be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and modify the above embodiments within the scope of the present invention.
Claims
1. A method for detecting surface defects and anomalies of industrial products based on a small number of samples, characterized in that: The following steps are involved: S1: Sample data collection Collect sample data to form a small number of sample data sets; S2: Building an anomaly detection model An anomaly detection model is constructed. The anomaly detection model includes three sequentially arranged local attention spatial transformation networks based on two-layer convolution with the same structure. After processing by the three local attention spatial transformation networks, the final output feature map is obtained. The Mahalanobis distance between the final output feature map and the normal sample feature library is calculated to generate an anomaly heat map. Anomaly detection is then performed using the anomaly heat map. The image-level anomaly score is the maximum value of the anomaly heat map. The pixel-level anomaly location is directly obtained by threshold segmentation of the anomaly heat map. The segmented area is the anomaly location. The processing process of a single local attention space transformer network is as follows: the input image is processed using Haar wavelet transform, and the Haar wavelet transform is deeply integrated with the convolution operation to obtain the first intermediate feature map; the offset of the extracted first intermediate feature map is obtained by convolution operation and added to the initial sampling coordinates to generate new sampling coordinates, and then the convolution operation is applied to extract features to obtain the second intermediate feature map; the local importance of the second intermediate feature map is calculated to generate an attention map, and then the attention map is used to weight the input features to obtain the third intermediate feature map; S3: Model training The anomaly detection model is trained using a training set in a small number of sample data sets to obtain a trained anomaly detection model; S4: Anomaly Detection The test set in a small number of sample data sets is input into the trained anomaly detection model for anomaly detection and the anomaly detection results are output.
2. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 1, characterized in that: In step S1, a small number of sample data sets include multiple item categories, each category has a test set and a training set, the training set contains only normal images, and the test set contains abnormal images and normal images.
3. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 1, characterized in that: In step S2, the specific process of processing the input image X using Haar wavelet transform is as follows: S211: Use one-dimensional Haar wavelet transform to perform channel-by-channel convolution on the input image in the width or height direction through a low-pass filter kernel and a normalized high-pass filter. Then downsample the convolution result with a stride of 2 to halve the spatial resolution. S212: At the same time, two-dimensional Haar wavelet convolution transform is used for processing. In the two-dimensional Haar wavelet convolution transform, a low-pass filter f is used. LL , used to extract directional low-frequency details; and three high-pass filters f LH 、f HL and f HH , used to extract directional high-frequency details; the convolution kernel size of each filter in the two-dimensional Haar wavelet convolution transform is as follows: The input image is convolved with the above convolution kernel to obtain four frequency components: [X LL X LH X HL X HH ]=Conv([f LL f LH f HL f HH ],X) Among them, X LL Represents the low-frequency component, X LH 、X HL and X HH They represent the high-frequency components in the horizontal, vertical and diagonal directions respectively, and X represents the input image.
4. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 3, characterized in that: In step S2, the Haar wavelet transform and the convolution operation are deeply integrated to obtain the first intermediate feature map. The specific processing process is as follows: S213: The low frequency component X among the four frequency components outputted from the previous stage is converted to (i-1) LL Decomposed into low frequency components step by step {X (i) LL } and high frequency components {X (i) H }, the specific formula is as follows: X (i) LL ,X (i) H =WT(X (i-1) LL ),i=1,2,...,n Among them, X (i) H Include X (i) LH 、X (i) HL and X (i) HH , WT represents wavelet transform; S214: After each level of decomposition, the resolution of the low-frequency component is halved, but the original input area covered is doubled. The following convolution operation is performed independently on the sub-band after each level of decomposition: Y (i) LL ,Y (i) H =Conv(W (i) ,(X (i) LL ,X (i) H )) Among them, W (i) is the convolution kernel weight of the i-th level; Y (i) LL and Y (i) H They are the low-frequency feature map and high-frequency feature map after convolution respectively; Conv represents the convolution operation; S215: In order to combine the outputs of different frequencies, the linear properties of the wavelet transform are used to merge the results of each layer step by step: Z (i) =IWT(Y (i) LL +Z (i+1) ,Y (i) H ) Among them, Z (i) is the aggregate output starting from level i, i.e. the first intermediate feature map X 1 ; IWT stands for inverse wavelet transform.
5. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 4, characterized in that: In step S2, the second intermediate feature map X 2 The acquisition process is as follows: S221: Obtain the first intermediate feature map X 1 Then, the offset ΔP is learned through convolution operation n , then the offset ΔP n Superimposed on the initial sampling coordinates, thereby generating new sampling coordinates corresponding to the convolution operation; S222: Based on the new sampling coordinates, resampling and interpolation are used to obtain the features of the corresponding position of the input feature map, and then convolution is used to extract features to obtain the second intermediate feature map X 2 , the processing formula of the above process is as follows: Among them, P0 is the center position coordinate of the current convolution operation, P n is the relative position offset in the sampling grid R, and ΔP n is the learned offset, is the corresponding position P n The convolution weights, X 1 is the input feature map, that is, the first intermediate feature map, X 1 (P0+P n +ΔP n ) indicates that the input feature map is at position P0+P n +ΔP n , LDConv represents the convolution operation.
6. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 5, characterized in that: In step S2, the second intermediate feature map X 2 The specific process of calculating local importance, generating an attention map, and then using the attention map to weight the input features to obtain the third intermediate feature map is as follows: S231: Generate an attention map by calculating the local importance of each pixel during downsampling; S232: Use the attention map to weight the input features to obtain a third intermediate feature map.
7. The method for detecting surface defects and anomalies of industrial products based on a small amount of samples according to claim 6, characterized in that: In step S231, the local importance calculation formula is as follows: Where R is X 2 The neighborhood centered on X 2 is the second intermediate feature map, W k are learnable weights used to refine the importance of the measurements, It's X 2 The local importance of Represents the Softmax normalization operation to obtain the relative importance weight of each pixel.
8. The method for detecting surface defects and anomalies of industrial products based on a small number of samples according to claim 6, characterized in that: In step S231, after calculating the local importance, the third intermediate feature map X is used 3 The first channel X 3 [0] As a gating signal to calibrate the local importance, the specific formula is as follows: Among them, σ represents the Sigmoid activation function, represents bilinear interpolation, ⊙ represents element-by-element multiplication, X 3 is the third intermediate feature map, X 2 is the second intermediate feature map.