Surface defect detection method and device based on feature disordering rearrangement

By using a feature reordering method, a feature reconstruction network is used to process multi-level fused feature maps, which solves the problem of the universality of existing anomaly detection algorithms under different settings, realizes effective anomaly detection in industrial environments, and improves detection performance.

CN118840650BActive Publication Date: 2026-11-24TSINGHUA UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411100928.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2026-11-24
Estimated Expiration
2044-08-12

AI Technical Summary

Technical Problem

Existing anomaly detection algorithms lack versatility in real industrial environments, cannot effectively detect anomalies under different settings, and fail to effectively consider the global semantic information of images.

Method used

A feature-based disordered rearrangement method is adopted, which rearranges the features of multi-level fused feature maps through a feature reconstruction network, trains the feature reconstruction network using global and local errors, and combines mean square error and cosine similarity for anomaly detection.

Benefits of technology

Effective anomaly detection was achieved under different industrial environment settings, improving detection performance. In particular, by considering the global semantic information of the image, the ability to distinguish between anomalies and normalities and the ability to detect defects at multiple scales were enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118840650B_ABST
    Figure CN118840650B_ABST
Patent Text Reader

Abstract

The application provides a surface defect detection method and device based on feature disorder rearrangement, and relates to the technical field of visual anomaly detection. The method comprises the following steps: acquiring a multi-level fusion feature map of a to-be-detected image; using a feature reconstruction network to perform feature disorder rearrangement on the multi-level fusion feature map to obtain a reconstructed feature map; and obtaining an anomaly detection result according to the difference between the multi-level fusion feature map and the reconstructed feature map. Since the sample reconstruction feature map is obtained by performing feature disorder rearrangement on the normal sample multi-level fusion feature map, different sample reconstruction feature maps can be constructed according to the task difficulty to adapt to different settings of the industrial environment, so that the feature reconstruction network trained based on the global error and the local error between the normal sample multi-level fusion feature map and the sample reconstruction feature map can effectively realize anomaly detection under different settings of the industrial environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of visual anomaly detection technology, and in particular to a surface defect detection method and apparatus based on feature disordered rearrangement. Background Technology

[0002] Visual anomaly detection is a binary classification task designed to determine whether a given image deviates from a normal pattern, a key component of industrial product quality control. Methods for visual anomaly detection include traditional methods and deep learning-based methods. Traditional methods detect anomalies by manually extracting features, but their generalization ability is poor. Deep learning-based methods, trained on large amounts of data, achieve automatic feature extraction, thus possessing stronger generalization performance.

[0003] Deep learning-based methods include two types: supervised learning and unsupervised learning. In real industrial environments, the number of abnormal samples is significantly less than the number of normal samples. Therefore, it is impractical to collect a large number of labeled abnormal samples for supervised learning in real industrial environments. Unsupervised learning, on the other hand, only requires normal samples for training, making it more feasible in industrial scenarios.

[0004] In real industrial environments, the number of normal samples can fluctuate, necessitating adjustments to anomaly detection settings. However, existing anomaly detection algorithms lack versatility, achieving good performance only under specific industrial conditions. When settings change, performance drops drastically, demonstrating a lack of universality. Therefore, achieving effective anomaly detection across various settings is a pressing technical challenge. Summary of the Invention

[0005] In view of the above problems, embodiments of this application provide a surface defect detection method and apparatus based on feature disordered rearrangement, so as to overcome the above problems or at least partially solve the above problems.

[0006] A first aspect of this application discloses a surface defect detection method based on feature disorder rearrangement, comprising:

[0007] Obtain multi-level fusion feature maps of the image to be detected;

[0008] The multi-level fused feature map is rearranged by using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by rearranging the features of the normal sample multi-level fused feature map.

[0009] Anomaly detection results are obtained based on the differences between the multi-level fused feature map and the reconstructed feature map.

[0010] Optionally, based on the difference between the multi-level fused feature map and the reconstructed feature map, an anomaly detection result is obtained, including:

[0011] Calculate the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map;

[0012] The mean square error and the cosine similarity are multiplied element-wise to obtain an initial anomaly localization map. The initial anomaly localization map is then adjusted to the same size as the image to be detected to obtain the anomaly localization map.

[0013] The anomaly detection result is obtained based on the standard deviation of the anomaly location map.

[0014] Optionally, the feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network, wherein the feature reconstruction network is trained according to the following steps:

[0015] Multi-level feature extraction is performed on normal sample images to obtain a multi-level fused feature map of normal samples;

[0016] The first linear layer is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks, and the multiple non-overlapping feature blocks are randomly rearranged according to the scrambling rate to obtain the sample rearranged feature sequence.

[0017] The feature repair network is used to perform feature repair processing on the rearranged feature sequence of the sample to obtain the repaired sample feature sequence, and the second linear layer is used to convert the repaired sample feature sequence into a sample reconstruction feature map;

[0018] Based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, a joint loss value is determined, and the network parameters of the feature reconstruction network are updated based on the joint loss value.

[0019] Optionally, the plurality of non-overlapping feature blocks are randomly rearranged according to the scrambling rate to obtain a sample rearranged feature sequence, including:

[0020] Multiple feature blocks to be rearranged are selected from the plurality of non-overlapping feature blocks according to the scrambling rate;

[0021] The positions of the remaining feature blocks, except for the plurality of feature blocks to be rearranged, remain unchanged, and a random rearrangement operation is performed on the plurality of feature blocks to be rearranged to obtain the initial sample rearranged feature sequence.

[0022] A fixed sinusoidal position code is added to the initial sample rearrangement feature sequence to obtain the sample rearrangement feature sequence.

[0023] Optionally, a joint loss value is determined based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, including:

[0024] The local loss value is determined based on the mean square error and cosine similarity between the normal sample multi-level fusion feature map and the sample reconstructed feature map;

[0025] The normal sample multi-level fusion feature map and the sample reconstruction feature map are respectively converted into a first feature vector and a second feature vector, and the global loss value is determined based on the cosine similarity between the first feature vector and the second feature vector.

[0026] The local loss value and the global loss value are weighted and summed to determine the joint loss value.

[0027] Optionally, a multi-level fusion feature map of the image to be detected is obtained, including:

[0028] Multi-level features of the image to be detected are extracted using a pre-trained convolutional neural network to obtain a multi-level feature map;

[0029] The multi-level feature maps are adjusted to the same size, and the adjusted multi-level feature maps are connected in the channel dimension to obtain a multi-level fused feature map.

[0030] Optionally, the feature repair network includes N visual transformers, which perform feature repair processing on the rearranged feature sequence of the sample through a multi-head attention mechanism to obtain the repaired sample feature sequence.

[0031] A second aspect of this application discloses a surface defect detection device based on feature disordered rearrangement, comprising:

[0032] The feature acquisition module is used to acquire multi-level fused feature maps of the image to be detected;

[0033] The feature reconstruction module is used to rearrange the features of the multi-level fused feature map using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by rearranging the features of the normal sample multi-level fused feature map.

[0034] An anomaly detection module is used to obtain anomaly detection results based on the differences between the multi-level fused feature map and the reconstructed feature map.

[0035] Optionally, the anomaly detection module includes:

[0036] The first calculation module is used to calculate the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map;

[0037] The anomaly localization map module is used to perform element-wise multiplication of the mean square error and the cosine similarity to obtain an initial anomaly localization map, and adjust the initial anomaly localization map to the same size as the image to be detected to obtain the anomaly localization map;

[0038] The anomaly detection result module is used to obtain anomaly detection results based on the standard deviation of the anomaly location map.

[0039] Optionally, the feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network; the device includes a training module for training the feature reconstruction network, the training module including:

[0040] The sample feature extraction module is used to extract multi-level features from normal sample images to obtain a multi-level fused feature map of normal samples.

[0041] The sample feature rearrangement module is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks using the first linear layer, and to perform random rearrangement operation on the multiple non-overlapping feature blocks according to the scrambling rate to obtain the sample rearranged feature sequence.

[0042] The sample feature repair module is used to perform feature repair processing on the rearranged feature sequence of the sample using the feature repair network to obtain the repaired sample feature sequence, and to use the second linear layer to convert the repaired sample feature sequence into a sample reconstructed feature map.

[0043] The parameter update module is used to determine the joint loss value based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, and to update the network parameters of the feature reconstruction network based on the joint loss value.

[0044] Optionally, the sample feature rearrangement module includes:

[0045] The feature selection module is used to select multiple feature blocks to be rearranged from the multiple non-overlapping feature blocks according to the scrambling rate;

[0046] The random rearrangement operation module is used to keep the positions of the remaining feature blocks other than the plurality of feature blocks to be rearranged unchanged, and to perform a random rearrangement operation on the plurality of feature blocks to be rearranged to obtain an initial sample rearranged feature sequence.

[0047] An additional module is added to the initial sample rearrangement feature sequence to add a fixed sinusoidal position code, thereby obtaining the sample rearrangement feature sequence.

[0048] Optionally, the parameter update module includes:

[0049] The first determining module is used to determine the local loss value based on the mean square error and cosine similarity between the multi-level fused feature map of the normal sample and the reconstructed feature map of the sample;

[0050] The second determining module is used to convert the normal sample multi-level fusion feature map and the sample reconstruction feature map into a first feature vector and a second feature vector, respectively, and to determine the global loss value based on the cosine similarity between the first feature vector and the second feature vector.

[0051] The third determining module is used to perform a weighted summation of the local loss value and the global loss value to determine the joint loss value.

[0052] Optionally, the feature acquisition module includes:

[0053] A multi-level feature module is used to extract multi-level features of the image to be detected using a pre-trained convolutional neural network to obtain a multi-level feature map.

[0054] The stitching module is used to adjust the multi-level feature maps to the same size and connect the multi-level feature maps after size adjustment in the channel dimension to obtain a multi-level fused feature map.

[0055] A third aspect of this application discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the surface defect detection method based on feature disorder rearrangement described in the first aspect of this application.

[0056] A fourth aspect of this application discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the surface defect detection method based on feature disorder rearrangement described in the first aspect of this application.

[0057] The embodiments of this application have the following advantages:

[0058] In this embodiment, a multi-level fusion feature map of the image to be detected is obtained; the multi-level fusion feature map is rearranged using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the multi-level fusion feature map of normal samples and the reconstructed feature map of samples, and the reconstructed feature map of samples is obtained by rearranging the features of the multi-level fusion feature map of normal samples; based on the difference between the multi-level fusion feature map and the reconstructed feature map, an anomaly detection result is obtained.

[0059] Since the reconstructed feature map is obtained by rearranging the features of a multi-level fused feature map of normal samples, different reconstructed feature maps can be constructed according to the task difficulty to adapt to different settings in industrial environments. This allows the feature reconstruction network trained based on the global and local errors between the multi-level fused feature map of normal samples and the reconstructed feature map to effectively achieve anomaly detection under different settings in industrial environments. Furthermore, training based on the global and local errors between the multi-level fused feature map of normal samples and the reconstructed feature map ensures that the feature reconstruction network not only focuses on the local features of the image but also considers the global semantic information of the image, thereby improving the detection performance of the feature reconstruction network. Attached Figure Description

[0060] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0061] Figure 1 This is a flowchart illustrating the steps of a surface defect detection method based on feature disorder rearrangement provided in an embodiment of this application.

[0062] Figure 2 This is a flowchart illustrating the steps of a feature reconstruction network training method provided in an embodiment of this application;

[0063] Figure 3 This is an overall architecture diagram of a surface defect detection method based on feature disorder rearrangement provided in an embodiment of this application;

[0064] Figure 4 This is a schematic diagram of the structure of a surface defect detection device based on feature disorder rearrangement provided in an embodiment of this application;

[0065] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0066] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0067] Since the number of normal samples in a real industrial environment may change constantly, the settings for anomaly detection tasks need to be adjusted accordingly. However, existing anomaly detection methods do not take into account the generality of the algorithms, resulting in problems such as difficulty in model fitting (i.e., the task difficulty significantly exceeds the model's capability) and model overfitting (i.e., the model's capability far exceeds the difficulty of the proxy task).

[0068] To overcome the limitations of related technologies, this application provides a surface defect detection method based on feature reordering. Specifically, to address the overfitting problem, a feature reordering strategy is introduced to mitigate model overfitting. Furthermore, to address the issue of the generality of existing anomaly detection methods, the difficulty of feature reordering is controlled by the scrambling rate, enabling the model to effectively detect anomalies under different settings in industrial environments. In addition, to address the issue that existing anomaly detection methods only focus on local information while ignoring global information, this application proposes training the feature reconstruction network based on a joint loss value of global and local optimization. This ensures that the feature reconstruction network not only focuses on local image features but also considers the global semantic information of the image, thereby improving the detection performance of the feature reconstruction network.

[0069] The surface defect detection method based on feature disorder rearrangement provided in this application will be described in detail below with reference to the accompanying drawings.

[0070] Reference Figure 1 As shown, Figure 1 This is a flowchart illustrating the steps of a surface defect detection method based on feature disorder rearrangement provided in an embodiment of this application. Figure 1 As shown, a surface defect detection method based on feature disorder rearrangement provided in this application embodiment may include steps S110 to S130:

[0071] Step S110: Obtain the multi-level fusion feature map of the image to be detected.

[0072] In this embodiment, the image to be detected refers to a surface image of a product, which can be acquired by an imaging device. Obtaining a multi-level fusion feature map of the image to be detected can be achieved by performing multi-level feature extraction on the image to be detected, converting the low-semantic image into a high-semantic multi-level fusion feature map. The multi-level fusion feature map contains feature information at different scales, thus enabling the detection of defects at different scales and improving anomaly detection performance.

[0073] Specifically, obtaining a multi-level fusion feature map of the image to be detected includes: extracting multi-level features of the image to be detected using a pre-trained convolutional neural network to obtain a multi-level feature map; adjusting the multi-level feature maps to the same size, and connecting the size-adjusted multi-level feature maps in the channel dimension to obtain a multi-level fusion feature map.

[0074] Here, a convolutional neural network refers to a network capable of feature extraction, and a multi-level feature map refers to feature maps at different scales. In this embodiment, a pre-trained convolutional neural network is used to process the image to be detected to obtain a multi-level feature map. Since industrial defects exhibit variability in size, in order for the feature reconstruction network to detect defects at different scales, the multi-level feature maps are fused (i.e., the multi-level feature maps are adjusted to the same size, and the adjusted multi-level feature maps are connected along the channel dimension) to obtain a multi-level fused feature map.

[0075] Step S120: Use a feature reconstruction network to rearrange the features of the multi-level fused feature map to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by rearranging the features of the normal sample multi-level fused feature map.

[0076] In this embodiment of the application, the feature reconstruction network refers to a network with feature reconstruction capabilities. The feature reconstruction network is trained unsupervised using normal sample images so that it can accurately construct the feature map corresponding to the normal image. Subsequently, anomaly detection can be performed based on the difference between the reconstructed feature map constructed by the feature reconstruction network and the image to be detected.

[0077] The reconstructed feature map is a feature map reconstructed based on the multi-level fusion feature map. Since the multi-level fusion feature map has rich semantic information, the high semantic multi-level fusion feature map is used to replace the low semantic image pixels as the reconstruction target, and the reconstructed feature map corresponding to the multi-level fusion feature map is obtained. Thus, anomaly detection is performed based on the feature map, which enhances the ability to distinguish between normal and abnormal, as well as the ability to detect defects at multiple scales.

[0078] Specifically, the feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network; the feature reconstruction network is used to rearrange the features of the multi-level fused feature map, including: using the first linear layer to divide the multi-level fused feature map into multiple non-overlapping feature blocks to obtain a feature sequence, and adding a fixed sinusoidal position code to the feature sequence to obtain a feature sequence with position code; using the feature repair network to perform feature repair processing on the feature sequence with position code to obtain a repaired feature sequence, and using the second linear layer to convert the repaired feature sequence into a reconstructed feature map.

[0079] Step S130: Obtain the anomaly detection result based on the difference between the multi-level fused feature map and the reconstructed feature map.

[0080] In this embodiment, since the feature reconstruction network is trained based on the global and local errors between the multi-level fused feature map of normal samples and the reconstructed feature map of samples, the feature reconstruction network can accurately reconstruct the feature map corresponding to the normal image to be detected (i.e., the image without defects); however, it cannot accurately construct the corresponding feature map for the image to be detected with defects. Therefore, the anomaly detection result can be obtained based on the difference between the multi-level fused feature map and the reconstructed feature map.

[0081] Specifically, obtaining an anomaly detection result based on the difference between the multi-level fused feature map and the reconstructed feature map includes: calculating the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map; performing element-wise multiplication on the mean square error and the cosine similarity to obtain an initial anomaly localization map, and adjusting the initial anomaly localization map to the same size as the image to be detected to obtain an anomaly localization map; and obtaining the anomaly detection result based on the standard deviation of the anomaly localization map.

[0082] In this embodiment of the application, the element-wise multiplication operation means multiplying the mean squared error and cosine similarity corresponding to the same position, and using the mean squared error and cosine similarity as two dimensions to measure the difference between the multi-level fused feature map and the reconstructed feature map.

[0083] For example, the mean squared error and cosine similarity between the multi-level fused feature map and the reconstructed feature map are respectively expressed as:

[0084]

[0085]

[0086] in, This represents the mean squared error between the multi-level fused feature map and the reconstructed feature map. Let (h, w) represent the cosine similarity between the multi-level fused feature map and the reconstructed feature map, and (h, w) represent the position of the feature in the feature map. The L2 norm is represented by "·", the inner product is represented by "·", and the modulus is represented by "||·||". This represents a multi-level fused feature map. H represents the reconstructed feature map. F W F and C F These represent the height, width, and number of channels of the feature map (multi-level fused feature map and reconstructed feature map), respectively.

[0087] The anomaly location map is represented as follows:

[0088]

[0089] Resize(·) means adjusting the anomaly localization map to the same size as the image to be detected. AS represents the element-wise multiplication operation. final This represents the anomaly localization map. Finally, the standard deviation of the anomaly localization map is used for image-level anomaly detection to obtain the anomaly detection results.

[0090] In summary, in this embodiment, since the sample reconstruction feature map is obtained by rearranging the features of a normal sample multi-level fusion feature map, different sample reconstruction feature maps can be constructed according to the task difficulty to adapt to different settings in the industrial environment. This allows the feature reconstruction network trained based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map to effectively achieve anomaly detection under different settings in the industrial environment. Furthermore, training based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map ensures that the feature reconstruction network not only focuses on the local features of the image but also considers the global semantic information of the image, thereby improving the detection performance of the feature reconstruction network.

[0091] The training method for the feature reconstruction network will be explained in detail below.

[0092] Reference Figure 2 As shown, Figure 2 This is a flowchart illustrating the steps of a feature reconstruction network training method provided in an embodiment of this application. Figure 2 As shown, the feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network. The feature reconstruction network is trained according to steps S210 to S240:

[0093] Step S210: Perform multi-level feature extraction on the normal sample image to obtain a multi-level fused feature map of the normal sample.

[0094] In this embodiment of the application, a normal sample image refers to a product surface image without defects. Multi-level features of the normal sample image are extracted using a pre-trained convolutional neural network to obtain a multi-level feature map of the sample. The multi-level feature maps of the sample are then adjusted to the same size, and the multi-level feature maps of the sample after size adjustment are connected in the channel dimension to obtain a multi-level fused feature map of the normal sample.

[0095] For example, for a normal sample image I n Using a pre-trained convolutional neural network φ, multi-level feature maps {φ1(I)} of the samples are obtained. n ),φ1(I n ),…φ M (I n )},in, H m W m and C m These represent the height, width, and number of channels of the feature map, respectively. Since industrial defects exhibit variability in size, to enable the feature reconstruction network to detect defects at different scales, multi-level feature maps of samples are fused to obtain a multi-level fused feature map of normal samples.

[0096] Multi-level fusion feature map of normal samples Represented as:

[0097]

[0098] Where Θ represents adjusting the multi-level feature maps of the samples to the same size H. F ×W F The operation, This represents the connection of the feature map in the channel dimension.

[0099] Step S220: The first linear layer is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks, and the multiple non-overlapping feature blocks are randomly rearranged according to the scrambling rate to obtain the sample rearranged feature sequence.

[0100] In this embodiment, the first linear layer uses a convolutional kernel of size P to perform linear projection, so as to divide the multi-level fused feature map of normal samples into multiple non-overlapping feature blocks of size P.

[0101] For example, the first linear layer dividing the multi-level fused feature map of normal samples into multiple non-overlapping feature blocks can be represented as:

[0102]

[0103] in, This represents multiple non-overlapping feature blocks. P represents the size of each non-overlapping feature block, and D represents the number of channels. and These represent the function and parameters of the first linear layer, respectively.

[0104] Next, a random rearrangement operation is performed on multiple non-overlapping feature blocks. This random rearrangement operation involves shuffling and rearranging the segmented non-overlapping feature blocks. For example, ... Rearranged as

[0105] In this embodiment, considering the alignment issue between the model and the difficulty of the proxy task in deep learning, when the difficulty of the proxy task significantly exceeds the model's capability, it may lead to model fitting difficulties; when the model's capability far exceeds the difficulty of the proxy task, it may lead to model overfitting. In this embodiment, randomly rearranging all non-overlapping feature blocks leads to model fitting difficulties, while feature reconstruction without random rearrangement leads to model overfitting. Therefore, this embodiment introduces a shuffling rate τ to control the degree of shuffling of the sample rearrangement feature sequence (i.e., controlling the difficulty of the training task), thereby obtaining the optimal performance of the feature reconstruction network under different task difficulties by rearranging the feature sequence according to different samples.

[0106] In one optional embodiment, the plurality of non-overlapping feature blocks are randomly rearranged according to a scrambling rate to obtain a sample rearranged feature sequence, including:

[0107] Multiple feature blocks to be rearranged are selected from the plurality of non-overlapping feature blocks according to the scrambling rate;

[0108] The positions of the remaining feature blocks, except for the plurality of feature blocks to be rearranged, remain unchanged, and a random rearrangement operation is performed on the plurality of feature blocks to be rearranged to obtain the initial sample rearranged feature sequence.

[0109] A fixed sinusoidal position code is added to the initial sample rearrangement feature sequence to obtain the sample rearrangement feature sequence.

[0110] Specifically, for L non-overlapping feature blocks, L×τ feature blocks to be rearranged are randomly selected for random rearrangement, while keeping the positions of the remaining L×(1-τ) feature blocks unchanged, to obtain the initial sample rearranged feature sequence. Then, a fixed sinusoidal position code is added to the initial sample rearranged feature sequence to obtain the sample rearranged feature sequence.

[0111] For example, the random rearrangement of multiple non-overlapping feature blocks according to the shuffling rate can be expressed as:

[0112] E r =R(E n ,τ)+E pos

[0113] Among them, E r Let R represent the sample rearrangement feature sequence, and let E represent the random rearrangement operation. pos ∈R L×D This represents a fixed sine wave position code. It should be noted that when E... pos When unchanged, it represents multiple non-overlapping feature blocks E n The original location.

[0114] Step S230: Use the feature repair network to perform feature repair processing on the rearranged feature sequence of the sample to obtain the repaired sample feature sequence, and use the second linear layer to convert the repaired sample feature sequence into a sample reconstruction feature map.

[0115] The feature inpainting network comprises N visual transformers, which perform feature inpainting on the rearranged feature sequences of samples using a multi-head attention mechanism to obtain inpainted sample feature sequences. Specifically, as shown... Figure 3 As shown, each visual transformer includes two normalization layers, multi-head self-attention, and a multi-layer perception mechanism.

[0116] In this embodiment, considering the inherent inductive bias (such as locality and translation equivariance) exhibited by convolutional neural networks, they are unsuitable for feature reordering tasks because they can only focus on information within a fixed region of the convolution kernel and cannot focus on global semantic information. Feature reordering tasks, however, require consideration of the interrelationships between feature blocks, which aligns with the multi-head attention mechanism inherent in visual transformers. Therefore, N visual transformers are used as the feature restoration network to further ensure anomaly detection performance.

[0117] For example, the feature repair network's function of rearranging feature sequences of samples can be represented as:

[0118]

[0119] in, f represents the repaired sample feature sequence. res and θ res These represent the function and parameters for repairing the network, respectively.

[0120] The second linear layer transforms the repaired sample feature sequence into a reconstructed sample feature map, which can be represented as:

[0121]

[0122] in, Represents the reconstructed feature map of the sample. and These represent the function and parameters of the second linear layer, respectively.

[0123] Step S240: Determine the joint loss value based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, and update the network parameters of the feature reconstruction network based on the joint loss value.

[0124] In this embodiment, the network is trained based on the global and local errors between the multi-level fusion feature map of normal samples and the reconstructed feature map of samples. This ensures that the feature reconstruction network not only focuses on the local features of the image but also considers the global semantic information of the image, thereby improving the detection performance of the feature reconstruction network.

[0125] Specifically, based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstructed feature map, the joint loss value is determined, including steps A1 to A3:

[0126] Step A1: Determine the local loss value based on the mean square error and cosine similarity between the normal sample multi-level fusion feature map and the sample reconstruction feature map.

[0127] In this embodiment of the application, the mean squared error and cosine similarity are used as local loss values, which are expressed as follows:

[0128]

[0129] IP2410347BCD-B-Priority review will be processed after entry.

[0130]

[0131] in, This represents the local loss value. Represents the global loss value. Let represent the L2 norm, · represent the inner product, ||·|| represent the modulus, and (h,w) represent the position of the feature in the feature map.

[0132] Step A2: Convert the normal sample multi-level fusion feature map and the sample reconstruction feature map into a first feature vector and a second feature vector, respectively, and determine the global loss value based on the cosine similarity between the first feature vector and the second feature vector.

[0133] For example, the global loss value is expressed as:

[0134]

[0135] Among them, L global This represents the global loss value, and vec(·) represents the combination of two-dimensional feature maps (such as multi-level fusion feature maps of normal samples and reconstructed feature maps of samples). Convert to one-dimensional feature vector The flattening operation, vec(F) n ) represents the first eigenvector. This represents the first eigenvector.

[0136] Step A3: Perform a weighted summation of the local loss value and the global loss value to determine the joint loss value.

[0137] For example, the joint loss value is expressed as:

[0138]

[0139] Among them, L res This represents the combined loss value.

[0140] In this embodiment, the joint loss value is used to perform backpropagation and gradient adjustment on the feature reconstruction network. After a certain number of iterations, the trained feature reconstruction network is obtained. Since the joint loss value includes both local and global loss values, training based on the joint loss value ensures that the feature reconstruction network not only focuses on the local features of the image but also considers the global semantic information of the image, thereby improving the anomaly detection performance.

[0141] For example, Figure 3 This is an overall architecture diagram of a surface defect detection method based on feature disorder rearrangement provided in this application embodiment. During the training phase, multi-level features of normal sample images are extracted based on a pre-trained convolutional neural network to obtain a multi-level fused feature map of normal samples. Then, a first linear layer is used to divide the multi-level fused feature map of normal samples into multiple non-overlapping feature blocks, and multiple feature blocks to be rearranged are selected from these non-overlapping feature blocks according to the scrambling rate for random rearrangement, resulting in an initial sample rearrangement feature sequence. A fixed sinusoidal position code is added to the initial sample rearrangement feature sequence to obtain a sample rearrangement feature sequence. Next, a feature repair network is used to perform feature repair processing on the sample rearrangement feature sequence to obtain a repaired sample feature sequence, and a second linear layer is used to convert the repaired sample feature sequence into a sample reconstruction feature map. Finally, based on the global and local errors between the multi-level fused feature map of normal samples and the sample reconstruction feature map, a joint loss value is determined, and the network parameters of the feature reconstruction network are updated according to the joint loss value to complete the unsupervised training of the feature reconstruction network.

[0142] In the detection phase, a pre-trained convolutional neural network extracts multi-level features from the image to be detected, resulting in a multi-level fused feature map. Then, a first linear layer divides the multi-level fused feature map into multiple non-overlapping feature blocks, obtaining a feature sequence. A fixed sinusoidal positional code is added to this feature sequence, resulting in a feature sequence with positional encoding. Next, a feature inpainting network performs feature inpainting on the positional-encoded feature sequence, obtaining a repaired feature sequence. A second linear layer then converts the repaired feature sequence into a reconstructed feature map. Finally, anomaly localization is performed based on the multi-level fused feature map and the reconstructed feature map, resulting in an anomaly localization map. The anomaly detection result is then obtained based on the standard deviation of the anomaly localization map.

[0143] Since the reconstructed feature map is obtained by rearranging the features of a multi-level fused feature map of normal samples, different reconstructed feature maps can be constructed according to the task difficulty to adapt to different settings in industrial environments. This allows the feature reconstruction network trained based on the global and local errors between the multi-level fused feature map of normal samples and the reconstructed feature map to effectively achieve anomaly detection under different settings in industrial environments. Furthermore, training based on the global and local errors between the multi-level fused feature map of normal samples and the reconstructed feature map ensures that the feature reconstruction network not only focuses on the local features of the image but also considers the global semantic information of the image, thereby improving the detection performance of the feature reconstruction network.

[0144] This application also provides a surface defect detection device based on feature disordered rearrangement, referring to... Figure 4 As shown, Figure 4 This is a schematic diagram of a surface defect detection device based on feature disorder rearrangement provided in an embodiment of this application, including:

[0145] Feature acquisition module 410 is used to acquire multi-level fusion feature maps of the image to be detected;

[0146] The feature reconstruction module 420 is used to perform feature reordering on the multi-level fused feature map using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by reordering the features of the normal sample multi-level fused feature map.

[0147] The anomaly detection module 430 is used to obtain anomaly detection results based on the difference between the multi-level fused feature map and the reconstructed feature map.

[0148] In one optional embodiment, the anomaly detection module includes:

[0149] The first calculation module is used to calculate the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map;

[0150] The anomaly localization map module is used to perform element-wise multiplication of the mean square error and the cosine similarity to obtain an initial anomaly localization map, and adjust the initial anomaly localization map to the same size as the image to be detected to obtain the anomaly localization map;

[0151] The anomaly detection result module is used to obtain anomaly detection results based on the standard deviation of the anomaly location map.

[0152] In one optional embodiment, the feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network; the apparatus includes a training module for training the feature reconstruction network, the training module including:

[0153] The sample feature extraction module is used to extract multi-level features from normal sample images to obtain a multi-level fused feature map of normal samples.

[0154] The sample feature rearrangement module is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks using the first linear layer, and to perform random rearrangement operation on the multiple non-overlapping feature blocks according to the scrambling rate to obtain the sample rearranged feature sequence.

[0155] The sample feature repair module is used to perform feature repair processing on the rearranged feature sequence of the sample using the feature repair network to obtain the repaired sample feature sequence, and to use the second linear layer to convert the repaired sample feature sequence into a sample reconstructed feature map.

[0156] The parameter update module is used to determine the joint loss value based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, and to update the network parameters of the feature reconstruction network based on the joint loss value.

[0157] In one optional embodiment, the sample feature rearrangement module includes:

[0158] The feature selection module is used to select multiple feature blocks to be rearranged from the multiple non-overlapping feature blocks according to the scrambling rate;

[0159] The random rearrangement operation module is used to keep the positions of the remaining feature blocks other than the plurality of feature blocks to be rearranged unchanged, and to perform a random rearrangement operation on the plurality of feature blocks to be rearranged to obtain an initial sample rearranged feature sequence.

[0160] An additional module is added to the initial sample rearrangement feature sequence to add a fixed sinusoidal position code, thereby obtaining the sample rearrangement feature sequence.

[0161] In one optional embodiment, the parameter update module includes:

[0162] The first determining module is used to determine the local loss value based on the mean square error and cosine similarity between the multi-level fused feature map of the normal sample and the reconstructed feature map of the sample;

[0163] The second determining module is used to convert the normal sample multi-level fusion feature map and the sample reconstruction feature map into a first feature vector and a second feature vector, respectively, and to determine the global loss value based on the cosine similarity between the first feature vector and the second feature vector.

[0164] The third determining module is used to perform a weighted summation of the local loss value and the global loss value to determine the joint loss value.

[0165] In one optional embodiment, the feature acquisition module includes:

[0166] A multi-level feature module is used to extract multi-level features of the image to be detected using a pre-trained convolutional neural network to obtain a multi-level feature map.

[0167] The stitching module is used to adjust the multi-level feature maps to the same size and connect the multi-level feature maps after size adjustment in the channel dimension to obtain a multi-level fused feature map.

[0168] In one optional embodiment, the feature repair network includes N visual transformers, which perform feature repair processing on the rearranged feature sequence of the samples through a multi-head attention mechanism to obtain the repaired sample feature sequence.

[0169] This application also provides an electronic device, see embodiments thereof. Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 5 As shown, the electronic device 500 includes a memory 510 and a processor 520. The memory 510 and the processor 520 are connected via a bus for communication. The memory 510 stores a computer program that can run on the processor 520 to implement the steps of the surface defect detection method based on feature disorder rearrangement described in the embodiments of this application.

[0170] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the surface defect detection method based on feature disorder rearrangement described in this application.

[0171] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0172] This application describes embodiments of methods, apparatus, and devices according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0173] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0174] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0175] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.

[0176] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0177] The foregoing has provided a detailed description of a surface defect detection method and apparatus based on feature disordered rearrangement provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and its core ideas. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A surface defect detection method based on feature disorder rearrangement, characterized in that, include: Obtain multi-level fusion feature maps of the image to be detected; The multi-level fused feature map is rearranged by using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by rearranging the features of the normal sample multi-level fused feature map. Anomaly detection results are obtained based on the differences between the multi-level fused feature map and the reconstructed feature map.

2. The surface defect detection method based on feature disorder rearrangement according to claim 1, characterized in that, Based on the difference between the multi-level fused feature map and the reconstructed feature map, anomaly detection results are obtained, including: Calculate the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map; The mean square error and the cosine similarity are multiplied element-wise to obtain an initial anomaly localization map. The initial anomaly localization map is then adjusted to the same size as the image to be detected to obtain the anomaly localization map. The anomaly detection result is obtained based on the standard deviation of the anomaly location map.

3. The surface defect detection method based on feature disorder rearrangement according to claim 1, characterized in that, The feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network. The feature reconstruction network is trained according to the following steps: Multi-level feature extraction is performed on normal sample images to obtain a multi-level fused feature map of normal samples; The first linear layer is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks, and the multiple non-overlapping feature blocks are randomly rearranged according to the scrambling rate to obtain the sample rearranged feature sequence. The feature repair network is used to perform feature repair processing on the rearranged feature sequence of the sample to obtain the repaired sample feature sequence, and the second linear layer is used to convert the repaired sample feature sequence into a sample reconstruction feature map; Based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, a joint loss value is determined, and the network parameters of the feature reconstruction network are updated based on the joint loss value.

4. The surface defect detection method based on feature disorder rearrangement according to claim 3, characterized in that, The multiple non-overlapping feature blocks are randomly rearranged according to the scrambling rate to obtain a sample rearranged feature sequence, including: Multiple feature blocks to be rearranged are selected from the plurality of non-overlapping feature blocks according to the scrambling rate; The positions of the remaining feature blocks, except for the plurality of feature blocks to be rearranged, remain unchanged, and a random rearrangement operation is performed on the plurality of feature blocks to be rearranged to obtain the initial sample rearranged feature sequence. A fixed sinusoidal position code is added to the initial sample rearrangement feature sequence to obtain the sample rearrangement feature sequence.

5. The surface defect detection method based on feature disorder rearrangement according to claim 3, characterized in that, Based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, the joint loss value is determined, including: The local loss value is determined based on the mean square error and cosine similarity between the normal sample multi-level fusion feature map and the sample reconstructed feature map; The normal sample multi-level fusion feature map and the sample reconstruction feature map are respectively converted into a first feature vector and a second feature vector, and the global loss value is determined based on the cosine similarity between the first feature vector and the second feature vector. The local loss value and the global loss value are weighted and summed to determine the joint loss value.

6. The surface defect detection method based on feature disorder rearrangement according to claim 1, characterized in that, Obtain multi-level fusion feature maps of the image to be detected, including: Multi-level features of the image to be detected are extracted using a pre-trained convolutional neural network to obtain a multi-level feature map; The multi-level feature maps are adjusted to the same size, and the adjusted multi-level feature maps are connected in the channel dimension to obtain a multi-level fused feature map.

7. The surface defect detection method based on feature disorder rearrangement according to claim 3, characterized in that, The feature repair network includes N visual transformers, which perform feature repair processing on the rearranged feature sequence of the sample through a multi-head attention mechanism to obtain the repaired sample feature sequence.

8. A surface defect detection device based on feature disorder rearrangement, characterized in that, include: The feature extraction module is used to obtain multi-level fused feature maps of the image to be detected; The feature reconstruction module is used to rearrange the features of the multi-level fused feature map using a feature reconstruction network to obtain a reconstructed feature map; wherein, the feature reconstruction network is trained based on the global and local errors between the normal sample multi-level fused feature map and the sample reconstructed feature map, and the sample reconstructed feature map is obtained by rearranging the features of the normal sample multi-level fused feature map. An anomaly detection module is used to obtain anomaly detection results based on the differences between the multi-level fused feature map and the reconstructed feature map.

9. A surface defect detection device based on feature disorder rearrangement according to claim 8, characterized in that, The anomaly detection module includes: The first calculation module is used to calculate the mean square error and cosine similarity between the multi-level fused feature map and the reconstructed feature map; The anomaly localization map module is used to perform element-wise multiplication of the mean square error and the cosine similarity to obtain an initial anomaly localization map, and adjust the initial anomaly localization map to the same size as the image to be detected to obtain the anomaly localization map; The anomaly detection result module is used to obtain anomaly detection results based on the standard deviation of the anomaly location map.

10. A surface defect detection device based on feature disorder rearrangement according to claim 8, characterized in that, The feature reconstruction network includes: a first linear layer, a second linear layer, and a feature repair network; the device includes a training module for training the feature reconstruction network, the training module including: The sample feature extraction module is used to extract multi-level features from normal sample images to obtain a multi-level fused feature map of normal samples. The sample feature rearrangement module is used to divide the multi-level fusion feature map of the normal sample into multiple non-overlapping feature blocks using the first linear layer, and to perform random rearrangement operation on the multiple non-overlapping feature blocks according to the scrambling rate to obtain the sample rearranged feature sequence. The sample feature repair module is used to perform feature repair processing on the rearranged feature sequence of the sample using the feature repair network to obtain the repaired sample feature sequence, and to use the second linear layer to convert the repaired sample feature sequence into a sample reconstructed feature map. The parameter update module is used to determine the joint loss value based on the global and local errors between the normal sample multi-level fusion feature map and the sample reconstruction feature map, and to update the network parameters of the feature reconstruction network based on the joint loss value.

11. A surface defect detection device based on feature disorder rearrangement according to claim 10, characterized in that, The sample feature rearrangement module includes: The feature selection module is used to select multiple feature blocks to be rearranged from the multiple non-overlapping feature blocks according to the scrambling rate; The random rearrangement operation module is used to keep the positions of the remaining feature blocks other than the plurality of feature blocks to be rearranged unchanged, and to perform a random rearrangement operation on the plurality of feature blocks to be rearranged to obtain an initial sample rearranged feature sequence. An additional module is added to the initial sample rearrangement feature sequence to add a fixed sinusoidal position code, thereby obtaining the sample rearrangement feature sequence.

12. A surface defect detection device based on feature disorder rearrangement according to claim 10, characterized in that, The parameter update module includes: The first determining module is used to determine the local loss value based on the mean square error and cosine similarity between the multi-level fused feature map of the normal sample and the reconstructed feature map of the sample; The second determining module is used to convert the normal sample multi-level fusion feature map and the sample reconstruction feature map into a first feature vector and a second feature vector, respectively, and to determine the global loss value based on the cosine similarity between the first feature vector and the second feature vector. The third determining module is used to perform a weighted summation of the local loss value and the global loss value to determine the joint loss value.

13. A surface defect detection device based on feature disorder rearrangement according to claim 8, characterized in that, The feature extraction module includes: A multi-level feature module is used to extract multi-level features of the image to be detected using a pre-trained convolutional neural network to obtain a multi-level feature map. The stitching module is used to adjust the multi-level feature maps to the same size and connect the multi-level feature maps after size adjustment in the channel dimension to obtain a multi-level fused feature map.

Citation Information

Patent Citations

  • Natural language model pre-training method based on out-of-order rearrangement and electronic equipment

    CN112487786A

  • Surface defect detection method based on feature reconstruction

    CN114419014A