Industrial image anomaly detection method based on deep learning
By combining a multi-scale image pyramid with a deep autoencoder network, a dynamic memory library, and an attention matching module, the problems of high false alarm rate, inaccurate defect localization, and real-time detection in existing technologies are solved, achieving efficient, accurate, and real-time detection of industrial image anomalies.
Patent Information
- Application Number
- CN202511222164.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-28
- Publication Date
- 2025-11-18
AI Technical Summary
Existing deep learning-based industrial image anomaly detection methods suffer from high false alarm rates when faced with data distribution drift in industrial settings, difficulty in achieving accurate pixel-level localization and segmentation of minute defects, inability to meet millisecond-level real-time detection requirements, and lack of secure and efficient online learning capabilities.
We employ multi-scale image pyramids and local binary patterns to extract illumination-invariant features, combine them with a deep autoencoder network for unsupervised training, establish a dynamic memory module for online clustering, design an attention matching module with learnable weights, generate anomaly scores through a dual-path fusion framework, and implement incremental learning and multi-level acceleration optimization.
It effectively reduced the false alarm rate caused by changes in environment and equipment, achieved accurate pixel-level localization and segmentation of minute defects, met the millisecond-level real-time detection requirements under high-resolution images, and enabled the safe online evolution and updating of the model.
Smart Images

Figure CN120976191A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial visual inspection technology, and more specifically, to a deep learning-based method for detecting anomalies in industrial images. Background Technology
[0002] Industrial visual inspection technology, as a core component of intelligent manufacturing and quality control, has undergone a significant evolution from traditional manual visual inspection to rule-based algorithm-based automated machine inspection, and now to data-driven methods represented by deep learning. Early methods heavily relied on manually designed features and thresholds, making it difficult to handle complex and ever-changing industrial scenarios. With breakthroughs in deep learning technology, especially the application of unsupervised learning models such as autoencoders and generative adversarial networks, industrial anomaly detection has made progress in generalization and robustness. The technological trend is moving towards higher accuracy, stronger adaptability, and real-time collaborative processing between edge and device.
[0003] However, existing deep learning-based detection solutions still have significant shortcomings in practical applications. First, most models rely on offline static datasets for training, making it difficult to adapt to the continuous data distribution drift in industrial settings, resulting in persistently high false positive rates. Second, existing methods mostly focus on image-level anomaly classification, or suffer from blurred boundaries and insufficient sensitivity to small defects in pixel-level localization, failing to meet the precision manufacturing requirements for accurate defect localization. Third, the high computational complexity of deep models presents a significant contradiction with the millisecond-level real-time response required for industrial inspection. Finally, the incremental update mechanism of the models is imperfect, prone to catastrophic forgetting when introducing new samples, and lacks safe and efficient online learning capabilities.
[0004] To address the aforementioned shortcomings, this invention aims to solve the following core problems: how to effectively reduce the false alarm rate caused by changes in environment and equipment; how to achieve accurate pixel-level localization and segmentation of minute defects; how to meet the computing power requirements for millisecond-level real-time detection under high-resolution images; and how to achieve safe online evolution and updating of the model when continuously receiving new samples, avoiding the forgetting of historical knowledge. Summary of the Invention
[0005] To overcome the aforementioned deficiencies of the prior art, embodiments of the present invention provide a deep learning-based industrial image anomaly detection method to address the problems mentioned in the background section.
[0006] To achieve the above objectives, this invention provides the following technical solution: a deep learning-based method for detecting anomalies in industrial images, comprising the following complete technical process: an illumination-invariant feature extraction is performed on industrial images using a preprocessing module integrating multi-scale image pyramids and local binary patterns to generate an enhanced feature map that fuses texture details and structural information; unsupervised training is performed on a normal sample set using a deep autoencoder network constructed with PyTorch, wherein the encoder uses a deep separable convolutional layer with residual connections to extract multi-level feature representations, and the decoder achieves high-fidelity image reconstruction through deconvolution and sub-pixel upsampling operations; a dynamic memory module based on streaming clustering is established to continuously store and update a cluster prototype set composed of feature vectors from normal samples; an attention matching module with a learnable weight matrix is designed to calculate the multi-dimensional spatial similarity distribution between the features to be tested and the memory prototypes; pixel-level reconstruction errors and feature space matching deviations are nonlinearly weighted and fused to generate anomaly scores, and pixel-level anomaly heatmaps and region bounding boxes are output using an adaptive threshold mechanism.
[0007] Optionally, the autoencoder network adopts a densely connected cross-scale feature fusion structure: the output feature map of each downsampling stage of the encoder is concatenated with the corresponding upsampling stage input of the decoder, and a spatial attention gating mechanism is introduced to selectively enhance abnormal sensitive features, and feature sparsity constraints are applied to the bottleneck layer to improve the discriminativeness of the latent representation.
[0008] Optionally, the update mechanism of the dynamic memory module includes: using an online clustering algorithm to process the feature vectors of normal samples generated during training in real time; automatically creating a new prototype when the distance between a new sample and the nearest prototype exceeds a dynamically adjusted similarity threshold; periodically performing weighted centroid fusion on redundant prototypes whose spatial distance is less than a merging threshold; and removing outdated prototypes through an elimination mechanism based on access frequency; and setting an isolation buffer to filter potential abnormal sample interference during training.
[0009] Optionally, the attention matching module employs a multi-head attention mechanism to process the feature subspace in parallel: the input features are mapped to multiple subspaces through a trainable projection matrix, the cosine similarity distribution with the prototypes in the memory is calculated independently in each subspace, the weight coefficients of each prototype are generated by softmax normalization, and finally the prototypes with weights exceeding a specific threshold are selected for feature bias weighted aggregation.
[0010] Optionally, the anomaly score calculation adopts a dual-path fusion framework: the reconstruction path calculates the multi-scale reconstruction error by weighted combination of structural similarity measurement and pixel-level L-norm difference; the feature matching path measures the statistical distribution difference between the feature to be tested and the attention-weighted prototype set by Mahalanobis distance. The outputs of the two paths are fused by adaptive balancing coefficients and then normalized to anomaly probability values by the sigmoid function.
[0011] Optionally, the adaptive threshold module is based on the historical normal sample abnormal score distribution within the sliding time window: it uses the kernel density estimation method to model the score probability distribution function, automatically determines the dynamic judgment boundary according to the preset false alarm rate tolerance, triggers the threshold recalibration process when the score distribution of multiple consecutive samples deviates beyond the stable threshold, and introduces a confidence interval verification mechanism to prevent over-adjustment.
[0012] Optionally, multi-level acceleration optimizations can be implemented during the inference phase: the computation graph can be compiled into an optimized intermediate representation using PyTorch's TorchScript; an overlapping block strategy can be used for high-resolution images, combined with multi-process parallel computing to accelerate feature extraction; and a mixed-precision model can be generated through quantized perception training to reduce the computational load on edge devices while maintaining detection accuracy.
[0013] Optionally, an incremental learning framework is included: when the system continuously receives new normal samples and the sample size reaches a preset threshold, the model is automatically updated; a collaborative strategy of feature replay and elastic weight solidification is adopted, which achieves the ability to recognize historical patterns while adapting to new data distributions by replaying the feature distribution of historical samples and constraining the range of key parameter changes.
[0014] Optionally, the deployment phase provides multimodal outputs: generating pixel-level anomaly probability heatmaps and using an adaptive region growing algorithm to extract anomaly region bounding boxes; outputting overall anomaly confidence scores and anomaly type probability distribution vectors; and simultaneously recording the contribution of each prototype in the feature matching path for interpretability analysis.
[0015] The technical effects and advantages of this invention are as follows:
[0016] Compared to existing technologies, this invention constructs a dynamic memory based on streaming clustering to learn and update the feature prototypes of normal samples online. This mechanism utilizes online clustering algorithms to process new samples in real time and automatically creates new prototypes or merges redundant prototypes based on dynamic similarity thresholds, while setting up isolation buffers to filter out abnormal interference. This allows the system to continuously adapt to data distribution drift in the production line, effectively overcoming the problem of increased false alarm rates caused by slow changes in environment, materials, or equipment, and improving the long-term reliability and stability of the system in dynamic industrial scenarios.
[0017] Compared to existing technologies, this invention enhances the ability to distinguish subtle anomalies by introducing a multi-head attention-weighted feature matching module. This module maps the features to be tested to multiple subspaces in parallel, calculates the similarity to prototypes in memory within each subspace, and performs weighted aggregation of biases after selecting key prototypes. This approach enhances the representation of anomaly-sensitive features and reduces false responses to complex background textures, thereby achieving more precise pixel-level localization of subtle defects (such as microcracks and cold welds), improving detection accuracy and interpretability.
[0018] Compared to existing technologies, this invention designs a dual-path detection framework that integrates pixel-level reconstruction error and differences in statistical distribution in the feature space. The reconstruction path preserves detailed differences, while the feature matching path detects distribution anomalies. After adaptive weight balancing, a comprehensive anomaly score is generated, and a dynamic threshold based on kernel density estimation is used for decision-making. This scheme simultaneously utilizes complementary information from the image space and feature space, overcoming the limitations of relying solely on reconstruction error or feature matching. It reduces false positives while ensuring high recall for true defects, comprehensively improving the overall performance of the detection system.
[0019] Compared to existing technologies, this invention optimizes the inference efficiency of high-resolution images by integrating multi-level acceleration strategies such as model compilation, block-based parallel processing, and mixed-precision quantization, meeting the production line cycle time requirements of millisecond-level real-time response. Simultaneously, it introduces an incremental learning framework combining feature playback and elastic weight solidification, enabling the model to effectively constrain changes in key parameters when incorporating new categories of normal samples, balancing new knowledge learning with the retention of historical knowledge. This resolves the contradiction between computational efficiency and detection accuracy, and between model updates and catastrophic forgetting, ensuring the system can evolve online safely and efficiently over the long term. Attached Figure Description
[0020] Figure 1 This is a system framework diagram of the present invention.
[0021] Figure 2 This is a flowchart of the dynamic memory workflow of the present invention.
[0022] Figure 3 This is a flowchart of the dual-path detection process of the present invention. Detailed Implementation
[0023] The following will refer to the appendices in the embodiments of the present invention. Figures 1-3 The technical solutions in the embodiments of the present invention are clearly and completely described herein. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0024] Example 1
[0025] A deep learning-based method for anomaly detection in industrial images includes the following complete technical process: An illumination-invariant feature extraction is performed on industrial images using a preprocessing module integrating multi-scale image pyramids and local binary patterns to generate an enhanced feature map that fuses texture details and structural information; an unsupervised training is performed on a normal sample set using a deep autoencoder network built with PyTorch, where the encoder uses a deep separable convolutional layer with residual connections to extract multi-level feature representations, and the decoder achieves high-fidelity image reconstruction through deconvolution and sub-pixel upsampling operations; a dynamic memory module based on streaming clustering is established to continuously store and update a cluster prototype set composed of feature vectors from normal samples; an attention matching module with a learnable weight matrix is designed to calculate the multi-dimensional spatial similarity distribution between the target feature and the memory prototype; pixel-level reconstruction errors and feature space matching deviations are nonlinearly weighted and fused to generate anomaly scores, and an adaptive threshold mechanism is used to output pixel-level anomaly heatmaps and region bounding boxes.
[0026] The preprocessing stage achieves multi-scale image representation by constructing a Gaussian pyramid, typically with four layers, each decreasing in scale by a factor of 0.5. At each scale level, a rotation-invariant local binary mode operator is applied to calculate the LBP feature vector for each pixel, which is then concatenated with the gradient magnitude map of that level to form a multi-scale feature tensor with illumination robustness. This tensor is normalized and then input into a deep autoencoder network. The encoder part of the autoencoder employs a depthwise separable convolutional structure, with batch normalization and ReLU activation functions following each convolutional layer, and residual connections are introduced to mitigate the vanishing gradient problem. The encoder contains five downsampling stages, each halving the feature map size through convolutions with a stride of 2, while the number of channels doubles with each stage. The decoder uses a combination of transposed convolutions and subpixel convolutions to achieve upsampling, gradually restoring the image resolution, and finally outputting a reconstructed image with the same size as the input. The dynamic memory module uses an online K-means clustering algorithm, randomly selecting several samples from the training set features as initial prototype centers during initialization. During training, for each input feature vector of a normal sample, its Euclidean distance to all prototypes is calculated. If the minimum distance is greater than the current dynamic threshold, the feature vector is added as a new prototype; otherwise, it is assigned to the nearest prototype, and the center position of that prototype is updated. The dynamic threshold is updated based on the 90th percentile of the recent sample distance distribution. The attention matching module contains a set of learnable linear transformation matrices that map the input features to 8 subspaces. In each subspace, the cosine similarity between the input features and all prototypes is calculated independently, normalized to a weight distribution using the Softmax function, and the prototypes with the top 5% weights are selected for subsequent weighted aggregation. The anomaly score consists of two parts: reconstruction error and feature matching bias. The reconstruction error is a weighted sum of the multi-scale structural similarity index and L1 loss, and the feature matching bias is measured using Mahalanobis distance. The two scores are fused through a learnable weight parameter and finally converted into anomaly probabilities using the Sigmoid function. The adaptive threshold module maintains a sliding window of length 1000 to store the anomaly scores of recent normal samples, uses Gaussian kernel density estimation to fit the score distribution, and determines the dynamic threshold based on a preset 1% false alarm rate. Threshold recalibration is triggered when the mean score of 20 consecutive samples deviates from the historical mean by more than 3 standard deviations.
[0027] In this embodiment, the autoencoder network adopts a densely connected cross-scale feature fusion structure: the output feature map of each downsampling stage of the encoder is concatenated with the corresponding upsampling stage input of the decoder, and a spatial attention gating mechanism is introduced to selectively enhance abnormal sensitive features, and feature sparsity constraints are applied to the bottleneck layer to improve the discriminativeness of the latent representation.
[0028] The output feature map of each downsampling stage of the encoder is passed to the corresponding stage of the decoder via skip connections. Before the upsampling operation, it is concatenated with the input feature map of the decoder at that stage in terms of channel dimension. The concatenated feature map is first adjusted for the number of channels by a 1×1 convolution before being input to the subsequent upsampling module. The spatial attention gating mechanism is implemented through two parallel convolutional layers: one uses the sigmoid activation function to generate a spatial attention weight map, and the other maintains linear activation for feature transformation. The attention weight map is multiplied element-wise with the transformed feature map to achieve feature selection enhancement. In the bottleneck layer, an L1 sparse regularization constraint is applied to the latent feature vector, with the regularization coefficient set to 0.001, prompting the network to learn a more discriminative and compact representation. In addition, a layer-by-layer gradient pruning strategy is adopted during training to limit the gradient norm to no more than 1.0, ensuring training stability. Each upsampling stage of the decoder uses sub-pixel convolution operations. First, the number of channels is expanded to a squared multiple of the magnification through convolution, and then resolution is improved through pixel recombination. The final output layer uses the Tanh activation function to constrain pixel values to the range of [-1, 1], which is consistent with the numerical range of the preprocessed input image.
[0029] In this embodiment, the update mechanism of the dynamic memory module includes: using an online clustering algorithm to process the feature vectors of normal samples generated during training in real time; automatically creating a new prototype when the distance between a new sample and the nearest prototype exceeds a dynamically adjusted similarity threshold; periodically performing weighted centroid fusion on redundant prototypes whose spatial distance is less than a merging threshold; and removing outdated prototypes through an elimination mechanism based on access frequency; and setting an isolation buffer to filter potential abnormal sample interference during training.
[0030] The dynamic memory employs an improved online K-means clustering algorithm. Each prototype maintains a feature vector center and a counter recording the number of samples belonging to that prototype. The similarity threshold is initially set to 0.5 times the average distance between feature vectors in the training set and is dynamically updated based on the minimum distance distribution of the most recent 100 samples, with an update frequency of once every 100 samples processed. The merging threshold is set to 0.3 times the current average prototype distance, and a prototype merging operation is performed once every 1000 samples processed: the Euclidean distance between all prototypes is calculated, and prototype pairs with distances less than the merging threshold are weighted and merged. The new center is the weighted average of the features of the two prototypes, with the weights being their counter values. The elimination mechanism is based on the prototype access frequency. The number of times each prototype is accessed is counted every 24 hours, and prototypes whose access counts are less than 0.1% of the total access counts for three consecutive statistical periods are removed. The isolation buffer uses a first-in, first-out queue with a maximum capacity of 100, storing sample features with reconstruction errors more than twice the current threshold. Every 10 of these samples are manually verified, and only those confirmed as normal samples are allowed to enter the memory update process. All operations in the memory are designed to be thread-safe, supporting concurrent access and updates by multiple threads.
[0031] In this embodiment, the attention matching module uses a multi-head attention mechanism to process the feature subspace in parallel: the input features are mapped to multiple subspaces through a trainable projection matrix, the cosine similarity distribution with the prototypes in the memory is calculated independently in each subspace, the weight coefficients of each prototype are generated by softmax normalization, and finally the prototypes with weights exceeding a certain threshold are selected for feature bias weighted aggregation.
[0032] The attention matching module comprises eight independent subspace projection matrices, each projecting input features from the original dimension to a 64-dimensional subspace. The projection matrices are orthogonally initialized, and orthogonal regularization constraints are applied during training to maintain subspace independence. Within each subspace, the cosine similarity between the input features and all prototype features is calculated, with L2 normalization applied to the feature vectors before similarity calculation. The temperature coefficient of the Softmax function is set to 0.1 to enhance the discriminative power of the weight distribution. A weight threshold of 0.01 is set, retaining only prototypes with weights higher than this value for subsequent calculations. For each subspace, the weighted aggregated feature bias vector is calculated as a weighted sum of the differences between the selected prototype features and the input features, with weights being the normalized similarity coefficients. The final comprehensive matching bias is obtained by averaging the L2-normalized bias vectors from the eight subspaces. All learnable parameters are optimized using gradient descent with a learning rate of 0.001, and the Adam optimizer is used for parameter updates. During the inference phase, parallel computation is achieved through matrix multiplication and lookup table optimizations to improve processing speed.
[0033] Multi-head attention-weighted feature matching bias formula:
[0034]
[0035] Where s represents the final feature matching bias obtained by synthesis;
[0036] N represents the total number of attention heads;
[0037] i represents the index of the current attention head;
[0038] Ω represents the set of key prototypes selected through attention weights;
[0039] k represents the index of the prototype in set Ω;
[0040] This represents the attention weight of the k-th prototype in the i-th subspace;
[0041] f represents the feature vector of the image to be tested;
[0042] p_k: represents the k-th prototype in the memory;
[0043] f-p_k represents the feature deviation vector between the feature to be tested and the k-th prototype.
[0044] This formula defines the calculation process for the attention-weighted feature matching bias s. It integrates a multi-head attention mechanism (i subspaces) and prototype selection (k∈Ω) to finally obtain a comprehensive matching bias.
[0045] In this embodiment, the anomaly score calculation adopts a dual-path fusion framework: the reconstruction path calculates the multi-scale reconstruction error by weighted combination of structural similarity measurement and pixel-level L-norm difference; the feature matching path measures the statistical distribution difference between the feature to be tested and the attention-weighted prototype set by Mahalanobis distance. The outputs of the two paths are fused by adaptive balance coefficients and then normalized to anomaly probability values by the sigmoid function.
[0046] Dual-path anomaly score fusion formula:
[0047] S final =σ(α·E r +(1-α)·D m )
[0048] Where S_final represents the final fused anomaly score;
[0049] σ represents the Sigmoid activation function, which normalizes the scores to the (0,1) interval.
[0050] α represents the adaptive balancing coefficient, which is used to weigh the contributions of the two paths, and its value is dynamically adjusted based on historical data.
[0051] E_r: Represents the multi-scale reconstruction error calculated from the reconstruction path.
[0052] D_m: Represents the Mahalanobis distance deviation calculated from the feature matching path.
[0053] This formula defines the core of the decision fusion in the dual-path detection framework. It adaptively weights and fuses the outputs of the pixel-level reconstruction error path and the feature space matching path, and normalizes them to anomaly probabilities using the Sigmoid function. This formula is the core of this method for achieving high-precision localization and robust detection.
[0054] The reconstruction path calculates reconstruction errors at each of the four levels of the multi-scale pyramid. The structural similarity index for each level is calculated using an 11×11 Gaussian filter kernel, with a brightness / contrast parameter set to 0.01 and a structure parameter set to 0.03. Before calculating the pixel-level L1 loss, the image is smoothed using a Gaussian filter with a kernel size of 5×5. The weights for the two error terms are 0.7 and 0.3, respectively. The final multi-scale reconstruction error is obtained by weighted summing the errors from each level, with the weights decreasing linearly with decreasing scale. In the feature matching path, Mahalanobis distance calculation requires estimation of the covariance matrix based on the prototype set. The covariance matrix is updated every 1000 samples using an exponentially weighted moving average method for smoothing. To maintain numerical stability, a 0.001 identity matrix regularization term is added to the covariance matrix. The adaptive balancing coefficient is initially set to 0.5 and dynamically adjusted based on the relative magnitude of the error values of the two paths in the most recent 100 samples, with an adjustment step size of 0.01. The fused outlier scores are mapped to probability values using the Sigmoid function, and the slope parameter of the Sigmoid function is adjusted according to the score distribution of the training set to enhance discriminative power.
[0055] In this embodiment, the adaptive threshold module is based on the abnormal score distribution of historical normal samples within a sliding time window: it uses a kernel density estimation method to model the score probability distribution function, automatically determines the dynamic judgment boundary according to the preset false alarm rate tolerance, triggers the threshold recalibration process when the score distribution of multiple consecutive samples deviates beyond the stable threshold, and introduces a confidence interval verification mechanism to prevent over-adjustment.
[0056] The adaptive thresholding module maintains a circular buffer of 1000 to store the outlier scores of the most recent normal samples. Kernel density estimation uses a Gaussian kernel function, and bandwidth selection is automatically determined using the Silverman rule. Probability density estimation is updated every 100 new samples. The dynamic threshold is determined based on a preset 1% false alarm rate, i.e., finding score values that result in an estimated cumulative distribution function value of 0.99. Stability monitoring compares the mean and standard deviation of the scores of the most recent 50 samples with the statistics of the historical 1000 samples. Threshold recalibration is triggered when the difference between the most recent mean and the historical mean exceeds two historical standard deviations. During recalibration, the kernel density function is re-estimated using the latest 1000 samples, and a new threshold is calculated. Confidence interval verification is performed using the Bootstrap method, resampling 1000 times from the current samples to calculate the 95% confidence interval of the threshold estimate. The new threshold is only adopted if the difference from the original threshold does not exceed three times the radius of the confidence interval; otherwise, the original threshold remains unchanged. All statistical calculations employ numerically stable algorithms to prevent floating-point overflow and undercurrent issues.
[0057] In this embodiment, multi-level acceleration optimization is implemented during the inference stage: the computation graph is compiled into an optimized intermediate representation using PyTorch's TorchScript; an overlapping block strategy is adopted for high-resolution images and combined with multi-process parallel computing to accelerate feature extraction; a mixed-precision model is generated through quantized perception training to reduce the computational load on edge devices while maintaining detection accuracy.
[0058] Inference optimization first converts the model into a static computation graph using TorchScript, enabling graph optimization options including operation fusion, constant folding, and redundant computation elimination. For high-resolution input, an overlapping block processing strategy is employed, with a block size of 512×512 pixels and an overlap area of 64 pixels. Block processing is executed in parallel by four processes, each bound to a dedicated CPU core. Intermediate tensors during feature extraction are managed using a memory pool to reduce dynamic memory allocation overhead. Model quantization uses post-training quantization, converting weights to INT8 format and employing dynamic range quantization for activation values. The quantized model is implemented using a symmetric quantization strategy, with the scaling factor determined based on the maximum absolute value. On hardware supporting INT8 computation, a deep convolution acceleration instruction set is enabled to improve computational throughput. Furthermore, an asynchronous execution pipeline is used to overlap image preprocessing, model inference, and post-processing stages, hiding data transmission latency. Ultimately, real-time performance with a single-frame processing time of less than 50 milliseconds is achieved.
[0059] In this embodiment, an incremental learning framework is included: when the system continuously receives new normal samples and the sample size reaches a preset threshold, the model is automatically updated; a collaborative strategy of feature replay and elastic weight solidification is adopted, which replays the feature distribution of historical samples and constrains the range of variation of key parameters to achieve the ability to recognize historical patterns while adapting to new data distribution.
[0060] Incremental learning is triggered by accumulating 1000 new normal samples. Feature replay randomly selects feature vectors from 2000 samples in the historical training set and mixes them with the new samples to form a fine-tuning dataset. Elastic weight solidification measures parameter importance by calculating the diagonal elements of the Fisher information matrix of network parameters on historical tasks. Importance weights are updated after each full training iteration. During fine-tuning, L2 regularization constraints are applied to important parameters, with the regularization strength proportional to the importance weight, and a scaling factor of 10. The learning rate is set to 0.1 times the initial training rate, and stochastic gradient descent with momentum is used for optimization, with a momentum parameter of 0.9. The number of training iterations is limited to 20 epochs, and an early stopping strategy is triggered when the validation loss does not decrease for three consecutive epochs. Simultaneously, the memory module is updated synchronously, and new samples participate in the prototype creation and merging process. The threshold module is recalibrated using the abnormal score distribution of the new samples. The entire update process is executed asynchronously in the background without affecting the normal detection process. After the update is completed, the running model is replaced through a hot-swap mechanism.
[0061] In this embodiment, the deployment phase provides multimodal output: generating a pixel-level anomaly probability heatmap and using an adaptive region growing algorithm to extract the bounding boxes of anomaly regions; outputting the overall anomaly confidence score and anomaly type probability distribution vector; and simultaneously recording the contribution of each prototype in the feature matching path for interpretability analysis.
[0062] Pixel-level anomaly heatmaps are upsampled to the original image resolution using bicubic interpolation and then Gaussian smoothed (kernel size 5×5). The region growing algorithm starts with seed points where the anomaly probability is greater than 0.5, with the growth threshold adaptively set to 1.5 times the local probability mean. The minimum region area threshold is set to 50 pixels to eliminate false regions caused by noise. Bounding boxes are represented using the minimum bounding rectangle and extended by 5 pixels to ensure complete inclusion of the anomaly region. The overall anomaly confidence score is the logarithmic weighted sum of the probability value of the largest anomaly region in the image and the region area. The anomaly type probability distribution is calculated by querying a historical anomaly case database and using the K-nearest neighbor algorithm to calculate the similarity between the current anomaly features and various anomaly prototypes. Prototype contribution is recorded as the top 3 prototype identifiers with the highest attention weights and their weight values. All outputs are encapsulated in JSON format, including metadata such as the original image ID, timestamp, and processing time. A visualization report is also generated, overlaying the heatmap and bounding box previews on the original image for easy manual review.
[0063] Finally, the following points should be noted: First, in the description of this application, it should be noted that, unless otherwise specified and limited, the terms "installation", "connection", and "linkage" should be interpreted broadly, and can be mechanical or electrical connections, or internal connections between two components, or direct connections. "Up", "down", "left", "right", etc. are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may change.
[0064] Secondly: The accompanying drawings of the embodiments disclosed in this invention only involve the structures involved in the embodiments disclosed in this invention. Other structures can refer to the general design. In the absence of conflict, the same embodiment and different embodiments of this invention can be combined with each other.
[0065] In conclusion, the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A deep learning-based method for detecting anomalies in industrial images, characterized in that... The complete technical process includes the following steps: An illumination-invariant feature extraction is performed on industrial images using a preprocessing module integrating multi-scale image pyramids and local binary patterns to generate enhanced feature maps that fuse texture details and structural information; an unsupervised training is performed on a normal sample set using a deep autoencoder network built with PyTorch, where the encoder uses a deep separable convolutional layer with residual connections to extract multi-level feature representations, and the decoder achieves high-fidelity image reconstruction through deconvolution and sub-pixel upsampling operations; a dynamic memory module based on streaming clustering is established to continuously store and update a cluster prototype set composed of feature vectors from normal samples; an attention matching module with a learnable weight matrix is designed to calculate the multi-dimensional spatial similarity distribution between the test feature and the memory prototype; pixel-level reconstruction errors and feature space matching deviations are non-linearly weighted and fused to generate anomaly scores, and combined with an adaptive threshold mechanism to output pixel-level anomaly heatmaps and region bounding boxes.
2. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The autoencoder network adopts a densely connected cross-scale feature fusion structure: the output feature map of each downsampling stage of the encoder is concatenated with the corresponding upsampling stage input of the decoder. At the same time, a spatial attention gating mechanism is introduced to selectively enhance abnormal sensitive features, and feature sparsity constraints are applied to the bottleneck layer to improve the discriminativeness of the latent representation.
3. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The update mechanism of the dynamic memory module includes: using an online clustering algorithm to process the feature vectors of normal samples generated during training in real time; automatically creating a new prototype when the distance between a new sample and the nearest prototype exceeds a dynamically adjusted similarity threshold; periodically performing weighted centroid fusion on redundant prototypes whose spatial distance is less than the merging threshold; and removing outdated prototypes through an elimination mechanism based on access frequency; and setting an isolation buffer to filter out potential abnormal sample interference during training.
4. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The attention matching module employs a multi-head attention mechanism to process the feature subspace in parallel: the input features are mapped to multiple subspaces through a trainable projection matrix, the cosine similarity distribution with the prototypes in the memory is calculated independently in each subspace, the weight coefficients of each prototype are generated by softmax normalization, and finally the prototypes with weights exceeding a specific threshold are selected for feature bias weighted aggregation.
5. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The anomaly score calculation adopts a dual-path fusion framework: the reconstruction path calculates the multi-scale reconstruction error by weighted combination of structural similarity measurement and pixel-level L-norm difference; the feature matching path measures the statistical distribution difference between the feature to be tested and the attention-weighted prototype set by Mahalanobis distance. The outputs of the two paths are fused by adaptive balancing coefficients and then normalized to anomaly probability values by the sigmoid function.
6. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The adaptive threshold module is based on the distribution of abnormal scores of historical normal samples within a sliding time window: it uses a kernel density estimation method to model the score probability distribution function, automatically determines the dynamic judgment boundary according to the preset false alarm rate tolerance, triggers the threshold recalibration process when the score distribution of multiple consecutive samples deviates beyond the stable threshold, and introduces a confidence interval verification mechanism to prevent over-adjustment.
7. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... Multi-level acceleration optimization is implemented during the inference phase: the computation graph is compiled into an optimized intermediate representation using PyTorch's TorchScript; an overlapping block strategy is adopted for high-resolution images and combined with multi-process parallel computing to accelerate feature extraction; and a mixed-precision model is generated through quantized perception training to reduce the computational load on edge devices while maintaining detection accuracy.
8. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... It includes an incremental learning framework: when the system continuously receives new normal samples and the sample size reaches a preset threshold, it automatically triggers model updates; it adopts a collaborative strategy of feature replay and elastic weight solidification, by replaying the feature distribution of historical samples and constraining the range of key parameter changes, it can maintain the ability to recognize historical patterns while adapting to new data distributions.
9. The industrial image anomaly detection method based on deep learning according to claim 1, characterized in that... The deployment phase provides multimodal outputs: generating pixel-level anomaly probability heatmaps and using an adaptive region growing algorithm to extract anomaly region bounding boxes; outputting overall anomaly confidence scores and anomaly type probability distribution vectors; and simultaneously recording the contribution of each prototype in the feature matching path for interpretability analysis.
Citation Information
Cited By
Industrial defect image transformation detection method based on cost capacity function
CN121437504A
Transform detection method of industrial defect images based on cost capacity function
CN121437504B
Distributed industrial fault diagnosis system and method
CN121657628A
Intelligent AI image real-time processing method and system for edge computing scene
CN121660868A
Intelligent ai image real-time processing method and system for edge computing scenarios
CN121660868B