Untrained anomaly detection method and system

CN122967051APending Publication Date: 2026-10-23SOUTHERN UNIVERSITY OF SCIENCE AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611391294.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-09
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0008]针对现有技术的不足,本发明提供了一种无训练异常检测方法与系统,旨在解决以下技术问题:在训练集可能含有缺陷样本污染且不使用任何缺陷标注、不进行任何模型参数梯度更新的约束下,如何同时抑制污染样本进入正常特征参照集合所造成的检测精度退化,以及如何消除多个特征层之间k近邻距离尺度不一致所导致的跨层聚合失真

Benefits of technology

(1)在训练集含有缺陷样本污染的条件下,本发明通过对图像级异常分数进行统计分布建模,依据统计分布建模的结果,从训练图像集中确定由正常样本构成的干净核并将污染样本排除在正常特征参照集合之外,检测精度接近以完全干净训练集运行的同构检测器,显著优于直接在污染训练集上运行而不做任何清洗与标准化处理的方案。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122967051A_ABST
    Figure CN122967051A_ABST
Patent Text Reader

Abstract

The application discloses a kind of training exception detection method and system, belong to computer vision technical field.Aiming at the industrial constraint that training set can contain defect sample pollution and no label no training, the statistical distribution modeling of the unlabeled mutual evaluation score of training image set is carried out, the clean core is filtered out according to the statistical distribution characteristics of image level exception score, and the normal feature reference set is constructed with the clean core as source;The mean value and standard deviation of k nearest neighbor distance of each layer are determined according to the clean core for each feature layer of pre-training feature extraction network, and the abnormal score is generated after z-score standardization and cross-layer aggregation for each layer of the image to be measured.The whole process does not need defect label, does not need gradient training.The detection precision of the application approaches the level of completely clean training set under the condition that training set is polluted, single picture reasoning reaches millisecond level, and is suitable for industrial real-time production line quality inspection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, and specifically to a method and system for detecting anomalies without training. Background Technology

[0002] Anomaly detection methods based on memory (represented by PatchCore) are one of the mainstream paradigms in current industrial visual quality inspection. The core process involves: using a pre-trained feature extraction network with frozen parameters to extract image patch features from training images; constructing a normal feature memory after core set reduction; and using the k-nearest neighbor distance from the test image patch to the memory as the anomaly score during testing. This type of method does not require gradient training for specific tasks, has low deployment costs, and fast inference speed, and has been widely used in surface defect detection on industrial production lines.

[0003] However, this type of method generally suffers from the following technical drawbacks in industrial deployments: Defect 1: The assumption of a pure training set is severely inconsistent with industrial realities. This type of method implicitly assumes that the training set must consist entirely of normal samples. Once defective images are mixed into the training set, their corresponding defect features are written into the memory. During testing, similar defects are misclassified as normal because they are closer to the features in the memory, leading to a significant increase in the false negative rate. In real industrial scenarios, due to factors such as imperfect production line quality gating, limited normal sample acquisition windows, and equipment status fluctuations, defective images inevitably mix into the training data pool, and the higher the contamination ratio, the more severe the degradation in detection accuracy.

[0004] Defect 2: Existing anti-contamination schemes rely on gradient training or defect labeling, limiting their applicability. To mitigate contamination degradation, existing schemes each have limitations. Soft-weighted schemes (such as SoftPatch) apply learnable weights to image patch features to suppress contamination, but rely on gradient iterative optimization, making them unusable in scenarios lacking training infrastructure. Schemes based on decoupled representation learning require supervised training with defect-labeled data, contradicting the "unlabeled" industrial constraint. Schemes based on simple percentile truncation require no training, but when the score distributions of contaminated and normal samples overlap, they are prone to mis-screening and under-screening, lacking guaranteed effectiveness. In summary, existing schemes all rely on gradient training or defect labeling to varying degrees, lacking effective means under the completely unlabeled industrial constraint of prohibiting gradient updates.

[0005] Defect 3: Cross-layer feature scale heterogeneity has been neglected for a long time. Different feature layers of pre-trained feature extraction networks have different numerical distribution characteristics. The mean scale of the k-nearest neighbor distance calculated on different layers for the same image patch may differ by more than an order of magnitude. Existing methods usually directly concatenate multi-layer features (such as PatchCore) or simply average them, with high-scale layers numerically dominating and suppressing the discriminative information of low-scale layers, resulting in the failure to fully utilize the complementary advantages of multi-layer features. This defect is unrelated to whether the training set is contaminated and is an independent technical problem.

[0006] Defect 4: Existing applications of Gaussian mixture models in anomaly detection are orthogonal to this invention. While Gaussian mixture models have been applied in visual anomaly detection, their uses are fundamentally different from those of this invention. For example, PaDiM establishes a multivariate Gaussian distribution for each image patch location, using Mahalanobis distance to measure anomalies; DAGMM models Gaussian mixtures on the sample reconstruction residuals. The Gaussian models in these schemes all operate on the image patch feature space or sample encoding space to directly generate anomaly scores. Existing technologies do not demonstrate the application of Gaussian mixture models to the training set image-level anomaly scores to identify clean training subsets.

[0007] In summary, existing memory-based methods cannot simultaneously suppress contamination degradation and eliminate cross-scale heterogeneity when the training set is contaminated and industrial scenarios prohibit the use of defect labeling and gradient training. Summary of the Invention

[0008] To address the shortcomings of existing technologies, this invention provides a training-free anomaly detection method and system, aiming to solve the following technical problems: how to simultaneously suppress the degradation of detection accuracy caused by contaminated samples entering the normal feature reference set, and how to eliminate cross-layer aggregation distortion caused by inconsistent k-nearest neighbor distance scales between multiple feature layers, under the constraints that the training set may contain defective samples and no defect annotations or model parameter gradient updates are used.

[0009] To achieve the above objectives, the present invention adopts the following technical solution: Firstly, a training-free anomaly detection method includes: Obtain an unlabeled training image set that may be contaminated by defective images, use a pre-trained feature extraction network with frozen parameters to extract multi-layer image patch features of each image in the training image set, and obtain the image-level anomaly score of each training image. The image-level anomaly scores are statistically distributed and modeled. Based on the results of the statistical distribution modeling, a clean kernel composed of normal samples is determined from the training image set, and a normal feature reference set is constructed using the clean kernel as the source. For each of the multiple feature layers of the pre-trained feature extraction network, a normal feature reference set for that layer is constructed using the image patch features in the clean kernel as the source. The mean and standard deviation of that layer are determined based on the k nearest neighbor distance between the clean kernel image patch and the normal feature reference set of that layer. For the image patch features of the image under test at each layer, calculate the k nearest neighbor distance of each feature relative to the normal feature reference set of the corresponding feature layer, and perform layer-by-layer z-score standardization based on the mean and standard deviation of the layer. Then, aggregate the standardized scores of each layer across layers to generate the abnormal score result of the image under test. The determination of the clean kernel and the entire process of anomaly scoring do not use any defect annotations, do not update the parameters of the pre-trained feature extraction network through gradient backpropagation, and the mean and standard deviation of each layer used in the layer-by-layer z-score standardization are calculated from the image patch features in the clean kernel.

[0010] Furthermore, the image-level anomaly score is obtained through leave-one-out mutual scoring: for each training image, the multi-scale nearest neighbor dissimilarity between the training image and the other training images is calculated with reference to the multi-layer image patch features of the other training images, and the dissimilarity is used as the image-level anomaly score of the training image.

[0011] Furthermore, the statistical distribution modeling is implemented using a two-component Gaussian mixture model: A two-component Gaussian mixture model is fitted to all image-level anomaly scores in the training image set. The two-component Gaussian mixture model is expressed as: p(s)=π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²); Where s is the image-level anomaly score, π0 is the mixing weight of the normal component, π1 is the mixing weight of the anomaly component, N(·|μ,σ²) is the Gaussian probability density function, μ0 and σ0² are the mean and variance of the normal component, respectively, and μ1 and σ1² are the mean and variance of the anomaly component, respectively. The component with the smaller mean value among the two Gaussian components is forcibly identified as the normal component, and the other is identified as the abnormal component, with the condition that μ0 < μ1. The posterior probability of each training image belonging to the normal component is calculated according to Bayes' theorem, and the posterior probability is calculated as follows: P(z=0|s)=π0·N(s|μ0,σ0²) / [π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²)]; Where z=0 indicates that it belongs to the normal component; The training image whose posterior probability reaches a predetermined threshold τ is determined as a clean kernel, and the predetermined threshold τ ranges from 0.5 to τ to 0.99.

[0012] Furthermore, the layer-by-layer z-score normalization is performed according to the following formula: z n (p)=(d n (p)-μ n ) / (σ n +ε); Where, d n (p) represents the average k-nearest neighbor distance of the image under test in the nth layer, μ n With σ n These are the mean and standard deviation of the nearest neighbor distances in the nth layer determined by the clean kernel image block, respectively, and ε is a constant to prevent division by zero; The cross-layer aggregation includes: averaging the standardized scores of each feature layer to obtain an image block-level anomaly score, and then aggregating the average scores of the image blocks with the highest scores to obtain the image-level anomaly score of the image to be tested; the image block-level score is then upsampled and smoothed to obtain a pixel-level anomaly rating map.

[0013] Furthermore, the multiple feature layers are derived from at least two different depth levels of the pre-trained feature extraction network, which is a self-supervised visual transformation network or a residual convolutional network; the normal feature reference set is constructed after reduction by the farthest point sampling core set.

[0014] Secondly, a training-free anomaly detection system includes: The feature extraction module is used to extract multi-layer image patch features from an unlabeled training image set that may be contaminated by defective images using a pre-trained feature extraction network with frozen parameters, and to obtain an image-level anomaly score for each training image based on the extracted multi-layer image patch features. The clean kernel estimation module is used to perform statistical distribution modeling on the image-level anomaly scores, determine clean kernels composed of normal samples from the training image set based on the results of the statistical distribution modeling, and construct a normal feature reference set using the clean kernels as the source. The layer-by-layer standardization scoring module is used to construct a normal feature reference set for each layer of the pre-trained feature extraction network, using the image patch features in the clean kernel as the source. The mean and standard deviation of the layer are determined based on the k-nearest neighbor distance of the clean kernel image patch relative to the normal feature reference set of the layer. The k-nearest neighbor distance of the image patch features of the image to be tested in each layer relative to the normal feature reference set of the corresponding feature layer is calculated. Layer-by-layer z-score standardization is performed based on the mean and standard deviation of the layer. The standardized scores of each layer are aggregated across layers to generate the abnormal score result of the image to be tested. The determination of the clean kernel and the entire process of anomaly scoring do not use any defect annotations, do not update the parameters of the pre-trained feature extraction network through gradient backpropagation, and the mean and standard deviation of each layer used in the layer-by-layer z-score standardization are calculated from the image patch features in the clean kernel.

[0015] Furthermore, the feature extraction module includes an image-level anomaly score acquisition unit, which is used to acquire the image-level anomaly score of each training image through leave-one-out mutual scoring: for each training image, taking the global reference feature set formed by merging the image patch features of the other training images in multiple feature layers as a reference, the multi-scale nearest neighbor dissimilarity between the training image and the global reference feature set is calculated, and the dissimilarity is used as the image-level anomaly score of the training image.

[0016] Furthermore, the statistical distribution modeling is implemented using a two-component Gaussian mixture model, and the clean kernel estimation module includes: A Gaussian mixture model fitting unit is used to fit a two-component Gaussian mixture model to all image-level anomaly scores in the training image set. The two-component Gaussian mixture model is expressed as follows: p(s)=π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²); Where s is the image-level anomaly score, π0 is the mixing weight of the normal component, π1 is the mixing weight of the anomaly component, N(·|μ,σ²) is the Gaussian probability density function, μ0 and σ0² are the mean and variance of the normal component, respectively, and μ1 and σ1² are the mean and variance of the anomaly component, respectively. The condition for forcibly identifying the Gaussian component with the smaller mean value as the normal component is μ0 < μ1. The posterior probability calculation unit is used to calculate the posterior probability of each training image belonging to the normal component based on Bayes' theorem. P(z=0|s)=π0·N(s|μ0,σ0²) / [π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²)]; Where z=0 indicates that it belongs to the normal component; A threshold determination and selection unit is used to determine the training image whose posterior probability reaches a predetermined threshold τ as a clean kernel, wherein the predetermined threshold τ ranges from 0.5 to τ to 0.99. In this method, the Gaussian component with the smaller mean value is forcibly identified as the normal component, while the other is identified as the abnormal component, with the criterion being μ0 < μ0. 1。

[0017] Furthermore, the layer-by-layer z-score normalization is performed according to the following formula: z n (p)=(d n (p)-μ n ) / (σ n +ε); Where, d n (p) represents the average k-nearest neighbor distance of the image under test in the nth layer, μ n With σ n These are the mean and standard deviation of the nearest neighbor distances in the nth layer determined by the clean kernel image block, respectively, and ε is a constant to prevent division by zero; The cross-layer aggregation includes: averaging the standardized scores of each feature layer to obtain an image block-level anomaly score, and then aggregating the average scores of the image blocks with the highest scores to obtain the image-level anomaly score of the image to be tested; the image block-level score is then upsampled and smoothed to obtain a pixel-level anomaly rating map.

[0018] Furthermore, the multiple feature layers are derived from at least two different depth levels of the pre-trained feature extraction network, which is a self-supervised visual transformation network or a residual convolutional network; the normal feature reference set is constructed after reduction by the farthest point sampling core set.

[0019] Compared with the prior art, the beneficial effects of the present invention are as follows: (1) Under the condition that the training set contains defective samples, the present invention performs statistical distribution modeling on the image-level anomaly scores. Based on the results of the statistical distribution modeling, it determines the clean kernel composed of normal samples from the training image set and excludes the contaminated samples from the normal feature reference set. The detection accuracy is close to that of the isomorphic detector running on a completely clean training set, which is significantly better than the scheme that runs directly on the contaminated training set without any cleaning and standardization.

[0020] (2) The present invention performs z-score normalization on the k nearest neighbor distances of multiple feature layers and then aggregates them across layers, which eliminates the order of magnitude difference in numerical scale between different feature layers, so that the discrimination information of each layer can be fully utilized. Even if the training set is completely uncontaminated, this normalization operation can still independently bring detection accuracy gain.

[0021] (3) This invention relies only on forward inference and parameterless statistical operations of pre-trained feature extraction, without involving any gradient backpropagation or parameter optimization, which has significant advantages in industrial deployment scenarios where training infrastructure is lacking or defect annotations cannot be obtained.

[0022] (4) Single-graph inference reaches the millisecond level and can be deployed on industrial real-time production lines; clean kernel estimation and reference set construction are one-time offline costs that do not increase linearly with the number of test samples. This invention performs stably on various backbone networks, various industrial anomaly detection datasets, and multiple segments from uncontaminated to high contamination rates without performance crashes. Attached Figure Description

[0023] Figure 1 This is a schematic diagram of the training-free anomaly detection method of the present invention; Figure 2 This is a schematic block diagram of the training-free anomaly detection system of the present invention.

[0024] Explanation of reference numerals in the attached figures: 10. Feature Extraction Module; 11. Training Image Feature Extraction Unit; 12. Image-Level Anomaly Score Acquisition Unit; 20. Clean Kernel Estimation Module; 21. Gaussian Mixture Model Fitting Unit; 22. Posterior Probability Calculation Unit; 23. Threshold Determination and Selection Unit; 24. Failure-Safe Unit; 30. Layer-by-Layer Standardized Scoring Module; 31. Reference Set Construction Unit; 32. Layer-by-Layer Statistics Calculation Unit; 33. k-Nearest Neighbor Distance Calculation Unit; 34. z-Score Standardization Unit; 40. Anomaly Score Output Module; 41. Cross-Layer Aggregation Unit; 42. Image-Level Scoring Unit; 43. Pixel-Level Scoring Map Generation Unit. Detailed Implementation

[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0026] The following is combined Figure 1 The overall implementation of the training-free anomaly detection method provided by the present invention will be described in detail.

[0027] like Figure 1 As shown, the method of the present invention includes the following steps: Step S101: Obtain an unlabeled training image set that may be contaminated by defective images.

[0028] The training image set consists of product surface images captured by image acquisition equipment on industrial production lines (such as industrial cameras and line scan scanners). Due to factors such as imperfect quality gating on the production line and a limited normal sample acquisition window, a certain proportion of defective samples may be mixed into this training image set. The training image set does not contain any defect annotation information; that is, each image has no pixel-level or image-level defect labels.

[0029] Step S102: Use the parameter-frozen pre-trained feature extraction network to extract multi-layer image patch features from each image in the training image set.

[0030] In this embodiment, the pre-trained feature extraction network can be a residual convolutional network (such as WideResNet50) pre-trained on a large-scale image dataset (such as ImageNet) or a self-supervised visual transformation network (such as ViT pre-trained on DINO). The parameters of the network remain frozen throughout the process, i.e., no gradient updates or fine-tuning are performed.

[0031] Specifically, the input image is scaled to a uniform size (e.g., 224×224 pixels) and fed into a pre-trained feature extraction network. The output feature maps of several intermediate layers of the network (e.g., the 2nd, 3rd, and 4th residual blocks or transformer layers) are selected, and sliding window sampling is performed on each feature map to obtain an image patch feature vector. For the image patch at spatial location (i,j), its feature vectors output by each layer are stored separately for use in subsequent steps.

[0032] Step S103: Obtain the image-level anomaly score for each training image.

[0033] In this embodiment, the image-level anomaly score is obtained through leave-one-out mutual scoring. Specifically, for each image x in the training image set... i , to divide x i The remaining training images are used as the reference image set, and the image patch features of each reference image at each feature layer are merged into the global reference feature set of the corresponding layer (hereinafter referred to as the reference set); using the reference set as a reference, x is calculated. i The multi-scale nearest neighbor dissimilarity with the reference set refers to the nearest neighbor dissimilarity calculated by integrating different spatial scales corresponding to multiple feature layers. This dissimilarity is used as x. i Image-level anomaly score i For a detailed explanation of the calculation process, please refer to the detailed explanation of the peer review below.

[0034] The basic principle of mutual scoring is that normal images are relatively close to other training images in the feature space, with a small k-nearest neighbor distance; defective images are far from most training images due to their abnormal appearance, with a large k-nearest neighbor distance. The lower the score, the more likely the image is to be a normal image, and the higher the score, the more likely it is to be a defective image.

[0035] It should be noted that this implementation adopts a leave-one-out mutual scoring method, the purpose of which is to avoid the k-nearest neighbor distance estimation bias caused by including the image to be evaluated itself in the global reference feature set. If the image itself is used as a reference, its nearest neighbor distance with its own features is zero, which will significantly lower the average nearest neighbor distance of the image, causing normal images to produce the illusion of abnormally low scores due to their own reference, thereby affecting the effectiveness of image-level abnormal scores.

[0036] In step S103, the image-level anomaly score for each training image is obtained through a leave-one-out mutual scoring method. This step provides a detailed explanation of the specific calculation process for this mutual scoring method.

[0037] (a) Basic settings for peer evaluation.

[0038] Let the training image set be {x} i | i=1,2,...,M}, where M is the total number of training images. For each training image x i Use it as the query image, excluding x. i The remaining M-1 training images, excluding those from step S102, are used as the reference image set (i.e., leave-one-out method). Using the multi-layer image patch features extracted in step S102, x is calculated respectively. i Image-level anomaly score relative to the reference image set i .

[0039] (ii) Layer-by-layer calculation of multi-scale nearest neighbor dissimilarity.

[0040] Suppose the pre-trained feature extraction network outputs L feature layers. For the nth layer (n=1,2,...,L), the following operation is performed: For query image x i The set of all image patch features Q at layer n i n ={q i,n (u,v) | (u,v)∈Grid n}, where Grid n Let (u,v) be the spatial location grid of the nth layer feature map, where (u,v) are the spatial coordinates.

[0041] For reference image x j (j≠i) The set of all image patch features R in the nth layer j n ={r j,n (u,v) |(u,v)∈Grid n}

[0042] Merge the image patch features of all reference images at layer n to form the global reference feature set R for that layer. (-i)n =∪ j≠i R j n .

[0043] For query image x i Each image patch feature q in the nth layer i,n (u,v) Calculate its position in the global reference feature set R {(-i)} n k-nearest neighbor distance in: d i,n (u,v) =(1 / k)· ;

[0044] Where, r t q is the median of the global reference feature set. i,n (u,v) Let t be the nearest eigenvector, and ||·||2 be the Euclidean distance.

[0045] (iii) Cross-layer aggregation of image-level anomaly scores.

[0046] Query image x i The average of the k nearest neighbor distances of all image patches in the nth layer is used to obtain x. i Interlayer dissimilarity at layer n: D i,n =mean (u,v) [d i,n (u,v) ]; The interlayer dissimilarity of each feature layer is further averaged to obtain x. i Image-level anomaly score: s i =(1 / L)· ; (iv) Technical principles of peer scoring.

[0047] When querying image x i When it is a normal image, the features of each layer of the image patch are quite similar to the features of the corresponding image patch in most reference images, d i,n (u,v) The value is relatively small, therefore s i Smaller.

[0048] When querying image x i When the image is a defective image, the image patch features of its defective region lack nearest neighbor matching in the reference image set, d i,n (u,v) The value is relatively large, therefore s i Relatively large.

[0049] In this way, each training image obtains an independent image-level anomaly score s. i This is used for Gaussian mixture model fitting in step S104.

[0050] Step S104: Fit a two-component Gaussian mixture model to all image-level anomaly scores in the training image set to determine the clean kernel.

[0051] This step is one of the core inventive points of this invention. It involves calculating the image-level anomaly scores for all training images obtained in step S103. (M is the total number of training images) Fit a two-component Gaussian mixture model. The fitting can be performed using the expectation-maximization algorithm, which iteratively updates the weights, mean, and variance of each component until convergence.

[0052] After fitting, two Gaussian components are obtained: component 0 with weight π0, mean μ0, and variance σ0²; and component 1 with weight π1, mean μ1, and variance σ1². Since a lower image-level anomaly score indicates a higher probability of normality, this invention forcibly identifies the Gaussian component with the smaller mean as the normal component, i.e., satisfying μ0 < μ1.

[0053] Subsequently, the posterior probability of each training image belonging to a normal component is calculated based on Bayes' theorem: P(z=0|s)=π0·N(s|μ0,σ0²) / [π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²)]; Training images whose posterior probability reaches a predetermined threshold are defined as "clean kernels": Clean kernel = {x i |P(z=0|s)≥τ}; In this invention, the value of the predetermined threshold τ directly affects the balance between the purity of the clean kernel and the sample size. The higher the value of τ, the higher the posterior probability of the images selected for the clean kernel, and the higher the purity of the clean kernel, but the number of selected samples may decrease; the lower the value of τ, the more selected samples, and the higher the stability of the statistical estimate, but boundary contamination samples may be mixed in.

[0054] The value range of τ is selected based on the actual pollution characteristics in the industrial scenario and the size of the training set. Preferably, the value range of τ is 0.5 to 0.99. This embodiment provides the following three typical value examples: When τ = 0.5: When the training set is small (e.g., less than 500 images) or the contamination rate is low (e.g., less than 5%), the distribution of image-level anomaly scores may be relatively concentrated, and the separation between normal and anomaly components may be limited. In such scenarios, using a posterior probability threshold of τ=0.5 allows images with a posterior probability exceeding 50% to be selected for clean kernels. This maximizes the number of training samples while ensuring a certain level of purity, thus ensuring the mean μ of subsequent layers is maintained. n With standard deviation σ n The statistical estimates are supported by sufficient samples.

[0055] When τ = 0.99: When the training set is large (e.g., more than 2000 images) and the production line quality gating is relatively lenient, with a potential high contamination rate (e.g., above 10%), a high threshold of τ=0.99 is used. Only high-confidence normal images with a posterior probability higher than 99% are selected for the clean kernel. In this case, even if the number of selected images is relatively small, the large sample size still ensures the stability of the statistical estimation; at the same time, the extremely high threshold excludes contaminated samples to the greatest extent, significantly improving the purity of the clean kernel and effectively ensuring the reliability of the normal feature reference set.

[0056] When τ = 0.8: In most industrial scenarios, where the training set size is moderate (500-2000 images) and the contamination rate is approximately 5%-10%, τ=0.8 achieves a good balance between purity and sample size, ensuring both the reliability of clean kernels and the stability of layer-by-layer statistics. τ=0.8 is the preferred embodiment of this invention under the above conditions.

[0057] The value of τ can be adjusted from 0.5 to 0.99 depending on the size of the training set, the estimated level of contamination, and the actual application requirements, and is not limited to the specific example values ​​mentioned above.

[0058] Step S105: Construct a reference set of normal features for each layer using clean kernels as the source, and determine the statistics for each layer.

[0059] Using the image patch features in the clean kernel image set determined in step S104 as the source, a normal feature reference set is constructed for each of the multiple feature layers of the pre-trained feature extraction network.

[0060] Specifically, suppose there are L feature layers (L≥2). For the nth layer (n=1,2,...,L), the kernel set is reduced by sampling the furthest point from all image patch features output by the clean kernel image of that layer, resulting in the normal feature reference set M of that layer. n The retention ratio of the farthest point sampling can be set according to storage and computing resources, generally retaining 10% to 20% of the original image patch count, in order to reduce storage and search overhead while maintaining detection accuracy.

[0061] Subsequently, the features of each image patch in the clean kernel are calculated relative to M. n The average distance of k nearest neighbors is used to determine the mean μ of the nth layer. n With standard deviation σ n : μ n =mean({d n (q)|q∈clean kernel image block}); σ n =std({d n (q)|q∈clean kernel image block}); Where d n (q) represents the reference set M of the image patch feature q at the nth layer. n The k-nearest neighbor average distance is used, where k can range from 5 to 20, with k=9 being the preferred value.

[0062] Step S106: Calculate the k-nearest neighbor distance layer by layer for the image under test and perform z-score normalization.

[0063] For the image to be tested (a new product image requiring anomaly detection), the same pre-trained feature extraction network is used to extract image patch features at each layer. For each image patch feature p in the nth layer of the image to be tested, its reference to the normal feature set M of that layer is calculated. n k-nearest neighbor average distance d n (p).

[0064] Subsequently, the mean μ of the nth layer determined in step S105 is used. n With standard deviation σ n Apply the following formula to d n (p) Perform z-score normalization layer by layer: z n (p)=(d n (p)-μ n ) / (σ n +ε); Where ε is a constant used to prevent the denominator from being zero, it is generally taken as 1 × 10⁻⁶. -6 .

[0065] Step S107: Generate anomaly scoring results through cross-layer aggregation.

[0066] First, the standardized fractional images of each layer are upsampled to a common grid size U×V using bilinear interpolation. The common grid size is selected from the lowest resolution layer among all layers to ensure the rationality of the upsampling.

[0067] Subsequently, the standardized scores are averaged across layers according to spatial location on the common grid: score(u,v)=(1 / L)· ; Since the scores of each layer have been standardized by z-score, direct averaging will not cause the problem of one layer dominating the result due to its large numerical scale, and the discriminative information of each layer can be fully integrated.

[0068] Subsequently, the score(u,v) of all grid positions in the image under test is sorted from high to low. The image blocks with the highest scores, representing a predetermined percentage (e.g., 10%), are selected, and their average score is calculated as the image-level anomaly score of the image under test. This image-level score can be used for binary judgment of "pass / fail" on the production line; a value exceeding a preset threshold indicates a defective product.

[0069] The image block-level scores are upsampled to the original size of the image under test by bilinear interpolation, and then smoothed by Gaussian filtering (kernel size 5×5, σ=1.0) to obtain a pixel-level anomaly score map, where the value of each pixel represents the probability of a defect at that location, and the higher the value, the greater the probability of an anomaly.

[0070] This completes the anomaly detection of the image under test, and outputs an image-level anomaly score (used for image-level judgment, such as "pass / fail") and a pixel-level anomaly score map (used for defect location).

[0071] In step S107, the standardized scores of each layer need to be averaged across layers according to spatial location. Since the multiple feature layers of the pre-trained feature extraction network have different spatial resolutions, it is necessary to map the feature maps of each layer to a common image patch location grid. The mapping method in this embodiment is as follows: (a) Standardization of grid size.

[0072] Let the size of the image to be tested after scaling be H×W (e.g., 224×224 pixels). Let the spatial size of the output feature map of the nth layer of the pre-trained feature extraction network be H. n ×W n For different depth levels, H n and W n They may differ (for example, the second layer is 28×28, the third layer is 14×14, and the fourth layer is 7×7).

[0073] To perform cross-layer aggregation, a common image patch location grid G={(u,v)|u=1,...,U, v=1,...,V} is defined, where U and V are uniform grid sizes.

[0074] (ii) Mapping of feature maps of each layer to the common grid.

[0075] For the feature map of the nth layer, its spatial size is H. n ×W nBilinear interpolation is used to upsample the images to a common grid size U×V, so that each image patch feature in the nth layer corresponds to a spatial location on the common grid. The interpolation method is as follows:

[0076] For a target location (u,v) on a common grid, find its four nearest neighbor locations (top left, top right, bottom left, bottom right) in the original feature map of the nth layer, obtain the feature vectors of these locations, and obtain the feature vector of the target location by weighted average according to distance, or directly calculate the interpolation distance of the target location in the original grid.

[0077] Since the object of cross-level averaging in this invention is the standardized score z n (p) is not the original feature vector, therefore a simpler mapping method is:

[0078] The standardized score plot z of the nth layer n (·) (size is H) n ×W n The z-axis is directly upsampled to a common grid size U×V using bilinear interpolation. n (grid) (u,v). After each layer completes the upsampling operation, for each location (u,v) on the common grid, there are L standardized scores z1. (grid) (u,v), z2 (grid) (u,v), ..., z L (grid) (u,v).

[0079] (iii) Selection of common grid size.

[0080] The selection of the common mesh size U×V should satisfy the following condition: for all feature layers n=1,2,...,L, H n ≥U and W n ≥V, meaning the upsampling operation will not introduce interpolation information exceeding the resolution of the original feature map. In the preferred embodiment, U=min(H) n V=min(W) n That is, the feature layer with the lowest resolution is used as the common grid size, and other layers are upsampled to this size.

[0081] (iv) Cross-layer aggregation.

[0082] On the common grid, the standardized scores are averaged across layers according to spatial location: score(u,v) = (1 / L) · ; The score(u,v) is the image block-level anomaly score in step S107.

[0083] (v) Generation of pixel-level rating images.

[0084] The image block-level anomaly score (score(u,v) on the common grid G ​​is upsampled to the original input image size H×W using bilinear interpolation, and then smoothed using Gaussian filtering to obtain a pixel-level anomaly score map. The value of each pixel represents the probability of a defect existing at that location.

[0085] The clean kernel estimation steps based on the Gaussian mixture model in this invention will be described in more detail below.

[0086] The specific process of clean kernel estimation includes:

[0087] Step S201: Input the training set image-level anomaly scores obtained in step S103. .

[0088] Step S202: For Fitting a two-component Gaussian mixture model: p(s)=π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²) The fitting employs the expectation-maximization algorithm. This algorithm is executed iteratively in the following two steps until convergence: Calculate each sample s i Posterior probabilities of belonging to each component: γ {i,j} =π j ·N(s i |μ j ,σ j ²) / [π0·N(s i |μ0,σ0²)+π1·N(s i [|μ1,σ1²)],j=0,1; Update the parameters of each component: π j =(1 / M)·Σ i γ {i,j} ; μ j =(Σ i γ {i,j} s i ) / (Σ i γ {i,j} )σ j ²=(Σ i γ {i,j} ,j)·(s i -μ j ) 2 / (Σ i γ {i,j} ) Iterate until the change in the log-likelihood function is less than a preset threshold (e.g., 1×10). -6 Stop when ).

[0089] Step S203: Force μ0 < μ1 to determine the normal component. If μ0 > μ1 in the fitting result, swap all parameters of the two components to ensure that μ0 is the mean of the normal component.

[0090] Step S204: Calculate the posterior probability of each training image belonging to a normal component according to the following formula: P(z=0|s i )=π0·N(si|μ0,σ0²) / [π0·N(s i |μ0σ0²)+π1·N(s i |μ1,σ1²)] Step S205: Determine P(z=0|s) i Is it ≥ the predetermined threshold τ?

[0091] Step S206: If P(z=0|si)≥τ, assign the image to a clean kernel.

[0092] Step S207: If P(z=0|si)<τ, the image is determined to be a contaminated or suspected contaminated sample and is excluded from the subsequent construction of the normal feature reference set.

[0093] Step S208: Output a clean kernel set consisting of all images that meet the conditions.

[0094] In this way, the present invention filters out a high-confidence normal sample subset from a potentially contaminated training set in a completely unsupervised manner, fundamentally eliminating the influence of contaminated samples on the normal feature reference set.

[0095] It should be understood that the clean kernel estimation of the present invention is not limited to Gaussian mixture models. Any statistical modeling method that selects a normal training subset based on the statistical distribution characteristics of image-level anomaly scores under the constraint of no labeling and no gradient updates, such as kernel density estimation and log-normal distribution fitting, is within the scope of the present invention. Those skilled in the art can make reasonable extensions based on this.

[0096] Since the actual distribution of image-level anomaly scores may not be an ideal bimodal shape (for example, when the contamination ratio is extremely low or the characteristics of contaminated samples are not significantly different from those of normal samples, the score distribution may show a single peak), this invention incorporates a failure safety mechanism in the clean kernel estimation process.

[0097] In this embodiment, the fail-safe mechanism specifically includes: (I) Reliability Judgment Based on BIC. The Bayesian Information Criterion (BIC) is used to evaluate the goodness of fit between the single-component Gaussian model and the two-component Gaussian model. The formula for calculating BIC is:

[0098] in is the maximum likelihood value of the model, k is the number of model parameters (k=2 for a single-component model, k=5 for a two-component model), and M is the total number of samples.

[0099] Calculate the difference in Bimodal Constituent Intelligence (BIC) between the two-component model and the single-component model, ΔBIC = BIC1 - BIC2. ΔBIC > 0 indicates that the two-component model is superior, and a larger ΔBIC indicates stronger evidence of a bimodal distribution. Only when ΔBIC exceeds a predetermined threshold (e.g., ΔBIC > 6, corresponding to a "strong evidence" level) is the two-component Gaussian mixture model used for posterior probability discrimination.

[0100] If ΔBIC does not exceed the threshold, it indicates that the score distribution does not have significant bimodality. In this case, a robust z-score selection method based on the median and median absolute deviation (MAD) is first used to coarsely screen image-level outlier scores. Specifically, the median(s) and median absolute deviation (MAD) of the score sequence are calculated as: median(s) = median(|s ... i -median(s)|). Training images with scores below the threshold median(s)-λ·MAD(s) are retained as a coarse candidate set (the lower the score, the more likely it is a normal sample). Then, the abnormal scores of the coarse candidate set are refitted with a statistical distribution model (such as a two-component Gaussian mixture model), and the clean kernel is finally determined based on the posterior probability, where λ is a predetermined constant (generally taken as 2.5~3.5).

[0101] (ii) Minimum size limit for clean cores. Set a minimum size limit N for clean cores. min (e.g. N) min =50). When the number of images with selected clean kernels is less than N... min When backtracking, the process involves retaining a subset of training images with the lowest image-level anomaly scores (specifically, N images). min This is to ensure the statistical stability of the subsequent reference set construction.

[0102] Through the aforementioned dual failure safety mechanism, this invention can operate stably under different pollution ratios and pollution forms, avoiding algorithm crashes due to the failure of the bimodal hypothesis.

[0103] The following provides a more detailed explanation of the hierarchical standardized nearest neighbor scoring steps based on clean kernel statistics in this invention.

[0104] The hierarchical standardized scoring process includes: Step S301: Input the clean kernel image block features determined in step S104.

[0105] Step S302: Construct a normal feature reference set M for the nth layer (n=1,2,...,L). n Specifically, from all image patch features in the clean kernel image at layer n, a predetermined proportion of feature vectors are preserved through farthest point sampling. The algorithm flow for farthest point sampling is as follows: Randomly select the first point from all feature points as the starting point; Select the points that have the largest minimum distance from the already selected point set one by one, until the preset number of points to be retained is reached; The final set of points retained is M. n .

[0106] This sampling method can guarantee M n It covers the normal feature space to the greatest extent possible while avoiding feature redundancy.

[0107] Step S303: For each image patch feature q in the clean kernel, calculate its path to M. n The Euclidean distances of all features are taken, and the average of the k smallest distances is calculated to obtain d. n (q).

[0108] Step S304: Based on all d n (q) Calculate the mean μ of the nth layer. n With standard deviation σ n : μ n =mean(d n (q))σ n =std(d n (q)); Step S305: Input the nth layer image block feature p of the image to be tested.

[0109] Step S306: Calculate p to M n The average of the k smallest Euclidean distances among all features is used to obtain d. n (p).

[0110] Step S307: Perform z-score normalization layer by layer according to the following formula: z n (p)=(d n (p)-μ n ) / (σ n +ε);

[0111] Through this standardization process, the original mean scales of each layer may have differed by an order of magnitude d. n (p) is transformed to a uniform scale with a mean of 0 and a standard deviation of 1.

[0112] Step S308: Output the standardized score z of each image patch in the nth layer. n (p), for use in subsequent cross-layer aggregation.

[0113] The following provides a more detailed explanation of the cross-layer aggregation and anomaly scoring output steps in this invention.

[0114] The cross-layer aggregation and anomaly scoring output process includes: Step S401: Input the standardized scores z1(p), z2(p), ..., z obtained in step S307 for each layer. L (p). For an image patch at the same spatial location, there is a corresponding standardized score at each layer.

[0115] Step S402: Average the standardized scores at the same location in each feature layer to obtain the anomaly score for that image patch. score(p) = (1 / L)· (p);

[0116] Since the scores of each layer have been standardized by z-score, direct averaging will not cause the problem of one layer dominating the result due to its large numerical scale, and the discriminative information of each layer can be fully integrated.

[0117] Step S403: Sort the score(p) of all image blocks in the image to be tested from high to low, select the image blocks with the highest scores at a predetermined percentage (e.g., 10%), and calculate their average score as the image-level anomaly score of the image to be tested. This image-level score can be used for the binary judgment of "pass / fail" on the production line; if the value exceeds a preset threshold, it is considered a non-conforming product.

[0118] Step S404: Upsample the image block-level anomaly score to the original size of the image under test using bilinear interpolation, and then smooth it using Gaussian filtering (kernel size 5×5, σ=1.0) to obtain a pixel-level anomaly score map. The value of each pixel represents the probability that a defect exists at that location.

[0119] Step S405: Output image-level anomaly scores and pixel-level anomaly scoring maps for subsequent quality inspection or defect location.

[0120] The following is combined Figure 2 The training-free anomaly detection system provided by this invention will be described in detail.

[0121] like Figure 2As shown, the training-free anomaly detection system of the present invention includes: a feature extraction module 10, a clean kernel estimation module 20, a layer-by-layer standardized scoring module 30, and an anomaly scoring output module 40.

[0122] The feature extraction module 10 is used to extract multi-layer image patch features from an unlabeled training image set that may be contaminated by defective images using a pre-trained feature extraction network with frozen parameters, and to obtain an image-level anomaly score for each training image based on the extracted multi-layer image patch features.

[0123] Feature extraction module 10 further includes:

[0124] The training image feature extraction unit 11 is used to input the training image into the pre-trained feature extraction network and extract image patch features from multiple intermediate layers. The image-level anomaly score acquisition unit 12 is used to calculate the image-level anomaly score for each training image using a leave-one-out mutual scoring method.

[0125] The clean kernel estimation module 20 is used to fit a two-component Gaussian mixture model to all image-level anomaly scores in the training image set, forcibly identifying the Gaussian component with the smaller mean value as the normal component and the other as the anomaly component, calculating the posterior probability of each training image belonging to the normal component according to Bayes' theorem, identifying the training images whose posterior probability reaches a predetermined threshold as clean kernels, and constructing a normal feature reference set based on the clean kernels.

[0126] Clean kernel estimation module 20 further includes: Gaussian mixture model fitting unit 21 is used to fit a two-component Gaussian mixture model to the image-level anomaly score and uses the expectation-maximization algorithm to estimate the parameters of each component. The posterior probability calculation unit 22 is used to calculate the posterior probability of each image belonging to the normal component according to Bayes' theorem. The threshold determination and selection unit 23 is used to determine the training image whose posterior probability reaches a predetermined threshold as a clean kernel; Fail-safe unit 24 is used to execute a fallback selection mechanism when the score distribution is unimodal and to execute a fallback strategy when the clean core size is insufficient.

[0127] The layer-by-layer standardization scoring module 30 is used to construct a normal feature reference set for each layer of the multiple feature layers of the pre-trained feature extraction network, based on the image patch features in the clean kernel. The mean and standard deviation of the layer are determined according to the k-nearest neighbor distance of the clean kernel image patch relative to the normal feature reference set of the layer. The k-nearest neighbor distance of the image patch features of the image to be tested in each layer relative to the normal feature reference set of the corresponding feature layer is calculated. Layer-by-layer z-score standardization is performed according to the mean and standard deviation of the layer. The standardized scores of each layer are aggregated across layers to generate the abnormal score result of the image to be tested.

[0128] The hierarchical standardized scoring module 30 further includes: Reference set construction unit 31 is used to construct normal feature reference sets for each layer by sampling from the farthest point, using clean kernel image patch features as the source. The layer-by-layer statistical calculation unit 32 is used to calculate the k-nearest neighbor distance of the clean kernel image patch relative to the reference set of each layer, and then determine the mean and standard deviation of each layer; k-nearest neighbor distance calculation unit 33 is used to calculate the average k-nearest neighbor distance of the image block under test relative to each layer reference set; z-score normalization unit 34 is used to normalize the distance between layers of the image under test based on the mean and standard deviation of each layer.

[0129] The anomaly scoring output module 40 is used to generate image-level anomaly scores and pixel-level anomaly scoring maps of the image under test based on the standardized scores after cross-layer aggregation.

[0130] The anomaly scoring output module 40 further includes: The cross-layer aggregation unit 41 is used to average the standardized scores of each layer to obtain the image block-level anomaly score; Image-level scoring unit 42 is used to aggregate the average scores of the image blocks with the highest scores at a predetermined proportion into an image-level anomaly score; The pixel-level score map generation unit 43 is used to generate a pixel-level anomaly score map by upsampling and smoothing the image block-level scores.

[0131] The functions of each module correspond one-to-one with the steps in the aforementioned method embodiments. For the specific implementation methods, please refer to the method embodiments, which will not be repeated here.

[0132] The present invention also provides an embodiment of a non-volatile computer-readable storage medium and a computer program product.

[0133] (a) Non-volatile computer-readable storage media.

[0134] A non-volatile computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the training-free anomaly detection method as described in the foregoing method embodiments.

[0135] The non-volatile computer-readable storage media include, but are not limited to, read-only memory (ROM), random access memory (RAM), hard disk, solid-state drive (SSD), USB flash drive, optical disc (CD-ROM, DVD), magnetic disk, flash memory card, and other media capable of storing data in a non-volatile form. These storage media can be used in electronic devices with data processing capabilities, such as industrial control computers, edge computing devices, servers, or personal computers in industrial settings.

[0136] When the computer program is executed by the processor, the following steps are performed:

[0137] An unlabeled training image set potentially contaminated by defective images is acquired using image acquisition equipment such as industrial cameras or linear scanners. A pre-trained feature extraction network with frozen parameters is used to extract multi-layer image patch features from each image in the training image set, and an image-level anomaly score is obtained for each training image. A two-component Gaussian mixture model is fitted to all image-level anomaly scores in the training image set. The component with the smaller mean is forcibly identified as the normal component, and the other as the anomaly component. The posterior probability of each training image belonging to the normal component is calculated based on Bayes' theorem. Training images whose posterior probability reaches a predetermined threshold are identified as clean kernels. The normal feature reference set is constructed using the clean kernel as the source. For each of the multiple feature layers of the pre-trained feature extraction network, a normal feature reference set for that layer is constructed using the image patch features in the clean kernel as the source. The mean and standard deviation of that layer are determined based on the k-nearest neighbor distance of the clean kernel image patch relative to the normal feature reference set of that layer. For the image patch features of the image to be tested in each layer, the k-nearest neighbor distance of the patch features relative to the normal feature reference set of the corresponding feature layer is calculated. Then, z-score standardization is performed layer by layer based on the mean and standard deviation of that layer. The standardized scores of each layer are aggregated across layers to generate the abnormal score result of the image to be tested.

[0138] For details on the specific implementation of each of the above steps, please refer to the aforementioned method embodiments, which will not be repeated here.

[0139] (ii) Computer program products.

[0140] A computer program product includes computer program instructions that, when executed by a processor, implement the training-free anomaly detection method as described in the foregoing method embodiments.

[0141] The computer program product can be stored on any non-volatile computer-readable storage medium and can be transmitted and distributed in signal form via a network or other transmission medium. The computer program product includes, but is not limited to, the following forms: installer package (e.g., .exe, .msi), library file (e.g., .dll, .so), standalone executable file, source code, script, or program modules integrated into industrial quality inspection software systems or cloud-based testing platforms. The computer program product can be used in various deployment environments such as offline industrial control computers, edge computing devices, or cloud servers, and its specific implementation is consistent with the aforementioned method embodiments.

[0142] When the computer program instructions are executed by the processor, their execution flow corresponds one-to-one with the steps described in the foregoing method embodiments. Those skilled in the art should understand that the specific implementation of the computer program product can be adjusted according to different programming languages ​​and operating environments, but all remain within the core technical solution of the present invention.

[0143] Through the aforementioned computer-readable storage medium and computer program product, the method of the present invention can be packaged into a standardized software module, facilitating rapid deployment and reuse in various industrial testing scenarios.

[0144] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the invention. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A training-free anomaly detection method, characterized in that, include: Obtain an unlabeled training image set that may be contaminated by defective images, use a pre-trained feature extraction network with frozen parameters to extract multi-layer image patch features of each image in the training image set, and obtain the image-level anomaly score of each training image. The image-level anomaly scores are statistically distributed and modeled. Based on the results of the statistical distribution modeling, a clean kernel composed of normal samples is determined from the training image set, and a normal feature reference set is constructed using the clean kernel as the source. For each of the multiple feature layers of the pre-trained feature extraction network, a normal feature reference set for that layer is constructed using the image patch features in the clean kernel as the source. The mean and standard deviation of that layer are determined based on the k nearest neighbor distance between the clean kernel image patch and the normal feature reference set of that layer. For the image patch features of the image under test at each layer, calculate the k nearest neighbor distance of each feature relative to the normal feature reference set of the corresponding feature layer, and perform layer-by-layer z-score standardization based on the mean and standard deviation of the layer. Then, aggregate the standardized scores of each layer across layers to generate the abnormal score result of the image under test. The determination of the clean kernel and the entire process of anomaly scoring do not use any defect annotations, do not update the parameters of the pre-trained feature extraction network through gradient backpropagation, and the mean and standard deviation of each layer used in the layer-by-layer z-score standardization are calculated from the image patch features in the clean kernel.

2. The training-free anomaly detection method according to claim 1, characterized in that, The image-level anomaly score is obtained through leave-one-out mutual scoring: for each training image, the multi-scale nearest neighbor dissimilarity between the training image and the other training images is calculated with reference to the multi-layer image patch features of the other training images, and the dissimilarity is used as the image-level anomaly score of the training image.

3. The training-free anomaly detection method according to claim 1, characterized in that, The statistical distribution modeling is implemented using a two-component Gaussian mixture model. A two-component Gaussian mixture model is fitted to all image-level anomaly scores in the training image set. The two-component Gaussian mixture model is expressed as: p(s)=π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²); In this method, the component with the smaller mean value among two Gaussian components is forcibly identified as the normal component, and the other is identified as the abnormal component, with the condition that μ0 < μ1; s is the image-level anomaly score, π0 is the mixing weight of the normal component, π1 is the mixing weight of the abnormal component, N(·|μ,σ²) is the Gaussian probability density function, μ0 and σ0² are the mean and variance of the normal component, respectively, and μ1 and σ1² are the mean and variance of the abnormal component, respectively. The posterior probability of each training image belonging to the normal component is calculated according to Bayes' theorem, and the posterior probability is calculated as follows: P(z=0|s)=π0·N(s|μ0,σ0²) / [π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²)]; Where z=0 indicates that it belongs to the normal component; The training image whose posterior probability reaches a predetermined threshold τ is determined as a clean kernel, and the predetermined threshold τ ranges from 0.5 to τ to 0.

99.

4. The training-free anomaly detection method according to claim 1, characterized in that, The layer-by-layer z-score normalization is performed using the following formula: z n (p)=(d n (p)-m n ) / (s n +e); Where, d n (p) represents the average k-nearest neighbor distance of the image under test in the nth layer, μ n With σ n These are the mean and standard deviation of the nearest neighbor distances in the nth layer determined by the clean kernel image block, respectively, and ε is a constant to prevent division by zero; The cross-layer aggregation includes: averaging the standardized scores of each feature layer to obtain an image block-level anomaly score, and then aggregating the average scores of the image blocks with the highest scores to obtain the image-level anomaly score of the image to be tested; the image block-level score is then upsampled and smoothed to obtain a pixel-level anomaly rating map.

5. The training-free anomaly detection method according to claim 1, characterized in that, The multiple feature layers are derived from at least two different depth levels of the pre-trained feature extraction network, which is a self-supervised visual transformation network or a residual convolutional network; the normal feature reference set is constructed by reducing the core set after sampling from the farthest point.

6. A training-free anomaly detection system, characterized in that, include: The feature extraction module is used to extract multi-layer image patch features from an unlabeled training image set that may be contaminated by defective images using a pre-trained feature extraction network with frozen parameters, and to obtain an image-level anomaly score for each training image based on the extracted multi-layer image patch features. The clean kernel estimation module is used to perform statistical distribution modeling on the image-level anomaly scores, determine clean kernels composed of normal samples from the training image set based on the results of the statistical distribution modeling, and construct a normal feature reference set using the clean kernels as the source. The layer-by-layer standardization scoring module is used to construct a normal feature reference set for each layer of the pre-trained feature extraction network, using the image patch features in the clean kernel as the source. The mean and standard deviation of the layer are determined based on the k-nearest neighbor distance of the clean kernel image patch relative to the normal feature reference set of the layer. The k-nearest neighbor distance of the image patch features of the image to be tested in each layer relative to the normal feature reference set of the corresponding feature layer is calculated. Layer-by-layer z-score standardization is performed based on the mean and standard deviation of the layer. The standardized scores of each layer are aggregated across layers to generate the abnormal score result of the image to be tested. The determination of the clean kernel and the entire process of anomaly scoring do not use any defect annotations, do not update the parameters of the pre-trained feature extraction network through gradient backpropagation, and the mean and standard deviation of each layer used in the layer-by-layer z-score standardization are calculated from the image patch features in the clean kernel.

7. The training-free anomaly detection system according to claim 6, characterized in that, The feature extraction module includes an image-level anomaly score acquisition unit, which is used to acquire the image-level anomaly score of each training image by leave-one-out mutual scoring: for each training image, the global reference feature set formed by merging the image patch features of the other training images in multiple feature layers is used as a reference to calculate the multi-scale nearest neighbor dissimilarity between the training image and the global reference feature set, and the dissimilarity is used as the image-level anomaly score of the training image.

8. The training-free anomaly detection system according to claim 6, characterized in that, The statistical distribution modeling is implemented using a two-component Gaussian mixture model, and the clean kernel estimation module includes: A Gaussian mixture model fitting unit is used to fit a two-component Gaussian mixture model to all image-level anomaly scores in the training image set. The two-component Gaussian mixture model is expressed as follows: p(s)=π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²); In this method, the component with the smaller mean value among two Gaussian components is forcibly identified as the normal component, and the other is identified as the abnormal component, with the condition that μ0 < μ1; s is the image-level anomaly score, π0 is the mixing weight of the normal component, π1 is the mixing weight of the abnormal component, N(·|μ,σ²) is the Gaussian probability density function, μ0 and σ0² are the mean and variance of the normal component, respectively, and μ1 and σ1² are the mean and variance of the abnormal component, respectively. The posterior probability calculation unit is used to calculate the posterior probability of each training image belonging to the normal component based on Bayes' theorem. P(z=0|s)=π0·N(s|μ0,σ0²) / [π0·N(s|μ0,σ0²)+π1·N(s|μ1,σ1²)]; Where z=0 indicates that it belongs to the normal component; The threshold determination and selection unit is used to determine the training image whose posterior probability reaches a predetermined threshold τ as a clean kernel, wherein the predetermined threshold τ ranges from 0.5 to τ to 0.

99.

9. The training-free anomaly detection system according to claim 6, characterized in that, The layer-by-layer z-score normalization is performed using the following formula: z n (p)=(d n (p)-m n ) / (s n +e); Where, d n (p) represents the average k-nearest neighbor distance of the image under test in the nth layer, μ n With σ n These are the mean and standard deviation of the nearest neighbor distances in the nth layer determined by the clean kernel image block, respectively, and ε is a constant to prevent division by zero; The cross-layer aggregation includes: averaging the standardized scores of each feature layer to obtain an image block-level anomaly score, and then aggregating the average scores of the image blocks with the highest scores to obtain the image-level anomaly score of the image to be tested; the image block-level score is then upsampled and smoothed to obtain a pixel-level anomaly rating map.

10. The training-free anomaly detection system according to claim 6, characterized in that, The multiple feature layers are derived from at least two different depth levels of the pre-trained feature extraction network, which is a self-supervised visual transformation network or a residual convolutional network; the normal feature reference set is constructed by reducing the core set after sampling from the farthest point.