Abnormality detection method based on adaptive memory bank updating and multi-scale comparison aggregation

Through the methods of adaptive memory bank update and multi-scale comparison aggregation, the adaptability problem caused by data distribution changes in the prior art is solved, and anomaly detection with high accuracy and low complexity is achieved, adapting to product characteristics changes in industrial vision detection and reducing false alarm rates.

CN120339648APending Publication Date: 2025-07-18苏州旗开得电子科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510394474.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

The existing anomaly detection methods are difficult to adapt to when facing changes in data distribution, with high computational overhead and weak feature aggregation capabilities, so they cannot effectively identify unseen abnormalities, especially in industrial quality testing, which is difficult to adapt to product feature changes in different batches.

Method used

Adaptive memory update and multi-scale contrast aggregation methods are adopted, and high-dimensional features are extracted and dimensionalized by pre-training Vision Transformer. Combining the adaptive exponential moving average and cross-scale interactive attention mechanism, the memory is dynamically adjusted and feature aggregation optimization is performed, and the Marshallow distance and cosine similarity are fused for abnormal scores.

Benefits of technology

It realizes abnormal detection with high accuracy and low computing complexity, can adapt to product characteristics changes in different batches, improve detection stability, reduce false alarm rates, and can detect small defects and large-scale defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120339648A_ABST
    Figure CN120339648A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of anomaly detection, and discloses an anomaly detection method based on adaptive memory bank updating and multi-scale contrast aggregation, comprising the following steps: S1, memory bank initialization: performing dimension reduction processing on high-dimensional features, and performing memory bank initialization; s2, updating a self-adaptive memory bank: firstly dynamically adjusting the memory bank; detecting the performance of the model; s3, performing multi-scale comparison aggregation: performing feature enhancement by adopting multi-scale local feature descriptor coding, and performing feature aggregation optimization through a cross-scale comparison strategy; and S4, abnormal score calculation: carrying out abnormal score by fusing multi-scale nearest neighbor search and adaptive abnormal score. According to the invention, anomaly detection with high precision and low calculation complexity can be realized; in industrial visual inspection, the method can adapt to feature changes of products of different batches, and the detection stability is improved; small defects and large-range defects can be detected; the anomaly detection precision of products made of different materials can be improved, and the false alarm rate is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of anomaly detection, and specifically, to an anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation. Background Art

[0002] Anomaly detection plays a crucial role in many fields. Especially in key tasks such as industrial quality inspection, accurately detecting abnormal data can effectively improve the safety and reliability of the system; through anomaly detection, defects of products on the production line can be identified, such as anomalies, defects, missing parts, offsets, etc. of components on printed circuit boards.

[0003] However, in these application scenarios, abnormal samples are usually difficult to collect, and the distribution of normal samples may drift over time, which poses higher adaptability requirements for anomaly detection models; the existing anomaly detection mainly includes the following two methods:

[0004] 1. Anomaly detection methods based on deep learning: With the development of deep learning, many anomaly detection methods based on technologies such as convolutional neural networks (CNNs) and autoencoders have been proposed; however, these methods usually rely on large-scale labeled datasets and identify anomalies by learning the distribution characteristics of the data; however, these methods still cannot cope with the problem of zero-shot learning, that is, they cannot identify anomalies that have never been seen before, and a large amount of time and computing resources are required during model training.

[0005] 2. Methods based on feature comparison: Use a pre-trained CNN to extract image Patch-level features and perform k-nearest neighbor matching in the memory bank. However, the memory bank of Patch Core is fixed and cannot adapt to changes in data distribution, making it difficult to handle data drift problems.

[0006] It can be seen that the above two methods have problems such as high computational overhead, sensitivity to changes in data distribution, and weak feature aggregation ability in practical applications. Summary of the Invention

[0007] The purpose of the present invention is to provide an anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation to solve the problems raised in the above background art.

[0008] To achieve the above purpose, the present invention provides the following technical solutions:

[0009] An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation, comprising the following steps:

[0010] S1. Memory bank initialization: First, use a pre-trained Vision Transformer structure as a feature extractor to obtain high-dimensional features; then map the high-dimensional features to a low-dimensional space for dimensionality reduction processing and perform memory bank initialization;

[0011] S2. Adaptive memory bank update: First, dynamically adjust the memory bank based on adaptive exponential moving average; then detect the model performance through a data drift detection mechanism;

[0012] S3. Multi-scale contrast aggregation: Use multi-scale local feature descriptors for feature encoding to enhance features, and optimize feature aggregation through a cross-scale contrast strategy;

[0013] S4. Anomaly score calculation: Calculate the anomaly score by fusing multi-scale nearest neighbor search and an adaptive anomaly scoring strategy.

[0014] As a further solution of the present invention: In the step S1, the specific steps of using a pre-trained Vision Transformer structure as a feature extractor to obtain high-dimensional features are as follows:

[0015] S101. Perform local feature encoding through multi-scale local feature descriptors to obtain feature representations of different scales;

[0016] S102. Perform high-dimensional feature transformation using high-dimensional spectral transformation to improve feature stability.

[0017] As a further solution of the present invention: In the step S1, the specific steps of mapping the high-dimensional features to a low-dimensional space for dimensionality reduction processing and performing memory bank initialization are as follows:

[0018] S111. Use a method combining local manifold embedding and principal component analysis to map the high-dimensional features to a low-dimensional space to reduce feature redundancy and achieve dimensionality reduction;

[0019] S112. Store the features after dimensionality reduction in the memory bank to construct an initial normal sample feature bank.

[0020] As a further solution of the present invention: In the step S2, the method for dynamically adjusting the memory bank based on adaptive exponential moving average is specifically as follows:

[0021] S21. Calculate the feature vector of the new training data;

[0022] S22. Use the adaptive exponential moving average update memory bank rule to calculate the central feature of the current memory bank;

[0023] S23. Through the adaptive learning weight mechanism, the memory bank can be quickly and dynamically adjusted when the data distribution drifts, so as to reduce the impact of data drift on the detection performance and maintain stability when the data distribution changes.

[0024] As a further solution of the present invention: In the S2 step, the specific method for the data drift detection mechanism to detect the model performance is as follows:

[0025] Calculate the KL divergence between the new sample distribution and the memory bank distribution; if the KL divergence value exceeds the set threshold, perform dynamic expansion of the memory bank to allow additional features to be stored, so as to enhance the adaptability of the model to the new distribution.

[0026] As a further solution of the present invention: In the S3 step, during the feature enhancement process using the multi-scale local feature descriptor encoding, extract the Patch features of different scales in the image through the multi-scale Transformer structure to enhance the context awareness ability at the local image block level.

[0027] As a further solution of the present invention: In the S3 step, the method for optimizing feature aggregation through the cross-scale contrast strategy is as follows:

[0028] S301. Use the cross-scale interactive attention mechanism to calculate the similarity between features of different scales;

[0029] S302. Perform feature aggregation optimization through the self-supervised contrast loss function.

[0030] As a further solution of the present invention: In the S4 step, the specific method for performing anomaly scoring by fusing multi-scale nearest neighbor search and adaptive anomaly scoring strategy is as follows:

[0031] S401. Calculate the distance between the test sample feature and the nearest neighbor feature in the memory bank;

[0032] S402. Fuse the Mahalanobis distance and cosine similarity for joint anomaly scoring, construct a more stable anomaly scoring mechanism, supplement the Mahalanobis distance with cosine similarity, improve the model's ability to capture abnormal patterns; further enhance the robustness of anomaly detection.

[0033] Compared with the prior art, the beneficial effects of the present invention:

[0034] Through the adaptive exponential moving average memory bank update, the memory bank can be dynamically adjusted with the change of data distribution, reducing the impact of data drift on the detection performance; through the multi-scale local feature descriptor encoding for feature enhancement, and through the cross-scale contrast strategy for feature aggregation optimization, the ability to distinguish abnormal features is improved; through the fusion of multi-scale nearest neighbor search and adaptive anomaly scoring strategy for anomaly scoring, the computational resource requirements are reduced, making the method more efficient, thus achieving high-precision and low-computational-complexity anomaly detection; in industrial vision detection, it can adapt to the product feature changes in different batches, improving the detection stability; it can simultaneously detect small defects (such as microcracks) and large-scale defects (such as uneven coatings); it can improve the anomaly detection accuracy on products of different materials and reduce the false alarm rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 FIG. is a schematic flow diagram of an anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation. DETAILED DESCRIPTION OF THE INVENTION

[0036] Please refer to Figure 1 , in the embodiment of the present invention, an anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation includes the following steps:

[0037] S1. Memory bank initialization:

[0038] First, local feature encoding is performed through a multi-scale local feature descriptor (MSPD) to obtain feature representations of different scales; among them, the calculation formula of the feature representations of different scales is as follows:

[0039]

[0040] In the above formula (1), represents the l-th layer feature extraction network, X t is the input sample, and L is the number of network layers; is the feature representation output by the l-th layer;

[0041] Next, high-dimensional spectral transformation (HDST) is used for high-dimensional feature transformation to obtain high-dimensional features; to improve feature stability;

[0042] Next, a method combining local manifold embedding (LME) and principal component analysis (PCA) is used to map the high-dimensional features to a low-dimensional space to reduce feature redundancy and achieve dimensionality reduction; among them, the calculation formula of the combination of local manifold embedding and principal component analysis is as follows:

[0043]

[0044] In the above formula (2), P represents principal component analysis, is a high-dimensional feature, is a low-dimensional space;

[0045] Next, the dimension-reduced features are stored in the memory bank to construct an initial normal sample feature bank, so as to achieve dimension reduction and memory bank initialization;

[0046] S2. Adaptive memory bank update:

[0047] First, for the new training data X t , calculate its feature vector:

[0048] F t = f θ (X t ) (3),

[0049] In the above formula (3), f θ is the feature extraction function; F t is the feature vector;

[0050] Next, adopt the adaptive exponential moving average (A-EMA) to update the memory bank rule and calculate the central feature of the current memory bank:

[0051] M’ = μM + (1 - μ)F t (4),

[0052] In the above formula (4), M′ is the central feature of the current memory bank, M is the central feature stored in the memory bank, μ is the weight, and μ dynamically adjusts its calculation formula according to the data distribution as follows:

[0053]

[0054] In the above formula (5), d(F t , M) is the Euclidean distance between the new sample feature and the central feature of the memory bank, and α is the rate factor of dynamic learning;

[0055] Next, through the adaptive learning weight mechanism (ALW), the memory bank can be quickly and dynamically adjusted when the data distribution drifts, so as to reduce the impact of data drift on the detection performance, and thus remain stable when the data distribution changes;

[0056] Next, the performance of the model is detected through the data drift detection mechanism to enhance the adaptability of the model to the new distribution; among them, the specific method for the data drift detection mechanism to detect the model performance is as follows:

[0057] Calculate the KL divergence (Kullback-Leibler Divergence) between the new sample distribution and the memory bank distribution:

[0058]

[0059] In the above formula (6), P i is the true distribution or target distribution, and Q i is the approximate distribution or reference distribution;

[0060] If D KL exceeds the set threshold, then perform dynamic memory bank expansion (DME) to allow the storage of additional features to enhance the model's adaptability to the new distribution;

[0061] S3. Multi-scale contrast aggregation:

[0062] Feature enhancement is performed using multi-scale local feature descriptor coding, and feature aggregation optimization is carried out through a cross-scale contrast strategy;

[0063] During the process of feature enhancement using multi-scale local feature descriptor coding, Patch features at different scales in the image are extracted through a multi-scale Transformer structure to enhance the context awareness ability at the local image patch level. The calculation formula is as follows:

[0064] P t = f Trans (X t ) (7),

[0065] In the above formula (7), P t is the enhanced feature, f Trans is the Transformer structure, and X t is the image data.

[0066] In the step S3, the method for feature aggregation optimization through a cross-scale contrast strategy is as follows:

[0067] First, the cross-scale interaction attention mechanism (CSIA) is used to calculate the similarity between features at different scales. The calculation formula is as follows:

[0068]

[0069] In the above formula, A i,j is the similarity score, F i ·F j is the dot product of features F i and F j , which reflects the sum of their element-wise products; ||F i || and ||F j || are the 2-norms (magnitudes) of the features, used to normalize the dot product result;

[0070] Then, feature aggregation optimization is carried out through a self-supervised contrastive loss function;

[0071] S4. Abnormality score calculation:

[0072] First, calculate the distance between the test sample feature and the nearest neighbor feature in the memory bank:

[0073]

[0074] In the above formula (9), F test is the feature vector of the test sample; M k is the feature vector of the Kth nearest neighbor sample in the memory bank; d(F test , M k ) is the original distance (such as Mahalanobis distance, cosine similarity) between the test sample and the kth nearest neighbor; w k is the weight of the kth nearest neighbor, which is adaptively adjusted according to the local density of the test sample; D kNN is the weighted comprehensive distance;

[0075] Next, fuse the Mahalanobis distance and cosine similarity to perform joint abnormality scoring, construct a more stable abnormality scoring mechanism, supplement the Mahalanobis distance with cosine similarity to improve the model's ability to capture abnormal patterns; further enhance the robustness of abnormality detection, thereby improving the ability to distinguish abnormal features; the calculation formula of the abnormality score is as follows:

[0076]

[0077] In the above formula (10), d Maha (F test , M k ) is the Mahalanobis distance between the test sample and the kth nearest neighbor; d cos (F test , M k ) is the cosine similarity; S anamoly is the abnormality score.

[0078] The above is only the preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention, according to the technical solution of the present invention and its inventive concept, makes equivalent substitutions or changes, and should be covered by the protection scope of the present invention.

Claims

1. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation, characterized in that It includes the following steps: S1. Memory bank initialization: First, use a pre-trained Vision Transformer structure as a feature extractor to obtain high-dimensional features; then map the high-dimensional features to a low-dimensional space for dimensionality reduction processing and perform memory bank initialization; S2. Adaptive memory bank update: First, dynamically adjust the memory bank based on adaptive exponential moving average; then detect the model performance through a data drift detection mechanism; S3. Multi-scale contrast aggregation: Use multi-scale local feature descriptors for feature encoding to enhance features, and optimize feature aggregation through a cross-scale contrast strategy; S4. Anomaly score calculation: Calculate the anomaly score by fusing multi-scale nearest neighbor search and an adaptive anomaly scoring strategy.

2. The anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, wherein In the step S1, the specific steps of using a pre-trained Vision Transformer structure as a feature extractor to obtain high-dimensional features are as follows: S101. Perform local feature encoding through multi-scale local feature descriptors to obtain feature representations of different scales; S102. Use high-dimensional spectral transformation for high-dimensional feature transformation to improve feature stability.

3. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that In the step S1, the specific steps of mapping the high-dimensional features to a low-dimensional space for dimensionality reduction processing and performing memory bank initialization are as follows: S111. Use a method combining local manifold embedding and principal component analysis to map the high-dimensional features to a low-dimensional space to reduce feature redundancy and achieve dimensionality reduction; S112. Store the features after dimensionality reduction in the memory bank to construct an initial normal sample feature bank.

4. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that, In the step S2, the method of dynamically adjusting the memory bank based on adaptive exponential moving average is as follows: S21. Calculate the feature vector of the new training data; S22. Use the adaptive exponential moving average update memory bank rule to calculate the central feature of the current memory bank; S23. Through an adaptive learning weight mechanism, the memory bank can be quickly and dynamically adjusted when the data distribution drifts, so as to reduce the impact of data drift on the detection performance and maintain stability when the data distribution changes.

5. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that In the step S2, the specific method of the data drift detection mechanism for detecting the model performance is as follows: Calculate the KL divergence between the new sample distribution and the memory bank distribution; if the KL divergence value exceeds the set threshold, perform memory bank dynamic expansion to allow additional features to be stored to enhance the model's adaptability to the new distribution.

6. The anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that, In the step S3, during the process of using multi-scale local feature descriptors for feature encoding to enhance features, extract Patch features of different scales in the image through a multi-scale Transformer structure to enhance the context awareness ability at the local image block level.

7. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that, In the step S3, the method of optimizing feature aggregation through a cross-scale contrast strategy is as follows: S301. Use a cross-scale interactive attention mechanism to calculate the similarity between features of different scales; S302. Optimize feature aggregation through a self-supervised contrast loss function.

8. An anomaly detection method based on adaptive memory bank update and multi-scale contrast aggregation according to claim 1, characterized in that, In the step S4, the specific method of calculating the anomaly score by fusing multi-scale nearest neighbor search and an adaptive anomaly scoring strategy is as follows: S401. Calculate the distance between the test sample feature and the nearest neighbor feature in the memory bank; S402. Combine the Mahalanobis distance and cosine similarity to perform joint anomaly scoring, construct a more stable anomaly scoring mechanism, supplement the Mahalanobis distance with cosine similarity to improve the model's ability to capture abnormal patterns; further enhance the robustness of anomaly detection.