An adaptive anomaly detection method based on feature fusion and screening
An adaptive anomaly detection method based on feature fusion and filtering utilizes the ConvNeXt-Tiny backbone network and a multi-scale differential attention feature extraction module to dynamically filter key features and adaptively fuse them, thus solving the problem of interference from complex background noise and improving the accuracy of anomaly detection and localization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGSHA UNIVERSITY OF SCIENCE AND TECHNOLOGY
- Filing Date
- 2026-04-16
- Publication Date
- 2026-06-09
AI Technical Summary
Existing unsupervised anomaly detection methods lack sufficient detection and localization accuracy when dealing with anomalies with large size variations, complex anomaly structures, and minute defects, especially in complex background areas where they are prone to noise interference.
An adaptive anomaly detection method based on feature fusion and filtering is adopted, including a ConvNeXt-Tiny backbone network, a multi-scale differential attention feature extraction module, a parallel flow module, and an adaptive feature fusion flow module. Anomaly detection results and region localization are output through a dynamic anomaly scoring strategy.
It enhances the response capability to edges, textures and small abnormal areas, reduces background noise interference, improves detection performance in complex texture and small defect scenes, and achieves high-precision anomaly localization.
Smart Images

Figure CN122176475A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of anomaly detection technology, and in particular to an adaptive anomaly detection method based on feature fusion and screening. Background Technology
[0002] Unsupervised anomaly detection aims to identify and locate anomalous regions in test samples by training models using only normal samples. It has significant application value in fields such as surface defect detection in industrial products and medical image analysis. Based on different modeling methods, existing approaches mainly include reconstruction-based methods, synthesis-based methods, feature embedding-based methods, and probability density estimation methods based on normalized flow.
[0003] Reconstruction-based methods typically utilize generative models such as autoencoders or generative adversarial networks. By learning the distribution of normal samples pixel by pixel, the model can reconstruct normal regions well, but it struggles to accurately recover unseen anomalous regions, using the reconstruction error to achieve anomaly detection. However, while this method has strong generalization capabilities, anomalous regions may be incorrectly reconstructed; that is, for images with complex textures or minor anomalies, the reconstruction error may be small enough to prevent their identification.
[0004] Feature embedding-based methods utilize pre-trained networks to efficiently establish the local feature distribution of normal samples and identify anomalies through distance metrics or memory matching. This method performs well in anomaly localization for images with simple categories, but when anomaly features exhibit complex structures or significant scale variations, different categories of features tend to overlap in spatial distribution, making it difficult to effectively distinguish between anomalies and normal features.
[0005] Synthetic methods achieve anomaly detection by generating pseudo-defects in normal samples for supervised training. While such methods can provide effective supervision signals for the model in the absence of real anomaly samples, the synthesized pseudo-defects are usually relatively simple in form and differ significantly from real defects in morphology and distribution, thus limiting the model's generalization performance.
[0006] In recent years, normalized flow models have been introduced into unsupervised anomaly detection. This method maps complex data distributions to simple Gaussian distributions through invertible transformations and has been widely used due to its advantages in accurate likelihood estimation and invertible density modeling. It identifies anomalous samples by learning the probability distribution of normal samples and using the log-likelihood or probability density of the samples as anomaly scores. However, while existing methods have achieved multi-scale feature modeling through strategies such as cross-scale flow structures and attention mechanisms, current fusion methods ignore the distributional differences between features at different scales. Furthermore, the uniform modeling of simple background regions and complex structural regions weakens the model's ability to model key anomalous features. The resulting background redundancy noise interferes with the flow model's accurate estimation of key anomaly distributions, particularly affecting the detection and localization performance of minute defects. Summary of the Invention
[0007] (a) Technical problems to be solved
[0008] Based on this, the present invention provides an adaptive anomaly detection method based on feature fusion and screening to solve the problems mentioned in the background art, such as the difficulty in detection caused by large variations in anomaly size and insufficient modeling ability of key anomaly features, as well as the insufficient detection and positioning accuracy of complex anomaly structures and minute defects.
[0009] (II) Technical Solution
[0010] To achieve the above objectives, this invention provides an adaptive anomaly detection method based on feature fusion and filtering, comprising:
[0011] Step S1: Construct and train an anomaly detection model based on feature fusion and filtering;
[0012] The anomaly detection model includes a pre-network structure and a dynamic anomaly scoring strategy structure; the pre-network structure is used for feature extraction, and the dynamic anomaly scoring strategy structure is used to output anomaly detection results and anomaly region localization.
[0013] The pre-network structure includes a ConvNeXt-Tiny backbone network, a multi-scale differential attention feature extraction module, a parallel flow module, and an adaptive feature fusion flow module; the processing flow of the pre-network structure specifically includes:
[0014] Step L1: Input the image into the pre-trained ConvNeXt-Tiny backbone network to obtain multi-scale features in four stages. ;in, Indicates the stage number;
[0015] Step L2: The multi-scale differential attention feature extraction module is used for differential modeling and feature enhancement to obtain multi-scale differential attention features. ;
[0016] Step L3: [The text appears to be incomplete and contains several grammatical errors. A more accurate translation would require the full context.] The input is independently encoded by asymmetric parallel streaming modules to obtain streaming features. ;
[0017] Step L4: The input adaptive feature fusion stream module obtains the fused features. ;
[0018] The input to the dynamic anomaly scoring strategy structure is ;
[0019] Step S2: Input the image to be detected into the trained anomaly detection model, and output the anomaly detection result and anomaly region location.
[0020] Specifically, in step L1, the image is input into a pre-trained ConvNeXt-Tiny backbone network; this backbone network consists of four stages, each outputting feature maps at different scales, with the number of output channels for each stage being 96, 192, 384, and 768, respectively; the multi-scale features output by the four stages are denoted as... , , and The spatial resolution and number of channels of the multi-scale features output at different stages are different. These are shallow, high-resolution features. It represents deep, low-resolution features.
[0021] Specifically, in step L2, when describing the multi-scale differential attention feature extraction module, the input is set as... to The outputs correspond to to ;
[0022] First, multi-scale features Each sample is downsampled using average pooling, and then adjusted to the same number of channels using a 1×1 convolution. ;
[0023] Next, a layer-by-layer difference fusion strategy is adopted, specifically: features ; By using bilinear interpolation Upsampling to With the same spatial resolution, and The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. ; By using bilinear interpolation Upsampling to At the same spatial resolution, with The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. ; By using bilinear interpolation Upsampling to At the same spatial resolution, with The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module, which outputs features. ;Will After restoring the original number of channels through convolutional layers, the final result is obtained. .
[0024] Specifically, in step L2, when describing the difference attention mechanism module, the input features are set as difference features. and fusion features The output features are First, the differences in characteristics Channel attention weights are generated by using channel attention and spatial attention mechanisms respectively. Spatial attention weights Next, a learnable scaling factor is introduced. After multiplying the spatial attention weights and channel attention weights generated above, the result is combined with the fused features obtained from cross-layer fusion. Perform multiplication; then, with residual perturbation, combine with the original fused features. Add them together; finally, output the enhanced feature representation processed by the difference attention mechanism. As shown below:
[0025] .
[0026] Specifically, in step L3, the parallel flow module includes four independent parallel branches. Each branch uses a normalized flow structure block capable of inverse transformation for feature mapping, where the normalized flow structure block is called a Flow block, and the number of cascaded Flow blocks differs in different branches; specifically, , , and After passing through 2, 5, 6, and 8 Flow blocks respectively, we obtain... , , and .
[0027] Specifically, in step L4, the adaptive feature fusion flow module includes a key feature extraction module, whose process includes downsampling and upsampling. When describing the downsampling process of the adaptive feature fusion flow module, shallow key features are dynamically selected from shallow features and then concatenated with adjacent next-layer features along the channel dimension. Deep fusion is then achieved through convolution operations. This process is repeated layer by layer to build a bottom-up encoding structure. In detail... Obtained through the key feature extraction module ; and The fused features are obtained through concatenation and convolution. ; and The fused features are obtained through concatenation and convolution. ; and The fused flow features are obtained through concatenation and convolution. Symmetrically, the upsampling process progressively backfeeds information with global receptive fields from deep features to shallow features, resulting in fused stream features; specifically... After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features ;
[0028] The key feature extraction module includes a teacher weight generator, a student weight generator, and a threshold calculator; the teacher weight generator is used to generate the importance ranking of each channel of the input features, and the student weight learner is used to learn the importance ranking of each channel of the input features generated by the teacher weight generator.
[0029] When describing the key feature extraction module, let the input be features. Its dimensions are First, Compressing operation yields Its dimensions are Next, feature filtering and rearrangement are performed to obtain... The process of filtering and rearranging is as follows:
[0030] Teacher weight generator dynamic evaluation The information content of each channel is distributed according to the channel importance based on the generation sample. The student weight generator uses learned parameters to output a channel importance distribution independent of the sample input data. During the training phase, by minimizing and The KL divergence loss between the two approaches allows the student weight generator to gradually approach the expected channel importance distribution of the teacher weight generator; during the inference phase, the student weight generator obtains a stable and reliable channel importance distribution without additional statistical computation. ;
[0031] An adaptive segmentation threshold is obtained using a threshold calculator. ;
[0032] When describing the threshold calculator, its input is: The processing flow includes:
[0033] Step a1: Extract global average pooling features using both global average pooling and standard deviation pooling. and standard deviation pooling features As shown below:
[0034]
[0035] in, Indicates global average pooling; Indicates standard deviation pooling;
[0036] Step a2: and After being concatenated, the data is input into the evaluation module to obtain the feature information score. As shown below:
[0037]
[0038] in, ; Represents the sigmoid function;
[0039] Step a3: According to the stage number and feature information scoring Generate adaptive segmentation threshold As shown below:
[0040]
[0041] in, Indicates the basic threshold constant; and All are coefficients;
[0042] Features The channels are sorted in descending order based on their importance distribution, and then sorted according to the segmentation threshold. Feature segmentation It consists of two parts, namely and As shown below:
[0043]
[0044] in, These are key features that retain the characteristics of highly important channels, including high-frequency edges, complex textures, and potential anomaly information; Non-critical features, including background or smoothed normal features, are removed from high-importance channel features. These non-critical features are diverted to the latent space as constraint outputs and do not participate in the fusion.
[0045] Specifically, in step L4, when describing the teacher weight generator, its input is... The processing flow includes:
[0046] Global average pooling and standard deviation pooling are used to extract global average pooling features respectively. and standard deviation pooling features ;
[0047] Will and After splicing, the data are sequentially input into the Multilayer Perceptron (MLP) and Softmax functions to obtain the channel importance distribution.
[0048] Specifically, in step L4, the input to the dynamic anomaly scoring strategy structure is: The intermediate output is a probability graph. A dynamic anomaly scoring strategy is proposed, which first uses a saliency-entropy dynamic weighting method for... Hierarchical probability graph The peak significance ratio is introduced to quantify the relative response intensity, as shown below:
[0049]
[0050] in, Indicates peak significance; Represents a constant;
[0051] Treating the probability graph as a spatial probability distribution, we calculate its normalized spatial Shannon entropy as follows:
[0052]
[0053] in, Represents entropy; Represents the normalized image pixels The probability of; Indicates the number of pixels in the image; Represents a constant;
[0054] based on and Calculate the first Hierarchical normalized adaptive weights As shown below:
[0055]
[0056] in, Represents an exponential function; ; ;
[0057] get Then, the probability maps at each scale are weighted and fused to obtain the fused probability map. As shown below:
[0058]
[0059] Since the output of the normalized flow model is a normal probability distribution, the final pixel-level anomaly score map will be obtained. Defined as an abnormal probability distribution to visually reflect the degree to which each pixel deviates from the normal manifold, as shown below:
[0060]
[0061] Finally, to generate robust image-level anomaly scores and discrimination results, the following approach is adopted: The aggregation mechanism identifies the highest probability anomalies in the score graph. The statistics were performed on each pixel, and the results are shown below:
[0062]
[0063] in, Indicates abnormal rating; The highest probability in the anomaly score graph 1 pixel; express The probability of an anomaly;
[0064] The dynamic anomaly scoring strategy structure outputs image-level anomaly detection results based on anomaly scores, and also outputs pixel-level anomaly region localization.
[0065] (III) Beneficial Effects
[0066] As can be seen from the above technical solution, the adaptive anomaly detection method based on feature fusion and screening proposed in this invention has the following beneficial effects:
[0067] 1. By using the multi-scale difference attention feature extraction module, the difference information between shallow and deep features is fully explored, which enhances the model's ability to respond to edges, textures and small anomaly regions.
[0068] 2. A key feature extraction module including a teacher-student weight generator and adaptive threshold segmentation is designed to dynamically select channel features with high information content to participate in fusion, and divert non-key features to the constraint space, which effectively reduces the interference of low information background noise on anomaly modeling, especially improving the detection performance in complex texture and small defect scenes.
[0069] 3. The peak significance ratio and normalized spatial Shannon entropy are introduced to adaptively weight and fuse the probability maps at each level, overcoming the neglect of the difference in anomaly response capability at different scales by the fixed weight fusion method; combined with the Top-K aggregation mechanism, image-level anomaly scores are generated, and pixel-level anomaly region localization is output. Attached Figure Description
[0070] The features and advantages of the invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the invention in any way. In the drawings:
[0071] Figure 1 This is a schematic diagram of the anomaly detection model based on feature fusion and screening of the present invention;
[0072] Figure 2 This is a schematic diagram of the multi-scale differential attention feature extraction module of the present invention;
[0073] Figure 3 This is a schematic diagram of the key feature extraction module of the present invention;
[0074] Figure 4 This is a visualization of the results of this invention on the MVTec-AD dataset;
[0075] Figure 5 This is a visualization of the results of this invention on the VisA dataset. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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, 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.
[0077] This invention provides an adaptive anomaly detection method based on feature fusion and filtering, comprising:
[0078] Step S1: Construct and train an anomaly detection model based on feature fusion and filtering;
[0079] like Figure 1 As shown, the anomaly detection model includes a pre-network structure and a dynamic anomaly scoring strategy structure; the pre-network structure is used for feature extraction, and the dynamic anomaly scoring strategy structure is used to output the anomaly detection results and locate the anomaly region.
[0080] The pre-processing network structure includes a ConvNeXt-Tiny backbone network, a multi-scale differential attention feature extraction module, a parallel stream module, and an adaptive feature fusion stream module. The processing flow of the pre-processing network structure is as follows: the image is input into the pre-trained ConvNeXt-Tiny backbone network to obtain multi-scale features in four stages. ,in, Indicates the stage (scale) number; The multi-scale differential attention feature extraction module is used for differential modeling and feature enhancement to obtain multi-scale differential attention features. ;Will The input is independently encoded by asymmetric parallel streaming modules to obtain streaming features. ;Will The fused stream features are obtained by inputting the adaptive feature fusion stream module. Specifically, this includes:
[0081] Step L1: Input the image into the pre-trained ConvNeXt-Tiny backbone network to obtain multi-scale features in four stages. ;
[0082] The image is input into a pre-trained ConvNeXt-Tiny backbone network; this backbone network consists of four stages, each outputting feature maps at different scales, with the number of output channels for each stage being 96, 192, 384, and 768, respectively; the multi-scale features output by the four stages are denoted as... , , and The spatial resolution and number of channels of the multi-scale features output at different stages are different. These are shallow, high-resolution features. It represents deep, low-resolution features.
[0083] Step L2: Input the multi-scale differential attention feature extraction module to obtain multi-scale differential attention features. ;
[0084] like Figure 2 As shown, when describing the multi-scale differential attention feature extraction module, the inputs are set to 1 to 4 (i.e., ... to The outputs of ) correspond to outputs 1 to 4 respectively (i.e. to ).
[0085] First, multi-scale features Each sample is downsampled using average pooling, and then adjusted to the same number of channels (768) using a 1×1 convolution. .
[0086] Next, a layer-by-layer difference fusion strategy is adopted, specifically: (1) Features (2) By using bilinear interpolation to... Upsampling to With the same spatial resolution, and The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. (3) Using bilinear interpolation to... Upsampling to With the same spatial resolution, and The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. (4) Using bilinear interpolation to... Upsampling to With the same spatial resolution, and The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module, which outputs features. (4) After restoring the original number of channels through a convolutional layer (i.e.) and (with the same number of channels), to obtain the final .
[0087] When describing the differential attention mechanism module, let the input features be differential features. and fusion features The output features are First, the differences in characteristics. Channel attention weights are generated by using channel attention and spatial attention mechanisms respectively. Spatial attention weights Next, a learnable scaling factor is introduced. After multiplying the spatial attention weights and channel attention weights generated above, the result is combined with the fused features obtained from cross-layer fusion. Perform multiplication. Then, using residual perturbation, combine it with the original fused features. Add them together. Finally, output the enhanced feature representation processed by the difference attention mechanism. As shown below:
[0088]
[0089] Step L3: [The text appears to be incomplete and contains several grammatical errors. A more accurate translation would require the full context.] The input is independently encoded by asymmetric parallel streaming modules to obtain streaming features. ;
[0090] The parallel flow module comprises four independent parallel branches. Each branch uses a reversibly transformable normalized flow structure block (i.e., a Flow block) for feature mapping, and the number of cascaded Flow blocks varies across branches. The core of the normalized flow structure block is an affine coupling layer, which achieves a strictly reversible transformation of the features by channel splitting the input features and using sub-networks to predict scaling and translation factors. The specific internal implementation structure of this affine coupling layer is prior art and will not be detailed here. Specifically, , , and After passing through 2, 5, 6, and 8 Flow blocks respectively, we obtain... , , and .
[0091] Because the number of flow blocks varies in each branch, the model can adaptively allocate modeling capacity according to the complexity of each multi-scale differential attention feature, thus achieving multi-scale differential attention feature processing. Highly efficient independent coding.
[0092] Step L4: The input adaptive feature fusion stream module obtains the fused features. ;
[0093] In multi-scale feature fusion, uniformly extracting and fusing all feature information can easily lead to the propagation of redundant features such as low-information backgrounds, thereby weakening the model's ability to model key feature information and limiting the accuracy of anomaly distribution modeling. The adaptive fusion flow module designed in this invention filters and adaptively segments features to select key features for fusion, suppressing redundant noise interference, achieving accurate modeling of complex anomalies, and improving overall anomaly detection performance.
[0094] The adaptive feature fusion module includes a key feature extraction module, whose process includes downsampling and upsampling. When describing the downsampling process of the adaptive feature fusion module, shallow key features are dynamically selected from shallow features and then concatenated with adjacent features from the next layer along the channel dimension. Deep fusion is then achieved through convolution operations; this process is repeated layer by layer to build a bottom-up encoding structure. Specifically, Obtained through the key feature extraction module ; and The fused features are obtained through concatenation and convolution. ; and The fused features are obtained through concatenation and convolution. ; and The fused flow features are obtained through concatenation and convolution. Symmetrically, the upsampling process progressively backfeeds information with global receptive fields from deep features to shallow features, resulting in fused stream features. Specifically, After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features .
[0095] The adaptive feature fusion module aggregates multi-scale contextual information and focuses on key feature regions in the image, greatly improving the model's accuracy in detecting complex anomalies and defects.
[0096] The key feature extraction module includes a teacher weight generator, a student weight generator, and a threshold calculator. The teacher weight generator is used to generate the importance ranking of each channel of the input features, and the student weight learner is used to learn the importance ranking of each channel of the input features generated by the teacher weight generator.
[0097] When describing the key feature extraction module, let the input be features. First, Compressing operation yields This improves channel modeling capabilities and reduces spatial resolution. Next, feature filtering and rearrangement are performed to obtain... The screening and rearrangement process is as follows:
[0098] (1) Dynamic evaluation of teacher weight generator The information content of each channel is distributed according to the channel importance based on the generation sample. The student weight generator uses learnable parameters to output a channel importance distribution independent of the sample input data. During the training phase, by minimizing and The KL divergence loss between the two approaches allows the student weight generator to gradually approach the expected channel importance distribution of the teacher weight generator; during the inference phase, the student weight generator can obtain a stable and reliable channel importance distribution without additional statistical computation. .
[0099] (2) Obtain the adaptive segmentation threshold based on the threshold calculator ;
[0100] When describing the threshold calculator, its input is: The processing flow includes:
[0101] Step a1: Extract global average pooling features using both global average pooling and standard deviation pooling. and standard deviation pooling features As shown below:
[0102]
[0103] in, Indicates global average pooling; This indicates standard deviation pooling.
[0104] Step a2: and After being concatenated, the data is input into the evaluation module to obtain the feature information score. As shown below:
[0105]
[0106] in, ; Represents the sigmoid function;
[0107] Step a3: According to the stage number and feature information scoring Generate adaptive segmentation threshold As shown below:
[0108]
[0109] in, Indicates the basic threshold constant; and All are coefficients;
[0110] (3) Features The channels are sorted in descending order based on their importance distribution, and then sorted according to the segmentation threshold. Feature segmentation It consists of two parts, namely and As shown below:
[0111]
[0112] in, These are key features that retain the characteristics of highly important channels, including high-frequency edges, complex textures, and potential anomaly information; Non-critical features, including background or smoothed normal features, are removed from high-importance channel features. These non-critical features are diverted to the latent space as constraint outputs and do not participate in the fusion.
[0113] The teacher weight generator represents the channel importance distribution generated by the teacher model during the training phase. When describing the teacher weight generator, its input is... The processing flow includes:
[0114] (1) Global average pooling and standard deviation pooling are used to extract global average pooling features respectively. and standard deviation pooling features ;
[0115] (2) and After concatenation, the data is sequentially input into the Multilayer Perceptron (MLP) and Softmax functions to obtain the channel weight distribution (i.e., the channel importance distribution).
[0116] The input to the dynamic anomaly scoring strategy structure is The intermediate output is a probability graph. (i.e., log-likelihood plot). Due to the scale variability of anomaly information, the log-likelihood plots output at different levels exhibit varying responsiveness to anomalies. Shallow features include minute texture defects, while deep features include structural anomalies. Therefore, this invention proposes a dynamic anomaly scoring strategy, first using saliency-entropy dynamic weighting for... Hierarchical probability graph The peak significance ratio is introduced to quantify the relative response intensity, as shown below:
[0117]
[0118] in, Indicates peak significance; Represents a constant;
[0119] Treating the probability graph as a spatial probability distribution, we calculate its normalized spatial Shannon entropy as follows:
[0120]
[0121] in, Represents entropy; Represents the normalized image pixels The probability of; Indicates the number of pixels in the image; Represents a constant.
[0122] The lower the entropy value, the more concentrated the response and the more obvious the abnormal structure.
[0123] based on and Calculate the first Hierarchical normalized adaptive weights As shown below:
[0124]
[0125] in, Represents an exponential function; ; ;
[0126] get Then, the probability maps at each scale (i.e., each level) are weighted and fused to obtain the fused probability map. As shown below:
[0127]
[0128] Since the output of the normalized flow model is a normal probability distribution, the final pixel-level anomaly score map will be obtained. Defined as an abnormal probability distribution to visually reflect the degree to which each pixel deviates from the normal manifold, as shown below:
[0129]
[0130] Finally, to generate robust image-level anomaly scores and discrimination results, the following approach is adopted: The aggregation mechanism identifies the highest probability anomalies in the score graph. The statistics were performed on each pixel, and the results are shown below:
[0131]
[0132] in, Indicates abnormal rating; The highest probability in the anomaly score graph 1 pixel; express The probability of an anomaly;
[0133] The dynamic anomaly scoring strategy structure outputs image-level anomaly detection results based on anomaly scores, and also outputs pixel-level anomaly region localization.
[0134] Step S2: Input the image to be detected into the trained anomaly detection model and output the anomaly region location.
[0135] To verify the effectiveness of the method of this invention, images from the MVTec-AD and VisA datasets were used as the images to be detected in experiments, and the results were visualized. The experimental results for the MVTec-AD and VisA datasets are as follows: Figure 4 and Figure 5As shown, the anomaly detection accuracies are 99.7% and 97.2%, respectively, and the pixel-level anomaly localization accuracies are 98.8% and 99.0%, respectively. The results demonstrate that the proposed method exhibits excellent anomaly and defect localization performance on both the MVTec-AD and VisA industrial datasets. In the MVTec-AD dataset, regardless of whether the background is simple or complex, the anomaly localization region of this method maintains a high degree of consistency with the real defect mask, achieving accurate localization and a low false negative rate even in scenarios with minute defects. In the VisA dataset, which contains multi-instance targets and complex structures, this method demonstrates excellent background suppression capabilities, effectively avoiding interference from complex background textures and normal features, and producing a strong and clearly defined high response at real minute defects. The visualization results intuitively demonstrate that the present invention has good detection accuracy and robustness for complex structures and minute defects.
[0136] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.
Claims
1. An adaptive anomaly detection method based on feature fusion and filtering, characterized in that, include: Step S1: Construct and train an anomaly detection model based on feature fusion and filtering; The anomaly detection model includes a pre-network structure and a dynamic anomaly scoring strategy structure; the pre-network structure is used for feature extraction, and the dynamic anomaly scoring strategy structure is used to output anomaly detection results and anomaly region localization. The pre-network structure includes a ConvNeXt-Tiny backbone network, a multi-scale differential attention feature extraction module, a parallel flow module, and an adaptive feature fusion flow module; The specific processing flow of the front-end network structure includes: Step L1: Input the image into the pre-trained ConvNeXt-Tiny backbone network to obtain multi-scale features in four stages. ;in, Indicates the stage number; Step L2: The multi-scale differential attention feature extraction module is used for differential modeling and feature enhancement to obtain multi-scale differential attention features. ; Step L3: [The text appears to be incomplete and contains several grammatical errors. A more accurate translation would require the full context.] The input is independently encoded by asymmetric parallel streaming modules to obtain streaming features. ; Step L4: The input adaptive feature fusion stream module obtains the fused features. ; The input to the dynamic anomaly scoring strategy structure is ; Step S2: Input the image to be detected into the trained anomaly detection model, and output the anomaly detection result and anomaly region location.
2. The method according to claim 1, characterized in that, In step L1, the image is input into a pre-trained ConvNeXt-Tiny backbone network. This backbone network consists of four stages, each outputting feature maps at different scales. The number of output channels for each stage is 96, 192, 384, and 768, respectively. The multi-scale features output by the four stages are denoted as follows: , , and The spatial resolution and number of channels of the multi-scale features output at different stages are different. These are shallow, high-resolution features. It represents deep, low-resolution features.
3. The method according to claim 2, characterized in that, In step L2, when describing the multi-scale differential attention feature extraction module, let the input be... to The outputs correspond to to ; First, multi-scale features Each sample is downsampled using average pooling, and then adjusted to the same number of channels using a 1×1 convolution. ; Next, a layer-by-layer difference fusion strategy is adopted, specifically: features ; By using bilinear interpolation Upsampling to At the same spatial resolution, with The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. ; By using bilinear interpolation Upsampling to With the same spatial resolution, and The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module to obtain the features. ; By using bilinear interpolation Upsampling to At the same spatial resolution, with The features are then added together and then subjected to a 3×3 convolution to obtain the fused features. Simultaneously, calculation Upsampled feature map and The absolute difference between them yields the difference characteristics. The differential features and fused features are input into the differential attention mechanism module, which outputs features. ;Will After restoring the original number of channels through convolutional layers, the final result is obtained. .
4. The method according to claim 3, characterized in that, In step L2, when describing the differential attention mechanism module, the input features are assumed to be differential features. and fusion features The output features are First, the differences in characteristics Channel attention weights are generated by using channel attention and spatial attention mechanisms respectively. Spatial attention weights Next, a learnable scaling factor is introduced. After multiplying the spatial attention weights and channel attention weights generated above, the result is combined with the fused feature obtained after cross-layer fusion. Perform multiplication; then, with residual perturbation, combine with the original fused features. Add them together; finally, output the enhanced feature representation processed by the difference attention mechanism. ; As shown below: 。 5. The method according to claim 4, characterized in that, In step L3, the parallel flow module includes four independent parallel branches. Each branch uses a normalized flow structure block capable of inverse transformation for feature mapping. This normalized flow structure block is called a Flow block, and the number of cascaded Flow blocks differs across branches. Specifically, , , and After passing through 2, 5, 6, and 8 Flow blocks respectively, we obtain... , , and .
6. The method according to claim 5, characterized in that, In step L4, the adaptive feature fusion flow module includes a key feature extraction module, and its process includes a downsampling process and an upsampling process. When describing the downsampling process of the adaptive feature fusion module, shallow features are dynamically filtered to identify key shallow features, which are then concatenated with the adjacent features of the next layer along the channel dimension. Deep fusion is then achieved through convolution operations; this process is repeated layer by layer to build a bottom-up encoding structure. Specifically... Obtained through the key feature extraction module ; and The fused features are obtained through concatenation and convolution. ; and The fused features are obtained through concatenation and convolution. ; and The fused flow features are obtained through concatenation and convolution. Symmetrically, the upsampling process progressively backfeeds information with global receptive fields from deep features to shallow features, resulting in fused stream features; specifically... After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features ; After upsampling operation and The splicing yields the fused flow features ; The key feature extraction module includes a teacher weight generator, a student weight generator, and a threshold calculator; the teacher weight generator is used to generate the importance ranking of each channel of the input features, and the student weight learner is used to learn the importance ranking of each channel of the input features generated by the teacher weight generator. When describing the key feature extraction module, let the input be features. Its dimensions are First, Compressing operation yields Its dimensions are ;then, Feature filtering and rearrangement are performed to obtain The process of filtering and rearranging is as follows: Teacher weight generator dynamic evaluation The information content of each channel is distributed according to the channel importance based on the generation sample. The student weight generator uses learned parameters to output a channel importance distribution independent of the sample input data. During the training phase, by minimizing and The KL divergence loss between the two approaches allows the student weight generator to gradually approach the expected channel importance distribution of the teacher weight generator; during the inference phase, the student weight generator obtains a stable and reliable channel importance distribution without additional statistical computation. ; The adaptive segmentation threshold is obtained based on the threshold calculator. ; When describing the threshold calculator, its input is: The processing flow includes: Step a1: Extract global average pooling features using both global average pooling and standard deviation pooling. and standard deviation pooling features As shown below: in, Indicates global average pooling; Indicates standard deviation pooling; Step a2: and After being concatenated, the data is input into the evaluation module to obtain the feature information score. As shown below: in, ; Represents the sigmoid function; Step a3: According to the stage number and feature information scoring Generate adaptive segmentation threshold As shown below: in, Indicates the basic threshold constant; and All are coefficients; Features The channels are sorted in descending order based on their importance distribution, and then sorted according to the segmentation threshold. Feature segmentation It consists of two parts, namely and As shown below: in, These are key features that retain the characteristics of highly important channels, including high-frequency edges, complex textures, and potential anomaly information; Non-critical features, including background or smoothed normal features, are removed from high-importance channel features. These non-critical features are diverted to the latent space as constraint outputs and do not participate in the fusion.
7. The method according to claim 6, characterized in that, In step L4, when describing the teacher weight generator, its input is: The processing flow includes: Global average pooling and standard deviation pooling are used to extract global average pooling features respectively. and standard deviation pooling features ; Will and After splicing, the data are sequentially input into the Multilayer Perceptron (MLP) and Softmax functions to obtain the channel importance distribution.
8. The method according to claim 7, characterized in that, In step L4, the input to the dynamic anomaly scoring strategy structure is: The intermediate output is a probability graph. ; A dynamic anomaly scoring strategy is proposed, which first uses a saliency-entropy dynamic weighting method for... Hierarchical probability graph The peak significance ratio is introduced to quantify the relative response intensity, as shown below: in, Indicates peak significance; Represents a constant; Treating the probability graph as a spatial probability distribution, we calculate its normalized spatial Shannon entropy as follows: in, Represents entropy; Represents the normalized image pixels The probability of; Indicates the number of pixels in the image; Represents a constant; based on and Calculate the first Hierarchical normalized adaptive weights As shown below: in, Represents an exponential function; ; ; get Then, the probability maps at each scale are weighted and fused to obtain the fused probability map. As shown below: Since the output of the normalized flow model is a normal probability distribution, the final pixel-level anomaly score map will be obtained. Defined as an abnormal probability distribution to visually reflect the degree to which each pixel deviates from the normal manifold, as shown below: Finally, to generate robust image-level anomaly scores and discrimination results, the following approach is adopted: The aggregation mechanism identifies the highest probability anomalies in the score graph. The statistics were performed on each pixel, and the results are shown below: in, Indicates abnormal rating; The highest probability in the anomaly score graph 1 pixel; express The probability of an anomaly; The dynamic anomaly scoring strategy structure outputs image-level anomaly detection results based on anomaly scores, and also outputs pixel-level anomaly region localization.