An industrial anomaly detection method based on re-calibrated attention

By constructing a teacher model, a student model, and an autoencoder, combined with a hierarchical anomaly scoring module (HSQ) and fine-tuning training, and dynamically allocating the quantization bit width, the problem of attention allocation bias in unsupervised industrial anomaly detection is solved, improving detection accuracy and efficiency, and achieving efficient industrial anomaly detection.

CN119762852BActive Publication Date: 2025-11-07XIAMEN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing unsupervised industrial anomaly detection methods are easily affected by the inherent bias of normal samples, leading to overfitting of the model to normal samples, ignoring potential defects in invariant regions, and having poor generalization ability, making it difficult to meet actual needs.

Method used

We employ a recalibrated attention-based approach, which involves constructing a teacher model, a student model, and an autoencoder. By combining the hierarchical anomaly scoring module (HSQ) with fine-tuning training, we dynamically allocate quantization bit width and recalibrate attention to optimize the model's attention allocation.

Benefits of technology

It effectively breaks the inherent bias of attention allocation, improves the model's ability to detect subtle anomalies in invariant regions, enhances detection accuracy and efficiency, significantly reduces the error rate, and achieves an average image-level AU-ROC of 98.9 and a detection speed of 113 FPS.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119762852B_ABST
    Figure CN119762852B_ABST
Patent Text Reader

Abstract

The application discloses an industrial anomaly detection method based on recalibration attention, comprising 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 auto-encoder; S2, adopting a hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, allocating corresponding quantization bit widths to each layer according to the anomaly recognition ability, and then quantizing the industrial anomaly detection model layer by layer after training; S3, fine-tuning the student model and the auto-encoder; S4, adopting the fine-tuned industrial anomaly detection model to perform industrial anomaly detection; the method systematically decomposes and recalibrates the attention graph, improves the generalization ability and anomaly detection precision of the model, and has significant practical value and application prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of anomaly detection technology, and more specifically to an industrial anomaly detection method based on recalibrated attention. Background Technology

[0002] Deep learning-based visual inspection has achieved significant results with the help of supervised learning. However, in real-world industrial scenarios, the scarcity of defect samples, the cost of annotation, and the lack of prior knowledge about defects can render supervised methods ineffective. In recent years, unsupervised anomaly detection (IAD) algorithms have been increasingly widely used in industrial inspection tasks. "Unsupervised" means that the training phase only includes normal images and no defect samples. IAD methods in the unsupervised paradigm avoid the following problems associated with supervised methods: 1. High costs associated with sufficient annotation; 2. Difficulty in collecting anomalous or defective samples; 3. Inability to predict defects that have not yet occurred; 4. Annotation noise unintentionally introduced during data labeling.

[0003] Based on these advantages, unsupervised anomaly detection methods have become the mainstream strategy for current IAD tasks. However, all unsupervised IAD methods face a common challenge: since only normal samples are used during training, the model is more susceptible to the inherent biases in normal samples, leading to overfitting. This causes the model to focus on the changing regions of normal samples while ignoring potential defects in invariant regions, resulting in incorrect judgments when anomalies appear in unchanged parts.

[0004] like Figure 2 As shown, this challenge is visualized using anomaly heatmaps from the MVTecAD and MVTec LOCO datasets. In each group, from left to right, are the normal sample of the corresponding category, the average anomaly heatmap of the normal sample, and the average normal heatmap of the anomaly sample. Brighter areas in the heatmap indicate a higher probability of attention. As shown by the white boxes in the second column, it is clear that the model is misled by the inherent bias of normal samples. In other words, attention maps obtained through unsupervised training are more likely to focus on changing areas in normal samples while ignoring unchanged areas. An intuitive idea is to abandon the attention mechanism altogether. However, completely ignoring attention maps is not a feasible solution, as they play a crucial role in anomaly detection. Therefore, how to make the model allocate attention more reasonably becomes a key issue.

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

[0006] Model quantization is a technique that reduces the computational resource requirement and memory footprint of a model by reducing the precision of its parameters (e.g., converting 32-bit floating point numbers to 8-bit integers). Existing neural network quantization algorithms can be divided into two categories according to their training strategies: post-training quantization (PTQ) and quantization-aware training (QAT). PTQ refers to quantizing a model after training without any fine-tuning or retraining, allowing for fast quantization at the cost of reduced precision. In contrast, QAT employs an online quantization strategy. This approach utilizes the entire training dataset during quantization. Therefore, it has higher precision but is limited in efficiency. Recently, several studies have explored integrating quantization techniques into anomaly detection tasks. Even post-training quantization is applied to device anomaly detection, achieving a balance between computational efficiency and detection accuracy. Recent quantization methods further expand the boundaries by employing mixed precision techniques, which assign different bit widths to different layers. However, it is clarified that model quantization is the method, not the goal, of this paper. During quantization, the model will be more inclined to learn and extract the most important information to complete the task due to the reduction in parameter precision. This limitation will force the model to actively focus its attention on the target subject during training, ignoring irrelevant factors such as background noise or irrelevant features. Fine-tuning is a transfer learning technique that involves further training on a specific dataset to adapt to the needs of a new task or new data distribution. During fine-tuning, attention is recalibrated to achieve the purpose of redistributing attention. In Figure 3 In (a), the anomaly heatmaps before and after model quantization are visualized. It can be observed that the model's attention is more focused 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, methods based on feature embedding, methods based on reconstruction, and methods based on anomaly synthesis. Methods based on feature embedding achieve more advanced performance, which can be divided into: teacher-student model, normalized flow, memory bank, and one-class classification. The most typical methods are memory bank and teacher-student model. The memory bank method embeds normal features into a compressed space. Anomaly 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 does not see abnormal images during training, the student usually cannot predict the teacher's output on these images, thereby achieving anomaly detection. Uninformed Student proposes a new framework called teacher-student anomaly detection, RD proposes reverse distillation, and the student decoder learns to recover features from the teacher's compact embedding. The GCCB method adopts a double student knowledge distillation framework, which enhances the detection ability of structural and logical anomalies. However, feature embedding-based methods rely on the size of the memory bank or the ability of the teacher network, which may lead to excessive memory occupation and slow inference time, or limit the generalization ability of the model.

[0008] Methods based on reconstruction, from autoencoders to generative adversarial networks to Transformers and diffusion models. Among them, the method of autoencoder relies on accurate reconstruction of normal images and inaccurate reconstruction of abnormal images, and compares 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 ambiguous and inaccurate reconstructions, which lead to an increase in false positives and are generally less performant than the aforementioned local methods.

[0009] Therefore, the 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, which are difficult to meet the actual use requirements. SUMMARY

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

[0011] To achieve the above purpose, the present application adopts the following technical scheme:

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

[0013] S1, an industrial anomaly detection model is constructed, and the industrial anomaly detection model is initialized; the industrial anomaly detection model is composed of a teacher model, a student model and an autoencoder;

[0014] S2, using a hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, and assigning a corresponding quantization bit width to each layer according to the anomaly recognition ability, and then training and quantizing the industrial anomaly detection model layer by layer;

[0015] S3, fine-tuning training of the student model and the autoencoder;

[0016] S4, using the fine-tuned industrial anomaly detection model to perform industrial anomaly detection.

[0017] Preferably, the initialization process of the industrial anomaly detection model in step S1 is that 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 pre-trained WideResNet-101 network is used to pre-train the teacher model on the ImageNet training set, and the pre-training of the teacher model is realized by minimizing the mean square error between the output of the teacher model and the output of the pre-trained network, and the calculation formula of the loss is:

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

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

[0021] The patch description network PDN is used as the feature extraction network of the teacher model and the student model, and the patch description network PDN only consists of four fully convolutional convolutional layers.

[0022] A standard convolutional autoencoder is used to learn the logical constraints of the training images and detect anomalies that violate the constraints, including cross-step convolution 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 complete image through a 64-dimensional bottleneck.

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

[0024] ​S21, the teacher model and the student model are processed by a hierarchical anomaly score module HSQ, the teacher model and the student model are one-to-one corresponding to the same depth layer, and an anomaly score s is calculated after each layer of convolution, s belongs to (0, 1), the anomaly score s measures the attention consistency between the teacher model and the student model, and is used to guide the attention to be redistributed to the defect-prone area;

[0025] S22, the bit width of the first layer is determined according to the anomaly score, and the calculation formula of the bit width of the first layer is:

[0026]

[0027] Wherein, b (l) is the bit width of the first layer, 1≤l≤N; Φ(s) is the bit width obtained according to the anomaly score; Φ(·) is a piecewise function, which determines the bit width according to the hierarchical quantization score, and selects 2, 3, 4 and 8 bits as the mixed precision; c (l) is the number of channels of the output feature of the first layer; w (l) is the width of the output feature of the first layer; h (l) is the height of the output feature of the first layer; is the output of the first layer of the teacher model; is the output of the first 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 industrial anomaly detection model is trained and quantized layer by layer by using a block-level reconstruction strategy, and the quantization formula is:

[0029] r=S(q-Z),

[0030]

[0031] Wherein, r is a floating point number before quantization, and its value range is (r min ,r max ); q is a fixed point number after quantization, and its value range is (q min ,q max ); S is a step size, Z is a zero point, clip is a clipping function, which limits the value to between 0 and 255;

[0032] The diagonal Fisher information matrix is used to measure the cross-layer dependence relationship within each block, and the second-order error of any block is converted into the output of the block, and the diagonal line of the pre-activation diagonal Fisher information matrix is equal to the square gradient of each element, and the weight target is:

[0033]

[0034] where Δz (l) is the change of the output feature of the l-th layer, i.e., the difference between after quantization and before quantization; is the expected value; is the Hessian matrix of the output feature of the l-th layer;(·) T is the transposition operation; is to minimize the quantization error; is the optimized variable; is a form of expected value of the second-order error, which measures the change of the feature Δz (l) after quantization on the whole loss; denotes the FIM diagonal matrix, whose diagonal elements are the square of the first-order gradient of the loss function L with respect to each output feature .

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

[0036]

[0037]

[0038] where L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the auto-encoder and the student model; L t-ae is the loss of the teacher model and the auto-encoder;(CWH) -1 is the reciprocal 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 auto-encoder; is the square of the F-norm; is the sum of the squares of the F-norms of all channels;

[0039] The calculation formula of the total loss is:

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

[0041] where Loss is the total loss, L t-s is the loss of the teacher model and the student model; L ae-sLoss for the autoencoder and the student model; L t-ae Loss for the teacher model and the autoencoder; l t-s Loss weight for the teacher model and the student model; l ae-s Loss weight for the autoencoder and the student model; l t-ae Loss weight 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, and in the inference process, a layer-by-layer quantization module is not required; the outputs of the teacher model, the student model and the autoencoder are M t , M s and M ae respectively;

[0045] S43, square difference is performed on the outputs of the teacher model and the student model to obtain a local anomaly map M local , and square difference is performed on the outputs of the autoencoder and the student model to obtain a global anomaly map M global ;

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

[0047] After the above technical solution is adopted, the present application has the following beneficial effects:

[0048] 1. The present application breaks the inherent bias of attention allocation in unsupervised IAD and guides the model to better detect subtle anomalies in invariant regions.

[0049] 2. The application proposes an industrial anomaly detection method based on re-calibration 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 application proposes a hierarchical anomaly scoring module HQS, which dynamically allocates bit width according to the anomaly detection ability of each layer, optimizes the alignment between quantization and attention, and improves the efficiency and accuracy of IAD.

[0051] 4. The application uses NVIDIA Geforce GTX 3090Ti to evaluate the industrial anomaly detection method based on re-calibration attention proposed by the application on 32 data sets from three IAD sets, especially on the MVTecAD data set, which achieves an average image-level AU-ROC of 98.9, a speed of 113FPS, and a half or more reduction in error rate after quantization, with significant practical value and application prospect. BRIEF DESCRIPTION OF DRAWINGS

[0052] Figure 1 The flowchart of the application is shown in the figure;

[0053] Figure 2 The visualization diagram of industrial products, normal samples and abnormal samples is shown in the figure;

[0054] Figure 3 The attention map and layer-by-layer attention output map of the model at different stages are shown in the figure;

[0055] Figure 4 The flowchart of the application is shown in the figure;

[0056] Figure 5 The structure diagram of the teacher model and student model of the application for calculating anomaly scores is shown in the figure;

[0057] Figure 6 The anomaly detection structure diagram of the industrial anomaly detection model of the application is shown in the figure;

[0058] Figure 7 The qualitative result diagram of the application on MVTec-AD and MVTec-AD LOCO data sets is shown in the figure. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical scheme and advantages of the application more clear and understandable, the application will be further described in detail below with examples. It should be understood that the specific examples described herein are only used to explain the application, and are not used to limit the application.

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

[0061] S1, construct an industrial anomaly detection model, and initialize the industrial anomaly detection model; the industrial anomaly detection model is composed of a teacher model, a student model and an auto-encoder;

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

[0063] Before training, the pre-trained WideResNet-101 network is used to pre-train the teacher model on the ImageNet training set, and the pre-training of the teacher model is realized by minimizing the mean square error between the output of the teacher model and the output of the pre-trained network. The calculation formula of the loss is:

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

[0065] Where L pre is the loss in the pre-training phase; Mean(·) is the average operation; I is an image from the ImageNet training set; E(I) is the normalized output of the input image after the feature extraction of the WideResNet-101 network feature extractor, i.e. E(I) = (extracted features - feature mean) / feature standard deviation; T(I) is the output of the teacher network; ||·|| is the absolute value square; 2

[0066] The patch description network PDN is used as the feature extraction network of the teacher model and the student model, and the patch description network PDN is only composed of four fully convolutional convolutional layers;

[0067] A standard convolutional auto-encoder is used to learn the logical constraints of the training images and detect anomalies that violate the constraints, including cross-step convolution in the encoder and bilinear upsampling in the decoder; compared with the student model based on the patch description network PDN, the auto-encoder encodes and decodes the complete image through a 64-dimensional bottleneck;

[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 width to each layer according to the anomaly recognition ability, and then quantize the industrial anomaly detection model layer by layer after training;

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

[0070] ​S21, the teacher model and the student model are processed by a hierarchical anomaly score module HSQ, the teacher model and the student model are one-to-one corresponding to the same depth layer, and an anomaly score s is calculated after each layer of convolution, s belongs to (0, 1), the anomaly score s measures the attention consistency between the teacher model and the student model, and is used to guide the attention to be redistributed to the defect-prone area;

[0071] S22, the bit width of the first layer is determined according to the anomaly score, and the calculation formula of the bit width of the first layer is:

[0072]

[0073] wherein b (l) is the bit width of the first 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 the mixed precision; c (l) is the number of channels of the output feature of the first layer; w (l) is the width of the output feature of the first layer; h (l) is the height of the output feature of the first layer; is the output of the first layer of the teacher model; is the output of the first 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 industrial anomaly detection model is trained and quantized layer by layer by using a block-level reconstruction strategy, and the quantization formula is:

[0075] r=S(q-Z),

[0076]

[0077] wherein r is a floating point number before quantization, the value range of r is (r min ,r max ); q is a fixed point number after quantization, the value range of q is (q min ,q max ); S is a step size, Z is a zero point, clip is a clipping function, limiting the value to between 0 and 255;

[0078] The diagonal Fisher information matrix is used to measure the cross-layer dependence relationship within each block, and the second-order error of any block is converted into the output of the block, and the diagonal line of the pre-activation diagonal Fisher information matrix is equal to the square gradient of each element, and the weight target is:

[0079]

[0080] where Δz (l) is the change of the output feature of the l-th layer, i.e., the difference between after quantization and before quantization; is the expected value; is the Hessian matrix of the output feature of the l-th layer;(·) T is the transpose operation; is to minimize the quantization error; is the optimized variable; is a form of expected value of the second-order error, which measures the change of the feature Δz (l) after quantization on the whole loss; denotes the FIM diagonal matrix, whose diagonal elements are the square of the first-order gradient of each output feature with respect to the loss function L.

[0081] S3, fine-tuning training of the student model and the autoencoder;

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

[0083]

[0084] where L t-s is the loss of the teacher model and the student model; L ae-s is the loss of the autoencoder and the student model; L t-ae is the loss of the teacher model and the autoencoder;(CWH) -1 is the reciprocal 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 calculation formula of the total loss is:

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

[0087] where Loss is the total loss, L t-s is the loss of the teacher model and the student model; L ae-sLoss for the autoencoder and the student model; L t-ae Loss for the teacher model and the autoencoder; l t-s Loss weight for the teacher model and the student model; l ae-s Loss weight for the autoencoder and the student model; l t-ae Loss weight for the teacher model and the autoencoder; l

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

[0089] The specific process of step S4 is as follows:

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

[0091] S42, inputting the image to be detected into the industrial anomaly detection model, and in the inference process, the layer-by-layer quantization module is not required; the outputs of the teacher model, student model and autoencoder are M t , M s and M ae respectively;

[0092] S43, performing square difference on the outputs of the teacher model and student model to obtain a local anomaly map M local , and performing square difference on the outputs of the autoencoder and student model to obtain a global anomaly map M global ;

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

[0094] Performance test:

[0095] 1) Simulation conditions

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

[0097] 2) Simulation content

[0098] The teacher model was pre-trained on the ImageNet dataset using a pre-trained WideResnet-101 network, both the teacher and student model used the minimal version of the patch description network (PDN), the output feature dimension of the student model was twice that of the teacher model, and the auto-encoder encoded and decoded the complete image through a 64-dimensional bottleneck. The hyperparameters λ t-s , λ t-ae , λ ae-s were set to 1. Both the training and fine-tuning stages froze the teacher model, used the Adam optimizer, and set the learning rate of the student model and the auto-encoder to 0.00001. By default, the experiment was performed on a 3090ti, each GPU had 24GB of RAM. The training of the industrial anomaly detection model of the present application was performed for 70k iterations, and the upper limit of the number of iterations for fine-tuning training was 60k, but according to the experiment, often the model can achieve the best performance without 60k iterations.

[0099] Table 1 is the anomaly detection result of the industrial anomaly detection method based on recalibration attention (RRAD) of the present application on the MVTec AD dataset, LOCO dataset and VisA dataset respectively.

[0100] Table 1: The anomaly detection result of the industrial anomaly detection method based on recalibration attention (RRAD) of the present application on the MVTec AD dataset, LOCO dataset and VisA dataset respectively

[0101]

[0102] Table 2 is the anomaly detection result of the industrial anomaly detection method based on recalibration attention (RRAD) of the present application 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: The anomaly detection result of the industrial anomaly detection method based on recalibration attention (RRAD) of the present application 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 is the ablation study results of a re-calibration attention-based industrial anomaly detection method (RRAD) of the present application. Among them, "Quant" means that the model uses post-training quantization, in which the weights and activations are quantized to 8-bit precision, and then fine-tuned. "HQS" means using hierarchical mixed-precision quantization.

[0106] Table 3: Ablation study results of a re-calibration attention-based industrial anomaly detection method (RRAD) of the present application

[0107]

[0108] The above description is only a preferred specific embodiment of the present application, but the protection scope of the present application is not limited to this. Any changes or replacements within the technical scope disclosed by the present application can be easily thought of by those skilled in the art, and should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. An industrial anomaly detection method based on recalibrated attention, characterized in that, Comprising 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 auto-encoder; S2, using a hierarchical anomaly scoring module HSQ to evaluate the anomaly judgment ability of each layer of the network in the industrial anomaly detection model, assigning corresponding quantization bit widths to each layer according to the anomaly recognition ability, and then training and quantizing the industrial anomaly detection model layer by layer; The specific evaluation process of the hierarchical anomaly scoring in step S2 is: S21, the teacher model and the student model are processed by the hierarchical anomaly scoring module HSQ, the layers of the same depth of the teacher model and the student model are one-to-one corresponding, and the anomaly score s is calculated after each layer of convolution, 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 attention to be redistributed to the defect-prone area; S22, the bit width of the lth layer is determined according to the anomaly score, and the calculation formula of the bit width of the lth layer is: wherein b (l) is the bit width of the l-th layer, 1≤l≤N; Φ(s) is the bit width obtained according to the abnormal score; Φ(·) is a piecewise function, which determines the bit width according to the hierarchical quantization score, and selects 2, 3, 4 and 8 bits as the hybrid precision; c (l) is the number of channels of the output feature of the l-th layer; w (l) is the width of the output feature of the l-th layer; h (l) is the height of the output feature of the l-th layer; is the output of the l-th layer of the teacher model; is the output of the l-th 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, using a block-level reconstruction strategy to train and quantize the industrial anomaly detection model layer by layer, and the quantization formula is: r=S(q-Z), wherein r is a floating-point number before quantization, whose value range is (r min ,r max ); q is a fixed-point number after quantization, whose value range is (q min ,q max ); S is a step size, Z is a zero point, clip is a clipping function, limiting the value between 0 and 255. Using a diagonal Fisher information matrix to measure the cross-layer dependency within each block, and converting the second-order error of any block into the output of the block, the diagonal line of the pre-activation diagonal Fisher information matrix is equal to the square gradient of each element, and the weight target is: where Δz (l) is the change of the output feature of the l-th layer, i.e., the difference between after and before quantization; is the expected value; is the Hessian matrix of the l-th layer output feature;(·) T is the transpose operation; is to minimize the quantization error; is the optimized variable; is a form of expected value of the second-order error, which measures the change of the feature Δz (l) after quantization; represents the FIM diagonal matrix, whose diagonal elements are the square of the first-order gradient of the loss function L with respect to each output feature ; S3, fine-tuning training of the student model and the auto-encoder; S4, using the industrial anomaly detection model after fine-tuning training for industrial anomaly detection.

2. The industrial anomaly detection method based on recalibrated attention of claim 1, wherein, The initialization process of the industrial anomaly detection model in step S1 is that the model is trained on a training set containing only normal images, and only the weights of the student model and the auto-encoder are updated during the training process; Before training, the pre-trained WideResNet-101 network is used to pre-train the teacher model on the ImageNet training set, and the pre-training of the teacher model is realized by minimizing the mean square error between the output of the teacher model and the output of the pre-trained network, and the calculation formula of the loss is: L pre = Mean(||E(I) - T(I) || 2 ) where L pre is the loss of the pre-training stage; Mean(·) is the mean operation; I is an image from the ImageNet training set; E(I) is the normalized output of the input image after the WideResNet-101 network feature extractor extracts the features, i.e., E(I) = (extracted features - feature mean) / feature standard deviation; T(I) is the output of the teacher network; ||·||2 2 is the absolute value square; Using a patch description network PDN as the feature extraction network of the teacher model and the student model, the patch description network PDN is only composed of four fully convolutional convolutional layers; A standard convolutional auto-encoder is used to learn the logical constraints of the training image and detect the anomalies of the illegal constraints, including the cross-step convolution in the encoder and the bilinear upsampling in the decoder; compared with the student model based on the patch description network PDN, the auto-encoder encodes and decodes the complete image through a 64-dimensional bottleneck.

3. The industrial anomaly detection method based on recalibrated attention of claim 1, wherein, The specific process of step S3 is that in the fine-tuning training process, the teacher model, the student model and the auto-encoder correspond to each other, generating three losses, and the calculation formula is: where L t-s is the loss for the teacher model and the student model; L ae-s is the loss for the autoencoder and the student model; L t-ae is the loss for 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 for all channels; The calculation formula of the total loss is: Loss = λ t-s L t-s + λ ae-s L ae-s + λ t-ae L t-ae , where Loss is the total loss, L t-s is the loss for the teacher model and the student model; L ae-s is the loss for the autoencoder and the student model; L t-ae is the loss for the teacher model and the autoencoder; λ t-s is the loss weight for the teacher model and the student model; λ ae-s is the loss weight for the autoencoder and the student model; λ t-ae is the loss weight for the teacher model and the autoencoder.

4. The industrial anomaly detection method based on recalibrated attention of claim 1, wherein, The specific process of step S4 is: S41, loading the fine-tuned teacher model, student model and auto-encoder; S42, input the image to be detected into the industrial anomaly detection model, and in the inference process, the layer-by-layer quantization module is not required; the outputs of the teacher model, the student model, and the autoencoder are M t , M s , and M ae , respectively. S43, the outputs of the teacher model and the student model are squared to obtain a local anomaly map M local , the outputs of the autoencoder and the student model are squared to obtain a global anomaly map M global ; S44, average the local anomaly map and the global anomaly map to compute a 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 is given, i.e. by D an anomaly score is assigned to each feature vector by averaging across channels, where, is a real number set of size W and H; M w,h is an anomaly score mask of size w and h; C -1 is the inverse of the number of channels; ∑ c D c,w,h is the sum of feature squared differences over all channels.

Citation Information

Patent Citations

  • 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