An industrial image anomaly detection method and system based on sparse reference samples

By reconstructing decentralized representations, reconstructing normal patterns from few samples, and mining abnormal patterns, the problems of centripetal collapse, identity mapping, and statistical noise masking in industrial image anomaly detection are solved, achieving efficient detection of minute anomalies.

CN122391232APending Publication Date: 2026-07-14EAST CHINA JIAOTONG UNIVERSITY

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
EAST CHINA JIAOTONG UNIVERSITY
Filing Date
2026-06-15
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing industrial image anomaly detection methods face problems such as centripetal collapse, identity mapping traps, and statistical noise masking under small sample conditions, which can lead to the submergence or missed detection of minute anomaly signals.

Method used

An industrial image anomaly detection method based on sparse reference samples is adopted. The decentralized representation reconstruction module (DRR), the few-sample normal pattern reconstruction branch (FNPR), and the anomaly pattern mining branch (APM) work together to perform feature calibration, spatial information blocking, and anomaly pattern mining, generating a pixel-level anomaly score map.

Benefits of technology

It effectively overcomes centripetal collapse, breaks the identity mapping dilemma, suppresses statistical noise interference, improves the ability to distinguish and locate minute anomalies, and achieves highly robust anomaly detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122391232A_ABST
    Figure CN122391232A_ABST
Patent Text Reader

Abstract

The application discloses an industrial image anomaly detection method and system based on sparse reference samples, comprising: obtaining an industrial image to be detected, a sparse normal reference sample set and an abnormal reference sample set, and extracting a hierarchical feature flow; performing decentralized representation reconstruction on the hierarchical feature flow to obtain query features, normal reference features and abnormal reference features; generating a normal guide map and reconstruction similarity based on the query features and the normal reference features, mining abnormal mode prototype data based on residual decoupling, and generating an abnormal guide map; dynamically weighting and fusing the normal guide map, the reconstruction similarity and the abnormal guide map to obtain a pixel-level anomaly score map and output an image-level anomaly detection result. The method can suppress centripetal collapse, identity mapping and statistical noise masking, and improve the accuracy of subtle anomaly recognition and positioning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of industrial image anomaly detection technology, specifically relating to an industrial image anomaly detection method and system based on sparse reference samples. Background Technology

[0002] Industrial anomaly detection (IAD) is a key technology for ensuring product quality in modern smart manufacturing. Its goal is to identify and locate various surface defects such as scratches, structural damage, or logical assembly errors in complex production environments. However, in actual production lines, defect occurrence is random, and collecting large amounts of data is costly, making traditional fully supervised learning paradigms that rely on large datasets difficult to implement. Therefore, current research focus has significantly shifted to the few-sample anomaly detection (FSAD) paradigm, which uses only a very small number of samples for inference. In recent years, the rapid development of large-scale visual foundation models (VFMs) and generative reconstruction methods have spurred several FSAD technology trajectories.

[0003] However, existing industrial anomaly detection methods still face three core bottlenecks in practical deployment: 1. Centripetal Collapse: The global inductive bias of the pre-trained base model forces normal patterns to be extremely compact in the feature space, causing small anomaly signals at the distribution edges to be easily submerged by background semantics during feature fusion; 2. Identity Mapping Trap: Under small sample constraints, decoders with overfitting capabilities easily degenerate into simple copy-paste channels, resulting in perfect restoration of anomalous regions and rendering the discrimination mechanism based on reconstruction error completely ineffective; 3. Statistical Noise Masking: Traditional distribution modeling is mainly performed in the absolute feature space, and high-variance background textures often mask pixel-level feature shifts, leading to missed detection of small defects. Summary of the Invention

[0004] The purpose of this invention is to overcome the above-mentioned problems of existing industrial image anomaly detection technology. This invention proposes an industrial image anomaly detection method and system based on sparse reference samples. The overall framework of the method and system is constructed by three core modules: decentralized representation reconstruction module (DRR), few-sample normal pattern reconstruction branch (FNPR), and anomaly pattern mining branch (APM).

[0005] To achieve the above objectives, this invention provides an industrial image anomaly detection method based on sparse reference samples, comprising: acquiring an industrial image to be detected, a sparse normal reference sample set, and an anomaly reference sample set, using the industrial image to be detected as a query sample; extracting hierarchical feature flows from the query sample, the normal reference sample set, and the anomaly reference sample set respectively; performing decentralized representation reconstruction on the hierarchical feature flows to obtain scale- and channel-aligned query features, normal reference features, and anomaly reference features; generating a normal guide map based on the similarity matching results between the query features and the normal reference features; and generating a spatial mask based on the normal guide map for the... The query features are spatially blocked and reconstructed to obtain reconstructed features. The feature similarity between the reconstructed features and their corresponding query features is calculated to obtain the reconstruction similarity. The query features and abnormal reference features are decoupled relative to the normal reference features to obtain query residual offset and abnormal residual offset. Abnormal pattern prototype data is mined from the abnormal residual offset, and an abnormal guidance map is generated from the matching result of the abnormal pattern prototype data and the query residual offset. The normal guidance map, reconstruction similarity and abnormal guidance map are dynamically weighted and fused to obtain a pixel-level abnormal score map, and the image-level abnormal detection result is output.

[0006] As a further improvement to the above technical solution, the normal reference sample set includes N normal reference samples, where N is 1, 2, or 4; the abnormal reference sample set includes a single abnormal reference sample. Extracting hierarchical feature flows from the query sample, normal reference sample set, and abnormal reference sample set respectively includes: inputting the query sample, each normal reference sample, and the single abnormal reference sample into the DINOv2 model with frozen parameters, extracting the output features of the 3rd, 6th, 9th, and 12th layers, and constructing the hierarchical feature flows.

[0007] As a further improvement to the above technical solution, the hierarchical feature flow is reconstructed through decentralized representation, including: constructing spatially decentralized residuals for each layer of features in the hierarchical feature flow, globally decoupling in the spatial dimension, and subtracting the spatial average term of each layer of features to obtain decentralized residual features; flattening the decentralized residual features along the spatial dimension into an input sequence, using the input sequence as a query vector, and using a learnable normal surrogate vector as a key vector and value vector, extracting the normal pattern projection component through a multi-head cross-attention mechanism, and subtracting the normal pattern projection component from the decentralized residual features to obtain anomaly perception features; uniformly upsampling the anomaly perception features of each layer to the spatial resolution of the final layer features, aligning the channel dimension through linear mapping, and performing feature fusion based on the two-layer fusion weights obtained by element-wise multiplication and normalization of spatial prior weights and a learnable dynamic adjustment matrix to obtain the query features, normal reference features, and anomaly reference features.

[0008] As a further improvement to the above technical solution, the process of generating the normal guide map includes: flattening and aggregating the normal reference features along the sample dimension and spatial dimension to construct a normal feature library; for any spatial location of the query feature, calculating its cosine similarity with each normal feature in the normal feature library, and extracting the strongest response value as the normal matching score of that spatial location; generating the normal guide map from the normal matching scores of each spatial location. The process of generating a spatial mask based on the normal guidance graph and blocking spatial information of the query features includes: mapping the normal guidance graph to a probability space using a Sigmoid function and applying a hard threshold to truncate it, generating a binarized spatial mask; and blocking element-by-element information of the query features in the spatial domain based on the spatial mask to obtain masked query features.

[0009] As a further improvement to the above technical solution, the reconstruction process of the reconstructed features includes: inputting the masked query features as key vectors and value vectors into the Transformer decoder, and using a set of learnable surrogate vectors as query vectors. The Transformer decoder adopts a 4-layer cascaded architecture, with each layer including self-attention, cross-attention, and feedforward networks; performing feature repair on the masked query features through the Transformer decoder, and outputting reconstructed features that are aligned with the dimensions of the original query features. The process of generating the reconstructed similarity includes: calculating the cosine similarity between the reconstructed feature and the original query feature to obtain the reconstructed similarity, wherein the original query feature is the query feature before spatial information blocking.

[0010] As a further improvement to the above technical solution, the process of generating the query residual offset and the abnormal residual offset includes: taking the normal reference feature aligned with the dimensions of the query feature and the abnormal reference feature as the normal baseline feature, calculating the difference between the query feature and the normal baseline feature, and the difference between the abnormal reference feature and the normal baseline feature, respectively, to obtain the query residual offset and the abnormal residual offset. It also includes: introducing two sets of learnable dynamic scalar parameters to adaptively fuse the query features and query residual offsets, and the abnormal reference features and abnormal residual offsets, respectively, to obtain fused query features and fused abnormal features.

[0011] As a further improvement to the above technical solution, the abnormal pattern prototype data is mined from the abnormal residual offset, including: introducing a set of learnable abnormal agents as query vectors, using the fused abnormal features as key vectors, using the abnormal residual offsets as value vectors, aggregating the abnormal residual response data through a multi-head cross-attention mechanism to obtain preliminary agent representation data; and refining the preliminary agent representation data using self-attention features to obtain abnormal pattern prototype data. The process of generating an anomaly guidance graph from the matching results of the anomaly pattern prototype data and the query residual offset includes: using the anomaly pattern prototype data as the query vector, the fused query feature as the key vector, and the query residual offset as the value vector, generating a preliminary response graph through a cross-attention mechanism, and refining the preliminary response graph through self-attention to obtain the anomaly guidance graph.

[0012] As a further improvement to the above technical solution, the generation process of the pixel-level anomaly score map includes: utilizing the normal guiding map Reconstructing similarity and abnormal guidance diagram Calculate pixel-level anomaly score maps: ; in, This indicates element-wise multiplication, and 1 indicates multiplication with the normal guide graph. Similarity to reconstruction All-one score maps with the same spatial dimension This is a normal prior penalty term. To reconstruct the difference terms.

[0013] As a further improvement to the above technical solution, the method further includes: during the training phase, using a joint loss function to perform end-to-end optimization of the learnable parameters introduced in the decentralized representation reconstruction, feature reconstruction, and anomaly pattern prototype data mining, wherein the joint loss function is: ; in, To divide the loss, For classifying losses, For reconstruction loss.

[0014] This invention also provides an industrial image anomaly detection system based on sparse reference samples, comprising: a sample acquisition module for acquiring an industrial image to be detected, a sparse normal reference sample set, and an abnormal reference sample set, using the industrial image to be detected as a query sample; a hierarchical feature extraction module for extracting hierarchical feature flows from the query sample, the normal reference sample set, and the abnormal reference sample set, respectively; a decentralized representation reconstruction module for performing decentralized representation reconstruction on the hierarchical feature flows to obtain scale- and channel-aligned query features, normal reference features, and abnormal reference features; and a normal pattern reconstruction module for generating a normal guide map from the similarity matching result between the query features and the normal reference features, generating a spatial mask based on the normal guide map, and reconstructing the query features... The system performs spatial information blocking and reconstruction to obtain reconstructed features, and calculates the feature similarity between the reconstructed features and the corresponding query features before spatial information blocking to obtain a reconstruction similarity. An anomaly pattern mining module decouples the query features and anomaly reference features relative to the normal reference features to obtain query residual offsets and anomaly residual offsets. Anomaly pattern prototype data is mined from the anomaly residual offsets, and an anomaly guidance map is generated from the matching results of the anomaly pattern prototype data and the query residual offsets. A dynamic fusion output module dynamically weights and fuses the normal guidance map, reconstruction similarity, and anomaly guidance map to obtain a pixel-level anomaly score map, and outputs image-level anomaly detection results based on the pixel-level anomaly score map.

[0015] Compared with existing technologies, the industrial image anomaly detection method and system proposed in this invention have the following advantages: 1. Feature calibration is performed through decentralized representation reconstruction (DRR) to overcome centripetal collapse. By removing the common mean term of the background through spatial global decoupling, the centripetal collapse trend of the pre-trained model is reversed at the topological level. Combined with anomaly perception projection to amplify the sensitivity to local distortion, high-fidelity discrimination of minor anomalies is ensured.

[0016] 2. Few-sample normal pattern reconstruction (FNPR) breaks the identity mapping dilemma. It generates an accurate dynamic spatial mask by utilizing the prior differences between the query sample and the normal reference, which blocks the leakage of anomalous signals at the physical level, forcing the network to strictly rely on the normal manifold for structural repair and cutting off the anomalous propagation path.

[0017] 3. Anomaly pattern mining (APM) in the difference space suppresses statistical noise interference. The matching perspective is shifted to the difference residual space, and a learnable anomaly agent is used to extract cross-domain migration defect prototypes from the residuals, successfully isolating background texture statistical noise and significantly improving localization accuracy. This invention achieves image-level AUROC of 97.1% and 94.07% respectively, and pixel-level AUROC of 96.0% and 97.6% respectively on the MVTecAD and VisA datasets in 1-shot format, demonstrating extremely high robustness. Attached Figure Description

[0018] Figure 1 This is a schematic diagram of the industrial image anomaly detection method in an embodiment of the present invention; Figure 2 This is a schematic diagram of the industrial image anomaly detection system in an embodiment of the present invention; Figure 3 A comparison diagram showing the effect of implementing the industrial image anomaly detection method of the present invention with existing technology methods; Figure 4 This is a flowchart of the algorithm for an industrial image anomaly detection method provided in an embodiment of the present invention; Figure 5 This is a flowchart of the decentralized representation reconstruction operation provided in the embodiments of the present invention; Figure 6 This is a flowchart of the few-sample normal pattern reconstruction (FNPR) operation provided in an embodiment of the present invention; Figure 7 This is a flowchart of the Anomaly Pattern Mining (APM) operation provided in this embodiment of the invention. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and examples.

[0020] See Figure 1 As shown, this invention provides a method and system for detecting anomalies in industrial images based on sparse reference samples. The method includes the following steps: S1: Obtain the industrial image to be detected, a sparse set of normal reference samples, and a set of abnormal reference samples, and use the industrial image to be detected as a query sample. S2: Extract hierarchical feature flows from the query sample, the normal reference sample set, and the abnormal reference sample set respectively; S3: Decentralize the representation and reconstruct the hierarchical feature flow to obtain scale- and channel-aligned query features, normal reference features, and abnormal reference features; S4: Generate a normal guide map based on the similarity matching results between the query features and the normal reference features. Generate a spatial mask based on the normal guide map. Block and reconstruct the query features using spatial information to obtain the reconstructed features. Obtain the reconstruction similarity from the feature similarity between the reconstructed features and their corresponding original query features. S5: Perform residual decoupling on the query feature and abnormal reference feature relative to the normal reference feature to obtain the query residual offset and abnormal residual offset; S6: Mine out the prototype data of abnormal patterns from the abnormal residual offsets, and generate an anomaly guide graph from the matching results of the abnormal pattern prototype data and the query residual offsets. S7: Perform dynamic weighted fusion of normal guide maps, reconstructed similarity maps, and abnormal guide maps to obtain pixel-level anomaly score maps and output image-level anomaly detection results.

[0021] like Figure 4 As shown, the algorithm of this invention takes query samples, sparse normal reference sample sets and abnormal reference sample sets as inputs. After the decentralized representation reconstruction module outputs alignment features, it enters the few-sample normal pattern reconstruction branch and the abnormal pattern mining branch respectively. Among them, the FNPR branch outputs the normal guide map and reconstruction similarity, and the APM branch outputs the abnormal guide map. The three types of results are dynamically weighted and fused to form the final abnormal score map.

[0022] Corresponding to Figure 2 The system structure shown in this invention includes: a sample acquisition module, a hierarchical feature extraction module, a decentralized representation reconstruction module, a normal pattern reconstruction module, an abnormal pattern mining module, and a dynamic fusion output module. The sample acquisition module acquires query samples, a normal reference sample set, and an abnormal reference sample set; the hierarchical feature extraction module extracts hierarchical feature flows; the decentralized representation reconstruction module generates query features, normal reference features, and abnormal reference features; the normal pattern reconstruction module generates a normal guide map, a spatial mask, reconstructed features, and reconstructed similarity; the abnormal pattern mining module generates query residual offsets, abnormal residual offsets, abnormal pattern prototype data, and abnormal guide maps; and the dynamic fusion output module generates pixel-level abnormal score maps and outputs image-level abnormal detection results.

[0023] Example 1 In this embodiment, the decentralized representation reconstruction module sequentially performs spatial decentralized residual construction, anomaly-aware projection, and two-layer weight fusion on the hierarchical feature stream. Among them, each layer of features is globally decoupled in the spatial dimension and the spatial average term is subtracted to obtain decentralized residual features. The decentralized residual features are subtracted by the normal mode projection component to generate anomaly-aware features, and then aligned by scale and channel to form query features, normal reference features, and anomaly reference features.

[0024] Combination Figure 5 As shown in the process, the DRR module first decentralizes the hierarchical features extracted by DINOv2, then uses normal proxy vectors and multi-head attention to obtain and subtract normal mode projection components, and finally upsamples, aligns channels and fuses multi-scale features of anomaly perception features at different levels.

[0025] In the self-supervised representation paradigm of industrial anomaly detection, DINOv2, with its geometric prior discriminative ability obtained through pre-training, establishes a superior upper bound for global representation. However, directly transferring this general backbone network to the industrial domain leads to significant representation misalignment, rooted in two inherent conflicts: the centripetal collapse of normal patterns and multi-scale semantic barriers. To address these dual bottlenecks, this invention proposes a DRR strategy, deconstructing the traditional linear feature propagation path and innovatively connecting three core components: spatially decentralized residual construction, anomaly-aware projection, and two-layer weight fusion.

[0026] Spatial decentralized residual construction: Input includes query samples sparse normal reference sample set and a single abnormal reference sample The outputs of layers 3, 6, 9, and 12 are extracted using DINOv2 with frozen parameters to construct hierarchical feature flows. ,in To reverse the "centripetal collapse" of the normal pattern in the feature space, we globally decouple the features of each layer in the spatial dimension, deriving the residual feature set: and The spatial dimensions of the features at this layer are represented respectively. This operation removes the dominant anchor point (spatial mean term) of the global distribution at the topological level, forcing subsequent representation interactions to strictly focus on non-stationary local responses that deviate from the normal center, thereby achieving nonlinear amplification of potential anomaly information without introducing zero additional parameters.

[0027] Anomaly-aware projection: Although the preceding "mean removal" operation weakens the interference of the global background, the residual features The internal structure may still contain semantic fragments of local normal patterns. The anomaly-aware projection mechanism can purify anomalous signals into a subspace orthogonal to the normal distribution through adaptive feature decoupling. Specifically, we construct a set of learnable surrogate vectors. This is used as a baseline anchor point to represent the "normal pattern." In the calculation process, the first step is to... Flattened into a sequence along spatial dimensions Subsequently, using the input sequence For query vectors, use normal proxy vectors Using the multi-head cross-attention (MHA) mechanism as the key and value, the projected component that is highly similar to the "normal pattern" in the input features is calculated and extracted. Finally, this common component is explicitly subtracted from the original features. Two-layer weighted fusion: To address the issue of multi-scale features not being directly aggregated, features at all scales are uniformly upsampled to the spatial resolution of the final layer features, and their channel dimensions are strictly aligned to the final layer's resolution through a linear mapping. To properly allocate the "attention" of each layer during feature addition, we introduce a two-layer fusion weight. It is achieved through element-wise multiplication ( The results obtained from the normalized calculation are as follows: As a spatial prior, shallow layers are given greater weight to strongly preserve pixel-level details of tiny imperfections; This is a uniformly initialized adjustment matrix, allowing the network to dynamically optimize the importance of each layer based on the specific anomaly distribution. This coupling mechanism of static prior and dynamic fine-tuning not only preserves the model's natural sensitivity to weak anomalies but also endows it with high flexibility in cross-scale aggregation.

[0028] Formula (1)-Formula (3), Represents the features of the i-th layer. Let B represent the decentralized residual feature of the i-th layer, B represent the batch size, and N represent the number of input samples. This represents the number of channels in the i-th layer. , Alternatively, H and W represent the spatial dimensions of the corresponding layer features. L represents the spatial location index; C represents the channel dimension; MHA represents the multi-head cross-attention mechanism; Wcombined represents the two-layer fusion weight identifier. Represents spatial prior weights, This represents a learnable, dynamically adjustable matrix, where i and j represent hierarchical indices.

[0029] After the three stages of enhancement and refinement described above, we finally obtained high-quality features with uniform dimensions. For different image inputs, the backbone network outputs normal reference features respectively. Query features and abnormal reference features The tensor dimensions of these three types of features are all strictly aligned to . (in (The number of tokens after flattening the spatial dimensions).

[0030] Example 2 In this embodiment, the FNPR branch flattens and aggregates normal reference features along the sample dimension and spatial dimension to form a normal feature library; a normal guide map is generated from the strongest response of the query feature and the normal feature library with the cosine similarity; the normal guide map is mapped by the Sigmoid function and truncated by a hard threshold to obtain a spatial mask; the masked query features blocked by the spatial mask are used as reconstruction input to obtain reconstructed features aligned with the dimensions of the original query features, and the cosine similarity between the reconstructed features and the original query features is calculated as the reconstruction similarity.

[0031] like Figure 6 As shown, the FNPR branch first calculates the normal guide graph using normal prior matching, then generates a spatial mask through Sigmoid mapping and hard thresholding, and uses this spatial mask to obtain the masked query features; the masked query features serve as the keys and values ​​of the Transformer decoder to participate in structural reconstruction, and the reconstructed features and the original query features are further calculated to obtain the reconstruction similarity.

[0032] To address the identity mapping trap in decoders under sparse reference sample scenarios, this invention proposes the FNPR branch. This branch uses sparse normal reference samples as priors to generate a spatial mask, actively masking potentially anomalous regions. It transforms unconstrained reconstruction into structural repair under constrained conditions, forcing the model to rely solely on local normal context for inference and filling in gaps, thus cutting off anomalous transmission at the physical pathway level. This method comprises three key steps: normal prior matching calculation, dynamic masking and structural reconstruction, and anomalous score evaluation guided by normal samples.

[0033] Normal prior matching calculation: given query features With normal characteristics ( (For the normal sample size), firstly, break the isolation of dimensions, and then... Flatten and aggregate along the sample and spatial dimensions This allows for the construction of a dense reference library encompassing global normal representations. For any spatial location of a query feature... In the latent space, the cosine similarity between the anchor point and all normal features in the reference library is calculated, and the strongest response value is extracted as the normal matching score for that anchor point. The resulting normal boot diagram In its physical essence, this value characterizes the degree to which local features fit the projection of normal features. The closer this value is to 1, the more the local pattern follows a normal distribution, thus providing reliable prior guidance for subsequent preliminary stripping and masking of high-risk anomaly regions.

[0034] Dynamic masking and structural reconstruction: in obtaining normal guidance maps Then, we use the Sigmoid function to map it to the probability space and apply a hard threshold. Truncate the data to generate a binary spatial mask. Subsequently, based on this mask, element-wise information blocking in the spatial domain is performed on the query features: This represents element-wise multiplication. Through the above operations, we introduce a strict information bottleneck at the input: only high-confidence normal regions (masked with 1) are allowed to participate in subsequent calculations, while suspected anomalous local features (masked with 0) are completely blocked. The core motivation of this design is to completely cut off the propagation loop of anomalous signals through physical forced "blinding"; to force the decoder to rely on the remaining normal contextual relationships for logical deduction and feature repair, thereby fundamentally blocking the shortcut for the network to degenerate into an "identity mapping".

[0035] In the feature restoration stage, masking features These are fed as keys and values ​​into the Transformer decoder. The decoder employs a 4-layer cascaded architecture and introduces a set of learnable surrogate vectors. As a query, relying on the standard decoding paradigm of "self-attention-cross-attention-feedforward network," the network adaptively extracts global dependencies and refines and repairs representations layer by layer. Finally, the decoder outputs high-fidelity reconstructed features. It achieves strict alignment with the original query features in terms of dimensions.

[0036] Anomaly score evaluation guided by normal samples: In this implementation, the reconstructed similarity is calculated by the cosine similarity between the reconstructed features and the original query features before spatial information blocking, as shown in the following formula: Formula (4)-Formula (6), This represents the query characteristics (i.e., the original query characteristics). represents the normal reference feature, b represents the batch index, m represents the spatial location index of the query feature, n represents the normal reference sample index, t represents the spatial location index in the normal feature library, and ||·|| represents the vector norm. Indicates the similarity of the reconstructions; Indicates the reconstruction features.

[0037] Example 3 In this embodiment, the APM branch performs residual decoupling on the query features and abnormal reference features relative to the normal reference features to obtain query residual offset and abnormal residual offset; two sets of learnable dynamic scalar parameters are introduced to obtain fused query features and fused abnormal features; then, learnable abnormal agents, multi-head cross-attention mechanism and self-attention features are used to refine and mine abnormal pattern prototype data, and an abnormal guidance graph is generated from the matching results of abnormal pattern prototype data and query residual offset.

[0038] like Figure 7 As shown, the APM branch first forms the query residual offset RQ and the abnormal residual offset RA through differential decoupling, and then adaptively fuses them with the original features. Subsequently, the abnormal agent forms abnormal pattern prototype data under the action of the fused abnormal features and abnormal residual offsets. The abnormal pattern prototype data then interacts with the fused query features and query residual offsets to generate an abnormal guidance graph.

[0039] To address the issues of insufficient sensitivity to subtle defects and the masking of anomalous features by the normal background in the few-sample normal reconstruction branch, this invention proposes the APM branch. This branch shifts the matching perspective from the absolute feature space to the residual space, explicitly modeling the anomalous distribution by actively filtering out homogeneous backgrounds, and then distilling highly generalizable anomalous pattern prototypes. This branch consists of three core modules: differential decoupling, prototype mining, and anomaly focusing.

[0040] Differential Decoupling: To effectively remove common interferences from the normal background and highlight anomalies, we first perform residual decoupling within the feature space. Given the normal features extracted by the backbone network... Query features and abnormal characteristics (Tensor dimension is) We calculate the residual offsets of the query and the abnormal features relative to the normal features, respectively: in, The spatial offset of samples from their normal distribution is explicitly quantified. This operation filters out homogeneous background semantics through a differencing mechanism, allowing residual features to focus on anomaly cues with high fidelity.

[0041] Subsequently, to balance the integrity of the original spatial information with the strong discriminativeness of the residual features, we introduce two sets of learnable dynamic scalar parameters. Adaptive fusion is performed on the original features and residual features: Features after fusion , While maintaining the global semantic context, it significantly amplifies the feature differences of local anomalies, providing highly discriminative input for subsequent anomaly mining.

[0042] Prototype Mining: The prototype mining module aims to distill anomaly pattern prototypes with cross-domain transferability from a limited set of anomaly samples. Specifically, this module introduces a set of learnable anomaly proxies. As a query vector, to fuse features As the key, based on residual characteristics Value. Leveraging the multi-head cross-attention mechanism, feature E can... Guided by global semantics, targeted aggregation High-frequency abnormal responses in the data are used to obtain preliminary proxy characterization data. : Subsequently, to enhance semantic consistency among agents and filter out redundant noise, we cascaded a self-attention operation pair. Feature refinement is performed. The final output is... This is prototype data for anomalous patterns. The prototype data explicitly encodes the essential features that deviate from the normal distribution in a small number of samples. This design achieves anomalous feature aggregation through residual space, transforming scattered local anomaly clues into highly generalized structured priors, thereby effectively overcoming the generalization bottleneck in scenarios with scarce samples.

[0043] Exception Focusing: Obtaining Exception Pattern Prototypes Subsequently, the AF module aims to dynamically adapt it to the current query sample to achieve accurate location of abnormal regions. Specifically, this module uses a prototype... As a query, to integrate query features As a key, with residual characteristics As a value, the higher-order anomaly prior interacts deeply with the query features through a cross-attention mechanism, selectively activating potential anomaly regions in the residual space that highly match the pattern, generating a preliminary response map. In Equations (11) to (12), CrossAttention represents the calculation of cross attention.

[0044] Subsequently, the response map is further refined through a cascaded self-attention mechanism to enhance the spatial coherence of anomalous activation regions, ultimately outputting a high-fidelity anomaly guidance map. Compared to conventional raw feature comparison, this residual space-based pattern matching completely eliminates aliasing interference from the normal background, thus exhibiting high perceptual sensitivity to minute feature shifts and effectively mitigating the missed detection of subtle defects.

[0045] Example 4 In this embodiment, the dynamic fusion output module adjusts the normal guide map, reconstructed similarity, and abnormal guide map to the same spatial dimension, and generates a pixel-level abnormal score map according to the pixel-level fusion formula; during the training phase, a joint loss function is used to perform end-to-end optimization of the learnable parameters introduced in decentralized representation reconstruction, feature reconstruction, and abnormal pattern prototype data mining.

[0046] To integrate multi-dimensional discriminative clues, we will reconstruct the normal guidance graph of the branches. Reconstructing similarity And the anomaly guidance graph of the anomaly pattern mining branch. Dynamic weighted fusion is performed to obtain the final pixel-level anomaly score map. : in, This indicates element-wise multiplication. The strategy uses "reconstruction quality" as an adaptive weight: when local reconstruction similarity is high, the model is more inclined to trust explicit anomalous pattern matching results. Conversely, when the reconstruction quality is poor, it relies more on the penalty term resulting from deviations from normal priors. .

[0047] Furthermore, to achieve end-to-end optimization of the network, we construct a joint loss function that encompasses pixel-level segmentation, image-level classification, and feature-level reconstruction: Segmentation loss ( Combining Focal Loss and Dice Loss for pixel-level anomaly maps With the real mask Supervision is conducted to sharpen boundary positioning: Classification loss ( The binary cross-entropy (BCE) loss is used to compare the image-level prediction results with the true class labels. Perform global discrimination and alignment: Reconstruction loss ( The reconstructed features of the decoder output are constrained using the mean square error (MSE). Compared with the original query features Consistency in representation between them: In formula (13), 1 represents the relationship with... and A single-score map with the same spatial dimension; in formula (16) This represents the image-level prediction result.

[0048] Example 5 In the experimental phase, this invention utilizes two publicly available anomaly detection datasets, MVTec AD and VisA. To objectively and systematically evaluate the performance of the proposed DDAD framework in anomaly detection tasks, we conducted a comprehensive quantitative comparison with several cutting-edge few-shot anomaly detection (FSAD) methods on the MVTec AD and VisA benchmark datasets (results are shown in Table 1). The comparison baselines cover self-supervised visual foundation models (such as AnomalyDINO and NAGL), visual-language cue learning (such as PromptAD, WinCLIP, IIPAD, and ReMP-AD), and convolutional neural networks (ResAD). In the experimental setup, we adopted a configuration more closely aligned with practical industrial applications: "few-shot normal images + single-shot anomaly images" (…). ) paradigm, respectively in The image-level classification capability and pixel-level fine-grained localization capability were tested under the specified configuration.

[0049] The metrics used include AUROC: the area under the ROC curve (True Positive Rate vs. False Positive Rate); AP: the area under the Precision-Recall curve; F1-max: the maximum F1-Score among all possible classification thresholds; and AUPRO: the area under the PRO curve, where the horizontal axis of the PRO curve represents the false positive rate and the vertical axis represents the region overlap rate.

[0050] Detection and localization performance on the MVTec AD dataset: On the MVTec AD dataset, DDAD demonstrates excellent and robust performance under various small sample settings.

[0051] Image-level anomaly detection: The proposed model maintains extremely high classification accuracy across different sample sizes. In the scenario where data is extremely scarce (N=1), our method achieves an I-AUROC of 97.1%, a 0.5% improvement over the second-best method, AnomalyDINO (96.6%). When the number of supporting samples increases to N=2, our method achieves an I-AUROC of 97.69% and an AP of 98.41%, further improving upon AnomalyDINO by 0.79% and 0.21%, respectively, under the same conditions. This demonstrates the model's effective absorption and generalization ability for features from extremely scarce samples.

[0052] Pixel-level fine-grained segmentation: For the crucial defect boundary delineation capability in industrial quality inspection, the AUPRO metric, which measures local segmentation accuracy, is the most convincing evaluation standard. DDAD demonstrates a consistently leading advantage in this metric. Under 1-shot conditions, our method achieves an AUPRO of 93.48%, exceeding the suboptimal baseline NAGL (92.9%) by 0.58 percentage points; when N=4, the AUPRO further improves to 93.98% (leading NAGL by 0.78 percentage points). This continuous leap in strict segmentation metrics fundamentally verifies the effectiveness of the proposed APM branch and normal pattern reconstruction mechanism, successfully overcoming the inherent defect of reconstruction networks easily falling into identity mappings under weak supervision.

[0053] Generalization validation on the VisA dataset in complex scenarios: Given that the VisA dataset contains more complex industrial target topologies and highly concealed logical anomalies, this benchmark can intuitively reflect the model's cross-domain generalization ability under complex background disturbances. On this dataset, DDAD exhibits a more dominant data performance.

[0054] A comprehensive leap in image-level metrics: As shown on the right side of Table 1, DDAD has achieved groundbreaking progress on the VisA dataset. Under the stringent N=1 configuration, our method achieves 94.07% I-AUROC, 94.58% AP, and 90.12% F1-max. Compared to the suboptimal methods in this setting (ReMP-AD's I-AUROC is 91.3%, F1-max is 87%, and NAGL's AP is 89.4%), our method achieves absolute improvements of 2.77%, 3.12%, and 5.18%, respectively. When N=4, the proposed method's AP (95.64%) still leads AnomalyDINO by 3.04 percentage points. This demonstrates that when facing complex structures, DDAD can stably construct an effective global semantic benchmark, whereas other baseline methods are prone to feature collapse due to limited support samples.

[0055] Precise Capture of Complex Logical Defects: In pixel-level evaluation, DDAD also demonstrates extremely strong anti-interference capabilities. Its P-AUROC consistently maintains a leading level of 97.6% to 97.8%. More importantly, its AUPRO metric significantly outperforms suboptimal methods in all small sample settings: surpassing ReMP-AD by 1.45 percentage points (93.65% vs. 92.2%) when N=1, and expanding its lead to 1.64 percentage points (94.54% vs. 92.9%) when N=4. This further confirms that by introducing a single anomalous reference sample (A¹) and combining it with pattern mining, the model can still keenly activate subtle anomalous features that violate global distributions when facing varied non-target interference (such as complex PCB backgrounds or irregular layouts), demonstrating strong potential for industrial deployment.

[0056] Table 1 Qualitative visualization analysis (such as Figure 3 The above quantitative conclusions are further corroborated by the data shown. Compared to PromptAD or ResAD, DDAD achieves more accurate spatial localization of anomalous regions with fewer false alarms. Especially when dealing with subtle defects in categories such as "cashews" and "pills," the heatmaps generated by DDAD are highly consistent with the actual labels. This framework effectively suppresses background noise and response drift problems common in existing methods, demonstrating its high sensitivity to fine-grained feature shifts that deviate from the global distribution. These characteristics highlight the robustness of DDAD in practical industrial deployments.

[0057] Figure 3 The upper half of the image corresponds to object examples from the MVTec AD dataset, and the lower half corresponds to object examples from the VisA dataset. Each row sequentially displays the original image, ground truth label, and heatmap results of PromptAD, ResAD, AnomalyDINO, IIPAD, ReMP-AD, and the method of this invention (Ours) for different industrial objects. The comparison shows that existing methods exhibit background response diffusion or target region shift on objects with complex textures or minor defects, such as carpets, pills, capsules, cashews, and printed circuit boards, while the response region of the method of this invention is more concentrated at the actual anomaly location.

[0058] Example 6 This invention is specifically applied to small-sample industrial anomaly detection based on a visual fundamental model, achieving high-precision identification and localization of subtle defects in complex industrial scenarios. To deeply quantify and verify the independent contributions and synergistic mechanisms of the three core modules—Decentralized Representation Reconstruction (DRR), Few-Shot Normal Pattern Reconstruction (FNPR), and Anomaly Pattern Mining (APM)—detailed ablation experiments were conducted on six key network configurations under the most challenging 1-shot setting. Specific quantitative results are detailed in Table 2.

[0059] Limitations of the Baseline Model: Experimental results show that the baseline model, which relies solely on the pre-trained visual base model (DINOv2) for feature extraction, performs poorly. On the MVTec AD and VisA datasets, its image-level AUROC is only 63.51% and 60.04%, respectively, and its fine-grained localization metric AUPRO is also as low as around 53%. This indicates that although the original features of the general-purpose visual model have semantic priors, they lack sensitivity to anomalies specific to industrial domains, making it difficult to extract discriminative anomaly representations under complex industrial background interference. This underscores the urgency and necessity of introducing the subsequent three major components.

[0060] Performance gains driven by single components: Introducing any of the proposed innovative modules enables the model to break through the baseline bottleneck, and each module exhibits significant differences in its performance improvement focus. 1) The embedding of the DRR module enables the I-AUROC of MVTec AD to reach 95.05% (an improvement of 31.54% over the baseline), verifying the calibration effect of spatially decentralized residual construction, anomaly-aware projection, and two-layer weight fusion on hierarchical feature flow. 2) After embedding the FNPR module alone, the pixel-level localization index P-AUROC of the VisA dataset is significantly improved to 97.94%, verifying the constraint effect of normal prior matching, dynamic masking, and structural reconstruction on the feature reconstruction process. 3) When APM is used as an independent diagnostic branch without the assistance of other modules, it can still raise the core index of both datasets to over 90%, which is attributed to its explicit modeling of the anomaly distribution in the residual space through anomaly pattern prototype data mining, generating anomaly guidance maps with sharp responses and clear boundaries.

[0061] Synergistic Effect and Generalization Bottleneck of Dual Components: The dual-component configuration (DRR+FNPR) exhibits preliminary synergistic effects on the MVTec AD dataset, with both I-AUROC (96.22%) and AUPRO (93.19%) outperforming the single-module configuration. This demonstrates the complementarity between high-discrimination representation and robust reconstruction weights. However, on the more logically complex VisA dataset, this combination encounters a generalization bottleneck (I-AUROC only 90.2%), which profoundly reveals that in complex cross-domain scenarios, relying solely on normal pattern reconstruction is insufficient to completely solve the "identity mapping" problem, necessitating the introduction of direct anomaly supervision signals.

[0062] Multi-component global collaboration: When the three modules work together, the network achieves a global improvement in classification and localization performance. The I-AUROC on the MVTec AD dataset reaches 97.1%, and on the VisA dataset, the I-AUROC increases from 90.2% with the two-component configuration to 94.07%, with AUPRO reaching 93.65%. These results correspond to... Figure 4 The overall process is as follows: DRR generates scale- and channel-aligned query features, normal reference features, and abnormal reference features; FNPR outputs a normal guide map and reconstruction similarity; APM outputs an abnormal guide map; and the three are dynamically weighted and fused to obtain a pixel-level abnormal score map.

[0063] Table 2 Ablation Experiment Results of Core Module Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the implementation methods of the present invention, and should be understood that the scope of protection of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific modifications and combinations based on the technical teachings disclosed in this invention without departing from the spirit of the invention, and these modifications and combinations are still within the scope of protection of the present invention.

Claims

1. An industrial image anomaly detection method based on sparse reference samples, characterized in that, include: Acquire the industrial image to be detected, a sparse set of normal reference samples, and a set of abnormal reference samples, and use the industrial image to be detected as a query sample. Hierarchical feature flows are extracted from the query sample, the normal reference sample set, and the abnormal reference sample set, respectively. The hierarchical feature flow is reconstructed by decentralization to obtain scale- and channel-aligned query features, normal reference features, and abnormal reference features; A normal guide map is generated based on the similarity matching results between the query features and normal reference features; a spatial mask is generated based on the normal guide map, and the query features are spatially blocked and reconstructed to obtain reconstructed features; the feature similarity between the reconstructed features and their corresponding query features is calculated to obtain the reconstruction similarity. The query feature and the abnormal reference feature are decoupled relative to the normal reference feature to obtain the query residual offset and the abnormal residual offset. The abnormal residual offset is used to mine the abnormal pattern prototype data, and the matching result between the abnormal pattern prototype data and the query residual offset is used to generate an abnormal guidance graph. The normal guide map, reconstructed similarity, and abnormal guide map are dynamically weighted and fused to obtain a pixel-level anomaly score map, and the image-level anomaly detection result is output.

2. The industrial image anomaly detection method based on sparse reference samples according to claim 1, characterized in that, The normal reference sample set includes N normal reference samples, where N is 1, 2 or 4; The abnormal reference sample set includes a single abnormal reference sample; Extracting hierarchical feature flows from the query sample, normal reference sample set, and abnormal reference sample set respectively includes: inputting the query sample, each normal reference sample, and the single abnormal reference sample into the DINOv2 model with frozen parameters, extracting the output features of the 3rd, 6th, 9th, and 12th layers, and constructing the hierarchical feature flows.

3. The industrial image anomaly detection method based on sparse reference samples according to claim 1, characterized in that, The decentralized representation reconstruction of the hierarchical feature flow includes: constructing spatially decentralized residuals for each layer of features in the hierarchical feature flow, globally decoupling in the spatial dimension, and subtracting the spatial average term of each layer's features to obtain decentralized residual features; flattening the decentralized residual features along the spatial dimension into an input sequence, using the input sequence as a query vector, and using a learnable normal surrogate vector as the key vector and value vector, extracting the normal pattern projection component through a multi-head cross-attention mechanism, and subtracting the normal pattern projection component from the decentralized residual features to obtain anomaly perception features; uniformly upsampling the anomaly perception features of each layer to the spatial resolution of the final layer's features, aligning the channel dimension through linear mapping, and performing feature fusion based on the two-layer fusion weights obtained by element-wise multiplication and normalization of spatial prior weights and a learnable dynamic adjustment matrix to obtain the query features, normal reference features, and anomaly reference features.

4. The industrial image anomaly detection method based on sparse reference samples according to claim 3, characterized in that, The process of generating the normal guide map includes: flattening and aggregating the normal reference features along the sample dimension and spatial dimension to construct a normal feature library; calculating the cosine similarity between any spatial location of the query feature and each normal feature in the normal feature library, and extracting the strongest response value as the normal matching score for that spatial location; and generating the normal guide map from the normal matching scores of each spatial location. The process of generating a spatial mask based on the normal guidance graph and blocking spatial information of the query features includes: mapping the normal guidance graph to a probability space using a Sigmoid function and applying a hard threshold to truncate it, generating a binarized spatial mask; and blocking element-by-element information of the query features in the spatial domain based on the spatial mask to obtain masked query features.

5. The industrial image anomaly detection method based on sparse reference samples according to claim 4, characterized in that, The reconstruction process of the reconstructed features includes: inputting the masked query features as key vectors and value vectors into the Transformer decoder, and using a set of learnable surrogate vectors as query vectors. The Transformer decoder adopts a 4-layer cascaded architecture, with each layer including self-attention, cross-attention, and feedforward networks; performing feature repair on the masked query features through the Transformer decoder, and outputting reconstructed features that are aligned with the dimensions of the original query features. The process of generating the reconstructed similarity includes: calculating the cosine similarity between the reconstructed feature and the original query feature to obtain the reconstructed similarity, wherein the original query feature is the query feature before spatial information blocking.

6. The industrial image anomaly detection method based on sparse reference samples according to claim 5, characterized in that, The process of generating the query residual offset and the abnormal residual offset includes: taking the normal reference feature aligned with the dimensions of the query feature and the abnormal reference feature as the normal baseline feature, calculating the difference between the query feature and the normal baseline feature, and the difference between the abnormal reference feature and the normal baseline feature, respectively, to obtain the query residual offset and the abnormal residual offset. It also includes: introducing two sets of learnable dynamic scalar parameters to adaptively fuse the query features and query residual offsets, and the abnormal reference features and abnormal residual offsets, respectively, to obtain fused query features and fused abnormal features.

7. The industrial image anomaly detection method based on sparse reference samples according to claim 6, characterized in that, Mining prototype data of abnormal patterns from the abnormal residual offsets includes: introducing a set of learnable abnormal agents as query vectors, using the fused abnormal features as key vectors, using the abnormal residual offsets as value vectors, aggregating abnormal residual response data through a multi-head cross-attention mechanism to obtain preliminary agent representation data; refining the preliminary agent representation data with self-attention features to obtain prototype data of abnormal patterns. The process of generating an anomaly guidance graph from the matching results of the anomaly pattern prototype data and the query residual offset includes: using the anomaly pattern prototype data as the query vector, the fused query feature as the key vector, and the query residual offset as the value vector, generating a preliminary response graph through a cross-attention mechanism, and refining the preliminary response graph through self-attention to obtain the anomaly guidance graph.

8. The industrial image anomaly detection method based on sparse reference samples according to claim 7, characterized in that, The generation process of the pixel-level anomaly score map includes: using the normal guide map Reconstructing similarity and abnormal guidance diagram Calculate pixel-level anomaly score maps: ; in, This indicates element-wise multiplication, and 1 indicates multiplication with the normal guide graph. Similarity to reconstruction All-one score maps with the same spatial dimension This is a normal prior penalty term. To reconstruct the difference terms.

9. The industrial image anomaly detection method based on sparse reference samples according to claim 8, characterized in that, Also includes: During the training phase, a joint loss function is used to perform end-to-end optimization of the learnable parameters introduced in the decentralized representation reconstruction, feature reconstruction, and anomaly pattern prototype data mining. The joint loss function is: ; in, To divide the loss, For classifying losses, For reconstruction loss.

10. An industrial image anomaly detection system based on sparse reference samples, characterized in that, include: The sample acquisition module is used to acquire the industrial image to be detected, a sparse normal reference sample set, and an abnormal reference sample set, and to use the industrial image to be detected as a query sample. The hierarchical feature extraction module is used to extract hierarchical feature flows from the query sample, the normal reference sample set, and the abnormal reference sample set, respectively. The decentralized representation reconstruction module is used to perform decentralized representation reconstruction on the hierarchical feature flow to obtain scale- and channel-aligned query features, normal reference features, and abnormal reference features. The normal mode reconstruction module is used to generate a normal guide map from the similarity matching result between the query feature and the normal reference feature, generate a spatial mask based on the normal guide map, perform spatial information blocking and reconstruction on the query feature to obtain the reconstructed feature, and calculate the feature similarity between the reconstructed feature and the query feature before spatial information blocking to obtain the reconstruction similarity. An anomaly pattern mining module is used to perform residual decoupling on the query feature and the anomaly reference feature relative to the normal reference feature, respectively, to obtain query residual offset and anomaly residual offset. Anomaly pattern prototype data is mined from the anomaly residual offset, and an anomaly guidance graph is generated from the matching result of the anomaly pattern prototype data and the query residual offset. The dynamic fusion output module is used to dynamically weight and fuse the normal guide map, the reconstructed similarity, and the abnormal guide map to obtain a pixel-level anomaly score map, and output the image-level anomaly detection result based on the pixel-level anomaly score map.