Image anomaly detection method and system based on combination of feature extraction and activation learning
By combining pretrained feature extraction and activation learning methods, the problems of excessive generalization and high computing resource consumption in image anomaly detection are solved, efficient anomaly detection in a small sample and noisy environment is achieved, and interpretable abnormal area location is provided.
Patent Information
- Application Number
- CN202510284096.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-11
- Publication Date
- 2025-06-27
AI Technical Summary
The prior art has an overgeneralization problem in image anomaly detection, making it difficult to effectively distinguish between normal and abnormal images, and most methods rely on complex network architectures and a large number of computing resources.
The image anomaly detection method based on pretrained feature extraction and activation learning is adopted, and feature extraction is performed using EfficientNet pretrained on ImageNet, and anomaly detection is performed using a fully connected network based on activation learning. This network does not rely on the BP algorithm and can be trained under unsupervised conditions.
It realizes effective anomaly detection in a less sample learning and noisy data environment, provides more intuitive and interpretable anomaly area location, reduces computing resource requirements, and outperforms state-of-the-art methods on multiple real-world datasets.
Smart Images

Figure CN120219824A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an image anomaly detection method and system based on the combination of feature extraction and activation learning, and belongs to the technical field of image anomaly detection. Background Art
[0002] With the wide application of imaging technology in various fields, image data has increased sharply. However, the existence of anomalies or outliers in these data has also become non-negligible. These anomalies usually contain key information and can manifest in various forms, such as abnormal changes in color, shape, texture, or illumination in image data, which may be caused by sensor failures, data processing errors, external environmental interference, or human operations. The fundamental task of image anomaly detection is to effectively distinguish normal and abnormal instances by constructing a model, so as to identify anomalies or unusual patterns in image data. Image anomaly detection technology has great practical value in many fields. Especially in industrial quality control, it can help identify defective products as early as possible during the manufacturing process. In the medical field, it can help detect diseases at an early stage by locating anomalies in medical images. In the field of environmental monitoring, it can detect ecological anomalies, such as land cover changes or the presence of pollutants, through satellite and aerial images.
[0003] Nowadays, advanced deep learning technologies have significantly enhanced the ability of image analysis, and a large number of studies have demonstrated the effectiveness of deep learning-based image anomaly detection methods. However, the inherent generalization ability of neural networks may lead to a relatively low error in reconstructing abnormal images, which may cause over-generalization problems. This phenomenon weakens the ability to distinguish normal and abnormal images. In addition, actual anomaly patterns usually have diversity and unpredictability, and the limited number of abnormal samples further restricts the acquisition of prior knowledge. More importantly, most state-of-the-art technologies rely on complex network architectures and use the backpropagation (BP) algorithm for training, which requires a predefined task-related loss function, and these methods usually require a large amount of computing resources. Therefore, exploring a new image anomaly detection method remains an important issue. Summary of the Invention
[0004] Aiming at the deficiencies of the prior art, the present invention proposes a new image anomaly detection method - an image anomaly detection method based on pre-trained feature extraction and activation learning.
[0005] Specifically, considering that pre-training the feature extractor on a large-scale database (such as ImageNet) can ensure the extraction of general features, PFEAL (the present invention) first uses a pre-trained model to extract high-dimensional data features, which are helpful for distinguishing abnormal regions in the original image. Subsequently, an activation learning-based neural network model is used for anomaly detection. This model does not rely on the BP algorithm and can be trained in an unsupervised manner based on the extracted features. The output activation value (the sum of squares of the output) of the activation learning-based network can reflect the typicality of the input pattern. Since the abnormal samples are not included in the training process, the output activation values of the abnormal samples are relatively low, which can be used as the basis for detecting anomalies.
[0006] PFEAL (the present invention) is a new anomaly detection method. First, in the activation learning-based anomaly detection module, the activation learning paradigm is adopted for training. Different from the traditional BP algorithm, it does not need to set any task-related loss function. Therefore, it is more task-flexible than deep learning-based methods. Second, a simple fully-connected network is used without any complex architectures or mechanisms. In addition, the proposed framework has been experimentally proven to have few-shot learning ability and strong robustness to noisy data, which makes it more practical for anomaly detection in the case of limited data. Finally, the activation value can reflect the typicality of the input pattern, which provides a more intuitive and interpretable role for image anomaly detection.
[0007] Term Explanation:
[0008] 1. ImageNet dataset: A large-scale image recognition database containing more than 14 million labeled images covering more than 20,000 categories. It is widely used in various computer vision tasks such as image classification, object detection, and object localization, aiming to promote the development of the computer vision field by providing rich image resources.
[0009] 2. EfficientNet: Generally translated as "Efficient Network" or "Efficient Neural Network"; it is an efficient convolutional neural network structure mainly used for image classification tasks. It unifies and scales the depth, width, and resolution of the neural network on the basis of the traditional convolutional neural network to find the optimal model scale. This method is more efficient than convolutional neural networks that only adjust one dimension alone and can achieve better performance with less computing resources. EfficientNet achieves better performance than traditional networks on the ImageNet dataset with fewer parameters and less computational effort. Due to its high computational efficiency, it is suitable for applications on mobile and embedded devices.
[0010] 3. Feature extraction: Pre-trained EfficientNet is generally trained on large-scale datasets such as ImageNet and provides open-source weights. Resize the input data to meet the format required by the network, and input it into the network to obtain the intermediate calculation results as the features of the original input data. Compared with the original data, the intermediate results reduce redundant information, thus achieving the effect of reducing the data dimension and retaining key information.
[0011] The technical solution of the present invention is as follows:
[0012] An image anomaly detection method based on the combination of feature extraction and activation learning, including:
[0013] Feature extraction;
[0014] Training an anomaly detection model based on activation learning;
[0015] After the image to be detected is subjected to feature extraction, it is input into the trained anomaly detection model based on activation learning for anomaly detection.
[0016] Among them, the anomaly detection module based on activation learning is a fully connected network based on activation learning. The last layer of the model calculates the sum of squares of all neurons as the activation value of the input data. The size of the activation value can reflect the relative probability size of the input data. Since there are only normal samples during the training process, the activation value output by normal samples is high during testing, while the activation value output by abnormal samples is relatively small. Set a threshold according to the activation value quantile and screen possible abnormal samples.
[0017] Preferably according to the present invention, a pre-trained feature extractor is used for feature extraction; including:
[0018] Using EfficientNet pre-trained on the ImageNet dataset as the feature extractor;
[0019] The original data {x1, x2, …, x n}} is uniformly scaled to 1024 * 1024 * 3, and after cropping, feature extraction is performed. The feature vectors {y1, y2, …, y n}} of the extracted features have a size of 15×15×304, where 15×15 represents the spatial resolution of the image, and 304 is the number of feature channels extracted.
[0020] Preferably according to the present invention, the anomaly detection model based on activation learning includes a normalization layer, two linear activation layers, and an output layer;
[0021] The linear activation layer includes a linear layer and an activation function;
[0022] The normalization layer is used to process the input data. After being processed by the normalization layer, the output data distribution is maintained with a mean of 0 and a variance of 1, and the sum of the squares of the input data is 1.
[0023] The linear activation layer is used to linearly transform the input data and learn the weighted combination of different features.
[0024] The output layer is used to calculate the sum of the squares of the output of the linear layer as the output of the anomaly detection model, and the output form is a scalar activation value.
[0025] Further preferably, the activation function g(x) is:
[0026] g(x) = λ·std(|x|)
[0027] where std(|x|) represents |x| minus its mean and then divided by the standard deviation, and λ is a scaling coefficient.
[0028] According to the present invention preferably, training the anomaly detection model based on activation learning includes:
[0029] 1) Obtain the input image, that is, the training data set;
[0030] 2) Use the pre-trained feature extractor to process the input image to extract the feature vector, and normalize the feature vector into a unit vector;
[0031] 3) Initialize the weights of each layer in the anomaly detection model using the normal distribution;
[0032] 4) Calculate the updated weight magnitude between two neurons using the local competition rule and update the weights according to the learning rate;
[0033] 5) Repeat step 4) to obtain a converged anomaly detection model;
[0034] 6) Test to determine the best anomaly detection model, which is the trained anomaly detection model.
[0035] According to the present invention preferably, calculating the updated weight magnitude between two neurons using the local competition rule; includes:
[0036] Activation learning updates the weights through the local competition learning rule, and the local competition learning rule is as follows:
[0037]
[0038] where l represents the number of neural network layers, i represents the neuron in the l-th layer of the neural network, and j and k are the neurons in the (l + 1)-th layer; and are the values of neurons j and k in the (l + 1)-th layer respectively; ω ikis the weight value between neuron i of the l-th layer neural network and neuron k of the (l + 1)-th layer neural network, Δω ij is the updated weight value of neurons i and j; the feedback term enhances the competition between neurons and regulates the total weight of neuron j; after sufficient training steps and using a small learning rate η, the connection weight ω tends to:
[0039] Cω - ωω T Cω = 0;
[0040] where C = hh T , which is the covariance matrix of the input samples; define V as the typical space composed of the eigenvectors v1, v2,..., v corresponding to the largest eigenvalue of the covariance matrix C = hh T ; therefore, calculate the distance d(h m , V) from h to the typical space to reflect the alignment degree of h with the most significant pattern captured by the anomaly detection model; this distance formula is as follows: l to the typical space distance d(h l , V), to reflect the alignment degree of h l with the most significant pattern captured by the anomaly detection model; this distance formula is as follows:
[0041]
[0042] When reaching the stable solution, the square norm ‖h l+1 ‖ 2 is bounded and determined by the following relationship:
[0043] ‖h l ‖ 2 - d 2 (h l , V).
[0044] According to the preference of the present invention, anomaly detection; includes:
[0045] Input the test image x j Processed by the pre-trained feature extractor to obtain the feature vector, j represents the j-th sample number;
[0046] After the forward propagation of the anomaly detection module to calculate the neuron output, calculate the sum of squares of neurons in the last hidden layer to obtain the anomaly score z j ; includes:
[0047] The input original picture data is first processed by the feature extractor to extract features, and the extracted features are used as the input of the anomaly detection module; first, it is processed by the normalization layer, followed by two linear activation layers, and the weighted calculation of each layer's weight is calculated according to the following formula:
[0048]
[0049] where represents the output of the linear activation layer, W i represents the weights of the linear activation layer, represents the input to the linear activation layer of the previous layer;
[0050] After being processed by the activation function, that is:
[0051]
[0052] where σ represents the activation function, is the output result after passing through the activation function;
[0053] Calculate the sum of squares of the output as the output of the anomaly detection module, that is, the anomaly score of the input data:
[0054]
[0055] Compare the obtained anomaly score z j with a predefined threshold γ to determine whether an anomaly has occurred;
[0056] In anomaly detection, set the threshold γ to distinguish anomaly samples, that is:
[0057]
[0058] where S(x) = 0 represents a normal sample, S(x) = 1 represents an anomaly sample, the threshold γ is obtained through grid search or quantiles, and z j refers to the activation value.
[0059] A computer device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements the steps of an image anomaly detection method based on the combination of feature extraction and activation learning.
[0060] A computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of an image anomaly detection method based on the combination of feature extraction and activation learning.
[0061] An image anomaly detection system based on the combination of feature extraction and activation learning, including:
[0062] A feature extraction module, configured to: extract features;
[0063] An anomaly detection module, configured to: extract normal sample features and train an anomaly detection model based on activation learning based on these normal sample features, and after the image to be detected is feature-extracted, input it into the trained anomaly detection model based on activation learning for anomaly detection.
[0064] The beneficial effects of the present invention are as follows:
[0065] 1. The present invention proposes a framework based on a pre-trained image feature extractor and an anomaly detection module based on activation learning, which is independent of task-oriented loss functions and complex network architectures, with flexible tasks and a simple architecture.
[0066] 2. The framework proposed by the present invention can perform few-shot learning, is robust to noisy data, and can also provide the localization of anomaly regions based on activation values, enhancing its interpretability and practicality in anomaly detection under limited data conditions.
[0067] 3. The present invention outperforms state-of-the-art methods on multiple real-world datasets and is competitive.
[0068] 4. The applicability of the present invention in multiple domains and datasets ensures its wide application in complex image tasks, improves the practicality and robustness of the model, provides innovative solutions for practical applications, has good economic value and social benefits, and is worthy of popularization and application. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] Figure 1 It is an architecture diagram of an image anomaly detection system based on the combination of feature extraction and activation learning according to the present invention;
[0070] Figure 2 It is a schematic diagram of the architecture of an anomaly detection model based on activation learning according to the present invention;
[0071] Figure 3 It is a schematic diagram of the training process of an anomaly detection model based on activation learning according to the present invention;
[0072] Figure 4 It is a schematic diagram of an image anomaly localization based on the combination of feature extraction and activation learning according to the present invention;
[0073] FIG. 5(a) is a schematic diagram of the anomaly localization result on the carpet data;
[0074] FIG. 5(b) is a schematic diagram of the anomaly localization result on the wooden board data;
[0075] FIG. 5(c) is a schematic diagram of the anomaly localization result on the tile data;
[0076] Figure 6 It is a schematic diagram of the AUROC value of the object category in the MVTec AD dataset according to the present invention;
[0077] Figure 7 It is a schematic diagram of the AUROC value of the texture category in the MVTec AD dataset according to the present invention;
[0078] Figure 8Schematic diagram of the visualization results of the activation values of the present invention on the water bottle category of the MVTec AD dataset;
[0079] Figure 9 Schematic diagram of the visualization results of the activation values of the present invention on the tile category of the MVTec AD dataset;
[0080] Figure 10 Schematic diagram for comparing few-shot learning of the present invention with other methods;
[0081] Figure 11 Schematic diagram of the anti-noise performance of the present invention on several categories of the MVTec AD dataset. Detailed implementation manner
[0082] The present invention will be further limited below in conjunction with the accompanying drawings of the specification and embodiments, but not limited thereto.
[0083] Embodiment 1
[0084] An image anomaly detection method based on the combination of feature extraction and activation learning, including:
[0085] Feature extraction;
[0086] Training an anomaly detection model based on activation learning;
[0087] After the image to be detected is subjected to feature extraction, it is input into the trained anomaly detection model based on activation learning for anomaly detection.
[0088] Among them, the anomaly detection module based on activation learning is a fully connected network based on activation learning. The last layer of the model calculates the sum of squares of all neurons as the activation value of the input data. The size of the activation value can reflect the relative probability size of the input data. For normal samples, since their proportion is relatively high, the output activation value is large; while the output activation value of abnormal samples is relatively small. A threshold is set according to the activation value quantile to screen possible abnormal samples.
[0089] Using a pre-trained feature extractor for feature extraction; including:
[0090] Using EfficientNet pre-trained on the ImageNet dataset as the feature extractor;
[0091] EfficientNet adopts a method called Compound Scaling, which aims to maximize the model's performance by balancing the network's depth (number of layers), width (number of channels per layer), and resolution (size of the input image), while increasing these three dimensions simultaneously. EfficientNet can reduce the computational overhead while maintaining high accuracy, so it is chosen as the feature extractor. The original data {x1, x2, …, x n} is uniformly scaled to 1024 * 1024 * 3, and after cropping, feature extraction is performed. The feature vectors {y1, y2, …, y n} of the extracted features are of size 15 × 15 × 304, where 15 × 15 represents the spatial resolution of the image, and 304 is the number of feature channels extracted. This unified processing flow and feature extraction strategy provide a stable foundation for subsequent anomaly detection and classification tasks.
[0092] Using a pre-trained feature extractor offers many advantages. It simplifies the feature set by removing irrelevant information, thus enhancing the focus on important anomaly patterns. This not only helps improve the detection performance but also reduces the computational burden on the anomaly detection module. The method used in the present invention is a general anomaly detection model and can be used in combination with various pre-trained feature extractors and active learning.
[0093] As Figure 2 shown, a simple fully connected network is applied. The anomaly detection model based on active learning includes a normalization layer, two linear activation layers, and an output layer;
[0094] The linear activation layer includes a linear layer and an activation function;
[0095] The normalization layer is used to process the input data. After being processed by the normalization layer, the output data distribution is maintained with a mean of 0, a variance of 1, and the sum of the squares of the input data is 1; this makes the neural network more robust to different input distributions and improves the generalization ability of the model.
[0096] The linear activation layer is used to linearly transform the input data and learn the weighted combination of different features; the essence of the linear layer is to perform a weighted sum of the input features, thereby mapping to a new feature space.
[0097] The output layer is used to calculate the sum of the squares of the output of the linear layer as the output of the anomaly detection model, and the output form is a scalar activation value.
[0098] To ensure the transferability of the activation intensity between different layers, an activation function needs to be added between each layer. The specifically selected activation function g(x) is:
[0099] g(x) = λ · std(|x|)
[0100] Among them, std(|x|) means that |x| subtracts its mean and then divides by the standard deviation, and λ is a scaling factor to keep the amplitude fixed.
[0101] As Figure 3 shown, training an anomaly detection model based on active learning includes:
[0102] 1) Obtain the input image, that is, the training data set;
[0103] 2) Use a pre-trained feature extractor to process the input image to extract feature vectors and normalize the feature vectors to unit vectors;
[0104] 3) Initialize the weights of each layer in the anomaly detection model with a normal distribution with a mean of zero and a small variance;
[0105] The way of initializing the weights affects the convergence speed and final performance of the model. Initializing the weights with a normal distribution with a mean of zero and a small variance is generally to avoid vanishing gradients or exploding gradients and make the input and output distributions of the network layers stable. Before training a neural network, its weights are randomly assigned, and the statistical distribution of the weights satisfies a normal distribution. In this invention, a normal distribution with a mean of 0 and a variance of 0.01 is selected for initialization.
[0106] 4) Use the local competition rule to calculate the magnitude of the updated weights between two neurons and update the weights according to the learning rate;
[0107] 5) Repeat step 4) to obtain a converged anomaly detection model;
[0108] 6) Test to determine the best anomaly detection model, which is the trained anomaly detection model.
[0109] After enough iterations, the anomaly detection module thoroughly learns the patterns of normal input images, enabling it to effectively detect unseen anomaly patterns.
[0110] Using the local competition rule to calculate the magnitude of the updated weights between two neurons; includes:
[0111] Active learning is an improvement to the training of neural networks based on the Hebb rule. According to the Hebb rule, if neuron i and neuron j are activated simultaneously, the weight ω between them ij will increase. When training a multi-layer neural network, the Hebb rule can be defined as:
[0112]
[0113] where, represents the value of neuron i in layer l, represents the value of neuron j in layer l + 1, and η is the learning rate. It can be obtained by the following formula:
[0114]
[0115] Among them, ω ij is the weight between neuron i and neuron j. However, this weight update method is unstable because the weight may grow infinitely.
[0116] In order to ensure the stability of training and promote competition between neurons, activation learning adopts a local competitive learning rule to update weights. The local competitive learning rule is as follows:
[0117]
[0118] Where l represents the number of neural network layers, i represents the neurons in the lth layer of the neural network, and j and k represent the neurons in the l+1th layer; and are the values of neurons j and k in the l+1th layer respectively; ω ik is the weight value between neuron i in the lth layer of the neural network and neuron k in the l+1th layer of the neural network, Δω ij is the updated weight value of neurons i and j; feedback term It enhances the competition between neurons and adjusts the total weight of neuron j; intuitively, if neuron k≠j in layer l+1 is activated, then the connection weight ω with neuron j ij will decrease by Therefore, neurons activated at the same time inhibit each other, leading to increased competitiveness between neurons in layer l+1. After enough training steps and using a small learning rate η, the connection weights ω tend to:
[0119] Cω-ωω T Cω=0;
[0120] Where C = hh T , is the covariance matrix of the input samples; when the number of neurons in the receiving layer is greater than 2, the number of stable solutions is infinite, and the specific stable solution to which the system finally converges depends on the initial state of the parameters and the training samples. Define V as the covariance matrix C = hh T The eigenvector v1,v2,…,v corresponding to the maximum eigenvalue m The typical space spanned by l The distance to the typical space d(h l ,V), to reflect h l The degree of alignment with the most salient pattern captured by the anomaly detection model; this distance is formulated as follows:
[0121]
[0122] When a stable solution is reached, the squared norm of the output activation ‖h l+1 ‖ 2 is bounded and determined by the following relationship:
[0123] ‖h l ‖ 2 -d 2 (h l ,V).
[0124] Therefore, when the input intensity ‖h l ‖ 2 is fixed, more common inputs are more likely to result in higher output activation values and can reflect the probability distribution of the inputs. In practical situations, abnormal samples or patterns are usually rare or never occur, which makes it complex to manually establish abnormal detection principles. The activation learning mechanism can utilize the global information of the entire dataset to estimate the statistical characteristics of the input patterns. Therefore, this mechanism provides a theoretical basis for applying activation learning to image abnormal detection.
[0125] Abnormal detection; including:
[0126] Input the test image x j Processed by a pre-trained feature extractor to obtain a feature vector, where j represents the serial number of the j-th sample;
[0127] Through forward propagation of the abnormal detection module, calculate the neuron output and calculate the sum of squares of the neurons in the last hidden layer to obtain the abnormal score z j ; including:
[0128] The input original picture data is first processed by a feature extractor to extract features, and the extracted features are used as the input of the abnormal detection module; first processed by a normalization layer, followed by two linear activation layers, calculate the weighted weights of each layer, and the calculation formula is as follows:
[0129]
[0130] Among them, represents the output of the linear activation layer, W i represents the weight of the linear activation layer, represents the input of the previous linear activation layer (the input features of this layer); the calculation process does not include the bias term;
[0131] Then processed by an activation function and used as the input of the next layer, that is:
[0132]
[0133] Among them, σ represents the activation function, is the output result after passing through the activation function;
[0134] Calculate the sum of squares of the output as the output of the anomaly detection module, that is, the anomaly score of the input data:
[0135]
[0136] Compare the obtained anomaly score z j with a predefined threshold γ to determine whether an anomaly has occurred;
[0137] Calculate the sum of squares of all neurons in the last output layer as the output activation value. After stacking multiple linear layers, a compact canonical space is formed, which plays a key role in representing the probability distribution of the input pattern. When the model weights converge to a stable solution, the model can be regarded as a general probability estimator. More typical or common input patterns generate higher activation values. From a statistical perspective, for a given input data x, its probability can be estimated using where α and β are constants.
[0138] In actual anomaly detection, set the threshold γ to distinguish abnormal samples, that is:
[0139]
[0140] where S(x) = 0 represents a normal sample, S(x) = 1 represents an abnormal sample, the threshold γ is obtained through grid search or quantiles, and z j refers to the activation value and can be used as a criterion for judging as an anomaly.
[0141] The 5% quantile can be used to determine the threshold γ. The 5% quantile means that in a set of data, 5% of the values are less than or equal to this value, and the remaining 95% of the values are greater than this value. Suppose there are N test data in total, and the sorted anomaly scores are {z1, z2,..., z N}, the position P of the 5% quantile is calculated as P = (N - 1) × 0.05 + 1 and then rounded down, and the P-th z P in the sorted anomaly scores is used as the threshold γ.
[0142] Based on the present invention, image anomaly localization is performed: Based on the present invention, image anomaly localization can be achieved, and the architecture diagram is as Figure 4As shown, first, the input data is block-processed, for example, processed into small blocks of size 2x2 or 4x4. Subsequently, the block data is scaled to the same size as the input dimension of the feature extractor for feature extraction. Based on the extracted features and combined with the local competition rule, the anomaly detection module is trained. After the model converges sufficiently, the parameters are fixed. During inference, the data is processed in the same way, and the anomaly detection module is applied to calculate the activation values of each small block. Since activation learning has higher activation values for more common patterns, the activation values of normal regions are larger, while those of abnormal regions are smaller. The activation values are plotted as a heatmap to achieve image anomaly localization. The effect diagrams are shown in Figures 5(a), 5(b), and 5(c).
[0143] The present invention is compared with domestic and foreign methods on the MVTec AD dataset, including Geo, Ganomaly, Patch-SVDD, DifferNet, CutPaste, CS-Flow, and Dist. The area under the feature curve (ROC curve) (Area Under the Receiver Operating Characteristic Curve, AUROC) is used to measure the effects of the present invention and other methods. This metric is obtained by plotting the true positive rate (TPR) as the vertical axis Y and the false positive rate (FPR) as the horizontal axis X on the ROC curve. TPR represents the proportion of actual abnormal samples that are correctly identified, while FPR measures the proportion of normal samples that are misidentified as abnormal. The MVTec AD (MVTec Anomaly Detection) dataset is a high-quality dataset designed specifically for industrial defect detection and anomaly detection tasks and is widely used in anomaly detection research in the fields of computer vision and deep learning. The dataset contains 5354 high-resolution images, a total of 15 different categories, covering a variety of industrial objects and textures. Each category includes normal images and abnormal images, where the abnormal images have different types of defects for testing and evaluating the performance of anomaly detection algorithms. As shown in Table 1, the results show that the present invention has better performance compared with methods in the same category.
[0144] Table 1
[0145]
[0146] The visualization of the AUROC metric of the present invention on this dataset Figure 6 is the AUROC value of the object category of the present invention on the MVTec AD dataset; the horizontal axis is the false positive rate, and the vertical axis is the true positive rate. The area formed is the AUROC value; Figure 7This is the AUROC value of the present invention in the texture category of the MVTec AD dataset. The abscissa is the false positive rate, and the ordinate is the true positive rate. The area formed is the AUROC value. The closer the broken line is to the upper left corner, the better the effect.
[0147] Visualization of the activation values of some categories of the present invention on the MVTec AD dataset Figure 8 This is the visualization result of the activation values of the present invention in the bottle category of the MVTec AD dataset; Figure 9 This is the visualization result of the activation values of the present invention in the tile category of the MVTec AD dataset. Replace the last layer of the activation learning module with two neurons, and map the values of the two neurons to the xy-axis as dimension 1 and dimension 2, so as to visualize the activation values. The black dots in the figure are normal samples, and the red dots are abnormal samples. The activation values of normal samples are much higher than those of abnormal samples. Therefore, positive and negative samples can be separated according to the size of the activation values.
[0148] The few-shot learning results of the present invention: Few-shot learning is particularly important in image anomaly detection because image datasets usually contain a large amount of unlabeled data, while anomalies usually only occupy a very small number of samples, making it more difficult to apply traditional methods. Through few-shot learning, the model can quickly learn the features of anomalies based on a small number of abnormal samples, and then effectively detect new and unseen anomaly patterns. Increase the training samples from 1 to 50 and compare the effects of the present invention with other methods. The present invention can still have good performance even when there is only a small amount of training data.
[0149] Figure 10 This is a comparison schematic diagram of the present invention and other methods; the abscissa is the number of training samples, and the ordinate is AUROC (%). For the robustness (noise resistance ability) analysis of the present invention, add noise to the training samples to explore the robustness of the present invention to noise. The added noise includes random flipping, random cropping, horizontal flipping, color transformation, Gaussian noise, and mixed noise. In most noise cases, the performance degradation is successfully maintained at a relatively low level. Especially in the face of high-intensity noise perturbations, the present invention can still better distinguish normal and abnormal samples.
[0150] Figure 11 This is the noise resistance performance of the present invention in several categories on the MVTec AD dataset. The horizontal axis is the data category, and the vertical axis is the AUROC value. Different colors represent whether noise is added and the noise category;
[0151] Example 2
[0152] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of an image anomaly detection method based on the combination of feature extraction and activation learning described in Embodiment 1 are implemented.
[0153] Embodiment 3
[0154] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the steps of an image anomaly detection method based on the combination of feature extraction and activation learning described in Embodiment 1 are implemented.
[0155] Embodiment 4
[0156] An image anomaly detection system based on the combination of feature extraction and activation learning, as Figure 1 shown, includes:
[0157] A feature extraction module, configured to: extract features;
[0158] An anomaly detection module, configured to: extract the features of normal samples and train an anomaly detection model based on activation learning based on these normal sample features, and after the image to be detected is subjected to feature extraction, input it into the trained anomaly detection model based on activation learning for anomaly detection.
Claims
1. An image anomaly detection method based on the combination of feature extraction and activation learning, characterized in that: include: Feature extraction; Train an activation-based learning anomaly detection model; After feature extraction, the image to be detected is input into the trained activation learning-based anomaly detection model for anomaly detection.
2. The image anomaly detection method based on the combination of feature extraction and activation learning according to claim 1 is characterized in that: Use pre-trained feature extractors for feature extraction; including: Use EfficientNet pre-trained on the ImageNet dataset as a feature extractor; The original data {x1,x2,…,x n } is uniformly scaled to 1024*1024*3, and feature extraction is performed after cropping. The feature vector of the extracted features {y1,y2,…,y n The size is 15×15×304, where 15×15 represents the spatial resolution of the image and 304 is the number of feature channels extracted.
3. The image anomaly detection method based on the combination of feature extraction and activation learning according to claim 1 is characterized in that: The activation learning-based anomaly detection model consists of a normalization layer, two linear activation layers, and an output layer; The linear activation layer includes the linear layer and the activation function; The normalization layer is used to process the input data. After the normalization layer is processed, the output data distribution is kept at a mean of 0 and a variance of 1, and the sum of the squares of the input data is 1; The linear activation layer is used to linearly transform the input data and learn the weighted combination of different features; The output layer is used to calculate the sum of squares of the linear layer output as the output of the anomaly detection model, and the output is in the form of a scalar activation value.
4. The image anomaly detection method based on the combination of feature extraction and activation learning according to claim 3 is characterized in that: The activation function g(x) is: g(x)=λ·std(|x|) Here, std(|x|) means |x| minus its mean and divided by the standard deviation, and λ is the scaling factor.
5. The image anomaly detection method based on the combination of feature extraction and activation learning according to claim 1 is characterized in that: Training an activation-based learning anomaly detection model, including: 1) Obtain input images, i.e. training data sets; 2) Process the input image using a pre-trained feature extractor to extract feature vectors, and normalize the feature vectors to unit vectors; 3) Use normal distribution to initialize the weights of each layer in the anomaly detection model; 4) Use the local competition rule to calculate the updated weight between two neurons, and update the weight according to the learning rate; 5) Repeat step 4) to obtain a converged anomaly detection model; 6) The best anomaly detection model determined by testing is the trained anomaly detection model.
6. The image anomaly detection method based on the combination of feature extraction and activation learning according to claim 5, characterized in that: The update weight between two neurons is calculated using the local competition rule; including: Activation learning updates weights through a local competitive learning rule, which is as follows: Where l represents the number of neural network layers, i represents the neurons in the lth layer of the neural network, and j and k represent the neurons in the l+1th layer; and are the values of neurons j and k in the l+1th layer respectively; ω ik is the weight value between neuron i in the lth layer of the neural network and neuron k in the l+1th layer of the neural network, Δω ij is the updated weight value of neurons i and j; feedback term The competition between neurons is enhanced and the total weight of neuron j is adjusted; after enough training steps and using a small learning rate η, the connection weight ω tends to: So-oh T Cω=0; Where C = hh T , is the covariance matrix of the input samples; define V as the covariance matrix C = hh T The eigenvector v1,v2,…,v corresponding to the maximum eigenvalue m The typical space spanned by l The distance to the typical space d(h l ,V), to reflect h l The degree of alignment with the most salient pattern captured by the anomaly detection model; this distance is formulated as follows: When a stable solution is reached, the squared norm of the output activation ‖h l+1 ‖ 2 is bounded, as determined by the following relationship: ‖h l ‖ 2 -d 2 (h l ,V)。 7. The image anomaly detection method based on the combination of feature extraction and activation learning according to any one of claims 1 to 6, characterized in that: Anomaly detection; including: Input test image x j Through the pre-trained feature extractor, the feature vector is obtained, and j represents the jth sample number; After forward propagation, the neuron output is calculated, and the square sum of the neurons is calculated in the last hidden layer to obtain the abnormal score z j ;include: The input raw image data is first extracted by the feature extractor, and the extracted features are used as the input of the anomaly detection module; it is first processed by the normalization layer, followed by two linear activation layers, and the weight of each layer is calculated. The calculation formula is as follows: in, represents the output of the linear activation layer, W i represents the weight of the linear activation layer, Represents the input of the linear activation layer of the previous layer; After the activation function is processed, that is: Among them, σ represents the activation function, is the output result after the activation function; The sum of squares of the output is calculated as the output of the anomaly detection module, which is the anomaly score of the input data: The obtained anomaly score z j Compare with the predefined threshold γ to determine whether an abnormality occurs; In anomaly detection, a threshold γ is set to distinguish abnormal samples, that is: Where S(x) = 0 represents a normal sample, S(x) = 1 represents an abnormal sample, the threshold γ is obtained by grid search or quantile, z j is the activation value.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the image anomaly detection method based on the combination of feature extraction and activation learning described in any one of claims 1-7 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of an image anomaly detection method based on the combination of feature extraction and activation learning are implemented as described in any one of claims 1 to 7.
10. An image anomaly detection system based on feature extraction and activation learning, characterized in that: include: The feature extraction module is configured to: extract features; The anomaly detection module is configured to: extract normal sample features and train an anomaly detection model based on activation learning based on these normal sample features, and input the image to be detected into the trained anomaly detection model based on activation learning for anomaly detection after feature extraction.