Search

CN-121120504-B - Few-sample anomaly detection method based on two-stage training

CN121120504BCN 121120504 BCN121120504 BCN 121120504BCN-121120504-B

Abstract

The invention discloses a few-sample anomaly detection method based on two-stage training, which relates to the technical field of few-sample anomaly detection and comprises a two-stage training network (TSTNet) based on metric learning, wherein geometric consistency loss is introduced in a pre-training stage so as to promote convergence of a normal sample and a geometric variant thereof in a feature space. In the measurement learning stage, an edge feature adaptive network is designed, so that fuzzy normal features can be clustered in a self-adaptive mode, and abnormal features can be effectively isolated. Numerous experiments on MVTecAD and VisA data sets have shown that this scheme is beyond the current level, and the present invention improves the performance on image level AUROC by 1.2% and 2.4% over MVTecAD and VisA, respectively, under a 2 sample experimental setup.

Inventors

  • MAN JUNFENG
  • WU XUEJUN
  • DENG ZHIPENG
  • YANG GEN
  • Xiao qianhui
  • MA JUNJIE
  • PENG XIA
  • LI LIN
  • PENG LIJUN
  • ZENG QINGSHUN

Assignees

  • 湖南第一师范学院
  • 湖南湘江鲲鹏信息科技有限责任公司

Dates

Publication Date
20260512
Application Date
20250812

Claims (9)

  1. 1. The few-sample abnormality detection method based on two-stage training is characterized by comprising the following steps of: S1, a pre-training stage, which comprises an online network and a target network; The online network includes a pre-training encoder Fully connected projection layer And a complete prediction header A neural network formed in sequence; the target network includes an encoder for momentum update And a projection layer A neural network formed in sequence; the online network and the target network are connected through a geometric consistency loss L GC , and the geometric consistency loss L GC is used for fine tuning the pre-training encoder; S2, a measurement learning stage comprises an edge characteristic adaptation network, wherein the edge characteristic adaptation network comprises a memory bank construction module, a dual-path characteristic construction module and an edge ternary loss; the memory bank construction module firstly utilizes a fine-tuned pre-training encoder to extract original patch-level features, and then adopts an intermediate layer encoder to construct a discrimination fine-grained memory bank; the dual-path feature construction module first generates enhanced samples through basic geometric transformation Then extracting multi-scale characteristics by using an intermediate layer encoder, and finally performing local neighborhood aggregation operation Constructing a positive example feature set At the same time, the Gaussian noise is directly added to the characteristic points of the enhanced sample To obtain abnormal feature points on feature level ; The edge ternary loss first calculates all feature points of the enhanced image All abnormal feature points To the feature points in the memory bank Nearest-neighbor Euclidean distance distribution, and then designing forward loss based on normal distribution assumption And negative loss The final dynamic ternary loss function is a weighted sum of positive and negative losses; s3, abnormality detection, namely obtaining corresponding patch-level feature points of the test image by directly passing through the fine-tuned pre-training encoder and the multi-layer perceptron And calculating Euclidean distance from each point to the nearest point in the memory bank, forming a pixel-level anomaly score map of the whole image by anomaly scores of all patch characteristic points, upsampling the anomaly score map by bilinear interpolation, and smoothing the result by Gaussian filtering.
  2. 2. The two-stage training-based few-sample anomaly detection method of claim 1, wherein the feature extraction of the pre-training stage comprises: s101, giving a training image Two random geometric transformations are applied to it, respectively denoted as And ; S102, the pre-trained encoder then extracts global feature embedding ; S103, passing through a projection layer with an activation function Embedding and mapping global features to low-dimensional space : S104, calculating final output by a prediction head of the network: Wherein, the For the full connection layer, reLU is the activation function.
  3. 3. The two-stage training based few-sample anomaly detection method of claim 2, wherein to prevent model collapse, the target network parameter θ is updated by momentum, and the given momentum parameters τ, θ are updated as follows: Wherein, the For updated model parameters.
  4. 4. A two-stage training based few-sample anomaly detection method according to claim 3, wherein the geometric consistency loss L GC between the two random geometrically transformed images is: 。
  5. 5. The two-stage training based few-sample anomaly detection method of claim 1, wherein the memory bank construction module extracting patch features comprises the steps of: s201, dividing an image into local areas of S multiplied by S; S202, aggregation through local area Increasing receptive field to generate high spatial discrimination characteristic representation ; S203, finally, the memory bank M reduces the number of characteristic points in the memory bank through a core set algorithm: 。
  6. 6. The two-stage training-based few-sample anomaly detection method of claim 1, wherein for each enhancement feature point The distance between the memory bank and the nearest neighbor anchor point is defined as: for each abnormal feature point The distance from its nearest anchor point is: 。
  7. 7. The two-stage training-based few-sample anomaly detection method according to claim 1, wherein the mean value of nearest neighbor distances of the normal distribution feature points And standard deviation of Calculated by the following formula: Wherein, the And representing the nearest neighbor distance of the ith feature point, wherein N is the total feature point number.
  8. 8. The two-stage training-based few-sample anomaly detection method of claim 7, wherein forward loss aims to pull the distance between key normal feature points and memory bank anchor points only when the normal feature points are Satisfy the following requirements When the loss function is counted : The negative loss aims to push away the distance between the abnormal characteristic point and the memory bank anchor point only when the abnormal characteristic point Satisfy the following requirements When the loss function is counted : Finally, the dynamic ternary loss function is a weighted sum of forward and recurrence losses: And (3) with Are all the super-parameters of the method, To balance the relative importance of the two types of losses, and m to control the distance between positive and negative samples.
  9. 9. The two-stage training-based few-sample anomaly detection method according to claim 1, wherein the anomaly score of the test image is defined as the maximum value of all feature point distances, and the expression is: 。

Description

Few-sample anomaly detection method based on two-stage training Technical Field The invention relates to the technical field of few-sample anomaly detection, in particular to a few-sample anomaly detection method based on two-stage training. Background Unsupervised Anomaly Detection (UAD) has achieved significant success in industrial quality detection. By learning from only non-defective samples, this approach effectively solves the problem of data imbalance and improves generalization ability for unseen anomaly types. However, obtaining large-scale normal samples in an industrial environment still faces challenges of obtaining limitations or information confidentiality issues. As an effective solution, the Few Sample Anomaly Detection (FSAD) can achieve accurate defect detection and localization by using only a small number of normal samples (e.g., 1 to 8 samples). FSAD exhibits significant advantages in training performance over UAD techniques. The memory bank-based anomaly detection method is an effective UAD method. As shown in fig. 1 (a), these methods first build a memory bank containing a wide range of normal features. By measuring the distance between the query feature and the nearest neighbor in the memory bank, these methods calculate anomaly scores that enable high-precision image-level anomaly detection and pixel-level localization. However, as shown in fig. 1 (b), in a few-sample scene, the feature space becomes sparse due to the scarcity of the normal samples. This phenomenon aggravates the distance between samples, thereby generating false negatives by misclassifying normal instances as abnormal instances. In addition, it obscures the decision boundary between normal and abnormal samples. Feature sparsity is therefore a key issue in FSAD implementation. In order to solve the feature sparsity problem, literature 【Y. Jiang, Y. Cao, and W. Shen, "Prototypical learning guided context- aware segmentation network for few-shot anomaly detection," IEEE Trans. Neural Networks Learn. Syst., pp. 1–11, Oct. 2024.】 proposes to reduce the distance between the normal feature and the average center by means of the hypersphere concept, thereby constructing a more compact normal feature space, and then to detect anomalies by means of the constructed adaptive feature and average center through the FPN-like segmentation network. Document 【A. Luo, G. Wen, Y. Cheng, S. Mei, H. Dong, and X. Liu, "Dmmgnet:A discrimination mapping and memory bank mean guidance-based network for high-performance few, sample industrial anomaly detection, "Neurocomputing, vol. 610, p. 128622, dec. 2024," proposes a mean-based strategy. In the training stage, the global feature mean center guides feature optimization. In the reasoning stage, abnormality detection is performed based on the mahalanobis distance between the test image and the center of the mean. These approaches solve the feature sparsity problem by compressing the overall normal feature space. However, simple global feature optimization strategies ignore differences in the importance of different features to anomaly detection, resulting in insufficient sensitivity of the model to edge normal features and to anomaly features near decision boundaries. Based on this, a few-sample anomaly detection method based on two-stage training is proposed. Disclosure of Invention The invention aims to provide a few-sample anomaly detection method based on two-stage training, so as to solve the problem that a simple global feature optimization strategy ignores the importance difference of different features on anomaly detection, so that the sensitivity of a model to normal edge features and anomaly features near decision boundaries is insufficient. In order to achieve the above purpose, the present invention provides the following technical solutions: the few-sample anomaly detection method based on two-stage training comprises the following steps: S1, a pre-training stage, which comprises an online network and a target network; The online network includes a pre-training encoder Fully connected projection layerAnd a complete prediction headerA neural network formed in sequence; the target network includes an encoder for momentum update And a projection layerA neural network formed in sequence; the online network and the target network are connected through a geometric consistency loss L GC, and the geometric consistency loss L GC is used for fine tuning the pre-training encoder; S2, a measurement learning stage comprises an edge characteristic adaptation network, wherein the edge characteristic adaptation network comprises a memory bank construction module, a dual-path characteristic construction module and an edge ternary loss; the memory bank construction module firstly utilizes a fine-tuned pre-training encoder Extracting original patch level features and then employing an intermediate layer encoderConstructing a discriminant fine-grained memory bank; the dual-path feature constructio