Industrial product unsupervised anomaly detection method and system based on conditional control diffusion model
By using a diffusion model based on conditional control and multi-scale dual attention mechanism, the problems of scale adaptability and noise interference in existing technologies are solved, achieving high accuracy and interpretability in industrial product anomaly detection.
Patent Information
- Application Number
- CN202511623468.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-07
- Publication Date
- 2026-02-03
AI Technical Summary
Existing technologies struggle to meet the feature representation requirements at different scales in industrial product anomaly detection, leading to loss of details or neglect of global contextual information. Furthermore, the generated heatmaps are severely affected by background noise, impacting the accuracy and interpretability of the detection.
A diffusion model based on conditional control and multi-scale dual attention mechanism is adopted. Semantic information at different scales is extracted through multi-scale convolutional blocks and parallel dual attention components. Combined with a two-stage background denoising algorithm and average post-sampling operation, accurate anomaly reconstruction images and clear anomaly heatmaps are generated.
It achieves accurate reconstruction of abnormal regions at different scales while preserving information of normal regions in the original image, and generates clear abnormal heatmaps, thus improving the accuracy and interpretability of detection.
Smart Images

Figure CN121458682A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of image processing and computer vision in computer intelligent information processing, and specifically relates to an unsupervised anomaly detection method and system for industrial products based on a conditional controlled diffusion model. Background Technology
[0002] In today's increasingly digital and automated era, anomaly detection technology has become an indispensable key technology in many fields, widely used in industrial product quality inspection, medical image-assisted diagnosis, and other scenarios. Traditional unsupervised anomaly detection methods mainly rely on statistical models and cluster analysis. Statistical model methods, represented by Gaussian mixture models, typically assume that the data follows a specific probability distribution and distinguishes between normal and abnormal samples by estimating distribution parameters. However, in complex real-world scenarios such as industrial quality inspection and medical image analysis, the data often has high dimensionality and complex structural features, making it difficult to conform to the distribution assumptions pre-set by statistical models. This limitation makes it difficult for statistical models to effectively extract and represent key features of images, thus weakening their ability to distinguish between normal and abnormal samples, making the accuracy of anomaly detection insufficient to meet practical needs. Cluster analysis-based methods divide the data into different clusters and identify data points far from the cluster center as anomalies. However, when faced with complexly distributed data, this method often struggles to select suitable clustering algorithms and parameters, and is prone to the "curse of dimensionality" problem when processing high-dimensional data, leading to a decline in clustering performance and thus affecting the accuracy of anomaly detection.
[0003] With the development of deep learning technology, deep learning methods based on models such as autoencoders have gradually emerged in the field of anomaly detection. Autoencoders learn the latent distribution of normal samples and construct a reconstruction model of the input image. This method aims to enable the trained model to reconstruct normal samples with a small reconstruction error, while incurring a large reconstruction error for anomalous samples, thus achieving anomaly identification. However, when processing image data with fine structure and rich details, autoencoders are prone to losing some information during encoding and decoding, resulting in feature loss. This information loss weakens the model's sensitivity to anomalous features, thus affecting detection accuracy and making it difficult to meet the performance requirements of practical applications. This problem is particularly prominent in subtle anomaly detection scenarios, where the inability of autoencoders to effectively capture subtle anomalous features ultimately leads to a significant decline in the model's detection performance.
[0004] Diffusion models, as an emerging generative modeling method, have achieved significant results in fields such as image generation. However, when applied to anomaly detection tasks, they still face two major problems: First, anomaly detection requires the model to accurately learn the feature distribution of normal samples in order to effectively identify anomalous samples. However, due to the lack of effective conditional control mechanisms, diffusion models struggle to focus on key features in normal samples, leading to biases in the learned feature distribution and affecting the overall performance of anomaly detection. Second, existing anomaly detection methods are severely affected by background noise when generating anomaly heatmaps. Anomaly heatmaps should intuitively present abnormal regions in an image, but excessive background noise can mask and confuse effective information, making it difficult to highlight the true defective regions. This not only interferes with the operator's accurate judgment of the location and severity of anomalies but also weakens the interpretability and practical application value of the anomaly detection results.
[0005] Several works on anomaly detection based on diffusion models have been published. For example, Dhariwal et al. proposed a classifier-guided diffusion model (DM) that achieves conditional image generation by introducing class labels. Chung et al. extended the diffusion solver, effectively handling the general noise inverse problem through a posterior sampling approximation method. Bercea et al. designed the AutoDDPM framework, which includes three stages: mask generation, image stitching, and resampling, forming a complete anomaly detection process. Lu et al. modeled the normal image reconstruction problem as a diffusion-driven denoising process. These works demonstrate the potential of generative models to reconstruct high-resolution normal images in unsupervised anomaly detection.
[0006] Although anomaly detection accuracy has been improved through techniques such as refining model architecture, optimizing noise handling, and enhancing feature mapping, the reconstruction process itself still lacks sufficient systematicity and controllability. While some methods have attempted to introduce external conditions to enhance control, such as DALL-E3 and ControlNet, which use additional text or image inputs to control the reconstruction process, and CCDM-UAD, which adds a conditional control subnetwork, these methods still have two limitations: (1) Industrial scenarios contain diverse anomalies, including subtle anomalies at the texture level (which require full preservation of original texture information) and large-area defects at the object level (which require higher reconstruction accuracy). Existing methods mostly adopt single-scale feature extraction strategies, which are difficult to take into account the feature expression needs at different scales, and are prone to loss of details or neglect of global context information. Therefore, the model is unable to accurately reconstruct anomaly regions at different scales while preserving normal region information in the original image, thus limiting the adaptability of conditional control networks in multi-scale scenarios.
[0007] (2) Regarding the construction of anomaly heatmaps, although the DIAD method proposed by He et al. is innovative, in-depth research has revealed two key problems: First, because the DIAD method lacks a focusing mechanism for key features of normal samples, the model is prone to losing detailed information related to anomaly discrimination during the encoding-decoding process, resulting in a weak response in subtle anomaly areas in the generated heatmap, making it difficult to highlight the real anomaly areas; Second, due to the complex industrial production environment, large areas of impurities are easily mixed into the collected data, which often results in unexpected noise responses in the background area of the generated heatmap. This interference information can obscure the real anomaly areas, leading to a decrease in the discernibility of the heatmap. Therefore, users cannot quickly and accurately locate anomaly areas based on the heatmap, nor can they reliably assess the degree of anomaly, seriously affecting the interpretability and practical usability of the detection results. Summary of the Invention
[0008] To address the problems existing in the prior art, this invention provides an unsupervised anomaly detection method for industrial products based on a diffusion model using conditional control and a multi-scale dual attention mechanism. The diffusion model based on conditional control and a multi-scale dual attention mechanism can effectively extract semantic information at different scales, enabling the conditional control network to receive semantic information from images at various scales and generate precise control signals to assist in defect reconstruction. This guides the denoising generation stage, ensuring that the reconstructed image maintains semantic consistency with the input image. Then, through a two-stage background denoising algorithm combined with average post-sampling image operations, more accurate anomaly detection and clear anomaly heatmap visualization are ultimately achieved.
[0009] To achieve the above objectives, the present invention provides the following solution: An unsupervised anomaly detection method for industrial products based on a diffusion model using conditional control and a multi-scale dual attention mechanism, the method comprising: A diffusion model based on conditional control and multi-scale dual attention mechanism is constructed. The diffusion model based on conditional control and multi-scale dual attention mechanism is used to reconstruct the test sample image to obtain a reconstructed image of the same size as the test sample image. By employing a two-stage background denoising algorithm combined with average post-sampling image operations, the test sample image and its reconstructed image are subjected to denoising, weighted fusion, average post-sampling, and heatmap generation operations using feature maps of various scales extracted by a pre-trained encoder, respectively, to generate the final anomaly heatmap, thereby achieving anomaly detection of the test sample.
[0010] Preferably, the diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder; The multi-scale dual attention module comprises multi-scale convolutional blocks and parallel dual attention components. The multi-scale convolutional blocks use convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention components are composed of channel compression and activation units and spatial compression and activation units, respectively, for feature recalibration. This module receives features output from the pre-trained encoder, processes them, and transmits them to the conditional control network. The signal generated by the conditional control network is processed and then input to the diffusion denoising network, interacting with the latent representation. Finally, the pre-trained decoder outputs the reconstruction result. The features output by the pre-trained encoder are: latent space representation ;in, The mean, For logarithmic variance, It is a random noise vector that follows a standard normal distribution; The denoising method of diffusion denoising network is as follows: the signal generated by the control network is processed and then input into the diffusion denoising network to interact with the latent representation and predict the noise. ,pass Iterative denoising, in which, For the diffusion process Step retention coefficient, The processed control signal, For time steps, For noisy latent representation, For the first The first step after denoising Latent space representation of the step; The method for outputting the reconstruction result by the pre-trained decoder is as follows: pre-trained decoder Potential representation of receiving recovery The transformation from the latent space to the original image space is achieved through multiple transposed convolution operations. The initial input is processed by the transposed convolution of the first layer, as shown in the formula. ,in, This is the feature map after the first layer of transposed convolution in the decoder. The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; The activation function performs the initial upsampling operation; subsequent upsampling operations... layer , , The total number of transposed convolutional layers in the decoder is given by the following formula: ,in, For decoder number Feature maps after layer transpose convolution processing For batch normalization operations, For the first Layer convolution kernel size, For bias, continuous upsampling is achieved by gradually increasing the feature map spatial size; finally, through... The number of channels is adjusted using the following formula: ,in, The reconstructed image is the final output of the decoder. For the output layer bias, we get ,make Compared with the original input image The dimensions are the same, thus completing the restoration from the latent space to the original image, that is, obtaining the reconstructed image.
[0011] Preferably, the method for denoising the feature map of the sample to be tested includes: preliminary filtering of background noise, refined denoising and enhancement of abnormal regions; The initial filtering of background noise is as follows: Feature maps at various scales are extracted from the test sample image and its reconstructed image using a pre-trained encoder. and Calculate feature maps at various scales and The cosine similarity between them yields the feature difference score map, and the formula is: ( ( ); The feature difference score maps at each scale are filtered based on a given threshold to filter out large, continuous regions of low outliers, thereby generating a mask map. ; mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. ; Will With reconstructed images Feature maps at the same scale Together, they will serve as input for the next stage.
[0012] Refined noise reduction and anomaly region enhancement are as follows: The feature map after initial denoising and The image is divided into small patches, and mean filtering is performed on each patch individually to obtain a denoised multi-scale feature map. and The formula for calculating the mean filter within a small image patch is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, For pixels within the filtering window, the horizontal direction (x-axis) relative to the center pixel is considered. The offset, For pixels within the filtering window, the vertical direction (y-axis) relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
[0013] Preferred methods for weighted fusion of feature maps of the test samples include: ; in, This is the initial anomaly feature map obtained after fusion. For the repetition order, For the first i Differential feature map at each scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy ; Feature difference map By analyzing the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map It is obtained by calculating the cosine similarity separately, and the specific calculation formula is as follows: .
[0014] The present invention also provides an unsupervised anomaly detection system for industrial products based on a conditional control diffusion model. The system is used to implement the aforementioned method and includes: a diffusion-conditional control reconstruction module and an anomaly detection and localization module. The diffusion-conditional control reconstruction module is used to construct a diffusion model based on conditional control and multi-scale dual attention mechanism. Using the diffusion model based on conditional control and multi-scale dual attention mechanism, the test sample image is reconstructed to obtain a reconstructed image of the same size as the test sample image. The anomaly detection and localization module is used to perform two-stage denoising, weighted fusion, average post-sampling, and heatmap generation operations on the feature maps of each scale extracted by the pre-trained encoder for the test sample image and its reconstructed image, using a two-stage background denoising algorithm combined with average post-sampling image operation, to generate the final anomaly heatmap, thereby realizing anomaly detection of the test sample.
[0015] Preferably, the diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder; The multi-scale dual attention module includes a multi-scale convolutional block and a parallel dual attention component. The multi-scale convolutional block uses convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention component consists of a channel compression and activation unit and a spatial compression and activation unit, which are used for feature recalibration. This module receives the features output by the pre-trained encoder, processes them, and transmits them to the control network. The signal generated by the control network is processed and input into the diffusion denoising network to interact with the latent representation. Finally, the pre-trained decoder outputs the reconstruction result. The features output by the pre-trained encoder are: latent space representation ;in, The mean, For logarithmic variance, It is a random noise vector that follows a standard normal distribution; The denoising process of the diffusion denoising network is as follows: the signal generated by the control network is processed and then input into the diffusion denoising network, interacting with the latent representation to predict noise. ,pass Gradual noise reduction, among which, For the diffusion process Step retention coefficient, The processed control signal, For time steps, For noisy latent representation, For the first The first step after denoising Latent space representation of the step; The process of the pre-trained decoder outputting the reconstruction result is as follows: Pre-trained decoder Potential representation of receiving recovery The transformation from the latent space to the original image space is achieved through multiple transposed convolution operations. The initial input is processed by the transposed convolution of the first layer, as shown in the formula. ,in, This is the feature map after the first layer of transposed convolution in the decoder. The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; The activation function performs the initial upsampling operation; subsequent upsampling operations... layer , , The total number of transposed convolutional layers in the decoder is given by the following formula: ,in, For decoder number Feature maps after layer transpose convolution processing For batch normalization operations, For the first Layer convolution kernel size, For bias, continuous upsampling is achieved by gradually increasing the feature map spatial size; finally, through... The number of channels is adjusted using the following formula: ,in, The reconstructed image is the final output of the decoder. For the output layer bias, we get ,make Compared with the original input image The dimensions are the same, thus completing the restoration from the latent space to the original image, that is, obtaining the reconstructed image.
[0016] Preferably, the two-stage denoising process for the feature map of the test sample includes: preliminary filtering of background noise, refined denoising, and enhancement of abnormal regions. The initial filtering of background noise is as follows: Feature maps at various scales are extracted from the test sample image and its reconstructed image using a pre-trained encoder. and Calculate feature maps at various scales and The cosine similarity is used to obtain the feature difference score map. The formula for calculating cosine similarity is: ( ( ); The feature difference score maps at each scale are filtered based on a given threshold to filter out large, continuous regions of low outliers, thereby generating a mask map. ; mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. ; Will and reconstructed images Feature maps at the same scale Together they serve as input for the next stage; Refined noise reduction and anomaly region enhancement are as follows: The feature map after initial denoising and The image is divided into small patches, and mean filtering is performed on each patch individually to obtain a denoised multi-scale feature map. and The formula for calculating the mean filter within a small image patch is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, For pixels within the filtering window, the horizontal direction (x-axis) relative to the center pixel is considered. The offset, For pixels within the filtering window, the vertical direction (y-axis) relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
[0017] Preferably, the process of weighted fusion of feature difference maps includes: ; in, This is the initial anomaly feature map obtained after fusion. For the repetition order, For the first i Differential feature map at each scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy ; Feature difference map By analyzing the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map The cosine similarity is calculated between them, and the specific calculation formula is as follows: .
[0018] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides an unsupervised anomaly detection method and system for industrial products based on a conditional control diffusion model. The diffusion model based on conditional control and a multi-scale dual attention mechanism can effectively extract semantic information at different scales, enabling the conditional control network to receive semantic information from images at various scales and generate precise control signals to assist in defect reconstruction. This guides the denoising generation stage, ensuring that the reconstructed image maintains semantic consistency with the input image. Then, through a two-stage background denoising algorithm combined with average post-sampling image operations, more accurate anomaly judgment and clear anomaly heatmap visualization can be achieved. Attached Figure Description
[0019] To more clearly illustrate the technical solution of the present invention, the drawings used in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a data processing flowchart for the diffusion-conditional control reconstruction stage in the method provided by the present invention; it shows the process of reconstructing the image from the input image through a pre-trained encoder, multi-scale dual attention, noise addition, conditional control diffusion denoising network, iterative denoising, and pre-trained decoder. Each processing step is represented by a box, and the directed arrows indicate the data flow direction. Figure 2 This is a data processing flowchart for the anomaly detection and localization stage in the method provided by the present invention; it shows the complete process of multi-scale feature extraction, two-stage denoising, multi-scale feature difference map fusion, average post-sampling, and heat map generation using a pre-trained feature extraction model. Each processing step is represented by a box, and the directed arrows indicate the data flow direction. Figure 3 This diagram illustrates the first stage of the two-stage denoising algorithm in the method provided by this invention; the diagram details the specific steps and data processing procedures. Figure 4 The diagram shows the second-stage denoising structure and anomaly heatmap generation process of the two-stage denoising algorithm provided in this invention; the diagram illustrates the specific steps and data processing process in detail. Figure 5 An anomaly heatmap generated directly without two-stage denoising; a comparison between the heatmap generated after one-stage denoising and the heatmap generated after two-stage denoising; Figure 6 The average post-sampling operation corresponds to the anomaly detection and localization stage; the left side shows the anomaly image. and After reconstructing the normal images, each image undergoes one-to-one feature extraction and similarity comparison to obtain... Zhang's feature difference map, through analysis of... After averaging the feature difference maps, the final anomaly heatmap can be obtained by applying the anomaly heatmap generation algorithm. ; Figure 7 for Figure 1 A simplified diagram is provided, illustrating different connection modes between the conditional control network and the stable diffusion model. The generation process is located on the left side of each example, and the control process is located on the right side, where the control network on the right side is the encoder part that replicates the original stable diffusion model SD network. (a) and (b) are two different control architectures (Type A) and (Type B), which differ in the way information is controlled between encoders and between encoders and decoders. Figure 8 A comparison of the reconstruction results of the input image by the diffusion model CCDM-MSDA based on conditional control and multi-scale dual attention mechanism provided by this invention with the Denoising Diffusion Probabilistic Models (DDPM) and Stable-Diffusion (SD) models. Figure 9 The image shows a comparison of reconstruction results using different average counts. Since the generative model generates results through random sampling, this uncertainty may make a single generated sample unreliable, leading to misjudgment. Therefore, this invention adopts the method of averaging multiple resampled images. The left side of the image shows the original image and the predicted anomaly heatmap. The right side of the image shows the reconstruction sampling results using different average counts (from left to right and from top to bottom, the average count gradually increases). Detailed Implementation
[0021] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0023] Example 1 Existing diffusion-based anomaly detection methods suffer from two major technical drawbacks: First, existing single-scale anomaly detection methods struggle to simultaneously address the representation needs of anomaly features at different scales, easily leading to loss of detail or neglect of global contextual information. Therefore, it is difficult to accurately reconstruct anomaly regions at different scales while preserving normal region information in the original sample image. Second, the generated heatmaps are severely affected by background noise and have a weak response to subtle anomaly regions, resulting in a large amount of noise in the heatmaps, failing to highlight true anomaly regions and thus impairing the accurate identification of anomalies.
[0024] This invention provides an unsupervised anomaly detection method for industrial products based on a conditionally controlled diffusion model, the method comprising: A diffusion model based on conditional control and multi-scale dual attention mechanism is constructed. The diffusion model based on conditional control and multi-scale dual attention mechanism is used to reconstruct the test sample image to obtain a reconstructed image of the same size as the test sample image. The test sample image and the reconstructed image are used to extract feature maps at different scales using the same pre-trained feature extraction model. Each scale feature map is then processed by a two-stage background denoising algorithm to obtain an initial anomaly feature map. The average value of multiple initial anomaly feature maps obtained using the same method is calculated to obtain the final anomaly feature map; A heatmap generation algorithm is used to process the final anomaly feature map to generate the final anomaly heatmap, thereby realizing anomaly detection of the sample to be tested.
[0025] In this embodiment, the diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder. The multi-scale dual attention module includes multi-scale convolutional blocks and parallel dual attention components. The multi-scale convolutional blocks use convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention components consist of channel compression and activation units and spatial compression and activation units, used for feature recalibration. This module receives features output from the pre-trained encoder, processes them, and then transmits them to the conditional control network (using...). Figure 7 The signal generated by the conditional control network (Type B architecture) is processed and then input into the diffusion denoising network, interacts with the latent representation, and finally outputs the reconstruction result through the pre-trained decoder; Specifically, such as Figure 1As shown, to address the first of the two major technical shortcomings mentioned above, this invention improves the proposed conditional control diffusion model CCDM-UAD by introducing the multi-scale dual attention mechanism provided in this invention into the CCDM-UAD model. This leads to the proposal of a diffusion model CCDM-MSDA based on conditional control and multi-scale dual attention mechanisms. Through a mechanism of "multi-scale dual attention + conditional control network + feature selection fusion attention," it achieves controllable transformation of anomalous samples into normal samples. Its core includes a pre-trained encoder. Multi-scale dual attention module, diffusion noise addition process, conditional control network, diffusion denoising network, and pre-trained decoder Specifically, it includes the following steps: Step 1: Input the image of the sample to be tested. Enter the pre-trained encoder The encoder consists of multiple convolutional layers, for... After performing convolution and ReLU activation operations, the model is progressively downsampled to output a feature map used to calculate the latent spatial distribution parameters. and Its function is to provide structured support for calculating latent spatial distribution parameters—preserving image semantic information while achieving dimensionality compression. Feature map and The mean of the latent space is obtained through specific operations. With log variance The parameters, i.e. , .in, It is used in the encoder to output the mean value. The parameter branch consists of one 1×1 convolutional layer, with the number of convolutional kernels equal to the potential spatial dimension. The parameters include the convolution kernel weights. With bias ,Right now ; It is used in encoders to output logarithmic variance. Parameter branches, structure and Consistent, the corresponding parameter is the convolution kernel weight. With bias ,Right now Then, by employing reparameterization techniques, we can utilize random noise vectors that follow a standard normal distribution and have the same dimension as the latent space. The latent space representation is derived. This completes the initial extraction and dimensionality reduction of image features. Among them, the random noise vector... Used to introduce randomness to meet the probabilistic modeling requirements of variational inference; Representing the normal distribution (Gaussian distribution), it is a mathematical symbol used to describe the probability distribution of a random variable; It is a dimension of The identity matrix ensures The distributions in each dimension of the latent space are independent of each other and have a variance of 1, ensuring the randomness and stability of the latent representation.
[0026] Step 2: Represent the latent space according to the rules of the diffusion and noise addition process. By gradually adding noise, we can obtain ( ,in For the diffusion process The latent space representation of the step, dimension and Consistency is a hybrid representation of initial latent features and accumulated noise, which varies with... As the noise level increases, the proportion of noise will gradually increase. The total number of diffusion steps is a preset positive integer hyperparameter, such as 1000 or 2000, used to control the fineness of noise addition. The larger the value, the smoother the transition. Noise is sampled from a standard normal distribution at each step. Through formula Update the latent representation, (where For the diffusion process The step retains the coefficient, which takes values in the open interval. ,satisfy And follow Monotonically decreasing, used to control exist The retention ratio in The smaller, The stronger the cumulative effect of noise in the middle. It is an independent and identically distributed standard Gaussian noise vector (taking values in the real number domain), from The noise obtained from the sampling is independent of each other and does not change with t. Finally... (T is the preset maximum number of noise addition steps) It approximately follows a standard Gaussian distribution. This allows for noise addition in the latent space according to diffusion rules.
[0027] Step 3: In the time step ( In this context, the conditional control network extracts multi-scale features from the input image based on a multi-scale dual attention module. Get control signal The feature extraction process of the multi-scale dual attention module is as follows: After the input image is pre-processed by the pre-trained encoder to obtain basic features F, F is input into the MSDA module: 1. Multi-scale feature extraction: The multi-scale convolutional block uses 3×3, 5×5 small-size convolutional kernels and 1×7 large-size convolutional kernels to extract features from F respectively, using the following formula: , , (in, for Convolution operation, (These correspond to the convolution biases, respectively), resulting in feature maps at different scales. , , 2. Parallel dual attention component processing: The channel compression unit uses global average pooling (GAP) to process the concatenated multi-scale features. Compressed into channel vectors, then passed through two fully connected layers ( FC 1. FC 2) Generation of channel weights after dimensionality reduction and activation ,in, Representing nonlinear functions; the spatial compression unit is processed by global max pooling (GMP) and global average pooling (GAP) respectively. Spatial weights are generated by concatenating the components and then performing a 1×1 convolution. 3. Weighted fusion: respectively with (Channel Dimension) (Spatial dimension) Element-wise multiplication, summation, yields the final multi-scale feature. , Will be used as a control signal The information is fed into the control network. In existing technologies, single-scale attention modules can only focus on local information and are unable to take into account features at different scales and global dependencies. To address this, this invention proposes a multi-scale dual attention module (MSDA). This module innovatively integrates multi-scale convolutional blocks (containing 3×3, 5×5, and 1×7 convolutional kernels) with parallel dual attention components: the multi-scale convolutional blocks can adapt to feature extraction from abnormal regions of different sizes (such as fine texture anomalies and large-area object defects), while the parallel channel compression and activation units and spatial compression and activation units can specifically recalibrate features. Through the collaborative weighting of "channel-space" dual weights, local patterns and global dependencies are integrated, feature fragmentation is avoided, and thus the conditional control effect is enhanced. The feature selection fusion attention module (FSFA) processes the data into... Traditional feature fusion methods indiscriminately retain redundant information, resulting in a lack of emphasis on key features. The FSFA module addresses this by adjusting the number of channels to ensure consistent feature dimensions across different levels, and then dynamically adjusting channel weights using channel gating vectors. This strengthens the weights of key anomalous feature channels and suppresses redundant channels, thereby resolving the interference from noise and redundant information in industrial data and improving the targeted nature of information delivery. Input diffusion denoising network, combined with To predict noise Through the denoising iterative formula Achieve gradual noise reduction. Among other things, For the front The cumulative product of the step retention coefficients; For the first The "feature retention coefficient" of the step has a range of values of 1000. Used to control the first The proportion of original latent features retained during the diffusion process ( The closer it is to 1, the more original features are preserved and the less noise is added; The closer to 0, the more noise is added. For the first The first step after denoising The latent space representation of the step, dimension and Consistency is a key intermediate carrier for the transition from noisy latent representations to clean latent representations, and its feature cleanliness increases with the number of iterations. (Decrease) Gradually increase, and eventually restore the latent representation. The specific process for recovering the latent representation is as follows: 1. Initialize the iteration starting point as... At this point, the noisy latent representation of the input diffusion denoising network is: (Approximately pure noise), synchronously input the current time step and the processed control signal 2. The diffusion denoising network is based on Predicting the first Step noise Substituting into the iterative denoising formula, we can calculate the result. 3. Decrease by 1, in order to As a new noisy input, repeat the "predict noise - compute denoised representation" process in step 2; 4. Continue iterating until... Calculations yielded This completes the reconstruction of the latent representation. Existing diffusion denoising techniques rely solely on... and time step The lack of feature guidance can easily lead to denoising bias. This solution introduces... (Carrying multi-scale feature information from the input image) Dynamically constraining the noise prediction direction makes the denoising process more closely match the true feature distribution of the image, thereby significantly improving... The recovery accuracy is improved. The multi-scale dual attention module uses convolutional kernels of different sizes for feature extraction, including two small-sized kernels (3×3, 5×5) and one large-sized kernel (1×7), to adapt to the feature extraction needs of objects of different sizes. The parallel dual attention component consists of a channel compression unit and a spatial compression unit. The channel compression unit compresses the feature map in the channel dimension through global average pooling, and then generates channel attention weights after dimensionality reduction through a fully connected layer to emphasize important channels. The spatial compression unit compresses the feature map in the spatial dimension through global max pooling and global average pooling, and then generates a spatial attention map through convolution after concatenating the two pooling results to highlight important regions. The optimized multi-scale features and the recalibrated attention map are combined through weighted fusion, where the attention weights are multiplied element-wise with the corresponding feature map and then accumulated to obtain the final feature representation.
[0028] Step 4: Pre-trained decoder Potential representation of receiving recovery This is achieved by using multiple layers of transposed convolution operations to transform the latent space into the original image space. The specific process is as follows: The initial input is processed by the transposed convolution of the first layer, as shown in the formula. (in The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; For activation function, This is the feature map after the first layer of the decoder's transposed convolution, used for the initial upsampling operation. Subsequent layers... layer ), The processing formula is: (total number of transposed convolutional layers in the decoder) (in, For batch normalization operations; For the first Layer convolution kernel size; For bias; For decoder number The feature map after transposed convolution is used to achieve continuous upsampling by gradually increasing the feature map spatial size (e.g., from 8×8 to 256×256). Finally, through... The number of channels is adjusted using the following formula: (in For output layer bias, (The reconstructed image is the final output of the decoder). Compared with the original input image The dimensions are the same, thus completing the reconstruction from the latent space to the original image.
[0029] Current anomaly detection methods do not denoise the extracted feature maps during anomaly detection and localization. Therefore, the final heatmap contains significant background noise, severely impacting the accurate identification of anomalous regions. In this embodiment, as... Figure 2 As shown, to address this problem (i.e., the second of the two major technical defects mentioned above), this invention proposes a two-stage denoising algorithm, which effectively removes background noise from the feature map. To obtain a smooth reconstructed region after denoising, this invention employs an average post-sampled anomaly feature image method. The specific steps of the anomaly detection and localization method based on two-stage denoising and average post-sampled anomaly feature images are as follows: Step 1: Use the CCDM-MSDA diffusion model based on conditional control and multi-scale dual attention mechanism to process the input original image. Reconstruction is performed to obtain the reconstructed image. Input image With reconstructed images Input into the same pre-trained feature extraction model (Based on a ResNet50 pre-trained on the ImageNet dataset), five feature maps at different scales are extracted. This model... The first 5 layers are structured as follows: Layer 1 is a 7×7 standard convolution (stride 2, output channels 64) + batch normalization + ReLU activation function, as shown in the formula. ( (For convolution bias); the second layer is 3×3 max pooling (stride 2), the formula is as follows: Layers 3-5 are all standard bottleneck residual blocks. The formula for layer 3 is... Output via residual connection The fourth and fifth layers have the same structure as the third layer, and output respectively. , Original image pass The multi-scale features extracted from different levels are represented as follows: Reconstructing the image pass The multi-scale features extracted from different levels are represented as follows: In these feature maps, low-scale features (such as...) High spatial resolution corresponds to high detail; while high-scale features (such as...) correspond to high spatial resolution, emphasizing details ... These features correspond to a high semantic level and reflect the overall structure of the image. Therefore, they provide multi-scale feature support for anomaly detection and localization.
[0030] Step 2: This invention proposes a two-stage denoising algorithm, which denoises the initial feature maps at each scale separately. and ( The following two-stage noise reduction process is performed: Phase 1: As Figure 3 As shown, this is the initial filtering of background noise.
[0031] First, calculate and The cosine similarity yields the feature difference score map, and the formula is: ( ( ); Secondly, for feature difference score maps at each scale, select the feature difference score map based on the given threshold. The image is filtered by using the percentage of elements less than 99.99% and the percentage of elements greater than or equal to 99.99% as a threshold, thus generating a mask image. (Noise area is 0, other areas are 1), this mask image can both retain areas with high outliers and remove large areas of background noise; Then, the mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. , Then no processing is required and the output is directly given. ; Finally, With reconstructed images Feature maps at the same scale Together, they will serve as input for the next stage.
[0032] Phase Two: As Figure 4 As shown, refined denoising and anomaly region enhancement are performed. The feature map after the initial denoising in the previous stage is then used. and (The process is as follows) Figure 3 (As shown in the diagram or see the first stage of the processing) The image is divided into small image patches of size 3, and then mean filtering is performed on each 3×3 small image patch individually. After mean filtering, the final multi-scale feature map after two stages of denoising will be obtained. and ( The specific expression is: , .in, For image patch division operations; Calculate the mean within the block; To restore small image patches to complete feature maps (see process below) Figure 4 Second-stage denoising). Small image patches. The formula for calculating the mean filter within the range is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, The pixels within the filtering window are positioned horizontally (x-axis) relative to the center pixel. The offset, The vertical direction (y-axis) of the pixels within the filtering window relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
[0033] Step 3: Process the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map ( Calculate the cosine similarity separately to obtain feature difference maps at each scale. The specific formula is as follows: By introducing The transformation makes The larger the value, the more significant the difference between the two feature maps, allowing it to directly reflect the degree of anomaly and provide a quantitative basis for subsequent anomaly localization.
[0034] Step Four: As Figure 4 As shown, the feature difference map for each scale. ( The initial anomaly feature map is obtained by fusing the features. , This indicates the first fusion, corresponding to the initial result. During fusion, existing methods average feature maps at different scales, while this invention averages feature maps at different scales. Assign different weights Integration is achieved through weighted summation, that is... .in, This is the initial anomaly feature map obtained after fusion. The order is repeated (see step five); For the feature difference map of the i-th scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy This process integrates multi-scale feature difference information, which can preserve low-scale detail differences and integrate high-scale semantic differences, thus providing a more comprehensive initial feature basis for anomaly detection.
[0035] Step 5: See Figure 4 and Figure 6 Repeat steps one through four above. Next, will get Zhang's abnormal feature map Regarding this The average value of the anomaly feature maps is calculated to obtain the final anomaly feature map. .
[0036] Step Six: Use a heatmap generation algorithm to generate the final anomaly feature map. The process is performed to generate the final anomaly heatmap. Specifically: First, will Normalize to [0, 255] and round down, the formula is: , Indicates the location The original value on; then, through Generate a JET color base heatmap. Among other things, This is a JET color mapping function that maps grayscale values to RGB color values. This represents the color value (usually represented as an RGB triple) after applying JET color mapping at position (x, y); finally, for the original image... through (in The mean value for image preprocessing. To preprocess the standard deviation, Original image The recovered image after inverse normalization restores the pixel values from the preprocessed normalized values (usually close to 0) to the original image. (The pixel range preserves the visual texture and spatial structure of the original image, providing a real image reference for subsequent heatmap fusion.) After inverse normalization, through... The weighted fusion is used to generate the final heatmap and then saved. This is a function in OpenCV that combines a JET pseudocolor image with another image with equal weights of 50% opacity to generate a blended image. This is the final generated anomaly heatmap.
[0037] Compared with existing anomaly detection techniques based on diffusion models, the advantages of the technical solution of this invention are: (1) The diffusion model CCDM-MSDA based on conditional control and multi-scale dual attention mechanism provided by this invention combines a stable diffusion model and a conditional control network (see Figure 7 This allows for more accurate learning of latent feature representations of normal samples. The multi-scale dual attention module in CCDM-MSDA extracts detailed information at different scales of the input image to maintain semantic consistency across these scales; the feature selection fusion attention mechanism extracts key features, thus more effectively reconstructing normal samples. Compared to traditional methods, the reconstruction results are significantly improved (see...). Figure 8 ).
[0038] (2) The anomaly detection and localization method based on a two-stage denoising method and an average post-sampled anomaly feature map provided by this invention greatly reduces background noise in the anomaly heatmap, making the anomaly area more prominent and clear, thereby achieving more accurate anomaly area localization, improving visualization quality, and making it easier for operators to accurately understand and analyze the detection results, thus improving the practical application value of anomaly detection. This is especially evident in detection scenarios with complex backgrounds and subtle anomaly areas. Specific effects are as follows: Figure 5 and Figure 9 As shown. By Figure 5 It can be seen that after using the two-stage denoising operation, the background noise of the abnormal heatmap was basically eliminated. Figure 9 It can be seen that after multiple average post-sampling operations, the details of the reconstructed object are smoother.
[0039] Example 2 The present invention also provides an unsupervised anomaly detection system for industrial products based on a conditional control diffusion model. The system is used to implement the method described in Embodiment 1. The system includes: a diffusion-conditional control reconstruction module and an anomaly detection and localization module.
[0040] The diffusion-conditional control reconstruction module is used to construct a diffusion model based on conditional control and multi-scale dual attention mechanism. Using the diffusion model based on conditional control and multi-scale dual attention mechanism, the test sample image is reconstructed to obtain a reconstructed image of the same size as the test sample image. The anomaly detection and localization module is used to perform denoising, weighted fusion, average post-sampling, and heatmap generation operations on the feature maps of various scales extracted by the pre-trained encoder for the test sample image and its reconstructed image through a two-stage background denoising algorithm combined with average post-sampling image operation, thereby generating the final anomaly heatmap and realizing anomaly detection of the test sample.
[0041] In this embodiment, the diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder. The multi-scale dual attention module includes multi-scale convolutional blocks and parallel dual attention components. The multi-scale convolutional blocks use convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention components consist of channel compression and activation units and spatial compression and activation units, used for feature recalibration. This module receives features output from the pre-trained encoder, processes them, and then transmits them to the conditional control network (using...). Figure 7 The signal generated by the conditional control network (Type B architecture) is processed and then input into the diffusion denoising network, interacts with the latent representation, and finally outputs the reconstruction result through the pre-trained decoder; The features output by the pre-trained encoder are: latent space representation ;in, The mean, For logarithmic variance, It is a random noise vector that follows a standard normal distribution; The denoising process of the diffusion denoising network is as follows: the signal generated by the control network is processed and then input into the diffusion denoising network, interacting with the latent representation to predict noise. ,pass Iterative denoising, in which, For the diffusion process Step retention coefficient, The processed control signal, For time steps, For noisy latent representation, For the first The first step after denoising Latent space representation of the step; The process of the pre-trained decoder outputting the reconstruction result is as follows: Pre-trained decoder Potential representation of receiving recovery The transformation from the latent space to the original image space is achieved through multiple transposed convolution operations. The initial input is processed by the transposed convolution of the first layer, as shown in the formula. ,in, This is the feature map after the first layer of transposed convolution in the decoder. The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; The activation function performs the initial upsampling operation; subsequent upsampling operations... layer , , The total number of transposed convolutional layers in the decoder is given by the following formula: ,in, For decoder number Feature maps after layer transpose convolution processing For batch normalization operations, For the first Layer convolution kernel size, For bias, continuous upsampling is achieved by gradually increasing the feature map spatial size; finally, through... The number of channels is adjusted using the following formula: ,in, The reconstructed image is the final output of the decoder. For the output layer bias, we get ,make Compared with the original input image The dimensions are the same, thus completing the restoration from the latent space to the original image, that is, obtaining the reconstructed image.
[0042] In this embodiment, the two-stage denoising process of the feature map of the sample to be tested includes: preliminary filtering of background noise, fine denoising and enhancement of abnormal regions. The initial filtering of background noise is as follows: Feature maps at various scales are extracted from the test sample image and its reconstructed image using a pre-trained encoder. and Calculate feature maps at various scales and The cosine similarity yields the feature difference score map, and the formula is: ( ( ); The feature difference score maps at each scale are filtered based on a given threshold to filter out large, continuous regions of low outliers, thereby generating a mask map. ; mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. ; Will With reconstructed images Feature maps at the same scale Together they serve as input for the next stage; Refined noise reduction and anomaly region enhancement are as follows: The feature map after initial denoising and The image is divided into small patches, and mean filtering is performed on each patch individually to obtain a denoised multi-scale feature map. and The formula for calculating the mean filter within a small image patch is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, The pixels within the filtering window are positioned horizontally (x-axis) relative to the center pixel. The offset, The vertical direction (y-axis) of the pixels within the filtering window relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
[0043] In this embodiment, the process of weighted fusion of the feature maps of the sample to be tested includes: ; in, For the repetition order, For the first i Differential feature map at each scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy ; Feature difference map By analyzing the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map It is obtained by calculating the cosine similarity separately, and the specific calculation formula is as follows: .
[0044] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.
Claims
1. An unsupervised anomaly detection method for industrial products based on a conditionally controlled diffusion model, characterized in that, The method includes: A diffusion model based on conditional control and multi-scale dual attention mechanism is constructed. The diffusion model based on conditional control and multi-scale dual attention mechanism is used to reconstruct the test sample image to obtain a reconstructed image of the same size as the test sample image. By employing a two-stage background denoising algorithm combined with average post-sampling image operations, the test sample image and its reconstructed image are subjected to denoising, weighted fusion, average post-sampling, and heatmap generation operations using feature maps of various scales extracted by a pre-trained encoder, respectively, to generate the final anomaly heatmap, thereby achieving anomaly detection of the test sample.
2. The method according to claim 1, characterized in that, The diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder. The multi-scale dual attention module includes a multi-scale convolutional block and a parallel dual attention component. The multi-scale convolutional block uses convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention component consists of a channel compression and activation unit and a spatial compression and activation unit, which are used for feature recalibration. This module receives the features output by the pre-trained encoder, processes them, and transmits them to the conditional control network. The signal generated by the conditional control network is processed and then input into the diffusion denoising network to interact with the latent representation. Finally, the pre-trained decoder outputs the reconstruction result. The features output by the pre-trained encoder are: latent space representation ;in, The mean, For logarithmic variance, It is a random noise vector that follows a standard normal distribution; The denoising method of diffusion denoising network is as follows: the signal generated by the conditional control network is processed and then input into the diffusion denoising network, where it interacts with the latent representation to predict noise. ,pass Gradual noise reduction, among which, For the diffusion process Step retention coefficient, The processed control signal, For time steps, For noisy latent representation, For the first The first step after denoising Latent space representation of the step; The method for outputting the reconstruction result by the pre-trained decoder is as follows: pre-trained decoder Potential representation of receiving recovery The transformation from the latent space to the original image space is achieved through multiple transposed convolution operations. The initial input is processed by the transposed convolution of the first layer, as shown in the formula. ,in, This is the feature map after the first layer of transposed convolution in the decoder. The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; The activation function performs the initial upsampling operation; subsequent upsampling operations... layer , , The total number of transposed convolutional layers in the decoder is given by the following formula: ,in, For decoder number Feature maps after layer transpose convolution processing For batch normalization operations, For the first Layer convolution kernel size, For bias, continuous upsampling is achieved by gradually increasing the feature map spatial size; finally, through... The number of channels is adjusted using the following formula: ,in, The reconstructed image is the final output of the decoder. For the output layer bias, we get ,make Compared with the original input image The dimensions are the same, thus completing the restoration from the latent space to the original image, that is, obtaining the reconstructed image.
3. The method according to claim 1, characterized in that, The two-stage denoising method for the feature map of the test sample includes: preliminary background noise filtering, refined denoising, and abnormal region enhancement. The initial filtering of background noise is as follows: Feature maps at various scales are extracted from the test sample image and its reconstructed image using a pre-trained encoder. and Calculate feature maps at various scales and The cosine similarity is used to obtain the feature difference score map, and the formula is: ( ( ); The feature difference score maps at each scale are filtered based on a given threshold to filter out large, continuous regions of low outliers, thereby generating a mask map. ; mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. ; Will and reconstructed images Feature maps at the same scale Together they serve as input for the next stage; Refined noise reduction and anomaly region enhancement are as follows: The feature map after initial denoising and The image is divided into small patches, and mean filtering is performed on each patch individually to obtain a denoised multi-scale feature map. and The formula for calculating the mean filter within a small image patch is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, For pixels within the filtering window, the horizontal direction (x-axis) relative to the center pixel is considered. The offset, For pixels within the filtering window, the vertical direction (y-axis) relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
4. The method according to claim 1, characterized in that, Methods for weighted fusion of feature difference maps include: ; in, This is the initial anomaly feature map obtained after fusion. For the repetition order, For the first i Differential feature map at each scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy ; Feature difference map By analyzing the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map The cosine similarity is calculated between them, and the specific calculation formula is as follows: .
5. An unsupervised anomaly detection system for industrial products based on a conditionally controlled diffusion model, the system being used to implement the method described in any one of claims 1-4, characterized in that, The system includes: a diffusion-conditional control reconstruction module and an anomaly detection and localization module; The diffusion-conditional control reconstruction module is used to construct a diffusion model based on conditional control and multi-scale dual attention mechanism. Using the diffusion model based on conditional control and multi-scale dual attention mechanism, the test sample image is reconstructed to obtain a reconstructed image of the same size as the test sample image. The anomaly detection and localization module is used to perform denoising, weighted fusion, average post-sampling, and heatmap generation operations on the feature maps of various scales extracted by the pre-trained encoder for the test sample image and its reconstructed image through a two-stage background denoising algorithm combined with average post-sampling image operation, thereby generating the final anomaly heatmap and realizing anomaly detection of the test sample.
6. The system according to claim 5, characterized in that, The diffusion model based on conditional control and multi-scale dual attention mechanism includes: a pre-trained encoder, a multi-scale dual attention module, a diffusion denoising network, a conditional control network, and a pre-trained decoder. The multi-scale dual attention module includes a multi-scale convolutional block and a parallel dual attention component. The multi-scale convolutional block uses convolutional kernels of different sizes to extract semantic information at different scales. The parallel dual attention component consists of a channel compression and activation unit and a spatial compression and activation unit, which are used for feature recalibration. This module receives the features output by the pre-trained encoder, processes them, and transmits them to the conditional control network. The signal generated by the conditional control network is processed and then input into the diffusion denoising network to interact with the latent representation. Finally, the pre-trained decoder outputs the reconstruction result. The features output by the pre-trained encoder are: latent space representation ;in, The mean, For logarithmic variance, It is a random noise vector that follows a standard normal distribution; The denoising process of the diffusion denoising network is as follows: the signal generated by the control network is processed and then input into the diffusion denoising network, interacting with the latent representation to predict noise. ,pass Gradual noise reduction, among which, For the diffusion process Step retention coefficient, The processed control signal, For time steps, For noisy latent representation, For the first The first step after denoising Latent space representation of the step; The process of the pre-trained decoder outputting the reconstruction result is as follows: Pre-trained decoder Potential representation of receiving recovery The transformation from the latent space to the original image space is achieved through multiple transposed convolution operations. The initial input is processed by the transposed convolution of the first layer, as shown in the formula. ,in, This is the feature map after the first layer of transposed convolution in the decoder. The k×k transpose convolution operation is used to expand the spatial range of the feature map; This is the size of the transposed convolution kernel of layer 1; For the corresponding bias; The activation function performs the initial upsampling operation; subsequent upsampling operations... layer , , The total number of transposed convolutional layers in the decoder is given by the following formula: ,in, For decoder number Feature maps after layer transpose convolution processing For batch normalization operations, For the first Layer convolution kernel size, For bias, continuous upsampling is achieved by gradually increasing the feature map spatial size; finally, through... The number of channels is adjusted using the following formula: ,in, The reconstructed image is the final output of the decoder. For the output layer bias, we get ,make Compared with the original input image The dimensions are the same, thus completing the restoration from the latent space to the original image, that is, obtaining the reconstructed image.
7. The system according to claim 5, characterized in that, The two-stage denoising process for the feature map of the test sample includes: initial background noise filtering, refined denoising, and abnormal region enhancement. The initial filtering of background noise is as follows: Feature maps at various scales are extracted from the test sample image and its reconstructed image using a pre-trained encoder. and Calculate feature maps at various scales and The cosine similarity is used to obtain the feature difference score map. The formula for calculating cosine similarity is: ( ( ); The feature difference score maps at each scale are filtered based on a given threshold to filter out large, continuous regions of low outliers, thereby generating a mask map. ; mask image and Element-by-element multiplication, i.e. The feature maps at various scales of the original image after preliminary denoising are obtained. ; Will and reconstructed images Feature maps at the same scale Together they serve as input for the next stage; Refined noise reduction and anomaly region enhancement are as follows: The feature map after initial denoising and The image is divided into small patches, and mean filtering is performed on each patch individually to obtain a denoised multi-scale feature map. and The formula for calculating the mean filter within a small image patch is as follows: ; in, These are the coordinates of the center pixel of the image patch. and They are respectively based on The width and height of the central image patch, For pixels within the filtering window, the horizontal direction (x-axis) relative to the center pixel is considered. The offset, For pixels within the filtering window, the vertical direction (y-axis) relative to the center pixel. The offset, Coordinates in the feature map The original pixel value at that location, i.e., within the filter window, relative to the center pixel. Offset The eigenvalues at the corresponding unfiltered positions reflect the intensity of the characteristic at that location. These are the pixel coordinates after mean filtering. The new value at that location.
8. The system according to claim 5, characterized in that, The process of weighted fusion of feature difference maps includes: ; in, This is the initial anomaly feature map obtained after fusion. For the repetition order, For the first i Differential feature map at each scale The fusion weights are set based on prior knowledge, and their values range from [value range missing]. And satisfy ; Feature difference map By analyzing the input image Feature maps at various scales obtained after two-stage denoising With reconstructed images Corresponding denoised feature map The cosine similarity is calculated between them, and the specific calculation formula is as follows: .
Citation Information
Cited By
High-frequency multi-scale inverse proportional weighted and lightweight adaptive retraining method for electronic product texture defect detection
CN122530648A