Industrial anomaly detection method based on re-calibration attention

By adopting a recalibration attention-based method in unsupervised industrial anomaly detection, using the teacher model, student model and automatic encoder, combined with the hierarchical anomaly scoring module for quantization and fine-tuning training, the problem of overfitting normal samples of the model is solved and the detection ability of unchanged area anomalies is improved.

CN119762852AActive Publication Date: 2025-04-04XIAMEN UNIV

Patent Information

Application Number
CN202411811497.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-10
Publication Date
2025-04-04
Estimated Expiration
2044-12-10

AI Technical Summary

Technical Problem

Unsupervised industrial anomaly detection methods are susceptible to the inherent deviation of normal samples, which leads to the model being overfitted to the normal sample change area, ignoring potential defects in the unchanged area, and thus leading to abnormal detection errors.

Method used

An industrial anomaly detection method based on recalibration attention is adopted. By constructing a model composed of teacher model, student model and automatic encoder, combined with the hierarchical anomaly scoring module HSQ for quantization and fine-tuning training, attention is reassigned to improve anomaly detection capabilities.

Benefits of technology

It effectively breaks the inherent deviation of attention allocation in unsupervised IAD, improves the model's ability to detect subtle anomalies in the invariant areas, and achieves higher anomaly sensitivity and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119762852A_ABST
    Figure CN119762852A_ABST
Patent Text Reader

Abstract

The invention discloses an industrial anomaly detection method based on re-calibration attention, and the method comprises the following steps: S1, constructing an industrial anomaly detection model, and initializing the industrial anomaly detection model; the industrial anomaly detection model is composed of a teacher model, a student model and an automatic encoder; s2, evaluating the anomaly judgment capability of each layer of the network in the industrial anomaly detection model by adopting a hierarchical anomaly scoring module HSQ, distributing a corresponding quantization bit width to each layer according to the anomaly recognition capability, training the industrial anomaly detection model layer by layer, and then performing quantization; s3, performing fine tuning training on the student model and the automatic encoder; s4, performing industrial anomaly detection by adopting the industrial anomaly detection model after fine tuning training; according to the method, the attention map is systematically decomposed and recalibrated, the generalization ability and the anomaly detection precision of the model are improved, and the method has remarkable practical value and application prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of anomaly detection, and in particular to an industrial anomaly detection method based on recalibrated attention. Background Art

[0002] Deep learning-based visual inspection has achieved great results with the help of supervised learning. However, in actual industrial scenarios, the scarcity of defect samples, the cost of annotation, and the lack of prior knowledge of defects may make supervised-based methods ineffective. In recent years, unsupervised anomaly detection (IAD) algorithms have been increasingly used in industrial inspection tasks. "Unsupervised" means that the training phase only contains normal images without any defect samples. The IAD method under the unsupervised paradigm avoids the following problems in supervised methods: 1. The high cost of sufficient annotation; 2. The difficulty in collecting abnormal or defective samples; 3. The inability to predict defects that have not occurred; 4. The annotation noise unintentionally introduced when labeling data.

[0003] Based on these advantages, unsupervised anomaly detection methods have become the mainstream strategy for IAD tasks. However, all unsupervised IAD methods face a common challenge: since there are only normal samples in the training process, the model is more susceptible to the inherent bias in normal samples and overfits to normal samples, which causes the model to focus on the changed areas of normal samples and ignore the potential defects in the unchanged areas, which in turn causes the model to make wrong judgments when anomalies appear in the unchanged parts.

[0004] like Figure 2 As shown in Figure 2, this challenge is visualized through anomaly heatmaps on the MVTecAD and MVTec LOCO datasets. In each group, from left to right are the normal samples of the corresponding category, the average anomaly heatmap of normal samples, and the average normal heatmap of anomaly samples. Brighter areas in the heatmap indicate a higher probability of being attended to. As shown in the white box in the second column, it is obvious that the model is misled by the inherent bias of normal samples. In other words, the attention map obtained through unsupervised training can more easily focus on the changed areas in normal samples and ignore the areas without changes. An intuitive idea is to abandon the attention mechanism. However, completely ignoring the attention maps is not a feasible solution because they play a vital role in anomaly detection. Therefore, how to make the model allocate attention more reasonably becomes a key issue.

[0005] A feasible solution is to first focus the model's attention on the target subject and then redistribute the attention. The former can be achieved by using model quantization, and the latter can be achieved by retraining.

[0006] Model quantization is a technique that reduces the computational resource requirements and memory footprint of a model by reducing the precision of model parameters (e.g., converting 32-bit floating point numbers to 8-bit integers). Existing neural network quantization algorithms can be divided into two categories based on their training strategies: post-training quantization (PTQ) and quantization-aware training (QAT). PTQ refers to quantizing the model after training without any fine-tuning or retraining, allowing fast quantization at the expense of reduced accuracy. In contrast, QAT adopts an online quantization strategy. This approach utilizes the entire training dataset during the quantization process. As a result, it has higher accuracy but limited efficiency. Recently, several studies have explored integrating quantization techniques into anomaly detection tasks. Even post-training quantization has been applied to device anomaly detection, achieving a balance between computational efficiency and detection accuracy. Recent quantization methods have further expanded the boundaries by adopting mixed precision techniques, which assign different bit widths to different layers. However, it should be clarified that model quantization is the method of this paper, not the goal. During the quantization process, due to the reduced precision of parameters, the model will be more inclined to learn and extract the most important information to complete the task. This limitation forces the model to actively focus on the target subject during training and ignore irrelevant factors such as background noise or irrelevant features. Fine-tuning is a transfer learning technique that further trains on a specific dataset to adapt to the needs of new tasks or new data distributions. During fine-tuning, attention is recalibrated to achieve the purpose of reallocating attention. Figure 3 In (a), the anomaly heatmaps before and after the model is quantized are visualized. It can be observed that the model focuses more on the subject and ignores the background compared to before quantization. Then, more accurate anomaly detection is achieved after fine-tuning.

[0007] There are three main methods for unsupervised IAD, namely, feature embedding-based methods, reconstruction-based methods, and anomaly synthesis-based methods. Feature embedding-based methods achieve advanced performance and can be specifically divided into: teacher-student model, normalization flow, memory bank, and single-class classification. The most typical methods are memory bank and teacher-student model. The memory bank method embeds normal features into a compressed space. Abnormal features are far away from the normal clusters in the embedding space. As for the teacher-student model, the teacher is a pre-trained frozen CNN, and the student network is trained to simulate the teacher's output on the training images. Since the student has not seen abnormal images during training, the student is usually unable to predict the teacher's output on these images, thereby achieving anomaly detection. UninformedStudent proposed a new framework called teacher-student anomaly detection, RD proposed reverse distillation, and the student decoder learned to recover features from the compact embedding of the teacher encoder. The GCCB method adopted a dual-student knowledge distillation framework to enhance the detection ability of structural and logical anomalies. However, the feature embedding-based methods rely on the size of the memory bank or the capacity of the teacher network, which may cause too much memory to occupy, resulting in slower inference time, or limit the generalization ability of the model.

[0008] Reconstruction-based methods range from autoencoders to generative adversarial networks to Transformer and diffusion models. Among them, autoencoder methods rely on accurate reconstruction of normal images and inaccurate reconstruction of abnormal images, comparing the reconstruction with the input image to detect anomalies. Reconstruction-based methods are more likely to capture information from the entire image. However, these methods often produce blurry and inaccurate reconstructions, which leads to an increase in false positives and are generally inferior to the above-mentioned local methods in performance.

[0009] Therefore, existing unsupervised industrial anomaly detection methods have problems such as model overfitting to normal samples, poor generalization ability, and trade-off between accuracy and inference speed, making it difficult to meet actual usage needs. Summary of the invention

[0010] To solve the above problems, the present invention proposes an industrial anomaly detection method based on recalibrated attention.

[0011] To achieve the above object, the present invention adopts the following technical solutions:

[0012] An industrial anomaly detection method based on recalibrated attention includes the following steps:

[0013] S1. Build an industrial anomaly detection model and initialize the industrial anomaly detection model; the industrial anomaly detection model consists of a teacher model, a student model and an autoencoder;

[0014] S2. Use the hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, assign corresponding quantization bit widths to each layer according to the anomaly recognition ability, and then train and quantize the industrial anomaly detection model layer by layer;

[0015] S3, fine-tune the student model and autoencoder;

[0016] S4. Use the fine-tuned trained industrial anomaly detection model to perform industrial anomaly detection.

[0017] Preferably, the initialization process of the industrial anomaly detection model in step S1 is: the model is trained on a training set containing only normal images, and only the weights of the student model and the autoencoder are updated during the training process;

[0018] Before training, the teacher model is pre-trained on the ImageNet training set using the pre-trained WideResNet-101 network. The pre-training of the teacher model is achieved by minimizing the mean square error between the teacher model output and the pre-trained network output. The loss is calculated as:

[0019] L pre =Mean(||E(I)-T(I)|| 2 )

[0020] Among them, L pre is the loss in the pre-training stage; Mean(·) is the averaging operation; I is an image from the ImageNet training set; E(I) is the normalized output after the WideResNet-101 network feature extractor extracts the features of the input image, that is, E(I) = (extracted features - feature mean) / feature standard deviation; T(I) is the output of the teacher network; ||·|| 2 is the absolute value square;

[0021] Use the Patch Description Network (PDN) as the feature extraction network for the teacher model and the student model. The Patch Description Network (PDN) consists of only four fully convolutional layers.

[0022] A standard convolutional autoencoder is used to learn logical constraints on training images and detect anomalies that violate the constraints, including strided convolutions in the encoder and bilinear upsampling in the decoder; compared to the student model based on the patch description network (PDN), the autoencoder encodes and decodes the full image through a bottleneck of 64 latent dimensions.

[0023] Preferably, the specific evaluation process of the hierarchical anomaly score in step S2 is:

[0024] S21, the teacher model and the student model are both processed by the hierarchical anomaly scoring module HSQ, which maps the layers of the same depth of the teacher model and the student model one by one, and uses the output of each convolution layer to calculate the anomaly score s, s∈(0,1). The anomaly score s measures the attention consistency between the teacher model and the student model, and is used to guide the reallocation of attention to defect-prone areas;

[0025] S22. The bit width of the lth layer is determined according to the anomaly score. The calculation formula of the bit width of the lth layer is:

[0026]

[0027] Among them, b (l) is the bit width of the lth layer, 1≤l≤N; Φ(s) is the bit width obtained according to the anomaly score; Φ(·) is a piecewise function, the bit width is determined according to the hierarchical quantization score, and 2, 3, 4 and 8 bits are selected as mixed precision; c (l) is the number of channels of the output feature of the lth layer; w (l) is the width of the output feature of the lth layer; h (l) is the height of the output feature of the lth layer; is the output of the teacher model layer l; is the output of the lth layer of the student model; is the square of the F norm; is the sum of the squares of the F norms of all channels;

[0028] S23, the block-level reconstruction strategy is used to train the industrial anomaly detection model layer by layer and then quantize it. The quantization formula is:

[0029] r=S(qZ),

[0030]

[0031] Among them, r is the floating point number before quantization, and its value range is (r min ,r max );q is a quantized fixed-point number, and its value range is (q min ,q max ); S is the step length, Z is the zero point, Clip is a clipping function that limits the value to between 0 and 255;

[0032] Using the diagonal Fisher information matrix, the cross-layer dependencies within each block are measured and the second-order error of any block is converted to the output of the block. The diagonal of the pre-activation diagonal Fisher information matrix is ​​equal to the squared gradient of each element, and the weight target is:

[0033]

[0034] Where Δz (l) is the change of the output feature of the lth layer, that is, the difference between the quantized and the unquantized; is the expected value; is the Hessian matrix of the output feature of the lth layer; (·) T is the transpose operation; To minimize the quantization error; is the variable to be optimized; It is an expected value form of the second-order error, which measures the feature change Δz after quantization (l) the impact on the overall loss; Represents the FIM diagonal matrix, whose diagonal elements are the loss function L for each output feature The square of the first-order gradient of .

[0035] Preferably, the specific process of step S3 is: during the fine-tuning training process, the teacher model, the student model and the autoencoder correspond to each other, and three losses are generated, and the calculation formula is:

[0036]

[0037]

[0038] Among them, L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; (CWH) -1 is the inverse of the product of the number of channels, width, and height; T(I) c is the output of the teacher model; S(I) c is the output of the student model; A(I) c is the output of the autoencoder; is the square of the F norm; is the sum of the squares of the F norms of all channels;

[0039] The total loss is calculated as:

[0040] Loss = λ t-s L t-s +λ ae-s L ae-s +λ t-ae L t-ae ,

[0041] Among them, Loss is the total loss, L t-s is the loss of the teacher model and the student model; L ae-sis the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; λ t-s is the loss weight of the teacher model and the student model; ae-s is the loss weight of the autoencoder and student model; λ t-ae are the loss weights for the teacher model and the autoencoder.

[0042] Preferably, the specific process of step S4 is:

[0043] S41, load the fine-tuned teacher model, student model and autoencoder;

[0044] S42, input the image to be detected into the industrial anomaly detection model. In the inference process, there is no need to use the layer-by-layer quantization module; the outputs of the teacher model, the student model and the autoencoder are M respectively. t 、M s and M ae ;

[0045] S43, the output of the teacher model and the student model are squared to obtain the local anomaly map M local , the output of the autoencoder and the student model is squared to obtain the global anomaly map M global ;

[0046] S44, averaging the local anomaly map and the global anomaly map to calculate the combined anomaly map M combined , and use the maximum value of the combined anomaly map as the image-level anomaly score, 2D anomaly score map By M w,h =C -1 ∑ c D c,w,h Given, that is, an anomaly score is assigned to each feature vector by averaging across channels D, where is a set of real numbers of size W and H; M w,h is anomaly score mask of size w and h; C -1 is the reciprocal of the number of channels; ∑ c D c,w,h is the sum of the squared differences of the features on all channels.

[0047] After adopting the above technical solution, the present invention has the following beneficial effects:

[0048] 1. This paper breaks the inherent bias of attention allocation in unsupervised IAD and guides the model to better detect subtle anomalies in invariant areas.

[0049] 2. We propose an industrial anomaly detection method based on recalibrated attention (RAAD), which systematically refines the attention map, uses quantization to reduce bias, and recalibrates the attention map through fine-tuning to improve anomaly sensitivity.

[0050] 3. The present invention proposes a hierarchical anomaly scoring module HQS, which is a module that dynamically allocates bit width according to the anomaly detection capability of each layer, and optimizes the alignment between quantization and attention to improve the efficiency and accuracy of IAD.

[0051] 4. The present invention evaluates an industrial anomaly detection method based on recalibrated attention on 32 data sets from three IAD sets using NVIDIA Geforce GTX 3090Ti. In particular, on the MVTecAD dataset, the industrial anomaly detection method based on recalibrated attention achieves an average image-level AU-ROC of 98.9, a speed of 113FPS, and the error rate is more than halved after quantization, which has significant practical value and application prospects. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 is a flow chart of the present invention;

[0053] Figure 2 Visualization diagrams of industrial products, normal samples and abnormal samples;

[0054] Figure 3 The attention maps at different stages of the model and the layer-by-layer attention output maps;

[0055] Figure 4 It is a flowchart of the present invention;

[0056] Figure 5 A schematic diagram of a structure for calculating anomaly scores for a teacher model and a student model of the present invention;

[0057] Figure 6 Schematic diagram of the anomaly detection structure of the industrial anomaly detection model of the present invention;

[0058] Figure 7 It is a qualitative result diagram on the MVTec-AD and MVTec-AD LOCO datasets of the present invention. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0060] like Figures 1 to 7As shown, an industrial anomaly detection method based on recalibrated attention includes the following steps:

[0061] S1. Build an industrial anomaly detection model and initialize the industrial anomaly detection model; the industrial anomaly detection model consists of a teacher model, a student model and an autoencoder;

[0062] The initialization process of the industrial anomaly detection model in step S1 is: the model is trained on a training set containing only normal images, and only the weights of the student model and the autoencoder are updated during the training process;

[0063] Before training, the teacher model is pre-trained on the ImageNet training set using the pre-trained WideResNet-101 network. The pre-training of the teacher model is achieved by minimizing the mean square error between the teacher model output and the pre-trained network output. The loss is calculated as:

[0064] L pre =Mean(||E(I)-T(I)|| 2 )

[0065] Among them, L pre is the loss in the pre-training stage; Mean(·) is the averaging operation; I is an image from the ImageNet training set; E(I) is the normalized output after the WideResNet-101 network feature extractor extracts the features of the input image, that is, E(I) = (extracted features - feature mean) / feature standard deviation; T(I) is the output of the teacher network; ||·|| 2 is the absolute value square;

[0066] Use the Patch Description Network (PDN) as the feature extraction network for the teacher model and the student model. The Patch Description Network (PDN) consists of only four fully convolutional layers.

[0067] A standard convolutional autoencoder is used to learn logical constraints on training images and detect anomalies that violate the constraints, including strided convolutions in the encoder and bilinear upsampling in the decoder. Compared with the student model based on the patch description network (PDN), the autoencoder encodes and decodes the full image through a bottleneck of 64 latent dimensions.

[0068] S2. Use the hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, assign corresponding quantization bit widths to each layer according to the anomaly recognition ability, and then train and quantize the industrial anomaly detection model layer by layer;

[0069] The specific evaluation process of the hierarchical anomaly score in step S2 is:

[0070] S21, the teacher model and the student model are both processed by the hierarchical anomaly scoring module HSQ, which maps the layers of the same depth of the teacher model and the student model one by one, and uses the output of each convolution layer to calculate the anomaly score s, s∈(0,1). The anomaly score s measures the attention consistency between the teacher model and the student model, and is used to guide the reallocation of attention to defect-prone areas;

[0071] S22. The bit width of the lth layer is determined according to the anomaly score. The calculation formula of the bit width of the lth layer is:

[0072]

[0073] Among them, b (l) is the bit width of the lth layer, 1≤l≤N; Φ(s) is the bit width obtained according to the anomaly score; Φ(·) is a piecewise function, the bit width is determined according to the hierarchical quantization score, and 2, 3, 4 and 8 bits are selected as mixed precision; c (l) is the number of channels of the output feature of the lth layer; w (l) is the width of the output feature of the lth layer; h (l) is the height of the output feature of the lth layer; is the output of the teacher model layer l; is the output of the lth layer of the student model; is the square of the F norm; is the sum of the squares of the F norms of all channels;

[0074] S23, the block-level reconstruction strategy is used to train the industrial anomaly detection model layer by layer and then quantize it. The quantization formula is:

[0075] r=S(qZ),

[0076]

[0077] Among them, r is the floating point number before quantization, and its value range is (r min ,r max );q is a quantized fixed-point number, and its value range is (q min ,q max ); S is the step length, Z is the zero point, Clip is a clipping function that limits the value to between 0 and 255;

[0078] Using the diagonal Fisher information matrix, the cross-layer dependencies within each block are measured and the second-order error of any block is converted to the output of the block. The diagonal of the pre-activation diagonal Fisher information matrix is ​​equal to the squared gradient of each element, and the weight target is:

[0079]

[0080] Where Δz (l) is the change of the output feature of the lth layer, that is, the difference between the quantized and the unquantized; is the expected value; is the Hessian matrix of the output feature of the lth layer; (·) T is the transpose operation; To minimize the quantization error; is the variable to be optimized; It is an expected value form of the second-order error, which measures the feature change Δz after quantization (l) the impact on the overall loss; Represents the FIM diagonal matrix, whose diagonal elements are the loss function L for each output feature The square of the first-order gradient of .

[0081] S3, fine-tune the student model and autoencoder;

[0082] The specific process of step S3 is as follows: During the fine-tuning training process, the teacher model, the student model and the autoencoder correspond to each other, generating three losses, and the calculation formula is:

[0083]

[0084] Among them, L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; (CWH) -1 is the inverse of the product of the number of channels, width, and height; T(I) c is the output of the teacher model; S(I) c is the output of the student model; A(I) c is the output of the autoencoder; is the square of the F norm; is the sum of the squares of the F norms of all channels;

[0085] The total loss is calculated as:

[0086] Loss = λ t-s L t-s +λ ae-s L ae-s +λ t-ae L t-ae ,

[0087] Among them, Loss is the total loss, L t-s is the loss of the teacher model and the student model; L ae-sis the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; λ t-s is the loss weight of the teacher model and the student model; ae-s is the loss weight of the autoencoder and student model; λ t-ae is the loss weight of the teacher model and the autoencoder;

[0088] S4, use the fine-tuned trained industrial anomaly detection model to perform industrial anomaly detection;

[0089] The specific process of step S4 is:

[0090] S41, load the fine-tuned teacher model, student model and autoencoder;

[0091] S42, input the image to be detected into the industrial anomaly detection model. In the inference process, there is no need to use the layer-by-layer quantization module; the outputs of the teacher model, the student model and the autoencoder are M respectively. t 、M s and M ae ;

[0092] S43, the output of the teacher model and the student model are squared to obtain the local anomaly map M local , the output of the autoencoder and the student model is squared to obtain the global anomaly map M global ;

[0093] S44, averaging the local anomaly map and the global anomaly map to calculate the combined anomaly map M combined , and use the maximum value of the combined anomaly map as the image-level anomaly score, 2D anomaly score map By M w,h =C -1 ∑ c D c,w,h Given, that is, an anomaly score is assigned to each feature vector by averaging across channels D, where is a set of real numbers of size W and H; M w,h is anomaly score mask of size w and h; C -1 is the reciprocal of the number of channels; ∑ c D c,w,h is the sum of the squared differences of the features on all channels.

[0094] Performance Test:

[0095] 1) Simulation conditions

[0096] The present invention is developed on the Ubuntu platform, and the developed deep learning framework is based on Pytorch. The main language used in the present invention is Python.

[0097] 2) Simulation content

[0098] The teacher model is pre-trained on the ImageNet dataset using the pre-trained WideResnet-101 network. Both the teacher model and the student model use a minimal version of the patch description network (PDN). The output feature dimension of the student model is twice that of the teacher model, and the autoencoder encodes and decodes the full image through a bottleneck of 64 potential dimensions. Hyperparameter λ t-s , t-ae , ae-s The training and fine-tuning stages are all frozen with the teacher model, and the Adam optimizer is used. The learning rate of the student model and the autoencoder is set to 0.00001. By default, the experiment is conducted on a 3090ti, with each GPU having 24GB RAM. The industrial anomaly detection model of the present invention is trained for 70k iterations, and the upper limit of the number of iterations for fine-tuning training is 60k. However, according to experiments, the model can often achieve the best performance without 60k iterations.

[0099] Table 1 shows the anomaly detection results of an industrial anomaly detection method (RRAD) based on recalibrated attention in the present invention on the MVTecAD dataset, LOCO dataset and VisA dataset respectively.

[0100] Table 1: Anomaly detection results of an industrial anomaly detection method based on recalibrated attention (RRAD) on the MVTecAD dataset, LOCO dataset and VisA dataset

[0101]

[0102] Table 2 shows the anomaly detection results of an industrial anomaly detection method based on recalibrated attention (RRAD) of the present invention and other advanced methods such as PatchCore, GCAD, SimpleNet and EfficientAD-S on the MVTec AD dataset, LOCO dataset and VisA dataset respectively.

[0103] Table 2: Anomaly detection results of an industrial anomaly detection method based on recalibrated attention (RRAD) of the present invention and other advanced methods such as PatchCore, GCAD, SimpleNet and EfficientAD-S on the MVTec AD dataset, LOCO dataset and VisA dataset respectively

[0104]

[0105] Table 3 shows the ablation study results of an industrial anomaly detection method (RRAD) based on recalibrated attention in the present invention. “Quant” indicates that the model uses post-training quantization, where weights and activations are quantized to 8-bit precision and then fine-tuned. “HQS” indicates the use of hierarchical mixed precision quantization.

[0106] Table 3: Ablation study results of an industrial anomaly detection method based on recalibrated attention (RRAD) of the present invention

[0107]

[0108] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. An industrial anomaly detection method based on recalibrated attention, characterized in that: The following steps are involved: S1. Build an industrial anomaly detection model and initialize the industrial anomaly detection model; the industrial anomaly detection model consists of a teacher model, a student model and an autoencoder; S2. Use the hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, assign corresponding quantization bit widths to each layer according to the anomaly recognition ability, and then train and quantize the industrial anomaly detection model layer by layer; S3, fine-tune the student model and autoencoder; S4. Use the fine-tuned trained industrial anomaly detection model to perform industrial anomaly detection.

2. The industrial anomaly detection method based on recalibrated attention according to claim 1, characterized in that: The initialization process of the industrial anomaly detection model in step S1 is: the model is trained on a training set containing only normal images, and only the weights of the student model and the autoencoder are updated during the training process; Before training, the teacher model is pre-trained on the ImageNet training set using the pre-trained WideResNet-101 network. The pre-training of the teacher model is achieved by minimizing the mean square error between the teacher model output and the pre-trained network output. The loss is calculated as: L pre =Mean(||E(I)-T(I)|| 2 ) Among them, L pre is the loss in the pre-training stage; Mean(·) is the averaging operation; I is an image from the ImageNet training set; E(I) is the normalized output after the WideResNet-101 network feature extractor extracts the features of the input image, that is, E(I) = (extracted features - feature mean) / feature standard deviation; T(I) is the output of the teacher network; ||·|| 2 is the absolute value square; Use the Patch Description Network (PDN) as the feature extraction network for the teacher model and the student model. The Patch Description Network (PDN) consists of only four fully convolutional layers. A standard convolutional autoencoder is used to learn logical constraints on training images and detect anomalies that violate the constraints, including strided convolutions in the encoder and bilinear upsampling in the decoder; compared to the student model based on the patch description network (PDN), the autoencoder encodes and decodes the full image through a bottleneck of 64 latent dimensions.

3. The industrial anomaly detection method based on recalibrated attention according to claim 1, characterized in that: The specific evaluation process of the hierarchical anomaly score in step S2 is: S21, the teacher model and the student model are both processed by the hierarchical anomaly scoring module HSQ, which maps the layers of the same depth of the teacher model and the student model one by one, and uses the output of each convolution layer to calculate the anomaly score s, s∈(0,1). The anomaly score s measures the attention consistency between the teacher model and the student model, and is used to guide the reallocation of attention to defect-prone areas; S22. The bit width of the lth layer is determined according to the anomaly score. The calculation formula of the bit width of the lth layer is: Among them, b (l) is the bit width of the lth layer, 1≤l≤N; Φ(s) is the bit width obtained according to the anomaly score; Φ(·) is a piecewise function, the bit width is determined according to the hierarchical quantization score, and 2, 3, 4 and 8 bits are selected as mixed precision; c (l) is the number of channels of the output feature of the lth layer; w (l) is the width of the output feature of the lth layer; h (l) is the height of the output feature of the lth layer; is the output of the teacher model layer l; is the output of the lth layer of the student model; is the square of the F norm; is the sum of the squares of the F norms of all channels; S23, the block-level reconstruction strategy is used to train the industrial anomaly detection model layer by layer and then quantize it. The quantization formula is: r=S(qZ), Among them, r is the floating point number before quantization, and its value range is (r min ,r max );q is a quantized fixed-point number, and its value range is (q min ,q max ); S is the step length, Z is the zero point, Clip is a clipping function that limits the value to between 0 and 255; Using the diagonal Fisher information matrix, the cross-layer dependencies within each block are measured and the second-order error of any block is converted to the output of the block. The diagonal of the pre-activation diagonal Fisher information matrix is ​​equal to the squared gradient of each element, and the weight target is: Where Δz (l) is the change of the output feature of the lth layer, that is, the difference between the quantized and the unquantized; is the expected value; is the Hessian matrix of the output feature of the lth layer; (·) T is the transpose operation; To minimize the quantization error; is the variable to be optimized; It is an expected value form of the second-order error, which measures the feature change Δz after quantization (l) the impact on the overall loss; Represents the FIM diagonal matrix, whose diagonal elements are the loss function L for each output feature The square of the first-order gradient of .

4. The industrial anomaly detection method based on recalibrated attention according to claim 1, characterized in that: The specific process of step S3 is as follows: During the fine-tuning training process, the teacher model, the student model and the autoencoder correspond to each other, generating three losses, and the calculation formula is: Among them, L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; (CWH) -1 is the inverse of the product of the number of channels, width, and height; T(I) c is the output of the teacher model; S(I) c is the output of the student model; A(I) c is the output of the autoencoder; is the square of the F norm; is the sum of the squares of the F norms of all channels; The total loss is calculated as: Loss=λ t-s L t-s +λ ae-s L ae-s +λ t-ae L t-ae , Among them, Loss is the total loss, L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the autoencoder and student model; L t-ae is the loss of the teacher model and the autoencoder; λ t-s is the loss weight of the teacher model and the student model; ae-s is the loss weight of the autoencoder and student model; λ t-ae are the loss weights for the teacher model and the autoencoder.

5. The industrial anomaly detection method based on recalibrated attention according to claim 1, characterized in that: The specific process of step S4 is: S41, load the fine-tuned teacher model, student model and autoencoder; S42, input the image to be detected into the industrial anomaly detection model. In the inference process, there is no need to use the layer-by-layer quantization module; the outputs of the teacher model, the student model and the autoencoder are M respectively. t 、M s and M ae ; S43, the output of the teacher model and the student model are squared to obtain the local anomaly map M local , the output of the autoencoder and the student model is squared to obtain the global anomaly map M global ; S44, averaging the local anomaly map and the global anomaly map to calculate the combined anomaly map M combined , and use the maximum value of the combined anomaly map as the image-level anomaly score, 2D anomaly score map By M w,h =C -1 ∑ c D c,w,h Given, that is, an anomaly score is assigned to each feature vector by averaging across channels D, where is a set of real numbers of size W and H; M w,h is anomaly score mask of size w and h; C -1 is the reciprocal of the number of channels; ∑ c D c,w,h is the sum of the squared differences of the features on all channels.

Citation Information

Patent Citations

  • Data enhancement method based on prior defect features and SSPCAB attention mechanism

    CN116912625A

  • Image classification heterogeneous hardware acceleration method based on FPGA and quantitative distillation

    CN117935025A

  • Detection method for structural anomaly and logic anomaly in image, and storage medium

    CN118014932A

  • Asymmetrically hierarchical networks with attentive interactions for interpretable review-based recommendation

    US20210065278A1

Cited By

  • Product defect detection method based on adaptive complementary channel and full-span enhancement

    CN120725981A