Unsupervised anomaly detection method based on adaptive diffusion model

By using the adaptive diffusion model and synthetic abnormal image training in unsupervised anomaly detection, the problems of limited training methods and unsuitable noise addition in the existing technology are solved, and the accuracy of image reconstruction and anomaly detection is improved.

CN118570118AActive Publication Date: 2024-08-30HARBIN INST OF TECH

Patent Information

Application Number
CN202410461982.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-17
Publication Date
2024-08-30
Estimated Expiration
2044-04-17

AI Technical Summary

Technical Problem

Existing unsupervised anomaly detection algorithms can only use normal samples when training diffusion models, resulting in poor image reconstruction results, and cannot adaptively add noise, resulting in low anomaly detection accuracy.

Method used

An unsupervised anomaly detection method based on the adaptive diffusion model is adopted. The model is trained by synthesizing abnormal images and normal images as supervised label data. The optimal number of denoising steps is adaptively determined during the inference process, and appropriate noise is added for different anomaly types. Image reconstruction.

Benefits of technology

The reconstruction capability and anomaly detection accuracy of the model are improved, ensuring the reconstruction of abnormal-free images while maximizing the retention of normal area information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118570118A
    Figure CN118570118A
Patent Text Reader

Abstract

The invention discloses an unsupervised anomaly detection method based on an adaptive diffusion model, and belongs to the field of industrial image anomaly detection. The problem that the image reconstruction effect is poor due to the fact that a traditional training mode is used for training a diffusion model in a traditional unsupervised anomaly detection algorithm is solved; and noise cannot be adaptively added in an image reconstruction process, so that the image anomaly detection accuracy is low. According to the method, a diffusion model is trained by using a normal image and a synthetic abnormal image, model optimization is supervised, and the model reconstruction capability is enhanced; step-by-step adaptive denoising reconstruction is carried out on an input to-be-detected image by using the trained diffusion model, the optimal denoising step number is determined in the denoising process, and noise of different synchronization numbers is adaptively added for different abnormities; and finally, performing feature space comparison on the images before and after reconstruction to obtain a space comparison abnormal graph and an abnormal score. The method is mainly used for carrying out anomaly detection on the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of industrial image anomaly detection. Background Art

[0002] Anomaly detection on product surfaces is crucial in industrial manufacturing. However, there are many types of anomalies in industrial products, and the design and production process of products are constantly changing. It is very difficult to collect all types of abnormal images in actual production. Therefore, unsupervised anomaly detection methods that only use normal images have received widespread attention.

[0003] Existing reconstruction-based industrial anomaly detection methods assume that the image reconstruction model trained on normal images can only reconstruct the normal area of ​​the input image, while the abnormal area will not be reconstructed. The abnormal area is detected and located by comparing the two images before and after reconstruction. At present, some more advanced industrial anomaly detection methods use the diffusion model as the image reconstruction model. First, the diffusion model is trained with normal samples, and then a sample with random noise is reconstructed. Since the diffusion model only models the distribution of normal samples during the training process, after adding enough noise, the model can reconstruct the input noisy image into a normal image. These methods achieve high-quality image reconstruction, but there are still some shortcomings.

[0004] First, the current unsupervised anomaly detection algorithm uses the traditional diffusion model training method, which can only be trained using normal samples. The trained diffusion model is then used to reconstruct the normal image by predicting and removing the Gaussian noise added to the input normal samples.

[0005] However, when reconstructing images in the actual application stage, it is also necessary to reconstruct abnormal images, so there is a difference in data distribution between the training stage and the actual application stage. For normal areas, it is reasonable to predict and remove Gaussian distribution noise, but for abnormal areas, predicting and removing a Gaussian noise is likely to reconstruct the anomaly. The traditional diffusion model training method is not suitable for anomaly detection, resulting in poor reconstruction effect in the actual application stage and low accuracy of anomaly detection. Therefore, how to use synthetic abnormal samples to train the diffusion model is a problem that needs to be solved.

[0006] In addition, during the reconstruction process, these methods using diffusion model reconstruction add a fixed number of random noise steps to the input image, which is not suitable for all abnormal samples. Compared with subtle scratches and other inconspicuous abnormalities, some obvious abnormal types such as missing parts require more noise to ensure that the reconstructed image does not contain abnormal areas. Therefore, this method of adding a fixed number of random noise steps during the image reconstruction process is not a universal solution. In practice, different degrees of noise need to be added adaptively for different types of abnormalities. Summary of the invention

[0007] The purpose of the present invention is to solve the problems that the traditional unsupervised anomaly detection algorithm uses the traditional training method to train the diffusion model, resulting in poor image reconstruction effect; and the image reconstruction process cannot adaptively add noise, resulting in low accuracy of image anomaly detection. The present invention provides an unsupervised anomaly detection method based on an adaptive diffusion model.

[0008] An unsupervised anomaly detection method based on an adaptive diffusion model includes the following steps:

[0009] Step 1: Use each original normal image I n To synthesize the corresponding abnormal image I a , and each original normal image I n The corresponding abnormal image I a As a sample;

[0010] Step 2: Preprocess each sample:

[0011] For each abnormal image I in the sample a Encode to get the feature map x a , in the feature map x a Add Gaussian noise ε of random step number S to get the feature map after adding noise For each sample, the original normal image I n Encode to obtain feature map x′; add Gaussian noise ε of random step number S to feature map x′ and then compare it with feature map x a Combine them, and the combined result is used as the supervised label data of the sample;

[0012] Step 3: Train the diffusion model:

[0013] The feature map of each sample after adding noise As the input data of the diffusion model, the supervised label data of the sample is used as the true value of the diffusion model, and the diffusion model is trained for noise prediction to obtain the trained diffusion model;

[0014] Step 4: Use the trained diffusion model to perform adaptive denoising to achieve image reconstruction:

[0015] Encode the image I to be detected to obtain the feature map x, add Gaussian noise ε with a fixed step number T to the feature map x, and obtain the feature map x after adding noise T Input into the trained diffusion model, and add noise to the feature map x T Perform the first round of step-by-step noise prediction and denoising to determine the optimal number of denoising steps;

[0016] Then, the abnormal area positioning map and the normal area positioning map under the optimal denoising step number are used to perform feature synthesis to obtain a synthetic feature map;

[0017] After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, it is input into the trained diffusion model for the second round of step-by-step noise prediction and denoising. After the noise removal is completed, decoding is performed to obtain a clear image without abnormalities. This clear image without abnormalities is the reconstructed image.

[0018] Step 5: Image I to be detected and image reconstructed Perform feature space comparison to obtain a spatial comparison anomaly map; then obtain an anomaly score based on the spatial comparison anomaly map to complete anomaly detection.

[0019] Preferably, in step 1, each original normal image I n To synthesize the corresponding abnormal image I a The implementation methods include:

[0020] Step 11: In each original normal image I n Generate an abnormal area on top;

[0021] Step 12: For the original normal image I n After image enhancement, an enhanced image is generated; one of the enhanced images or texture images in the texture data set is randomly selected as an abnormal image, and added to the abnormal area to generate an abnormal image;

[0022] Preferably, in step 5, the detected image I and the reconstructed image The implementation methods of performing feature space comparison and obtaining a spatial comparison anomaly map include:

[0023] Extract features of the image I to be detected and obtain M layers of image features F I ;

[0024] Reconstructed image Perform feature extraction to obtain M-layer image features

[0025] M-layer image features F I With M-layer image features There is a one-to-one correspondence;

[0026] The image features F of each layer I The features of each position in the image are respectively related to the image features of the corresponding layer The cosine distance is calculated between the features at all positions in , and the minimum value of all cosine distances is taken as the outlier value of the position in the anomaly map of the corresponding layer;

[0027] The abnormal values ​​at corresponding positions in the M-layer abnormal map are superimposed to obtain a spatial contrast abnormal map.

[0028] Preferably, the detected image I and the reconstructed image Feature extraction is implemented using a feature extraction network, and the feature extraction network is DINO.

[0029] Preferably, in step 5, the implementation method of obtaining the anomaly score according to the spatial contrast anomaly map includes:

[0030] Take the average of the first K largest outliers in the spatial contrast anomaly map and use the average as the spatial contrast anomaly map to obtain the anomaly score.

[0031] Preferably, the diffusion model is implemented using a UNet network, and the loss function L of the abnormal training paradigm of the diffusion model is ATP The expression is:

[0032]

[0033] in, For the known training data (x′,x a ), the maximum likelihood estimate of the model parameter θ, N(0,I) is the standard normal distribution obeyed by the added noise, 0 is the mean of the standard normal distribution, I is the variance of the standard normal distribution, p data is the distribution of input data, is a parameter set in advance that decreases as the number of random steps S increases, ε θ is the noise predicted by the diffusion model, and ||·||2 is the binary norm.

[0034] Preferably, in step 4, the feature map x after adding noise T The first round of step-by-step noise prediction and denoising is performed to determine the optimal number of denoising steps. The implementation methods include:

[0035] Step 411, the first noise prediction and denoising in the first round of step-by-step noise prediction and denoising process:

[0036] The trained diffusion model receives the feature map x after adding noise T After that, the noise prediction is performed to predict the noise ε θ1 , using the noise ε θ1 In the feature map x T After one step of denoising, we get the predicted noisy feature map

[0037] Step 412: Add Gaussian noise ε with step number Ti to the feature map x to obtain the real noisy feature map x T-i , the initial value of i is 1 and is less than T;

[0038] Step 413, the (i+1)th noise prediction and denoising in the first round of step-by-step noise prediction and denoising:

[0039] The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(i+1) ;

[0040] Step 414: feature space comparison:

[0041] Using noise ε θ(i+1) Predicting noisy feature maps and the true noisy feature map x T-i After all denoising, the predicted clear feature maps are obtained respectively And the real clear feature map x T-i→0 , the predicted clear feature map And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i , determine whether there is f i ≥δ, δ is a threshold value, if the result is yes, then it is determined that the optimal denoising step number is Ti=Tt, t is the total number of the first round of step-by-step denoising, and the spatial contrast anomaly map under the optimal denoising step number Tt is used as the abnormal area positioning map m, otherwise, execute step 415;

[0042] Step 415: Using noise ε θ(i+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map Then, let i=i+1 and execute step 412.

[0043] Preferably, in step 414, the predicted clear feature map And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i The implementation methods include:

[0044] Clear feature map for prediction Perform feature extraction to obtain M layers of predicted clear image features;

[0045] For the real clear feature map x T-i→0 Perform feature extraction to obtain M layers of real and clear image features;

[0046] There is a one-to-one correspondence between the M-layer predicted clear image features and the M-layer real clear image features;

[0047] The cosine distance is calculated between the features of each position in each layer of predicted clear image features and the features of all positions in the real clear image features of the corresponding layer, and the minimum value of all cosine distances is taken as the outlier value of the position in the anomaly map of the corresponding layer; the outliers of the corresponding positions in the anomaly maps of M layers are superimposed to obtain a spatial contrast anomaly map; the average of the first K largest outliers in the spatial contrast anomaly map is taken, and the average is used as the spatial contrast anomaly map to obtain the anomaly score f i .

[0048] Preferably, in step 4, the abnormal region positioning map and the normal region positioning map under the optimal denoising step number are used to perform feature synthesis, and the implementation method of the obtained synthetic feature map includes:

[0049] Step 421: Subtract the pixel value of the corresponding pixel point in the abnormal area positioning map m from the image with all pixel values ​​1 to obtain the normal area positioning map. Figure 1 -m; the size of the abnormal area positioning map m is the same as the map with all pixel values ​​1;

[0050] Step 422, multiplying the abnormal value at each position in the abnormal region positioning map m by the feature of the corresponding position in the predicted clear feature map corresponding to the optimal denoising step number to obtain the abnormal region feature map;

[0051] Normal area positioning Figure 1 -The value at each position in m is multiplied by the feature at the corresponding position in the real clear feature map corresponding to the optimal denoising step number to obtain the normal area feature map;

[0052] Step 423: Add the values ​​of the corresponding positions of the abnormal region feature map and the normal region feature map to obtain a synthetic feature map.

[0053] Preferably, in step 4, after adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, the noise is input into the trained diffusion model for a second round of stepwise noise prediction and denoising. After the noise removal is completed, decoding is performed to obtain a clear image without abnormalities, which is the reconstructed image. The implementation methods include:

[0054] Step 431: After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, a predicted noisy feature map is formed. t is the total number of times of the first round of step-by-step denoising;

[0055] Step 432, the jth noise prediction and denoising in the second round of step-by-step noise prediction and denoising:

[0056] The initial value of j is 1, which will predict the noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θj, using the noise ε θj In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map ε θj is the noise predicted by the jth noise prediction of the diffusion model in the second round of stepwise noise prediction and denoising process;

[0057] Step 433: the j+1th noise prediction and denoising in the second round of step-by-step noise prediction and denoising:

[0058] The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(j+1) , using the noise ε θ(j+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map

[0059] Step 434: determine whether j+1=Tt is reached. If yes, it is determined that all denoising of the synthetic feature map under the optimal denoising step number is completed, and the denoised synthetic feature map is decoded to obtain a clear image without abnormalities. The clear image without abnormalities is the reconstructed image. If the answer is no, set j=j+1 and execute step 433.

[0060] Advantages of the present invention:

[0061] 1. The present invention is an unsupervised anomaly detection method based on an adaptive diffusion model. In the training process of the diffusion model, the present invention introduces a synthetic abnormal image training method, uses noisy normal images and synthetic abnormal images to generate supervised label data, and supervises the optimization process of the diffusion model, so that the model can better reconstruct abnormal areas into normal areas, thereby improving the reconstruction ability of the model. In addition, in the inference process, the optimal denoising steps are determined by comparing the information difference between the predicted noisy feature map and the real noisy feature map after adding noise, and different steps of noise are adaptively added for different anomalies;

[0062] Finally, a clear and abnormal-free image is reconstructed based on the original input image, and the abnormality is located and identified by comparing the difference between the reconstructed image and the original input image.

[0063] 2. The unsupervised anomaly detection method based on the adaptive diffusion model of the present invention proposes a diffusion model training method that adapts to abnormal samples and enhances the reconstruction ability of the model. , thus improving the accuracy of anomaly detection and positioning.

[0064] 3. The present invention realizes the selection of adaptive denoising steps for the image to be detected for the first time, so that the diffusion model can ensure abnormal-free reconstruction while maximally retaining the normal area information in the image to be detected. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] Figure 1 A schematic diagram of the principle of using the unsupervised anomaly detection method based on the adaptive diffusion model of the present invention to perform anomaly detection on the image I to be detected;

[0066] Figure 2 Flowchart for training the diffusion model;

[0067] Figure 3 Schematic diagram of the principle of image reconstruction for adaptive denoising;

[0068] Figure 4 Schematic diagram of the principle of feature space comparison. DETAILED DESCRIPTION

[0069] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0070] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0071] In view of the problems that the existing unsupervised anomaly detection algorithms use traditional training methods to train diffusion models, only normal images can be used for training, and the model has limited ability to reconstruct abnormal areas into normal areas; on the other hand, the image reconstruction process cannot adaptively add noise, which further leads to poor reconstruction effect and ultimately low accuracy of image anomaly detection. The present invention provides an unsupervised anomaly detection method based on an adaptive diffusion model. The anomaly detection method realizes anomaly-free reconstruction while retaining normal area information to the greatest extent, thereby improving the accuracy of anomaly detection and positioning.

[0072] See also Figure 1 and Figure 2 The present embodiment describes an unsupervised anomaly detection method based on an adaptive diffusion model, comprising the following steps:

[0073] Step 1: Use each original normal image I n To synthesize the corresponding abnormal image I a , and each original normal image I n The corresponding abnormal image I aAs a sample;

[0074] As a preferred example, using each original normal image I n To synthesize the corresponding abnormal image I a The implementation methods include:

[0075] Step 11: In each original normal image I n Generate an abnormal area on top;

[0076] Step 12: For the original normal image I n After image enhancement, an enhanced image is generated; one of the enhanced images or texture images in the texture data set is randomly selected as an abnormal image, and added to the abnormal area to generate an abnormal image;

[0077] Step 2: Preprocess each sample:

[0078] For each abnormal image I in the sample a Encode to get the feature map x a , in the feature map x a Add Gaussian noise ε of random step number S to get the feature map after adding noise For each sample, the original normal image I n Encode to obtain feature map x′; add Gaussian noise ε of random step number S to feature map x′ and then compare it with feature map x a Combine them, and the combined result is used as the supervised label data of the sample;

[0079] Step 3: Train the diffusion model:

[0080] The feature map of each sample after adding noise As the input data of the diffusion model, the supervised label data of the sample is used as the true value of the diffusion model, and the diffusion model is trained for noise prediction to obtain the trained diffusion model;

[0081] The above-mentioned introduction of synthetic abnormal images to train the diffusion model, and the use of Gaussian noise with a random step number S added to the normal image and the abnormal information in the synthetic abnormal image as the supervision label data to supervise the optimization process of the diffusion model, overcome the defect in the prior art that the diffusion model cannot be trained using abnormal images, and ensure the accuracy of the subsequent diffusion model for image reconstruction;

[0082] Step 4: Use the trained diffusion model to perform adaptive denoising to achieve image reconstruction:

[0083] Encode the image I to be detected to obtain the feature map x, add Gaussian noise ε with a fixed step number T to the feature map x, and obtain the feature map x after adding noise TInput into the trained diffusion model, and add noise to the feature map x T Perform the first round of step-by-step noise prediction and denoising to determine the optimal number of denoising steps;

[0084] Then, the abnormal area positioning map and the normal area positioning map under the optimal denoising step number are used to perform feature synthesis to obtain a synthetic feature map;

[0085] After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, it is input into the trained diffusion model for the second round of step-by-step noise prediction and denoising. After the noise removal is completed, decoding is performed to obtain a clear image without abnormalities. This clear image without abnormalities is the reconstructed image.

[0086] Step 5: Image I to be detected and image reconstructed Perform feature space comparison to obtain a spatial comparison anomaly map; then obtain an anomaly score based on the spatial comparison anomaly map to complete anomaly detection.

[0087] The present invention performs two rounds of step-by-step noise prediction and denoising. The first round of step-by-step noise prediction and denoising is to obtain the optimal denoising step number, and the purpose of determining the optimal denoising step number is to add the optimal step number to the input sample to ensure that most of the abnormal information can be covered while retaining the most normal area information. The second round of step-by-step noise prediction and denoising is to perform step-by-step denoising on the corresponding synthetic feature map obtained under the optimal denoising step number. The synthetic feature map adds the noise predicted by the diffusion model under the optimal denoising step number. The synthetic feature map removes the residual abnormal information in the optimal step number, and can ensure the accuracy of image reconstruction.

[0088] The pixel values ​​at each pixel point of the image after feature space comparison of the present invention are all values ​​between 0 and 1.

[0089] See also Figure 3 , providing a preferred implementation, in step 4, the feature map x after adding noise T The first round of step-by-step noise prediction and denoising is performed to determine the optimal number of denoising steps. The implementation methods include:

[0090] Step 411, the first noise prediction and denoising in the first round of step-by-step noise prediction and denoising process:

[0091] The trained diffusion model receives the feature map x after adding noise T After that, the noise prediction is performed to predict the noise ε θ1 , using the noise ε θ1 In the feature map x T After one step of denoising, we get the predicted noisy feature map

[0092] Step 412: Add Gaussian noise ε with step number Ti to the feature map x to obtain the real noisy feature map x T-i , the initial value of i is 1 and is less than T;

[0093] Step 413, the (i+1)th noise prediction and denoising in the first round of step-by-step noise prediction and denoising:

[0094] The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(i+1) ;

[0095] Step 414: feature space comparison:

[0096] Using noise ε θ(i+1) Predicting noisy feature maps and the true noisy feature map x T-i After all denoising, the predicted clear feature maps are obtained respectively And the real clear feature map x T-i→0 , the predicted clear feature map And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i , determine whether there is f i ≥δ, δ is a threshold value, if the result is yes, then it is determined that the optimal denoising step number is Ti=Tt, t is the total number of the first round of step-by-step denoising, and the spatial contrast anomaly map under the optimal denoising step number Tt is used as the abnormal area positioning map m, otherwise, execute step 415;

[0097] Step 415: Using noise ε θ(i+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map Then, let i=i+1 and execute step 412.

[0098] In this preferred embodiment, after each noise prediction, the predicted clear feature map formed after the predicted noise is completely removed, and the real noisy feature map containing the Gaussian noise of the corresponding number of steps is completely denoised to form a real clear feature map, and the information difference between the predicted clear feature map after complete denoising and the real clear feature map is compared to determine the optimal denoising steps, and the comparison of noisy features is converted into clear feature comparison. Since the predicted clear feature map does not contain abnormal information, by comparing the two clear feature maps, it is possible to more simply and efficiently detect whether the real clear feature map contains a large amount of abnormal information, thereby accurately predicting the optimal denoising steps.

[0099] Going further, predicting clear feature maps And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i The implementation methods include:

[0100] Clear feature map for prediction Perform feature extraction to obtain M layers of predicted clear image features;

[0101] For the real clear feature map x T-i→0 Perform feature extraction to obtain M layers of real and clear image features;

[0102] There is a one-to-one correspondence between the M-layer predicted clear image features and the M-layer real clear image features;

[0103] The cosine distance is calculated between the features of each position in each layer of predicted clear image features and the features of all positions in the real clear image features of the corresponding layer, and the minimum value of all cosine distances is taken as the outlier value of the position in the anomaly map of the corresponding layer; the outliers of the corresponding positions in the anomaly maps of M layers are superimposed to obtain a spatial contrast anomaly map; the average of the first K largest outliers in the spatial contrast anomaly map is taken, and the average is used as the spatial contrast anomaly map to obtain the anomaly score f i .

[0104] In this preferred embodiment, the features at each position in each layer of predicted clear image features and the features at all positions in the real clear image features of its corresponding layer are both vectors with a length of n.

[0105] See also Figure 3 , further providing a preferred implementation mode, in step 4, the abnormal region positioning map and the normal region positioning map under the optimal denoising step number are used to perform feature synthesis, and the implementation method of the obtained synthetic feature map includes:

[0106] Step 421: Subtract the pixel value of the corresponding pixel point in the abnormal area positioning map m from the image with all pixel values ​​1 to obtain the normal area positioning map. Figure 1 -m; the size of the abnormal area positioning map m is the same as the map with all pixel values ​​1;

[0107] Step 422, multiplying the abnormal value at each position in the abnormal region positioning map m by the feature at the corresponding position in the predicted clear feature map corresponding to the optimal denoising step number, to obtain an abnormal region feature map; the feature at each position in the predicted clear feature map is a vector with a length of n;

[0108] Normal area positioning Figure 1 -The value at each position in m is multiplied by the feature at the corresponding position in the real clear feature map corresponding to the optimal denoising step number to obtain the normal area feature map; the feature at the corresponding position in the clear feature map is a vector of length n;

[0109] Step 423: Add the values ​​of the corresponding positions of the abnormal region feature map and the normal region feature map to obtain a synthetic feature map.

[0110] In this preferred embodiment, the abnormal area positioning map m and the normal area positioning map Figure 1 -m, the predicted clear feature map corresponding to the optimal denoising step number, and the real clear feature map corresponding to the optimal denoising step number are all images of the same size. The advantage of synthesizing the feature map using the above steps is that features with no abnormal information can be generated, thereby ensuring abnormal image reconstruction.

[0111] See also Figure 3 , a preferred implementation is provided, in step 4, after adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, the noise is input into the trained diffusion model for a second round of stepwise noise prediction and denoising, and after the noise removal is completed, decoding is performed to obtain a clear image without abnormalities, which is the reconstructed image The implementation methods include:

[0112] Step 431: After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, a predicted noisy feature map is formed. t is the total number of times of the first round of step-by-step denoising;

[0113] Step 432, the jth noise prediction and denoising in the second round of step-by-step noise prediction and denoising:

[0114] The initial value of j is 1, which will predict the noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θj , using the noise ε θj In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map ε θj is the noise predicted by the jth noise prediction of the diffusion model in the second round of stepwise noise prediction and denoising process;

[0115] Step 433: the j+1th noise prediction and denoising in the second round of step-by-step noise prediction and denoising:

[0116] The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(j+1) , using the noise ε θ(j+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map

[0117] Step 434: determine whether j+1=Tt is reached. If yes, it is determined that all denoising of the synthetic feature map under the optimal denoising step number is completed, and the denoised synthetic feature map is decoded to obtain a clear image without abnormalities. The clear image without abnormalities is the reconstructed image. If the answer is no, set j=j+1 and execute step 433.

[0118] In this preferred embodiment, after adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map using steps 431 to 434, step-by-step noise prediction and denoising are performed. The synthetic feature map adds the noise predicted by the diffusion model under the optimal denoising step number. The synthetic feature map removes the residual abnormal information in the optimal step number, thereby ensuring the accuracy of image reconstruction.

[0119] See also Figure 4 , further, in step 5, the detected image I and the reconstructed image The implementation methods of performing feature space comparison and obtaining a spatial comparison anomaly map include:

[0120] Extract features of the image I to be detected and obtain M layers of image features F I ;

[0121] Reconstructed image Perform feature extraction to obtain M-layer image features

[0122] M-layer image features F I With M-layer image features There is a one-to-one correspondence;

[0123] The image features F of each layer I The features of each position in the image are respectively related to the image features of the corresponding layer The cosine distances are calculated between the features at all positions in the anomaly map, and the minimum value of all cosine distances is taken as the anomaly value of the position in the anomaly map of the corresponding layer; the anomaly values ​​of the corresponding positions in the anomaly map of the M layer are superimposed to obtain a spatial contrast anomaly map.

[0124] As a preferred example, the detected image I and the reconstructed image The feature extraction is implemented by using a feature extraction network, and the feature extraction network can be DINO.

[0125] Furthermore, in step 5, the implementation method of obtaining the anomaly score according to the spatial contrast anomaly map includes:

[0126] Take the average of the first K largest outliers in the spatial contrast anomaly map and use the average as the spatial contrast anomaly map to obtain the anomaly score.

[0127] Principle analysis: The present invention uses normal images and synthetic abnormal images to train the diffusion model; the noisy normal image and the synthetic abnormal image are combined as the supervision label data to supervise the model optimization process; the trained diffusion model is used to perform step-by-step adaptive denoising and reconstruction on the input image to be detected, and the optimal denoising steps are determined during the denoising process, and different steps of noise are adaptively added for different abnormalities; finally, the image to be detected I and the reconstructed image are used to perform adaptive denoising and reconstruction on the input image to be detected I and the synthetic abnormal image. Perform feature space comparison to obtain a spatial comparison anomaly map; then obtain an anomaly score based on the spatial comparison anomaly map to complete anomaly detection.

[0128] Although the present invention is described herein with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the present invention. It should therefore be understood that many modifications may be made to the exemplary embodiments and that other arrangements may be devised without departing from the spirit and scope of the present invention as defined by the appended claims. It should be understood that the various dependent claims and features described herein may be combined in a manner different from that described in the original claims. It should also be understood that features described in conjunction with individual embodiments may be used in other described embodiments.

Claims

1. An unsupervised anomaly detection method based on an adaptive diffusion model, characterized in that: The method comprises the following steps: Step 1: Use each original normal image I n To synthesize the corresponding abnormal image I a , and each original normal image I n The corresponding abnormal image I a As a sample; Step 2: Preprocess each sample: For each abnormal image I in the sample a Encode to get the feature map x a , in the feature map x a Add Gaussian noise ε of random step number S to get the feature map after adding noise For each sample in the original normal image I n Encode to obtain feature map x′; add Gaussian noise ε of random step number S to feature map x′ and then compare it with feature map x a Combine them, and the combined result is used as the supervised label data of the sample; Step 3: Train the diffusion model: The feature map of each sample after adding noise As the input data of the diffusion model, the supervised label data of the sample is used as the true value of the diffusion model, and the diffusion model is trained for noise prediction to obtain the trained diffusion model; Step 4: Use the trained diffusion model to perform adaptive denoising to achieve image reconstruction: Encode the image I to be detected to obtain the feature map x, add Gaussian noise ε with a fixed step number T to the feature map x, and obtain the feature map x after adding noise T Input into the trained diffusion model, and add noise to the feature map x T Perform the first round of step-by-step noise prediction and denoising to determine the optimal number of denoising steps; Then, the abnormal area positioning map and the normal area positioning map under the optimal denoising step number are used to perform feature synthesis to obtain a synthetic feature map; After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, it is input into the trained diffusion model for the second round of step-by-step noise prediction and denoising. After the noise removal is completed, decoding is performed to obtain a clear image without abnormalities. This clear image without abnormalities is the reconstructed image. Step 5: Image I to be detected and image reconstructed Perform feature space comparison to obtain a spatial comparison anomaly map; then obtain an anomaly score based on the spatial comparison anomaly map to complete anomaly detection.

2. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 1, the original normal images I n To synthesize the corresponding abnormal image I a The implementation methods include: Step 11: In each original normal image I n Generate an abnormal area on top; Step 12: For the original normal image I n After image enhancement, an enhanced image is generated; one of the enhanced images or texture images in the texture data set is randomly selected as an abnormal image and added to the abnormal area to generate an abnormal image.

3. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 5, the detected image I and the reconstructed image The implementation methods of performing feature space comparison and obtaining a spatial comparison anomaly map include: Extract features of the image I to be detected and obtain M layers of image features F I ; Reconstructed image Perform feature extraction to obtain M-layer image features M-layer image features F I With M-layer image features There is a one-to-one correspondence; The image features F of each layer I The features of each position in the image are respectively related to the image features of the corresponding layer The cosine distance is calculated between the features at all positions in , and the minimum value of all cosine distances is taken as the outlier value of the position in the anomaly map of the corresponding layer; The anomaly values ​​at corresponding positions in the M-layer anomaly map are superimposed to obtain a spatial contrast anomaly map.

4. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 3 is characterized in that: For the detected image I and the reconstructed image Feature extraction is implemented using a feature extraction network, and the feature extraction network is DINO.

5. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 5, the implementation method of obtaining the anomaly score according to the spatial contrast anomaly map includes: Take the average of the first K largest outliers in the spatial contrast anomaly map and use the average as the spatial contrast anomaly map to obtain the anomaly score.

6. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: The diffusion model is implemented using the UNet network, and the loss function L of the abnormal training paradigm of the diffusion model is ATP The expression is: in, For the known training data (x′,x a ), the maximum likelihood estimate of the model parameter θ, N(0,I) is the standard normal distribution obeyed by the added noise, 0 is the mean of the standard normal distribution, I is the variance of the standard normal distribution, p data is the distribution of input data, is a parameter that is set in advance and decreases as the number of random steps S increases, ε θ is the noise predicted by the diffusion model, and ||·||2 is the binary norm.

7. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 4, the feature map x after adding noise T The first round of step-by-step noise prediction and denoising is performed to determine the optimal number of denoising steps. The implementation methods include: Step 411, the first noise prediction and denoising in the first round of step-by-step noise prediction and denoising process: The trained diffusion model receives the feature map x after adding noise T After that, the noise prediction is performed to predict the noise ε θ1 , using the noise ε θ1 In the feature map x T After one step of denoising, we get the predicted noisy feature map Step 412: Add Gaussian noise ε with step number Ti to the feature map x to obtain the real noisy feature map x T-i , the initial value of i is 1 and is less than T; Step 413, the (i+1)th noise prediction and denoising in the first round of step-by-step noise prediction and denoising: The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(i+1) ; Step 414: feature space comparison: Using noise ε θ(i+1) Predicting noisy feature maps and the true noisy feature map x T-i After all denoising, the predicted clear feature maps are obtained respectively And the real clear feature map x T-i→0 , the predicted clear feature map And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i , determine whether there is f i ≥δ, δ is a threshold value, if the result is yes, then it is determined that the optimal denoising step number is Ti=Tt, t is the total number of the first round of step-by-step denoising, and the spatial contrast anomaly map under the optimal denoising step number Tt is used as the abnormal area positioning map m, otherwise, execute step 415; Step 415: Using noise ε θ(i+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map Then, let i=i+1 and execute step 412.

8. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 7, characterized in that: In step 414, the clear feature map is predicted And the real clear feature map x T-i→0 After feature space comparison, the anomaly score f is obtained based on the obtained spatial comparison anomaly map i The implementation methods include: Clear feature map for prediction Perform feature extraction to obtain M layers of predicted clear image features; For the real clear feature map x T-i→0 Perform feature extraction to obtain M layers of real and clear image features; There is a one-to-one correspondence between the M-layer predicted clear image features and the M-layer real clear image features; The cosine distance is calculated between the features of each position in each layer of predicted clear image features and the features of all positions in the real clear image features of the corresponding layer, and the minimum value of all cosine distances is taken as the outlier value of the position in the anomaly map of the corresponding layer; the outliers of the corresponding positions in the anomaly maps of M layers are superimposed to obtain a spatial contrast anomaly map; the average of the first K largest outliers in the spatial contrast anomaly map is taken, and the average is used as the spatial contrast anomaly map to obtain the anomaly score f i .

9. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 4, the abnormal region positioning map and the normal region positioning map under the optimal denoising step number are used to perform feature synthesis, and the implementation method of the obtained synthetic feature map includes: Step 421, subtract the pixel value of the corresponding pixel point of the abnormal area positioning map m from the map with all pixel values ​​of 1 to obtain the normal area positioning map 1-m; the size of the abnormal area positioning map m is the same as the map with all pixel values ​​of 1; Step 422, multiplying the abnormal value at each position in the abnormal region positioning map m by the feature of the corresponding position in the predicted clear feature map corresponding to the optimal denoising step number to obtain the abnormal region feature map; The value at each position in the normal region positioning map 1-m is multiplied by the feature at the corresponding position in the real clear feature map corresponding to the optimal denoising step number to obtain the normal region feature map; Step 423: Add the values ​​of the corresponding positions of the abnormal region feature map and the normal region feature map to obtain a synthetic feature map.

10. The unsupervised anomaly detection method based on the adaptive diffusion model according to claim 1, characterized in that: In step 4, after adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, it is input into the trained diffusion model for a second round of step-by-step noise prediction and denoising. After the noise removal is completed, decoding is performed to obtain a clear image without abnormalities. The clear image without abnormalities is the reconstructed image. The implementation methods include: Step 431: After adding the noise predicted by the diffusion model under the optimal denoising step number to the synthetic feature map, a predicted noisy feature map is formed. t is the total number of the first round of step-by-step denoising; Step 432, the jth noise prediction and denoising in the second round of step-by-step noise prediction and denoising: The initial value of j is 1, which will predict the noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θj , using the noise ε θj In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map ε θj is the noise predicted by the jth noise prediction of the diffusion model in the second round of stepwise noise prediction and denoising process; Step 433: the j+1th noise prediction and denoising in the second round of step-by-step noise prediction and denoising: The predicted noisy feature map After inputting into the trained diffusion model, noise prediction is performed to predict the noise ε θ(j+1) , using the noise ε θ(j+1) In predicting noisy feature maps After one step of denoising, we get the predicted noisy feature map Step 434: determine whether j+1=Tt is reached. If yes, it is determined that all denoising of the synthetic feature map under the optimal denoising step number is completed, and the denoised synthetic feature map is decoded to obtain a clear image without abnormalities. The clear image without abnormalities is the reconstructed image. If the answer is no, set j=j+1 and execute step 433.

Citation Information

Patent Citations

  • Abnormal image detection method based on self-supervised learning

    CN113344875A

  • Unsupervised defect detection model training method and defect detection method

    CN114693685A

  • Image restoration method and device, electronic equipment and storage medium

    CN115239593A

  • Image processing method and device, equipment and storage medium

    CN116958131A

  • Chromosome anomaly detection system and method based on de-noising diffusion probability model

    CN117011234A

Cited By

  • Model training method and device, image generation method and device, electronic equipment and medium

    CN119152324A

  • Unsupervised anomaly detection method and system for substation equipment

    CN120833525A

  • Generated picture blind box detection method and system based on diffusion model

    CN121767765A