Self-adaptive feature distribution defect detection method based on normalized stream
Mapping feature distributions to adaptive Gaussian distributions through the adaptive normalized flow model solves the problem of insufficient adaptability of the normalized flow network and achieves more efficient and accurate defect detection.
Patent Information
- Application Number
- CN202510553726.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-29
- Publication Date
- 2025-08-08
AI Technical Summary
In the unsupervised image defect detection, the normalized stream network is difficult to effectively adapt to the difference in feature distribution of different data sets, resulting in insufficient detection accuracy and generalization.
Adaptive normalized flow model is adopted to map the original feature distribution to the adaptive Gaussian distribution, and the detection score is calculated by designing the loss function and boundary optimization to improve the detection accuracy and robustness of the model.
Through adaptive feature distribution mapping, detection efficiency and accuracy are improved, especially in the identification and classification of different defect types, which enhances the generalization ability of the model.
Smart Images

Figure CN120451107A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical fields of pattern recognition, machine learning, defect detection and image processing, and more particularly to a normalized flow-based adaptive feature distribution defect detection method. Background Art
[0002] Image defect detection is an important research area in the field of computer vision. Image defect detection methods primarily utilize unsupervised learning, using only normal images to train the model. Finally, through the design of appropriate evaluation criteria, sample detection is achieved. Based on the granularity of detection, unsupervised defect detection can be categorized as image-level and pixel-level. Image-level detection focuses on the normality of the entire image, while pixel-level detection further requires locating defective areas within the image. Because image defect detection based on unsupervised learning has the advantages of low dataset requirements and the ability to locate pixel-level defect areas, it has been widely used in various fields, particularly in the detection of defective products in the industrial field and lesion detection in the medical field.
[0003] Before the advent of deep learning, research on unsupervised image defect detection primarily focused on developing defect detection strategies and mechanisms. The primary research question was: after manually acquiring shallow image features such as grayscale, SIFT, and HOG, attempts were made to develop different detection mechanisms based on statistical or traditional machine learning methods, such as density estimation, one-class classification, and image reconstruction. Following the development of deep learning technology, and particularly the success of deep convolutional neural networks in computer vision tasks, current research has focused on integrating the expressive power of deep convolutional networks with the task of image defect detection.
[0004] When using density estimation methods, the probability distribution of normal image features is first modeled. This distribution model is then used to examine a test image to accurately detect whether it is a defective image. Density estimation-based methods are typically based on a core assumption: the features of a defective image have low probability values in the probability distribution modeled by the features of a normal image.
[0005] When building a probability distribution model, the feature distribution of normal images is unknown, so it is difficult to model. Current research uses a mapping network to map the original unknown feature distribution to a known distribution, and then uses the mapped known distribution for modeling. The mapping network mainly includes autoencoders, Glow, and NormalizingFlow. DifferNet maps the original feature distribution to a standard Gaussian distribution by utilizing the normalizing flow architecture proposed in RealNVP. During the testing phase, the input sample is classified by calculating the probability value on the standard Gaussian distribution. The CFlow model extends the method based on normalizing flow to the pixel level, models the probability distribution of each pixel on the feature map, and achieves precise positioning at the pixel level.
[0006] To enable the normalized flow network to capture more neighborhood information, the FastFlow model modifies the 1×1 convolution in the normalized flow network into an architecture that alternates 1×1 and 3×3 convolutions. To reduce inter-image differences, the PyramidFlow model employs a training method based on contrastive learning, which can reduce the differences between normal image features. Furthermore, a multi-scale mapping and fusion module is designed to increase model generalization. To address the differences between features at different levels in the feature pyramid, the MSFlow model employs a parallel normalized flow framework with an asymmetric structure to process features at different levels. Subsequently, by using a fusion flow network, MSFlow effectively integrates information from features at different levels.
[0007] Therefore, it is an urgent problem for those skilled in the art to propose an adaptive feature distribution defect detection method based on normalized flow to solve the difficulties existing in the prior art. Summary of the Invention
[0008] In view of this, the present invention provides an adaptive feature distribution defect detection method based on normalized flow, which adaptively adjusts the defect image features through the normalized flow model, thereby achieving accurate identification and classification of different defect types and improving the accuracy and robustness of detection.
[0009] In order to achieve the above object, the present invention provides the following technical solutions:
[0010] The adaptive feature distribution defect detection method based on normalized flow includes the following steps:
[0011] S1. Obtain image: Obtain an input image and use a feature extractor to extract features of the input image;
[0012] S2, adaptive normalization flow processing: adaptive normalization flow processing is performed on the features of the extracted input image;
[0013] S3. Compression distribution: Design a loss function to pull the features distributed on both sides of the mean towards the mean;
[0014] S4, boundary optimization and detection score: Calculate the similarity between the features of the current location and the features of the surrounding neighborhood, and assign a weight to the detection score of the current location.
[0015] In the above method, optionally, the specific content of the adaptive normalization flow in S1 is:
[0016] S11. Input: Features extracted by the pre-trained WideResNet-50 network;
[0017] S12, distribution mapping: mapping the original feature distribution to the adaptive Gaussian distribution;
[0018] S13. Model training: Make the original features of normal samples obtain the maximum probability value in the target distribution.
[0019] In the above method, optionally, the specific process of distribution mapping in S12 is as follows:
[0020] First, the flow model takes the input feature y in Each channel is mixed, and then the channel dimension is divided into two equal parts according to the number of channels, which are the first input features and the second input feature Then they are sent to different coupling layers for calculation; finally, the output features of the first coupling layer are and the output characteristics of the second coupling layer Connect and generate output feature y out .
[0021] The above method optionally uses the following formula to calculate the coupling layer:
[0022]
[0023]
[0024]
[0025] Among them, ⊙ is the dot multiplication operation, is the addition operation, concat(·,·) is the feature connection operation along the channel layer, functions s(·) and t(·) are arbitrary differentiable functions, and a fully connected network is selected.
[0026] In the above method, the specific content of the model training in S13 is optional:
[0027] The original feature distribution is mapped to a Gaussian distribution with adaptive parameters to improve the accuracy of model detection and the generalization of detection of different types of samples. The loss function is calculated as follows:
[0028]
[0029] Among them, μ is the mean of the features of the previous generation of normal samples during the iterative optimization process, which is initialized to the mean of the original feature distribution, log p Y (y) is the logarithmic probability density of the original feature, log p Z (z) is the logarithmic probability density of the target distribution, is the penalty term for volume change during model transformation, is the loss function of the normalized flow model, z is the variable in the latent space, and σ is the standard deviation.
[0030] The above method is optional. The specific content of the loss function designed in S3 is:
[0031] The loss function is calculated as follows:
[0032]
[0033] Among them, N is the number of normal samples in the training set, z i is the normal sample feature, γ is a hyperparameter to control the compression strength, w i is the weight, is the loss function between the model’s prediction results and the target distribution;
[0034] Therefore, the total loss of the ADNF model is for:
[0035]
[0036] in, is the loss function of the normalized flow model, is the loss function between the model's prediction results and the target distribution.
[0037] The above method is optional. In S4, the boundary optimization and detection score are calculated to calculate the similarity between the features of the current position and the features of the surrounding neighborhood. The specific content of assigning weights to the detection scores of the current position is:
[0038] During the test phase, the ADNF model calculates the probability value of the input feature on the mapped target distribution, and then uses it as the detection score. The weight calculation formula is as follows:
[0039]
[0040] Among them, Z m(z t ) is the feature Z on the feature map t The neighborhood feature set of is the target feature vector, m is a hyperparameter used to specify the number of neighborhood features, and the detection score graph after weighting is:
[0041]
[0042] Among them, a map A weight map constructed for the detection scores of all locations on the feature map, is the detection score map of the most similar features, S map is the original detection score map. The image-level detection score still selects the largest score in the score map, that is:
[0043]
[0044] It can be seen from the above technical solutions that, compared with the prior art, the present invention discloses an adaptive feature distribution defect detection method based on normalized flow, which has the following beneficial effects:
[0045] By using a normalized flow network, the feature distribution of the original unknown normal road image is adaptively mapped into an adaptive Gaussian distribution. During the testing phase, only the probability of the current feature on the Gaussian distribution needs to be calculated to determine whether the current sample is a defective sample. This method avoids the feature retrieval process and improves detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0047] Figure 1 A flow chart of the adaptive feature distribution defect detection method based on normalized flow provided by the present invention;
[0048] Figure 2 This is the detection score graph of the repair category provided by the present invention in the testing phase; wherein 2a is the original detection score graph, and 2b is the ADNF score graph. DETAILED DESCRIPTION
[0049] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0050] The existing normalized flow method still has problems. The main problem is that when modeling the distribution of features, the method adopted is to map the original feature distribution to a fixed standard Gaussian distribution. This operation ignores the differences between data sets and overestimates the mapping ability of the normalized flow network. The normalized flow network cannot accurately map all original feature distributions to a fixed standard Gaussian distribution.
[0051] The goal of the normalized flow network is to map the original feature distribution to a standard Gaussian distribution. However, the actual mapped distribution does not perfectly conform to the standard Gaussian distribution; the mean is shifted. During the test phase, when calculating the probability of features in the distribution, a more compact Gaussian distribution constructed from normal road image features results in better model detection performance. Therefore, mapping the original feature distribution to a more compact target distribution, rather than a standard Gaussian distribution, is more beneficial for calculating detection scores.
[0052] Aiming at the problem of poor adaptability of standard Gaussian distribution in traditional normalized flow model, an adaptive feature distribution defect detection method based on normalized flow is proposed.
[0053] See also Figure 1 As shown, the present invention discloses a normalized flow-based adaptive feature distribution defect detection method, comprising the following steps:
[0054] S1. Obtain image: Obtain an input image and use a feature extractor to extract features of the input image;
[0055] S2, adaptive normalization flow processing: adaptive normalization flow processing is performed on the features of the extracted input image;
[0056] S3. Compression distribution: Design a loss function to pull the features distributed on both sides of the mean towards the mean;
[0057] S4, boundary optimization and detection score: Calculate the similarity between the features of the current location and the features of the surrounding neighborhood, and assign a weight to the detection score of the current location.
[0058] Furthermore, the specific content of the adaptive normalization flow in S1 is:
[0059] S11. Input: Features extracted by the pre-trained WideResNet-50 network;
[0060] S12, distribution mapping: mapping the original feature distribution to the adaptive Gaussian distribution;
[0061] S13. Model training: Make the original features of normal samples obtain the maximum probability value in the target distribution.
[0062] Furthermore, the specific process of distribution mapping in S12 is as follows:
[0063] First, the flow model takes the input feature y in Each channel is mixed, and then the channel dimension is divided into two equal parts according to the number of channels, which are the first input features and the second input feature Then they are sent to different coupling layers for calculation; finally, the output features of the first coupling layer are and the output characteristics of the second coupling layer Connect and generate output feature y out .
[0064] Furthermore, the coupling layer calculation formula is as follows:
[0065]
[0066]
[0067]
[0068] Among them, ⊙ is the dot multiplication operation, is the addition operation, concat(·,·) is the feature connection operation along the channel layer, functions s(·) and t(·) are arbitrary differentiable functions, and a fully connected network is selected.
[0069] Furthermore, the specific content of the model training in S13 is:
[0070] The original feature distribution is mapped to a Gaussian distribution with adaptive parameters to improve the accuracy of model detection and the generalization of detection of different types of samples. The loss function is calculated as follows:
[0071]
[0072] Among them, μ is the mean of the features of the previous generation of normal samples during the iterative optimization process, which is initialized to the mean of the original feature distribution, log p Y (y) is the logarithmic probability density of the original feature, log p Z (z) is the logarithmic probability density of the target distribution, To penalize the volume change during the model transformation, we need to ensure that the model transformation is reasonable and the data maintains a good structure in the latent space. is the loss function of the normalized flow model, z is the variable in the latent space, and σ is the standard deviation.
[0073] Furthermore, the specific content of the loss function designed in S3 is:
[0074] The loss function is calculated as follows:
[0075]
[0076] Among them, N is the number of normal samples in the training set, z i is the normal sample feature, γ is a hyperparameter to control the compression strength, w i is the weight, is the loss function between the model’s prediction results and the target distribution;
[0077] Therefore, the total loss of the ADNF model is for:
[0078]
[0079] in, is the loss function of the normalized flow model, is the loss function between the model's prediction results and the target distribution.
[0080] Furthermore, in S4, the boundary optimization and detection score are calculated to calculate the similarity between the features of the current position and the features of the surrounding neighborhood. The specific content of assigning weights to the detection score of the current position is:
[0081] During the test phase, the ADNF model calculates the probability value of the input feature on the mapped target distribution, and then uses it as the detection score. The weight calculation formula is as follows:
[0082]
[0083] Among them, Z m (z t ) is the feature Z on the feature map t The neighborhood feature set of is the target feature vector, m is a hyperparameter used to specify the number of neighborhood features, and the detection score graph after weighting is:
[0084]
[0085] Among them, a map A weight map constructed for the detection scores of all locations on the feature map, is the detection score map of the most similar features, S map is the original detection score map. The image-level detection score still selects the largest score in the score map, that is:
[0086]
[0087] In a specific embodiment:
[0088] To accurately evaluate the proposed method, we used the ADNF model's experimental results on a road defect dataset and the MVTecAD dataset, and compared it with several other methods to demonstrate the ADNF model's superior performance. The evaluation metrics used were Image-AUROC for defect classification and Pixel-AUROC for defect localization.
[0089] As shown in Table 1, in the experimental metric format (·,·), the former represents the image-level defect classification result (ImageAUROC), and the latter represents the pixel-level defect area localization result (Pixel-AUROC). In terms of the Image-AUROC metric, the ADNF model achieved the best experimental results for the crack, pothole, and patch categories, with scores of 99.5%, 99.3%, and 100%, respectively. Although the ADNF model did not achieve the best results for the crack category, it was only 0.2% lower than the FastFlow model, which achieved the best result of 98.1%. The FastFlow model and PyramidFlow model, also based on normalized flow, achieved scores of 99.0% and 96.9%, respectively, which were 0.2% and 2.3% lower than the ADNF model. This demonstrates that the ADNF model has advantages over traditional standard normalized flow methods in defect type classification. In terms of the Pixel-AUROC metric, the ADNF model achieved the best experimental results for the crack, patch, and crack categories, with scores of 97.2%, 97.0%, and 96.4%, respectively. In the pothole category, the FastFlow model achieved the best result of 96.9%, 0.4% higher than the ADNF model. Comparable methods, such as the FastFlow model and the PyramidFlow model, achieved results of 96.8% and 95.2%, respectively, on this metric. The latter's experimental result was 1.6% lower than the ADNF model. Experiments demonstrate that the ADNF model has excellent performance in locating defect areas.
[0090] Table 1 Experimental results of ADNF model and several other methods on road defect dataset
[0091]
[0092] As shown in Table 2, in terms of the Image-AUROC metric, the ADNF model achieved the best experimental results on six categories. Although the FastFlow model, also based on normalized flow, achieved the best results on nine categories among the comparison methods, for the "toothbrush" category, the FastFlow model only achieved an experimental result of 94.4%, far lower than the detection performance of other categories, while the ADNF model's detection performance across different categories was more stable. At the same time, the FastFlow model achieved an average performance of 99.4% across all categories, which was 0.1% lower than the ADNF model. The above results demonstrate that the generalization of the FastFlow model is worse than that of the ADNF model. Compared with the PyramidFlow model, the ADNF model has better detection performance, especially in the cable category, where the ADNF model leads by 7.8%. Compared with the Image-AUROC metric, the ADNF model has a more obvious advantage in the Pixel-AUROC metric. Specifically, compared to the DRAEM model, the most representative of image reconstruction-based methods, the ADNF model has more stable localization performance and better overall performance. However, for the "capsule" and "transistor" categories, the DRAEM model's performance is much lower than other methods, at only 94.3% and 90.9%. Compared to the feature retrieval-based PaDiM, PatchCore, and CFA models, the ADNF model achieves better results on almost all categories, with average metrics improvements of 6.7%, 0.4%, and 0.3%, respectively. Compared to FastFlow and PyramidFlow, which are also based on normalized flows, the ADNF model also has advantages in overall performance, with Pixel-AUROC metrics improved by 0.3% and 2.3%, respectively.
[0093] Table 2 Experimental results of ADNF model on the MCTexAD dataset for image-level defect classification ImageAUROC and pixel-level defect area localization Pixel-AUROC
[0094]
[0095]
[0096] like Figure 2Figure 2 shows the detection scores for the patched category during the testing phase. The green line represents the detection scores for normal samples, and the yellow line represents the detection scores for defective samples. Figure 2a shows the detection score distribution calculated using only the raw features extracted by the feature extractor, while Figure 2b shows the detection score distribution after adaptive feature mapping using the ADNF model. Compared to Figure 2a, the detection score distributions for both normal and defective samples in Figure 2b are more discrete. Therefore, after selecting an appropriate classification threshold, the ADNF model can achieve better detection results.
[0097] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0098] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. Adaptive feature distribution defect detection method based on normalized flow, characterized by: The following steps are involved: S1. Obtain image: Obtain an input image and use a feature extractor to extract features of the input image; S2, adaptive normalization flow processing: adaptive normalization flow processing is performed on the features of the extracted input image; S3. Compression distribution: Design a loss function to pull the features distributed on both sides of the mean towards the mean; S4, boundary optimization and detection score: Calculate the similarity between the features of the current location and the features of the surrounding neighborhood, and assign a weight to the detection score of the current location.
2. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 1, characterized in that: The specific content of the adaptive normalization flow in S1 is: S11, Input: Features extracted by the pre-trained network WideResNet-50; S12, distribution mapping: mapping the original feature distribution to the adaptive Gaussian distribution; S13. Model training: Make the original features of normal samples obtain the maximum probability value in the target distribution.
3. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 2, characterized in that: The specific process of distribution mapping in S12 is: First, the flow model takes the input feature y in Each channel is mixed, and then the channel dimension is divided into two equal parts according to the number of channels, which are the first input features and the second input feature Then they are sent to different coupling layers for calculation; finally, the output features of the first coupling layer are and the output characteristics of the second coupling layer Connect and generate output feature y out .
4. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 3, characterized in that: The coupling layer calculation formula is as follows: Among them, ⊙ is the dot multiplication operation, is the addition operation, concat(·,·) is the feature connection operation along the channel layer, functions s(·) and t(·) are arbitrary differentiable functions, and a fully connected network is selected.
5. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 2, characterized in that: The specific content of model training in S13 is: The original feature distribution is mapped to a Gaussian distribution with adaptive parameters to improve the accuracy of model detection and the generalization of detection of different types of samples. The loss function is calculated as follows: Among them, μ is the mean of the features of the previous generation of normal samples during the iterative optimization process, which is initialized to the mean of the original feature distribution, log p Y (y) is the logarithmic probability density of the original feature, log p Z (z) is the logarithmic probability density of the target distribution, is the penalty term for volume change during model transformation, is the loss function of the normalized flow model, z is the variable in the latent space, and σ is the standard deviation.
6. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 1, characterized in that: The specific content of the loss function designed in S3 is: The loss function is calculated as follows: Among them, N is the number of normal samples in the training set, z i is the normal sample feature, γ is a hyperparameter to control the compression strength, w i is the weight, is the loss function between the model’s prediction results and the target distribution; Therefore, the total loss of the ADNF model is for: in, is the loss function of the normalized flow model, is the loss function between the model's prediction results and the target distribution.
7. The method for defect detection based on adaptive feature distribution of normalized flow according to claim 1, characterized in that: In S4, the boundary optimization and detection score are calculated to calculate the similarity between the features of the current position and the features of the surrounding neighborhood. The specific content of assigning weights to the detection score of the current position is: In the test phase, ADNF calculates the probability value of the input feature on the mapped target distribution, and then uses it as the detection score. The weight calculation formula is as follows: Among them, Z m (z t ) is the feature Z on the feature map t The neighborhood feature set of is the target feature vector, m is a hyperparameter used to specify the number of neighborhood features, and the detection score graph after weighting is: Among them, a map A weight map constructed for the detection scores of all locations on the feature map, is the detection score map of the most similar features, S map is the original detection score map. The image-level detection score still selects the largest score in the score map, that is: