Multi-class anomaly detection method based on memory guidance and class decoupling
By constructing a category-specific memory and a category-guided decoupled fusion module, combined with anomaly data augmentation strategies, the problems of dependence on normal data and inter-class interference in multi-category image anomaly detection are solved, achieving high-precision detection of minute defects, which is suitable for industrial quality control.
Patent Information
- Application Number
- CN202610121058.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-29
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2046-01-29
AI Technical Summary
Existing multi-class image anomaly detection methods rely excessively on normal data, suffer from severe inter-class interference, have insufficient accuracy in detecting minute defects, and cannot effectively utilize limited labeled anomaly samples, resulting in weak detection performance.
A category-specific memory is constructed, and a classification module based on center loss and a category-guided decoupled fusion module are designed. Combined with an anomaly data augmentation module, a two-stage training strategy is adopted to improve detection accuracy and robustness.
It effectively utilizes limited labeled abnormal samples, reduces inter-class interference, improves the detection accuracy and generalization ability of multiple categories, and achieves high-precision localization of minute defects, making it suitable for product surface defect detection in industrial quality control.
Smart Images

Figure CN121600331A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image anomaly detection technology, and in particular to a multi-class anomaly detection method based on memory guidance and category decoupling. Background Technology
[0002] In industrial quality control, image anomaly detection is a core technology for detecting surface defects in products and ensuring production consistency. However, cross-category defect identification in large-scale manufacturing scenarios remains a critical challenge that urgently needs to be addressed. On the one hand, traditional single-category anomaly detection methods require separate model training for each category, resulting in high computational and storage costs, and due to domain-specific feature biases, they are difficult to generalize to new categories. On the other hand, some cross-category product defects exhibit visual similarities, and traditional methods cannot share these common features, leading to a redundant waste of training resources.
[0003] For example, Chinese patent document CN112101426A discloses an unsupervised learning image anomaly detection method based on autoencoder, which uses the latent spatial features of autoencoder and discriminant to improve the accuracy of unsupervised anomaly detection and can be applied to industrial, security or other unsupervised environments.
[0004] Chinese patent document CN118247254A discloses a joint industrial anomaly detection method based on multi-scale feature self-expression. It is an unsupervised learning method based on multi-scale feature self-reconstruction and self-expression tasks, which helps the model to better learn the feature representations of multiple categories of normal images. By fusing the differences between self-reconstruction and self-expression, it can achieve the discrimination and localization of abnormal images.
[0005] Current mainstream multi-class anomaly detection methods primarily employ an unsupervised reconstruction paradigm, achieving anomaly detection by learning the features of normal samples and their reconstruction patterns. When anomaly samples are input, the model's reconstruction performance is poor, generating significant errors, which are then used to locate the anomaly. However, these methods rely entirely on normal data, failing to utilize the limited but highly valuable labeled anomaly samples commonly available in real-world scenarios. This results in insufficient precision in defining the boundary between "normal" and "abnormal," leading to weak performance, especially when detecting minute defects. Summary of the Invention
[0006] The purpose of this invention is to provide a multi-class anomaly detection method based on memory guidance and category decoupling, which can solve the problems of excessive reliance on normal data, severe inter-class interference, and insufficient accuracy of small defect detection in existing multi-class image anomaly detection methods, thereby improving the accuracy and robustness of multi-class anomaly detection.
[0007] A multi-class anomaly detection method based on memory guidance and category decoupling includes the following steps: (1) Construct a category-specific memory to store the multi-scale normal features of normal samples in each category; (2) Construct a classification module based on center loss to generate discriminative class embeddings and class labels; (3) Design a category-guided decoupling and fusion module to decouple and fuse the features of the image to be detected with the retrieved normal features based on category embedding; (4) Construct an abnormal data augmentation module, and obtain extended abnormal samples, heterogeneous simulated abnormal samples, and homogeneous simulated abnormal samples through three types of strategies, and integrate them to obtain synthetic abnormal samples; (5) A two-stage training strategy is adopted. The first stage trains the classification module, and the second stage combines labeled abnormal samples and synthetic abnormal samples to train the decoupled fusion module and the decoder module to achieve abnormal mask prediction. (6) In the inference stage, the image to be detected is processed by a pre-trained encoder to obtain the features of the image to be detected; then the features of the image to be detected are processed by a classification module to obtain the category embedding and category label of the image to be detected. Subsequently, the category label and the features of the image to be detected are used to retrieve the corresponding multi-scale normal features in the category-specific memory. Finally, the features of the image to be detected, the retrieved normal features and the category embedding are input into the decoupled fusion module, and the fused features are input into the decoder module to obtain the abnormal segmentation map.
[0008] In step (1), the construction process of the category-specific memory is as follows: For each category, multiple normal samples are randomly sampled. Each normal sample is input into a pre-trained encoder to obtain five layers of features. The last three layers of features corresponding to each normal sample are stored in a category-specific memory. The result of global average pooling of the last layer of features is used as the corresponding storage descriptor for retrieving the corresponding normal features during the inference stage.
[0009] In step (1), the category-specific memory performs the following specific process during retrieval: The image to be detected is input into the encoder to obtain the features of the image to be detected; then the last layer of the features of the image to be detected is input into the classification module to obtain the category embedding and category label of the image to be detected; the corresponding retrieval category is selected according to the category label; The global descriptor obtained by global average pooling of the last layer of features in the image to be detected ; Global descriptors of the features of the image to be detected storage descriptors under the corresponding category Perform cosine similarity calculation to obtain the feature index of the best match. And based on feature index Retrieve normal features.
[0010] In step (2), the classification module uses EfficientNet-B4 as the backbone feature extractor. After the last layer of the image features to be detected is input into EfficientNet-B4, its output is expanded by 1×1 convolution. After global average pooling to aggregate spatial information, it is projected into a category embedding through a multilayer perceptron. At the same time, the category embedding is input into a softmax linear classifier, and the probability distribution of the sample classification is output to obtain the category label.
[0011] In step (3), the specific working process of the decoupling and fusion module is as follows: Based on category embedding, a multilayer perceptron with defined scales is used. Generate channel weights and apply category-based weighting to the features of the image to be detected and the retrieved normal features; Both the image features to be detected and the retrieved normal features are subjected to a 1×1 convolution with shared weights, which halves the channel dimension. Position encoding and non-local attention are introduced, and the weighted image features to be detected and the retrieved normal features are concatenated along the channel dimension to achieve fusion.
[0012] In step (4), the process of obtaining extended abnormal samples is as follows: Color enhancement and spatial transformation are applied to the abnormal regions of the labeled anomalous samples to obtain enhanced anomalous regions. Then, based on target region constraints, the enhanced anomalous regions are embedded into the foreground regions of normal samples to obtain expanded anomalous samples. The formula is as follows: ; in, To enhance the mask annotation corresponding to the abnormal region, For mask The reverse, This is a normal sample. For the enhanced abnormal region, For transparency parameters, This involves element-wise multiplication. In step (4), the process of obtaining the heterogeneous simulated anomaly samples is as follows: Generate Perlin noise map Compared with textures randomly selected and enhanced from the DTD texture library By fusing, a texture perturbation map is obtained. Then, the foreground region of a normal sample is embedded to obtain a heterogeneous simulated abnormal sample. The formula is as follows: ; ; in, The transparency parameter for heterogeneous fusion is adjusted by... Control the degree of fusion between heterogeneous textures and normal samples; The mask corresponding to the region in the noise map whose value is greater than the threshold T. For mask The reverse.
[0013] In step (4), the process of obtaining homologous simulated anomaly samples is as follows: For normal samples Perform color enhancement to obtain enhanced normal samples. ,Will The sample was uniformly divided into an 8×8 grid, and the grid order was randomly shuffled and then reassembled to obtain a disordered enhanced normal sample. ;Will Perlin noise plot Element-wise multiplication is performed, embedding the foreground region of normal samples, and pixel-level fusion is used to generate homogeneous simulated anomalous samples. The formula is as follows: ; in, This is the transparency parameter for homogeneous fusion.
[0014] In step (5), the loss function of the first stage of training for: ; in, For cross-entropy loss, For predicting categories, For the real category, As a balance factor, Loss at the center For sample feature vectors, It serves as a learning center for real-world categories.
[0015] In step (5), the loss function for the second stage of training for: ; in, To predict anomaly masks; As a true anomaly mask, by and It consists of two parts; As a balance factor, For binary cross-entropy loss, The loss is the focus.
[0016] Preferably, the balance factor The value is 2. The value is set to 5; the threshold T in the noise map is set to 0.8; the first stage uses the SGD optimizer with a learning rate of 1e-3 for the classification head and 0.5 for the feature center, training for 100 epochs with a batch size of 32; the second stage uses the AdamW optimizer with a learning rate of 5e-4 and adopts a cosine annealing learning rate scheduling strategy.
[0017] Compared with the prior art, the present invention has the following beneficial effects: 1. Integrating supervised information and memory guidance: Fully utilize limited labeled abnormal samples and combine them with normal feature benchmarks provided by category-specific memory banks to solve the problems of unsupervised methods relying on pure normal data and having ambiguous boundary definitions.
[0018] 2. Effectively reduce inter-class interference: By using a class decoupling-guided attention mechanism, channel weights are dynamically adjusted to enhance class-sensitive features, reduce interference caused by cross-class distribution differences, and improve detection accuracy in multi-class scenarios.
[0019] 3. Sample expansion improves generalization: By using three anomaly generation strategies and multiple real anomalies for each class as a basis, the generalization performance of the model is effectively improved and the overfitting caused by data imbalance is alleviated.
[0020] 4. High-precision anomaly localization: Combining feature fusion strategies of position encoding and non-local attention, it accurately captures global spatial structure and long-distance dependence, enabling effective localization of minute defects; 5. High practicality and scalability: Applicable to multiple scenarios, it can be directly applied to product surface defect detection in industrial quality control, compatible with multiple image types, and its hyperparameters can be flexibly adjusted to adapt to different application scenarios. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of a multi-class anomaly detection method based on memory guidance and category decoupling according to an embodiment of the present invention.
[0023] Figure 2 This is a schematic diagram of the classification module based on center loss in an embodiment of the present invention.
[0024] Figure 3 This is a schematic diagram illustrating feature selection during the inference phase of the category-specific memory in an embodiment of the present invention.
[0025] Figure 4 This is a schematic diagram of the category-guided decoupling and fusion module in an embodiment of the present invention.
[0026] Figure 5 This is a graph illustrating data augmentation strategies during the training process.
[0027] Figure 6 This is a flowchart illustrating the interaction between the various modules in this invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0029] It should be noted that, unless otherwise specified, the features in the following embodiments and implementation methods can be combined with each other.
[0030] like Figure 1 As shown, this embodiment of the invention provides a multi-class anomaly detection method based on memory guidance and category decoupling, which mainly includes three core parts: model construction, two-stage model training, and anomaly detection.
[0031] (I) Model Construction 1. Classification module based on center loss: such as Figure 2 As shown, to achieve efficient memory retrieval and high-quality feature decoupling, a classification module incorporating center loss is designed. Using EfficientNet-B4 as the backbone feature extractor, the final layer of the image features to be detected is input into EfficientNet-B4, and its output undergoes 1×1 convolution channel expansion. After global average pooling to aggregate spatial information, the features are projected into a 32-dimensional class center representation vector using an MLP. (Category Embedding) This vector encodes category-specific information, exhibiting strong intra-class compactness and inter-class discriminability; simultaneously, it inputs features into a softmax linear classifier, outputting a sample classification probability distribution to achieve accurate category segmentation.
[0032] 2. Category-specific memory: As the core innovation of the framework, this module stores multi-scale normal sample features for each category before training, providing a category-specific benchmark for anomaly detection.
[0033] Construction process: For each category memory bank Store the features extracted from the three deepest layers of the encoder. Obtain the features of each layer from normal samples before training. , For feature layer indexing, calculate global descriptors. For each category, 30 samples are randomly sampled as feature examples and stored in the corresponding memory bank to ensure coverage of the core feature patterns of the category.
[0034] Retrieval process: Feature selection in the category-specific memory during the inference stage, such as... Figure 3 As shown. During the training and testing phases, the predicted category of the image to be detected is first determined. Limit the search scope to First, feature comparison is performed to ensure semantic consistency; then, the global descriptor of the last layer of features in the image to be retrieved is calculated. With the storage descriptor in the memory bank The cosine similarity is used to select the example feature with the highest similarity as the category-specific normal prototype, providing an accurate reference for subsequent anomaly detection. The retrieval formula is as follows: ; in, For category The corresponding memory sample set, where CosSim represents the cosine similarity calculation function. Finally, based on the feature index... Retrieve normal features.
[0035] 3. Category-guided decoupling and fusion module: such as Figure 4 As shown, to address the defect detection bias caused by the heterogeneity of multi-category distribution, this module implements feature processing in two steps: Category Decoupling Guided Attention: Based on Category Center Representation Vector (Category Embedding) generates learnable channel weights through a scale-specific MLP, dynamically adjusts the importance of each channel, enhances category-sensitive features, reduces interference from cross-category weight sharing, and achieves category-level feature decoupling. It performs category-conditional weighting on the features of the image to be detected and the retrieved normal features. The core formula is as follows: ; in, The sigmoid activation function is used. For input features, This indicates element-wise multiplication.
[0036] Feature fusion based on change detection: First, a 1×1 convolution is performed on the features of the image to be detected and the retrieved normal features to reduce the dimensionality, halving the channel dimension. The query feature transformation formula is: ; Where B is the batch size. H represents the number of channels after dimensionality reduction, and H and W represent the height and width of the feature map.
[0037] Then, positional encoding is introduced to supplement spatial context information, and non-local attention is combined to enhance long-distance dependency modeling, thus solving the problem that traditional CNNs have difficulty capturing global positional information.
[0038] Finally, the weighted features of the image to be detected and the normal features are concatenated and fused to highlight the feature differences in abnormal regions. The formula is as follows: ; in, To integrate weights, and These are the enhanced query features and key features, respectively, with Concat representing the concatenation operation.
[0039] 4. Abnormal data enhancement module: such as Figure 5 As shown, to address the problem of scarce labeled abnormal samples, three generation strategies are designed, all based on foreground region constraints to ensure reasonable abnormal locations (the overlap between object and foreground is set to greater than 50%, and the entire image is used for texture).
[0040] Extended Anomalies: The anomaly regions of the labeled anomaly samples undergo color enhancement and spatial transformation to obtain enhanced anomaly regions. Color enhancement randomly selects two operations from equalization, exposure adjustment, tone shift, sharpening, automatic contrast, inversion, and gamma correction. Spatial transformations include rotation, shearing, and translation. Then, based on target region constraints, the enhanced anomaly regions are embedded into the foreground region of normal samples. For object datasets, the target region is the foreground; for texture datasets, the target region is the entire image region. Anomaly masks are generated through binarization. Finally, pixel-level fusion yields the extended anomaly samples, as shown in the following formula: ; in, To enhance the mask annotation corresponding to the abnormal region, For mask The reverse, This is a normal sample. For the enhanced abnormal region, For transparency parameters, This is for element-wise multiplication.
[0041] Heterogeneous Simulation Anomaly (HEA): Generating Perlin Noise Maps Compared with textures randomly selected and enhanced from the DTD texture library By fusing, a texture perturbation map is obtained. Then, the foreground region of a normal sample is embedded to obtain a heterogeneous simulated abnormal sample. The formula is as follows: ; ; in, The transparency parameter for heterogeneous fusion is adjusted by... Control the degree of fusion between heterogeneous textures and normal samples; This is the mask corresponding to the regions in the noise map whose values are greater than the threshold T. For mask The reverse.
[0042] Homologous Simulation Anomaly (HOA): For normal samples Perform color enhancement operations (same as EA's color enhancement strategy) to obtain enhanced normal samples. ,Will The sample was uniformly divided into an 8×8 grid, and the grid order was randomly shuffled and then reassembled to obtain a disordered enhanced normal sample. ;Will Perlin noise plot Element-wise multiplication is performed, embedding the foreground region of normal samples, and pixel-level fusion is used to generate homogeneous simulated anomalous samples. The formula is as follows: ; ; ; ; in, For the transparency parameter of homogeneous fusion, For the grid shuffling function, This is a recombination function.
[0043] The size of the target region is set to 20%-40% of the foreground size, and the shape is determined by random sampling. When generating synthetic anomalous samples, the batch composition ratio is normal samples: EA samples: HEA samples: HOA samples = 3:1:1:1 to ensure a balanced distribution of training data.
[0044] (II) Two-stage model training Phase 1: Classification Module Training: Freeze the pre-trained feature extractor and train the classification module using all normal class samples (4 images per class). The goal is to generate discriminative class centers. A loss function combining cross-entropy loss and center loss is used to balance classification accuracy and intra-class feature compactness. The optimizer is SGD, and training lasts for 100 epochs.
[0045] Loss function for the first stage of training for: ; in, For cross-entropy loss, For predicting categories, For the real category, As a balance factor, Loss at the center For sample feature vectors, It serves as a learning center for real-world categories.
[0046] Phase Two: After the category centers stabilize, the decoupled fusion module and decoder are trained. Synthetic anomalous samples are generated and enhanced using a paste and Berlin noise fusion method. Ten labeled anomalous samples are used for training in each category. The loss function combines binary cross-entropy loss and focus loss to enhance the learning of hard examples. The optimizer is AdamW, and a cosine annealing learning rate scheduling strategy is used.
[0047] Loss function for the second stage of training for: ; in, To predict anomaly masks; As a true anomaly mask, by and It consists of two parts; As a balance factor, For binary cross-entropy loss, The loss is the focus.
[0048] (III) Anomaly Detection like Figure 6 As shown, in the inference stage, the image to be detected is encoded by an encoder to obtain the image features; then, the image features are processed by a classification module to obtain the category embedding and category label of the image to be detected; subsequently, based on the image features and category label, a retrieval is performed in the category-specific memory to obtain the multi-scale normal features corresponding to the category. Next, the image features, the retrieved normal features, and the category embedding are input into a decoupling fusion module to obtain the fused features. Finally, the fused features are input into a decoder module to output image-level anomaly detection results (whether it is an anomalous sample) and pixel-level anomaly localization results (anomaly region mask).
[0049] The detection performance can be evaluated using metrics such as image-level AUROC (I-AUROC) and pixel-level AUROC (P-AUROC) according to actual detection needs.
[0050] To verify the effectiveness of the present invention, the method of the present invention was experimentally verified on the MVTec AD standard dataset.
[0051] 1. Data preparation: The MVTec AD dataset is used as the training and testing data. This dataset contains 15 categories and a total of 5354 high-resolution images, covering various types of surface defects in industrial products. Four normal images are selected from each category for the first stage of training, and all normal samples in each category and 10 randomly selected labeled abnormal samples in each category are used for the second stage of training.
[0052] 2. Initialization settings: Category embedding generation module: The backbone network is EfficientNet-B4, and the MLP output dimension is 32. .
[0053] Category-specific memory: Each category stores the features of the three deepest encoders for 30 normal samples, and the global descriptor dimension is 448.
[0054] Decoupling and fusion module: After 1×1 convolution dimensionality reduction, the number of channels is half of the original number of channels. .
[0055] 3. First Phase Training: Freeze the EfficientNet-B4 backbone feature extractor.
[0056] The SGD optimizer was used, with a learning rate of 1e-3 for the classification head, a learning rate of 0.5 for the feature centers, a batch size of 32, and training for 100 epochs.
[0057] The loss function is cross-entropy loss plus center loss, and the optimization objective is to generate discriminative class embeddings.
[0058] 4. Second phase of training: The unfrozen backbone feature extractor uses the AdamW optimizer with a learning rate of 5e-4 and cosine annealing learning rate scheduling.
[0059] A data augmentation module is used to generate and enhance synthetic anomalous samples.
[0060] The loss function is a combination of binary cross-entropy loss and focus loss, and the model is trained until it converges.
[0061] 5. Testing and verification: The input test sample passes through the classification module, category-specific memory, decoupling and fusion module, and decoder module in sequence.
[0062] Calculate image-level AUROC and pixel-level AUROC to evaluate performance.
[0063] Output the anomaly detection results and the anomaly region mask.
[0064] Benchmark comparisons show that, using the method of this invention, the image-level AUROC reaches 98.7% and the pixel-level AUROC reaches 98.0%, which is 15.4% higher than mainstream methods such as DRA. Experimental results show that the method of this invention effectively improves detection accuracy and generalization ability through memory guidance and category decoupling mechanisms, and the adaptation mechanism reduces the deployment cost in multi-category scenarios, making it widely applicable to industrial quality control fields such as electronic components and textile fabrics.
[0065] The method of this invention can also be combined with other anomaly detection optimization techniques, such as: replacing the backbone feature extractor with network structures such as ResNet-50 and ViT to adapt to different computing resource and detection accuracy requirements; adjusting the number of samples in the category-specific memory (e.g., 20-50) to balance memory capacity and retrieval efficiency; and changing the balance factor in the loss function. (1-3) and (3-7) Adapt to different types of defect detection scenarios; Combine with data augmentation techniques (such as random pruning, rotation, and noise addition) to further improve the model's generalization ability.
[0066] The embodiments described above provide a detailed explanation of the technical solutions and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, additions, and equivalent substitutions made within the scope of the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A multi-class anomaly detection method based on memory guidance and category decoupling, characterized in that, Includes the following steps: (1) Construct a category-specific memory to store the multi-scale normal features of normal samples in each category; (2) Construct a classification module based on center loss to generate discriminative class embeddings and class labels; (3) Design a category-guided decoupling and fusion module to decouple and fuse the features of the image to be detected with the retrieved normal features based on category embedding; (4) Construct an abnormal data augmentation module, and obtain extended abnormal samples, heterogeneous simulated abnormal samples, and homogeneous simulated abnormal samples through three types of strategies, and integrate them to obtain synthetic abnormal samples; (5) A two-stage training strategy is adopted. The first stage trains the classification module, and the second stage combines labeled abnormal samples and synthetic abnormal samples to train the decoupled fusion module and the decoder module to achieve abnormal mask prediction. (6) In the inference stage, the image to be detected is processed by a pre-trained encoder to obtain the features of the image to be detected; then the features of the image to be detected are processed by a classification module to obtain the category embedding and category label of the image to be detected. Subsequently, the category label and the features of the image to be detected are used to retrieve the corresponding multi-scale normal features in the category-specific memory. Finally, the features of the image to be detected, the retrieved normal features and the category embedding are input into the decoupled fusion module, and the fused features are input into the decoder module to obtain the abnormal segmentation map.
2. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 1, characterized in that, In step (1), the construction process of the category-specific memory is as follows: For each category, multiple normal samples are randomly sampled, and each normal sample is input into a pre-trained encoder to obtain five layers of features. The last three layers of features corresponding to each normal sample are stored in a category-specific memory. The result of global average pooling of the last layer of features is used as the corresponding storage descriptor for retrieving the corresponding normal features during the inference stage.
3. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 1, characterized in that, In step (1), the category-specific memory performs the following specific process during retrieval: The image to be detected is input into the encoder to obtain the features of the image to be detected; then the last layer of the features of the image to be detected is input into the classification module to obtain the category embedding and category label of the image to be detected. Select the corresponding search category based on the category label; The global descriptor obtained by global average pooling of the last layer of features in the image to be detected ; Global descriptors of the features of the image to be detected storage descriptors under the corresponding category Perform cosine similarity calculation to obtain the feature index of the best match. And based on feature index Retrieve normal features.
4. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 1, characterized in that, In step (2), the classification module uses EfficientNet-B4 as the backbone feature extractor. After the last layer of the image features to be detected is input into EfficientNet-B4, its output is expanded by 1×1 convolution. After global average pooling to aggregate spatial information, it is projected into a category embedding through a multilayer perceptron. At the same time, the category embedding is input into a softmax linear classifier, and the probability distribution of the sample classification is output to obtain the category label.
5. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 1, characterized in that, In step (3), the specific working process of the decoupling and fusion module is as follows: Based on category embedding, a multilayer perceptron with defined scales is used. Generate channel weights and apply category-based weighting to the features of the image to be detected and the retrieved normal features; Both the image features to be detected and the retrieved normal features are subjected to a 1×1 convolution with shared weights, which halves the channel dimension. Position encoding and non-local attention are introduced, and the weighted image features to be detected and the retrieved normal features are concatenated along the channel dimension to achieve fusion.
6. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 1, characterized in that, In step (4), the process of obtaining extended abnormal samples is as follows: Color enhancement and spatial transformation are applied to the abnormal regions of the labeled anomalous samples to obtain enhanced anomalous regions. Then, based on target region constraints, the enhanced anomalous regions are embedded into the foreground regions of normal samples to obtain expanded anomalous samples. The formula is as follows: ; in, To enhance the mask annotation corresponding to the abnormal region, For mask The reverse, This is a normal sample. For the enhanced abnormal region, For transparency parameters, This is for element-wise multiplication.
7. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 6, characterized in that, In step (4), the process of obtaining heterogeneous simulated anomaly samples is as follows: Generate Perlin noise map Compared with textures randomly selected and enhanced from the DTD texture library By fusing, a texture perturbation map is obtained. Then, the foreground region of a normal sample is embedded to obtain a heterogeneous simulated abnormal sample. The formula is as follows: ; ; in, The transparency parameter for heterogeneous fusion is adjusted by... Control the degree of fusion between heterogeneous textures and normal samples; This is the mask corresponding to the regions in the noise map whose values are greater than the threshold T. For mask The reverse.
8. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 7, characterized in that, In step (4), the process of obtaining homologous simulated anomaly samples is as follows: For normal samples Perform color enhancement to obtain enhanced normal samples. ,Will The grid was uniformly divided into 8×8 grids, and the grid order was randomly shuffled and then reassembled to obtain disordered enhanced normal samples. ;Will Perlin noise map Element-wise multiplication is performed, embedding the foreground region of normal samples, and pixel-level fusion is used to generate homogeneous simulated anomalous samples. The formula is as follows: ; in, This is the transparency parameter for homogeneous fusion.
9. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 8, characterized in that, In step (5), the loss function of the first stage of training for: ; in, For cross-entropy loss, For predicting categories, For the real category, As a balance factor, Loss at the center For sample feature vectors, It serves as a learning center for real-world categories.
10. The multi-class anomaly detection method based on memory guidance and category decoupling according to claim 9, characterized in that, In step (5), the loss function for the second stage of training for: ; in, To predict anomaly masks; As a true anomaly mask, by and It consists of two parts; As a balance factor, For binary cross-entropy loss, The loss is the focus.
Citation Information
Patent Citations
Unsupervised learning image anomaly detection method based on auto-encoder
CN112101426A
Joint industrial anomaly detection method and system based on multi-scale feature self-expression
CN118247254A
Construction method of texture surface defect detection model based on multi-class decomposition editing
CN115564724A
Image anomaly detection method based on core memory bank residual error
CN117079029A
Memory matching industrial defect detection method based on adaptive feature fusion
CN120339195A