A unified image anomaly detection method based on pseudo-anomalies and contrastive learning

By using pseudo-anomaly and contrastive learning methods, pseudo-anomaly images are generated and combined with multi-scale feature extraction and loss function optimization. This solves the feature confusion and identity mapping problems of single-class models in multi-class detection, and improves the accuracy and robustness of industrial parts detection.

CN122367927APending Publication Date: 2026-07-10SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610463302.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-09
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing single-class unsupervised image anomaly detection models suffer from feature confusion and identity mapping problems in multi-class scenarios, leading to performance degradation and increased false detection rate, and failing to effectively detect various types of defects in industrial parts.

Method used

We employ a pseudo-anomaly and contrastive learning approach. By generating pseudo-anomaly images and combining them with normal images, we utilize a twin data stream strategy and multi-scale feature extraction. We combine spatial contrast loss, mask-guided anomaly boundary loss, and global class-aware contrast loss to optimize a unified image anomaly detection network.

Benefits of technology

It improves the precision of normal feature reconstruction, breaks through the bottleneck of missed detection in identity mapping, solves feature confusion in multi-class fusion scenarios, and improves the sensitivity and detection accuracy of unknown anomalies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122367927A_ABST
    Figure CN122367927A_ABST
Patent Text Reader

Abstract

This invention discloses a unified image anomaly detection method based on pseudo-anomalies and contrastive learning. The method constructs a dual-teacher model containing teacher and student networks with identical structures. During training, a twin data flow strategy is employed: on the one hand, the original normal image data flow is preserved; on the other hand, multi-scale simplex noise and external textures are fused to generate pseudo-anomaly images and pixel-level masks, forming a pseudo-anomaly data flow. The network is segmented at the deep feature output end according to the data flow direction, calculating the spatial contrast loss to ensure the fidelity of normal feature reconstruction, the anomaly boundary loss guided by the mask to push away anomalous features, and the global class-aware contrast loss to separate multi-class semantics. This invention overcomes the identity mapping bottleneck of traditional unsupervised networks in multi-class unified scenarios, solves the feature confusion problem, and achieves high-precision multi-class unified anomaly detection without class priors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of computer vision and industrial defect detection technology, and in particular to a unified image anomaly detection method based on pseudo-anomalies and contrastive learning. Background Technology

[0002] Most current mainstream unsupervised image anomaly detection models follow a one-to-one single-class training paradigm. While these models excel at single-class detection tasks, in real-world industrial edge computing deployments, production lines often need to detect multiple different types of parts simultaneously. Traditional single-class models require independent training and network loading for each class, resulting in significant computational and storage overhead. Furthermore, when existing single-class unsupervised models are directly applied to unified anomaly detection (one-to-many) tasks involving multiple classes, they often suffer severe performance degradation, primarily due to the following two reasons: 1) Lack of negative sample priors leads to model degradation. Unsupervised knowledge distillation anomaly detection methods rely solely on normal samples for optimization. The model has never encountered any anomalous patterns during training and lacks explicit anomaly decision boundaries. In multi-class merging scenarios, because the model needs to encompass normal features from multiple categories, the network's strong fitting ability often leads to its degradation into an implicit identity mapping during optimization. When faced with unknown real-world anomalous images, the anomalous features reconstructed by the student network easily align with the teacher network, causing genuine defective regions to be classified as normal, resulting in serious false negatives.

[0003] 2) Multi-class semantic interference leads to category feature confusion. In unified detection scenarios, input data typically covers multiple categories with significant differences in morphology and texture. Due to the lack of explicit category discrimination constraints in unsupervised methods, deep features of different categories are prone to entanglement and aliasing in the latent feature space. This blurring of feature boundaries makes the model susceptible to interference from features of other categories when reconstructing features of a certain category, resulting in severe semantic confusion and an increased false detection rate. Summary of the Invention

[0004] This invention provides a unified image anomaly detection method based on pseudo-anomalies and contrastive learning, aiming to solve the problems of feature confusion and identity mapping degradation in existing single-class anomaly detection models in multi-class mixed scenarios, and improve the detection performance in multi-class mixed scenarios.

[0005] This invention provides a unified image anomaly detection method based on pseudo-anomalies and contrastive learning, comprising the following steps: A dataset of normal images of multiple mixed types is obtained, and a unified image anomaly detection network is constructed. The network includes a teacher network and a student network with the same structure. During the training phase, a twin data stream strategy is employed. For each batch of input normal images, the original normal images are retained to form the normal image data stream. Simultaneously, by generating multi-scale simplex noise and fusing it with external textures, pseudo-abnormal images and corresponding pixel-level binary masks are generated for the normal images. This constitutes a pseudo-anomaly image data stream; The normal image data stream and the pseudo-abnormal image data stream are concatenated and synchronously input into the teacher network and the student network for multi-scale feature extraction and reconstruction. At the feature output end, feature segmentation is performed according to the data flow direction, and spatial contrast loss, mask-guided anomaly boundary loss, and global class perception contrast loss are calculated respectively. The unified image anomaly detection network is then jointly optimized by combining the basic reconstruction loss. During the inference phase, the image to be detected is input into the trained unified image anomaly detection network. Anomaly score map is generated by calculating the similarity between the output features of the teacher network and the student network, thus completing the anomaly localization.

[0006] Optionally, the specific process of generating a pseudo-abnormal image from a normal image by generating multi-scale simplex noise and fusing it with external textures includes: Multiple simplex noises at different frequencies are superimposed to construct a multi-scale turbulence noise map. The calculation formula for multi-scale turbulence noise is as follows: In the formula, The multi-scale turbulence noise map in spatial coordinates The noise intensity value at that location, and These are the horizontal and vertical spatial coordinates of the image pixels, respectively. The number of iterations is the number of layers to be stacked. For the first Layer amplitude attenuation weight, The simplex noise function is based on this. The multi-scale turbulence noise map is subjected to threshold binarization to extract pixel-level binary masks representing defect regions. A texture image of the same size as the input normal image is randomly sampled from an external texture dataset, and a transparency blending factor is introduced. The original normal image and the texture image are fused pixel-by-pixel using the binary mask to obtain a synthesized pseudo-abnormal image. The fusion formula is as follows: In the formula, This is a synthesized pseudo-anomaly image. For original normal images, For texture images, A pixel-level binary mask. This is the Hadama product operation.

[0007] Optionally, the spatial contrast loss applies only to the normal image data stream, and its calculation process includes: Extract feature maps from the output of a certain layer in the teacher network and student network of the normal image data stream; for any spatial coordinate on the feature map, use the corresponding student feature vector as the anchor point; The feature vectors extracted by the teacher network at exactly the same spatial coordinates are taken as positive samples, and the feature vectors extracted by the teacher network at all other different spatial coordinates on the feature map are taken as negative samples. Calculate the single-point spatial contrastive loss that causes student network features to gravitate towards positive samples and move away from all negative samples. The formula for the single-point spatial contrastive loss is: In the formula, Spatial coordinates Single-point spatial contrast loss, For temperature hyperparameters, The cosine similarity between two feature vectors; The total spatial contrast loss is obtained by averaging the loss across all coordinate points on the feature map. The formula for the total spatial contrast loss is: In the formula, The height of the feature map, This represents the width of the feature map.

[0008] Optionally, the mask-guided anomaly boundary loss applies only to the pseudo-anomaly image data stream, and its calculation process includes: The original pixel-level binary mask is generated by applying a two-dimensional max pooling operation. Perform downsampling to align its spatial dimensions to the network's [number]. Resolution of deep feature maps This yields a binary mask of the corresponding scale. ; set up and The student network and the teacher network are respectively in the first... The output feature vector at the layer feature map location is defined as follows: For the first The set of coordinates for all masks in the layer that are marked as abnormal; For any abnormal pixel in the set Calculate single-point boundary loss The calculation formula is as follows: In the formula, The cosine similarity between feature vectors The threshold is a preset hyperparameter; when the similarity between teacher and student features in the abnormal region is greater than the threshold, a loss penalty is generated to force them to separate. For the first The average of the single-point boundary losses of all abnormal pixels on the layer feature map is used to obtain the boundary loss of that layer. Its formula is: Then, the boundary losses at multiple scales of the feature aggregation network output are summed. Assuming the number of feature layers in the teacher and student networks is n, the total mask-guided anomaly boundary loss is obtained, and its formula is: Optionally, a global class-aware contrastive loss is used to mitigate feature confusion in multi-class mixed scenarios, and its calculation process includes: Given a containing The training batch of images is used to compress the deepest output feature map extracted by the teacher network into a one-dimensional image-level global semantic feature vector using global average pooling. ; A nonlinear projection head composed of a multilayer perceptron is connected after the global semantic feature vector to map it to a low-dimensional latent space, obtaining the final contrast anchor vector. The mapping formula is as follows: In the formula, To compare anchor vectors, and The linear layer weight matrix of the projection head. For activation functions; Using the class labels provided by the training dataset, positive and negative sample pairs are constructed for each contrast anchor vector within a batch: other image features of the same class are set as the positive sample set, and other image features of different classes are set as the negative sample set. For index... The anchor point image, whose category label is set to Definition and Other image index sets of the same category are positive sample sets. The number of positive samples it contains is denoted as ; except for batches All other image sets besides are denoted as .

[0009] In batch Internally apply global class-aware contrast loss This forces the current image to cluster with features of the same class in the positive sample set and to repel features of different classes in the negative sample set. The formula is as follows: In the formula, Cosine similarity between two vectors; This is the temperature hyperparameter used to adjust the global semantic discriminative power.

[0010] Optionally, during the joint optimization of the unified image anomaly detection network, the normal image data stream also participates in calculating the fundamental knowledge distillation and reconstruction loss; the overall objective function of the unified image anomaly detection network during the training phase is a weighted combination of the fundamental knowledge distillation and reconstruction loss, the spatial contrast loss, the mask-guided anomaly boundary loss, and the global class-aware contrast loss, and its joint loss formula is: In the formula, The overall objective function is... Based on the loss from distillation of fundamental knowledge, For spatial contrast loss, For mask-guided anomalous boundary loss, To achieve global class-aware contrast loss. , , These are the hyperparameters that balance the weights of each loss term.

[0011] This invention provides a unified image anomaly detection method based on pseudo-anomalies and contrastive learning, which has the following beneficial effects: 1) Improved the precision of normal feature reconstruction: By introducing spatial contrast loss into the normal image data stream, the student network is forced to precisely align with the teacher features at the same location, avoiding the smoothing and blurring of local texture reconstruction, and providing more discriminative benchmark features for subsequent similarity calculation.

[0012] 2) Overcoming the bottleneck of missed detection caused by identity mapping: By designing a pseudo-anomaly synthesis mechanism that fuses multi-scale Simplex turbulent noise with external texture, and in conjunction with mask-guided anomaly boundary loss, a clear boundary for repulsion between normal and abnormal features is forcibly defined in the feature space, effectively cutting off anomaly leakage and improving the sensitivity to unknown anomalies.

[0013] 3) Solved the problem of feature confusion in multi-class fusion scenarios: By introducing global class-aware contrast loss in the deep semantic space and using the category label constraint within the batch, the high aggregation of features of the same category and the effective exclusion of features of different categories are achieved, which alleviates semantic interference and false detection during multi-class mixed training. Attached Figure Description

[0014] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 A flowchart of a unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall structure of the unified image anomaly detection network in an embodiment of the present invention; Figure 3 This is a schematic diagram of the pseudo-anomaly synthesis process based on the fusion of Simplex noise and external texture in an embodiment of the present invention. Figure 4 This is a comparison diagram of the feature space t-SNE manifold distribution of the mask-guided abnormal boundary loss effect in the embodiments of the present invention; Figure 5 This is a comparison diagram of the feature space t-SNE manifold distribution of the global class-aware contrastive loss effect in an embodiment of the present invention; Figure 6 (a) shows the baseline method's performance in anomaly detection heatmap localization of transistors in the MVTec AD dataset; Figure 6 (b) shows the anomaly detection heatmap localization effect of the method of the present invention on transistors in the MVTec AD dataset; Figure 6 (c) shows the baseline method's performance in locating anomalies such as bolt loosening in a self-built dataset using a heatmap. Figure 6 (d) represents the heatmap localization effect of the method of the present invention on the abnormal detection of bolts coming loose in the self-built dataset. Detailed Implementation

[0015] Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.

[0016] Figure 1 This is a flowchart illustrating a unified image anomaly detection method based on pseudo-anomalies and contrastive learning, according to an embodiment of the present invention. Figure 1 As shown, the method mainly includes the following steps: Step S101: Obtain a mixed dataset of normal images of multiple types and construct a unified image anomaly detection network.

[0017] In embodiments of the present invention, the network comprises a teacher network and a student network with identical structures. Traditional models, when dealing with multi-class unified anomaly detection scenarios, are prone to performance degradation due to implicit identity mapping caused by the confusion of multi-class features and the lack of anomaly priors. Therefore, the present invention introduces a pseudo-anomaly mechanism and contrastive learning for unified training based on the dual-teacher network.

[0018] Step S102: During the training phase, a twin data stream strategy is used to perform image preprocessing and pseudo-anomaly synthesis.

[0019] For an input batch containing multiple categories of normal images, not only is the original normal image data stream preserved, but a pseudo-anomaly image data stream is also constructed by synthesizing pseudo-anomaly images. Real defects often exhibit continuous, irregular, and amorphous shapes. This invention uses multi-scale simplex noise and fuses it with external textures to generate pseudo-anomalies. The synthesis process is as follows: Figure 3 As shown. Multiple simplex noises are superimposed at different frequencies to construct a multi-scale turbulence noise map, the calculation formula of which is: In the formula, The multi-scale turbulence noise map in spatial coordinates The noise intensity value at that location, and These are the horizontal and vertical spatial coordinates of the image pixels, respectively. The number of iterations is the number of layers to be stacked. For the first Layer amplitude attenuation weight, Based on the Simplex noise function, the generated multi-scale turbulence noise map is thresholded and binarized to extract pixel-level binary masks representing defect regions. Subsequently, a texture image of the same size as the input normal image is randomly sampled from the external texture dataset, and a transparency blending factor is introduced. The original normal image and the texture image are fused pixel-by-pixel using a binary mask to obtain a synthesized pseudo-abnormal image. In the formula, This is a synthesized pseudo-anomaly image. For original normal images, For texture images, A pixel-level binary mask. This is the Hadama product operation.

[0020] Step S103: The normal image data stream and the pseudo-abnormal image data stream are concatenated and synchronously input into the teacher network and the student network for multi-scale feature extraction and reconstruction.

[0021] like Figure 2 As shown, the preserved normal image data stream and the synthesized pseudo-abnormal image data stream are concatenated in the batch dimension, and then synchronously fed into teacher networks and student networks with the same structure for multi-scale feature extraction.

[0022] Step S104: At the feature output end, feature segmentation is performed according to the data flow direction. Spatial contrast loss, mask-guided anomaly boundary loss, and global class perception contrast loss are calculated respectively. The unified image anomaly detection network is then jointly optimized by combining the basic reconstruction loss.

[0023] At the network output, the deep features are re-segmented into normal features and pseudo-anomaly features according to the data flow direction, and the contrast loss is calculated in the following three dimensions: (1) Spatial contrast loss: This only applies to pure normal image data streams, forcing student features to align only with teacher features at the same location, and distancing them from features of the teacher network at all other spatial locations. Let the output feature maps of the teacher network and student network be and , respectively; calculate the single-point spatial contrast loss for any spatial coordinate: In the formula, Spatial coordinates Single-point spatial contrast loss, For temperature hyperparameters, Cosine similarity between two feature vectors For the natural constant An exponential function with base 0. The total spatial contrast loss is obtained by averaging the losses across all coordinate points. In the formula, The height of the feature map, This represents the width of the feature map.

[0024] (2) Mask-guided anomaly boundary loss: applies only to pseudo-anomaly image data streams. A two-dimensional max-pooling operation is used to apply the loss to the original mask. Perform downsampling and alignment to the network. Resolution of deep feature maps is defined as the set of coordinates of all masks marked as anomalous in this layer. For any point in this anomalous set... The single-point boundary loss is defined as: In the formula, The cosine similarity between feature vectors The preset boundary threshold hyperparameters, The function is designed to maximize the value of a feature; when the similarity between teacher and student features in an abnormal region exceeds the threshold, a loss penalty is applied to force them to separate. For the first The average of the single-point boundary losses of all abnormal pixels on the layer feature map is used to obtain the boundary loss of that layer. Its formula is: Then, the boundary losses at multiple scales of the feature aggregation network output are summed. Assuming the number of feature layers in the teacher and student networks is n, the total mask-guided anomaly boundary loss is obtained, and its formula is: (3) Global Class-Aware Contrast Loss: Applied to deep features in multi-class mixed scenarios to solve the feature confusion problem. Given a set of features... The training batch of images is used to compress the deepest output feature map extracted by the teacher network into a one-dimensional image-level global semantic feature vector using global average pooling. The vector is then mapped to the latent space via a multilayer perceptron to obtain the contrast anchor vector. In the formula, To compare anchor vectors, and The linear layer weight matrix of the projection head. For activation functions; Using the class labels provided by the training dataset, positive and negative sample pairs are constructed for each contrast anchor vector within a batch: other image features of the same class are set as the positive sample set, and other image features of different classes are set as the negative sample set. For index... The anchor point image, whose category label is set to Definition and Other image index sets of the same category are positive sample sets. The number of positive samples it contains is denoted as ; except for batches All other image sets besides are denoted as .

[0025] In batch Internally apply global class-aware contrast loss This forces the current image to cluster with features of the same class in the positive sample set and to repel features of different classes in the negative sample set. The formula is as follows: In the formula, Cosine similarity between two vectors; The temperature hyperparameter used to adjust global semantic discriminative power forces the features of the current image to cluster highly with those of images of the same category, while repelling features of different categories.

[0026] The overall objective function is composed of the three losses mentioned above and the basic reconstruction loss: In the formula, The overall objective function is... Based on the loss from distillation of fundamental knowledge, For spatial contrast loss, For mask-guided anomalous boundary loss, To achieve global class-aware contrast loss. , , These are the hyperparameters that balance the weights of each loss term.

[0027] Step S105: In the inference phase, the image to be detected is input into the trained unified image anomaly detection network. An anomaly score map is generated by calculating the similarity between the output features of the teacher network and the student network, thus completing the anomaly localization.

[0028] During the test inference phase, the network only needs to perform a forward propagation once, inputting the image to be detected into the trained unified model, calculating the similarity difference between the multi-scale features output by the teacher network and the student network to obtain anomaly score maps at each level, and generating high-resolution anomaly score maps and completing accurate anomaly localization by upsampling and fusing the score maps at each scale.

[0029] The following detailed description of a unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to the present invention will be provided through specific embodiments.

[0030] (1) Data set and experimental conditions This invention uses the MVTec AD dataset, the most widely used dataset in the field of unsupervised image anomaly detection, as the basic evaluation benchmark. This dataset covers 15 different typical industrial products. Furthermore, for specific engineering application backgrounds, this invention also constructs a railway freight car fault dataset using real business data. The original images in this dataset are all collected from a real railway freight car operation fault dynamic image detection system (TFDS). After screening and organization, this dataset mainly covers six real fault scenarios: bolt detachment, missing coupler safety tray, open door, missing feed plate, bent feed plate, and wheel rim damage. In the training set, the model uses only images of completely normal components for unified training across multiple classes (approximately 300 to 550 normal images corresponding to each fault class). To verify the effectiveness of this invention, experiments were conducted on CentOS 7.5 operating system using the PyTorch deep learning framework. The hardware environment configuration was: Intel Xeon Gold 5118 processor and a single NVIDIA V100 GPU (16GB VRAM). To comprehensively and objectively evaluate model performance, three evaluation metrics were used for the MVTec AD dataset: image-level AUROC%, pixel-level AUROC%, and pixel-level average precision (AP%). For the railway freight car fault dataset, image-level AUROC, precision, and recall were used.

[0031] (2) Comparison of quantitative experimental results Under the unified anomaly detection experimental setup, this embodiment conducted quantitative comparative experiments on the MVTec AD public benchmark dataset and a self-built railway freight car fault dataset. Normal images of all categories were used for training, and a unified evaluation was performed during testing. Specific comparative data between the method of this invention and traditional anomaly detection baseline methods (taking transistor and bolt detachment as examples) are shown in Table 1: Table 1 Experimental Results In transistor anomaly detection on the MVTec AD dataset, the method of this invention outperformed the baseline method in image-level AUROC, pixel-level AUROC, and pixel-level AP, improving them by 2.0, 0.3, and 1.8 percentage points, respectively. In bolt detachment detection on the truck fault dataset, the method of this invention improved precision by 1.11 percentage points, while image-level AUROC and recall only fluctuated slightly by 0.05 and 0.18 percentage points, respectively. This indicates that the model effectively reduced the false detection rate while maintaining overall performance, demonstrating the effectiveness of the method of this invention.

[0032] (3) Qualitative Visual Analysis In addition to quantitative performance improvements, to further intuitively verify the intrinsic mechanism by which this invention breaks identity mappings and eliminates feature confusion in multi-class unified tasks, network features were extracted and visualized using t-SNE. For example... Figure 4 As shown, after adding mask-guided anomaly boundary loss, a clear and explicit isolation boundary is formed between the anomalous and normal features in the student network reconstruction, effectively cutting off false negatives caused by anomaly leakage. Figure 5 As shown, after introducing global class-aware contrastive loss, the previously overlapping features of different classes are decoupled in the latent space. Features of the same class gradually converge, while features of different classes move further apart, mitigating semantic interference and false detections in multi-class merging scenarios. The baseline method PatchCore and the method of this invention demonstrate their performance in anomaly detection heatmap localization of transistors in the MVTec AD dataset as shown in the figure. Figure 6 of (a) Figure 6 As shown in (b), the anomaly detection heatmap localization effect of bolt detachment in the self-built dataset is as follows: Figure 6 (c) Figure 6 As shown in (d). From Figure 6 As can be seen, the method of the present invention can significantly suppress interference noise in the normal background area and generate a high-contrast red highlight response in the abnormal area, which proves that the method of the present invention has excellent robustness and performance in unsupervised unified anomaly detection tasks.

[0033] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0034] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature.

[0035] Any process or method description in the flowchart or otherwise herein can be understood as: representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.

Claims

1. A unified image anomaly detection method based on pseudo-anomalies and contrastive learning, characterized in that, Includes the following steps: Step 1: Obtain a dataset of normal images of multiple mixed types and construct a unified image anomaly detection network. The unified image anomaly detection network includes a teacher network and a student network with the same structure. Step 2: During the training phase, a twin data stream strategy is adopted. For the input batch of normal images, the original normal images are retained to form a normal image data stream. At the same time, by generating multi-scale simplex noise and fusing it with external textures, pseudo-abnormal images and corresponding pixel-level binary masks are generated for the normal images to form a pseudo-abnormal image data stream. Step 3: After splicing the normal image data stream and the pseudo-abnormal image data stream, input them synchronously into the teacher network and the student network for multi-scale feature extraction and reconstruction; Step 4: At the feature output end, perform feature segmentation according to the data flow direction, calculate spatial contrast loss, mask-guided anomaly boundary loss and global class perception contrast loss respectively, and combine them with basic reconstruction loss to jointly optimize the unified image anomaly detection network. Step 5: In the inference phase, the image to be detected is input into the trained unified image anomaly detection network. Anomaly score map is generated by calculating the similarity between the output features of the teacher network and the student network, thus completing the anomaly localization.

2. The unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to claim 1, characterized in that, The specific process of generating pseudo-abnormal images from normal images by generating multi-scale simplex noise and fusing it with external textures includes: Multiple simplex noises at different frequencies are superimposed to construct a multi-scale turbulence noise map. The calculation formula for any pixel in the multi-scale turbulence noise map is as follows: ; In the formula, The multi-scale turbulence noise map in spatial coordinates The noise intensity value at that location, and These are the horizontal and vertical spatial coordinates of the image pixels, respectively. The number of iterations is the number of layers to be stacked. For the first Layer amplitude attenuation weight, The simplex noise function is based on this. The multi-scale turbulence noise map is subjected to threshold binarization to extract pixel-level binary masks representing defect regions. A texture image of the same size as the input normal image is randomly sampled from an external texture dataset, and an opacity blending factor is introduced. The original normal image and the texture image are fused pixel-by-pixel using the binary mask to obtain a synthesized pseudo-abnormal image. The fusion formula is as follows: ; In the formula, This is a synthesized pseudo-anomaly image. For original normal images, For texture images, A pixel-level binary mask. Transparency blending factor This is the Hadama product operation.

3. The unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to claim 2, characterized in that, The spatial contrast loss applies only to the normal image data stream, and its calculation process includes: Extract feature maps from the output of a certain layer in the teacher network and student network of the normal image data stream; for any spatial coordinate on the feature map, use the corresponding student feature vector as the anchor point; The feature vectors extracted by the teacher network at exactly the same spatial coordinates are taken as positive samples, and the feature vectors extracted by the teacher network at all other different spatial coordinates on the feature map are taken as negative samples. Based on the Information Noise Contrast Estimation (InfoNCE) loss, the single-point spatial contrast loss that makes student network features gravitate towards positive samples and move away from all negative samples is calculated. The formula for the single-point spatial contrast loss is: ; In the formula, Spatial coordinates Single-point spatial contrast loss, The spatial coordinates of the student network and the teacher network are respectively. The feature vector at that location, and These are the traversal indices in the width and height directions of the feature map, respectively. For temperature hyperparameters, The cosine similarity between two feature vectors. The height of the feature map, The width of the feature map; The total spatial contrast loss is obtained by averaging the loss across all coordinate points on the feature map. The formula for the total spatial contrast loss is: 。 4. The unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to claim 3, characterized in that, The mask-guided anomaly boundary loss applies only to the pseudo-anomaly image data stream, and its calculation process includes: A two-dimensional max pooling operation is used to downsample the generated original pixel-level binary mask, aligning its spatial dimensions to the network's [number of pixels]. Resolution of deep feature maps This yields a binary mask of the corresponding scale. ; set up and The student network and the teacher network are respectively in the first... The output feature vector at the layer feature map location is defined as follows: For the first The set of coordinates for all masks in the layer that are marked as abnormal; For any abnormal pixel in the set Calculate single-point boundary loss The calculation formula is as follows: ; In the formula, The cosine similarity between feature vectors The threshold is a preset hyperparameter; when the similarity between teacher and student features in the abnormal region is greater than the threshold, a loss penalty is generated to force them to separate. For the first The average of the single-point boundary losses of all abnormal pixels on the layer feature map is used to obtain the boundary loss of that layer. Its formula is: ; Then, the boundary losses at multiple scales of the feature aggregation network output are summed. Assuming the number of feature layers in the teacher and student networks is n, the total mask-guided anomaly boundary loss is obtained, and its formula is: 。 5. The unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to claim 4, characterized in that, The global class-aware contrastive loss is used to alleviate feature confusion in multi-class mixed scenes, and its calculation process includes: Given a containing The training batch of images is used to compress the deepest output feature map extracted by the teacher network into a one-dimensional image-level global semantic feature vector using global average pooling. ; A nonlinear projection head composed of a multilayer perceptron is connected after the global semantic feature vector to map it to a low-dimensional latent space, obtaining the final contrast anchor vector. The mapping formula is as follows: ; In the formula, To compare anchor vectors, This is the weight matrix of the first linear layer in the projection head. This is the weight matrix of the second linear layer in the projection head. For activation functions; Using the class labels provided by the training dataset, construct positive and negative sample pairs for each contrast anchor vector within a batch: set other image features of the same class as the positive sample set, and other image features of different classes as the negative sample set; for index... The anchor point image, whose category label is set to Definition and Other image index sets of the same category are positive sample sets. The number of positive samples it contains is denoted as ; except for batches All other image sets besides are denoted as ; In batch Internally apply global class-aware contrast loss This forces the current image to cluster with features of the same class in the positive sample set and to repel features of different classes in the negative sample set. The formula is as follows: ; In the formula, This represents the total number of images included in the training batch. The temperature hyperparameter is used to adjust the global semantic discriminative power. For index The anchor point vector corresponding to the anchor point image. The index for the positive sample set is The image corresponding to the contrast anchor vector Remove index within batch The set of indices for all other images besides [the image itself]. For set Traversal index in For the corresponding index The contrast anchor vector of the image, This represents the number of positive samples contained in the positive sample set.

6. The unified image anomaly detection method based on pseudo-anomalies and contrastive learning according to claim 5, characterized in that, In the process of jointly optimizing the unified image anomaly detection network, the normal image data stream also participates in calculating the basic knowledge distillation and reconstruction loss; the overall objective function of the unified image anomaly detection network during the training phase is composed of a weighted combination of the basic knowledge distillation and reconstruction loss, spatial contrast loss, mask-guided anomaly boundary loss, and global class-aware contrast loss, and its joint loss formula is: ; In the formula, The overall objective function is... Based on the loss from distilling and reconstructing fundamental knowledge, For spatial contrast loss, For mask-guided anomalous boundary loss, To achieve global class-aware contrast loss. , , These are the hyperparameters that balance the weights of each loss term.