An industrial image anomaly detection method and system based on multi-source feature fusion and synthetic anomaly enhancement

By constructing a frozen multi-scale feature extractor and a non-parametric feature memory, combined with a multi-source feature parallel coding network and a spatial attention mechanism, the problem of high-precision pixel-level segmentation in industrial image anomaly detection under unsupervised conditions is solved, and accurate detection of minute defects on industrial surfaces is achieved.

CN122090225APending Publication Date: 2026-05-26SICHUAN SHUJU INTELLIGENT MFG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SICHUAN SHUJU INTELLIGENT MFG TECH CO LTD
Filing Date
2026-03-04
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing industrial image anomaly detection technologies struggle to achieve high-precision pixel-level segmentation under unsupervised conditions, resulting in insufficient feature utilization and blurred pixel-level segmentation edges, failing to meet the demands of precision quality inspection.

Method used

By combining a non-parametric memory prior with a parameterized fine-tuning filter network, a frozen multi-scale feature extractor and a non-parametric feature memory are constructed through multi-source feature fusion and spatial attention mechanisms to generate a coarse anomaly prior distribution. The multi-source feature parallel encoding network is trained by synthesizing anomaly samples, and hybrid forward propagation under gradient truncation is performed to optimize the network weights.

Benefits of technology

It achieves high-precision pixel-level segmentation of minute defects on industrial surfaces under unsupervised conditions, solving the problems of insufficient model generalization ability and feature utilization in traditional methods, and achieving high-precision anomaly detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

This invention relates to the field of computer vision and image processing technology, specifically to an industrial image anomaly detection method and system based on multi-source feature fusion and synthetic anomaly enhancement. This invention aims to solve the problems of insufficient feature utilization and pixel-level segmentation edge blurring in existing unsupervised industrial image anomaly detection methods. By combining a non-parametric memory prior with a parametric fine-tuning filter network, and introducing a spatial attention mechanism to guide multi-source feature fusion, this method can effectively detect minute defects on industrial surfaces with only normal sample training. The technical solution includes: constructing a frozen multi-scale feature extractor; establishing a non-parametric feature memory; generating a coarse anomaly prior map; designing a multi-source feature parallel encoding network; constructing an attention-guided feature fusion and decoding module; generating synthetic anomaly samples based on a Berlin noise field; performing gradient-truncation hybrid forward propagation; and performing forward inference to obtain anomaly localization results.
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 image processing technology, and in particular to an industrial image anomaly detection method and system based on multi-source feature fusion and synthetic anomaly enhancement. Background Technology

[0002] Industrial anomaly detection aims to identify areas that deviate from the distribution of normal samples. Due to the wide variety of defects and their low probability of occurrence in industrial settings, it is difficult to obtain large-scale defect annotation data. Therefore, unsupervised anomaly detection techniques based on "training with only normal samples" have become the mainstream.

[0003] Existing technologies can be mainly divided into the following categories:

[0004] Anomaly detection methods based on image reconstruction: These methods typically employ autoencoders (AEs) or generative adversarial networks (GANs) as their underlying architecture. The core idea is to train the model using normal samples, enabling it to reconstruct normal texture structures. During the inference phase, anomaly regions are located by calculating the residual (reconstruction error map) between the input image and the model's reconstructed image. However, in practical applications, this method struggles to precisely control the model's generalization ability. If the model has an overly strong fitting ability, it may approximate the reconstruction of anomaly regions, resulting in a low reconstruction error and missed detections. Furthermore, pixel-level reconstruction error calculation is highly sensitive to high-frequency noise. When processing industrial images with complex texture backgrounds, it can easily generate high residual responses at normal texture abrupt changes, leading to an increased false detection rate.

[0005] Anomaly detection methods based on feature embedding and memory banks, exemplified by the PatchCore algorithm, utilize convolutional neural networks (CNNs) pre-trained on large-scale datasets (such as ImageNet) as feature extractors to extract multi-scale features from the input image and construct a feature memory bank based on normal samples. During detection, an anomaly score map is generated by calculating the distance between the local features of the test sample and the nearest neighbor features in the memory bank. Although this method performs well in terms of detection accuracy, it has inherent limitations in pixel-level segmentation precision: because the backbone network usually includes multiple downsampling operations, the generated original anomaly feature map has a low resolution (usually 1 / 8 or 1 / 16 of the original image), and Gaussian filtering and bilinear interpolation are usually applied to smooth noise, resulting in blurred defect boundaries in the final output, making it difficult to accurately restore the geometry of small defects. Furthermore, this type of method usually only uses the calculated distance scalar as the discrimination criterion, failing to fully utilize the rich semantic and texture contextual information originally contained in the feature tensors of the intermediate layers of the backbone network.

[0006] General-purpose fully supervised semantic segmentation frameworks and methods: Represented by open-source frameworks such as MMSegmentation, existing technologies have established mature modular segmentation architectures of "backbone-neck-decodehead". These architectures perform well in fully supervised tasks with massive amounts of pixel-level labeled data, achieving high-precision edge segmentation. However, their application in industrial anomaly detection scenarios faces significant obstacles. General-purpose segmentation frameworks rely on closed-set training, making them unable to identify unknown defects undefined in the training set. Furthermore, these frameworks lack interaction mechanisms with non-parametric memory, failing to directly utilize prior distribution information provided by normal sample libraries. In addition, large-scale defect labeling data is difficult to obtain in industrial scenarios, and directly applying general-purpose segmentation frameworks can easily lead to severe overfitting problems.

[0007] In summary, existing technologies have significant limitations in handling high-precision anomaly detection tasks in industrial scenarios. Reconstruction-based methods struggle to balance model generalization ability and anomaly sensitivity, and lack robustness to environmental noise. While feature embedding-based methods address the cold-start problem with few samples, their limitations in feature map resolution and simple distance metrics lead to blurred defect segmentation boundaries, failing to meet the demands of precision quality inspection. General fully supervised segmentation frameworks, despite their sophisticated feature decoding capabilities, are constrained by closed-set training paradigms and high annotation costs, making them unsuitable for open industrial environments with scarce samples and unknown defect morphologies. Currently, there is a lack of integrated solutions that effectively combine the prior advantages of non-parametric memory with the refined architecture of parametric segmentation networks, achieving high-precision pixel-level anomaly segmentation under unsupervised conditions. Summary of the Invention

[0008] The purpose of this invention is to address the problem that existing industrial image anomaly detection technologies struggle to achieve high-precision pixel-level segmentation under unsupervised conditions, particularly addressing inaccurate detection due to insufficient feature utilization and blurred pixel-level segmentation edges. By combining a non-parametric memory prior with a parametric fine-tuning filter network and introducing a spatial attention mechanism to guide multi-source feature fusion, this invention provides a system and method capable of effectively detecting minute defects on industrial surfaces even with only normal samples available for training.

[0009] To achieve the above objectives, the present invention employs the following technical means:

[0010] This invention provides an industrial image anomaly detection method based on multi-source feature fusion and synthetic anomaly enhancement, the method comprising the following steps:

[0011] Step 1: Construct a frozen multi-scale feature extractor. Select a convolutional neural network pre-trained on a large-scale dataset as the backbone network, freeze all its weight parameters, and extract multi-scale feature maps from different levels of the backbone network.

[0012] Step 2: Construct a non-parametric feature memory library, and use a greedy core set sampling algorithm to select the most representative feature subset from the feature set of normal samples as a reference benchmark for the distribution of normal samples;

[0013] Step 3: Generate a coarse anomaly prior distribution, calculate the nearest neighbor distance between the local features of the test image and the features in the non-parametric feature memory, obtain the anomaly score map, and obtain a coarse anomaly prior map with the same size as the original image through upsampling operation;

[0014] Step 4: Construct a multi-source feature parallel encoding network, including multiple parallel branches that process the multi-scale feature map, the coarse anomaly prior map, and the original input image respectively, to generate semantic features, prior features, and texture features;

[0015] Step 5: Construct attention-guided feature fusion and decoder, generate spatial attention weights using the prior features, perform element-wise weighting on the semantic features, and then fuse them with the texture features. Output a detailed anomaly probability map through the decoding network.

[0016] Step 6: Generate synthetic anomalous samples based on the Berlin noise field. A two-dimensional Berlin noise field is generated by multi-octave band superposition algorithm. After threshold truncation and Gaussian blurring, a transparency fusion mask is generated. The foreign object source image is fused with the normal industrial image to construct training data.

[0017] Step 7: Perform hybrid forward propagation under gradient truncation, keeping the parameters of the frozen multi-scale feature extractor and non-parametric feature memory unchanged, and only updating the parameters of the multi-source feature parallel encoding network and attention-guided feature fusion and decoder, and optimizing the network weights through the binary segmentation objective function;

[0018] Step 8: Perform forward inference, preprocess the test image, input it into the trained network, generate a detailed anomaly probability map, and obtain the final anomaly region localization result through threshold truncation and morphological operations.

[0019] In the above scheme, step 1 includes the following sub-steps:

[0020] Step 1.1: Initialize a Wide_ResNet_50_2 network pre-trained on the ImageNet dataset as the backbone feature extractor. The backbone feature extractor Φ is used to extract multi-scale features from the input image;

[0021] Step 1.2: Select the middle and deep layers of the backbone feature extractor Φ as feature output nodes, for the input image tensor ,feature The extraction process is represented as follows:

[0022]

[0023] in, This represents the feature set of the input image I. This represents a Layer 2 layer feature containing rich texture details. This represents Layer 3 features containing semantic structure, where C is the number of channels in the input image, and H and W are the height and width of the input image, respectively. and These are the channel dimensions of the features in Layer2 and Layer3, respectively.

[0024] Step 1.4: During the entire model building and subsequent training process, freeze all weight parameters of the backbone feature extractor. ,Right now This is to ensure the stability of the feature space distribution and prevent the model from overfitting or feature collapse under small sample conditions.

[0025] In the above scheme, step 2 includes the following sub-steps:

[0026] Step 2.1: Construct a non-parametric feature memory Iterate through all normal training samples Extract its in and The features of the layer are analyzed and locally aggregated in the spatial dimension to form a set of local feature vectors. ;

[0027] Step 2.2: Employ a greedy core set sampling algorithm to sample the local feature vector set. The most representative subset is selected as the memory bank, and this process is achieved by solving the following mathematical optimization problem:

[0028]

[0029] in, This means that for each point in the large set... In the selected non-parametric feature memory Find the nearest eigenvector in the array. And calculate the distance between them, which measures the subset. For a single sample The degree of approximation;

[0030] The complete collection Relative to subset The one-way Hausdorff distance represents the worst-case coverage radius of the current memory bank when covering the feature space distribution;

[0031] Represents all possibilities, with a size of Find a specific subset from a set of subsets. This minimizes the coverage radius of the worst-case scenario.

[0032] Step 2.3: Calculate the optimal subset obtained from the solution. As a non-parametric feature memory, it serves as a reference benchmark in the subsequent anomaly detection process.

[0033] In the above scheme, step 3 includes the following sub-steps:

[0034] Step 3.1: Based on the constructed memory Define a non-parametric anomaly measurement mechanism for the local feature vector of the sample to be tested. Calculate its relationship with the memory bank Nearest neighbor Euclidean distance of all eigenvectors This quantifies the degree of anomaly at that location. The distance calculation formula is as follows:

[0035]

[0036] in, Indicates the spatial location of the sample to be tested. Local feature vectors at that location Show memory bank The feature vector in Represents the Euclidean distance norm;

[0037] Step 3.2: Introduce cosine similarity as a penalty term to correct the calculated distance, thereby enhancing the accuracy of anomaly detection;

[0038] Step 3.3: Reorganize the corrected scores of all spatial locations into a two-dimensional matrix. ,in and These represent the height and width of the feature map, respectively.

[0039] Step 3.4: Using bilinear interpolation The two-dimensional matrix S is upsampled to the original image size to generate a coarse anomaly prior map:

[0040]

[0041] in, It provides a global location prior for anomalous regions.

[0042] In the above scheme, step 4 includes the following sub-steps:

[0043] Step 4.1: Construct a multi-source feature parallel coding network, which is a trainable parameterized filtering network containing three parallel coding branches;

[0044] Step 4.2: In the semantic coding branch, receive the multi-scale feature maps extracted by the backbone network. and Semantic features are generated by compressing and unifying the channel dimensions through convolution operations and residual modules. and ;

[0045] Step 4.3: In the prior coding branch, receive the coarse anomaly prior map. Through nonlinear mapping functions Map it to high-dimensional features This is used to guide network attention to areas suspected of being abnormal.

[0046] Step 4.4: In the texture coding branch, the original input image I is directly received, and high-frequency edges and texture details are extracted through a shallow convolutional network to generate texture features. ;

[0047] Step 4.5: The calculation process for each branch is uniformly represented as follows:

[0048]

[0049] in, This represents the feature of the output of the k-th branch. This represents the nonlinear mapping function of the k-th branch. This represents the input data for the k-th branch.

[0050] In the above scheme, step 5 includes the following sub-steps:

[0051] Step 5.1: Construct an attention-guided feature fusion and decoder. The decoder introduces a spatial attention gating mechanism, uses prior features to generate spatial attention weights, and dynamically modulates semantic features.

[0052] Step 5.2: Activate prior features using the Sigmoid activation function σ(∙). Transformed into attention weight α:

[0053]

[0054] Where α represents the spatial attention weight, with a value between 0 and 1, and H and W are the height and width of the input image, respectively;

[0055] Step 5.3: Apply the attention weight α to the semantic feature Esem and perform element-wise weighting to obtain the weighted semantic feature. :

[0056]

[0057] Where ⨀ represents the Hadamard product, which is the element-wise multiplication of two tensors in space. The specific calculation method is as follows: , These represent the spatial coordinates of the feature map;

[0058] Step 5.4: Weight the semantic features Prior features With texture features The data is spliced ​​and merged along the channel dimension to form a fusion feature;

[0059] Step 5.5: Input the fused features into the cascaded decoding network. In the process, spatial resolution is restored through a series of upsampling and convolution operations, and finally a fine-grained anomaly probability map is output through the sigmoid function:

[0060]

[0061] in, This represents the anomaly probability map of the final output, where σ represents the Sigmoid activation function, Decoder represents the decoding network function, and [⋅,⋅,⋅] represents the concatenation operation along the channel dimensions.

[0062] In the above scheme, step 6 includes the following steps:

[0063] Step 6.1: A two-dimensional Berlin noise field P(x,y) is generated using a multioctave superposition algorithm. This generation process involves superimposing fundamental noise functions of different frequencies and amplitudes. The mathematical expression is as follows:

[0064]

[0065] in, This represents the generated two-dimensional Berlin noise field. The base noise function is represented by f, the frequency multiplication factor is β, the persistence parameter is K, the number of superimposed noise layers is K, and x and y represent the spatial coordinates.

[0066] Step 6.2: Process the generated Berlin noise field Threshold truncation is performed to determine the binary shape mask of the defect. ;

[0067] Step 6.3: Perform Gaussian blurring on the binarized shape mask Mgt to generate a continuously varying transparency blending mask. ,in This represents the transparency value of the blending mask, ranging from 0 to 1;

[0068] Step 6.4: Image of the foreign object source Compared with normal industrial images Through the transparency blending mask Perform natural fusion to generate synthetic anomalous images The mathematical expression for its fusion process is:

[0069]

[0070] in, This represents the generated synthetic anomalous image. This represents a normal industrial image. ⨀ represents the image of the foreign object source, and ⨀ represents the Hadamard product, which is the element-wise multiplication operation of two tensors in spatial position;

[0071] Step 6.5: Combine the synthesized abnormal image and its corresponding binarized shape mask As training samples, a training dataset is constructed for subsequent model training.

[0072] In the above scheme, step 7 includes the following steps:

[0073] Step 7.1: Perform gradient-truncation hybrid forward propagation to synthesize the anomalous image. The input is fed into a hybrid network architecture, where the frozen multi-scale feature extractor Φ and the non-parametric feature memory M∗ serve as the teaching module, and its parameter set... The network remains frozen throughout training and does not participate in gradient updates; the multi-source feature parallel encoding network and the attention-guided feature fusion and decoder serve as learning modules, forming a trainable filtering network. Its parameters Participate in gradient update;

[0074] Step 7.2: During the hybrid forward propagation process, the input image is processed... After normalization preprocessing, the data first passes through a frozen feature extraction module to generate multi-scale features. and rough anomaly prior map Then , and The common inputs are fed into a trainable filter network to generate the predicted output. :

[0075]

[0076] in, This represents a graph showing the anomaly probability predicted by the model. This represents the nonlinear mapping function of the filtering network. This indicates that the frozen backbone network is from the anomalous image. Features extracted from This represents the generated coarse anomaly prior map. This represents the set of trainable parameters for the filtering network.

[0077] Step 7.3: Construct a binary segmentation objective function, and use a binary cross-entropy loss function with Logits to calculate the difference between the predicted result and the synthesized true value. Defined as:

[0078]

[0079] Where H and W are the height and width of the image, respectively. Indicates spatial location The synthesized truth label at the location is taken from the binarization mask. , σ(∙) represents the unnormalized response value output by the model at position (i,j), and σ(∙) represents the Sigmoid activation function.

[0080] Step 7.4: Based on the calculated loss function, use the AdamW adaptive moment estimator to calculate the loss function relative to the filter network parameters. Find the gradient ∇θ and perform parameter updates:

[0081]

[0082] Where η is the learning rate. and These are the first and second moments of the gradient, respectively. For numerically stable smoothing terms;

[0083] Step 7.5: Repeat steps 7.1 to 7.4. Through multiple rounds of iterative training, the filtering network learns the ability to transform the coarse anomaly prior map into a fine anomaly segmentation map, thus completing the optimization of the network weights.

[0084] In the above scheme, step 8 includes the following sub-steps:

[0085] Step 8.1: Perform preprocessing on the test image. First, acquire the test image to be inspected using an industrial camera. A bicubic interpolation algorithm is used to adjust the image to a fixed resolution consistent with that used during the training phase. The processed image is obtained. ; then on Normalization is performed by subtracting the statistical mean μavg of the ImageNet dataset and dividing by the standard deviation σstandard to generate the preprocessed input tensor. :

[0086]

[0087] in, This represents the preprocessed input tensor. This represents the image after resolution adjustment. This represents the statistical mean of the ImageNet dataset. Indicates standard deviation;

[0088] Step 8.2: Convert the preprocessed input tensor The input is fed into the parameter-frozen feature extraction backbone network Φ to extract multi-scale features, and then based on the non-parametric feature memory. Calculate the minimum Euclidean distance between the local feature vector and the feature vector of normal samples in the memory bank to generate a rough anomaly prior map. ;

[0089] Step 8.3: Convert the input tensor Multi-scale features and rough anomaly prior map The input is fed into the trained filter network to generate a fine-grained anomaly probability map. :

[0090]

[0091] Where Ψ represents the trained filter network function. This represents the features extracted by the backbone network. The optimized network parameters;

[0092] Step 8.4: Develop a detailed anomaly probability map Binarization segmentation and anomaly region localization are performed, and a preset confidence threshold τ is introduced. Perform binarization truncation and apply the structuring element as... The morphological opening operation is used to filter the binary image to generate the final anomaly segmentation mask. :

[0093]

[0094] in, This represents the final anomaly segmentation mask. This represents the morphological opening operation, where l is the indicator function, taking the value 1 if the condition is met and 0 otherwise, and τ is a preset confidence threshold. Structural elements for morphological operations;

[0095] Step 8.5: Based on the aforementioned anomaly segmentation mask The connected component analysis algorithm is executed to extract the topological contours of all independent anomalous regions and calculate their minimum bounding rectangle, thereby accurately locating the anomalous regions on the original image.

[0096] Because the present invention employs the above-mentioned technical means, it has the following beneficial effects:

[0097] 1. This invention constructs a frozen multi-scale feature extractor (step 1), freezes all weight parameters of the pre-trained convolutional neural network, and extracts multi-scale feature maps from different levels. This effectively alleviates the technical problem that the model is prone to overfitting or feature collapse in small-sample industrial scenarios, and achieves the effect of maintaining the stability of feature space distribution and ensuring the reliability and consistency of feature extraction, thus providing a solid feature foundation for subsequent anomaly detection.

[0098] 2. This invention solves the computational redundancy problem caused by full feature storage in traditional methods by constructing a non-parametric feature memory (step 2) and using a greedy core set sampling algorithm to select the most representative feature subset from the normal sample feature set. This achieves the effect of establishing a reference benchmark that fully covers the feature space distribution of normal samples within a limited storage space, and improves the statistical reliability of anomaly detection.

[0099] 3. This invention generates a coarse anomaly prior distribution (step 3), calculates the nearest neighbor distance between local features of the test image and features in the memory bank, and upsamples to obtain an anomaly score map. This solves the technical problem of difficulty in obtaining large-scale defect annotation data in industrial scenarios, and achieves the effect of generating global anomaly location prior information without real defect samples, providing an effective guiding signal for subsequent fine processing.

[0100] 4. This invention constructs a multi-source feature parallel encoding network (step 4), designs parallel encoding branches corresponding to semantic features, prior features, and texture features respectively, and jointly encodes multi-scale feature maps, coarse anomaly prior maps, and the original input image. This solves the technical limitation of existing technologies that only use distance scalars while ignoring rich semantic and texture context information. It achieves a complete feature representation effect that simultaneously captures deep semantic consistency, global anomaly location priors, and original physical texture details, laying a multi-dimensional information foundation for accurate segmentation.

[0101] 5. This invention constructs an attention-guided feature fusion and decoder (step 5), uses prior features to generate spatial attention weights to weight semantic features element by element, and then fuses them with texture features. This solves the technical problems of lack of specificity and blurred edges in the feature fusion process in traditional methods, and achieves the effect of dynamically suppressing background interference and enhancing the feature response of suspected abnormal areas. It realizes the improvement from low-resolution coarse estimation to high-precision pixel-level segmentation.

[0102] 6. This invention generates synthetic abnormal samples based on the Berlin noise field (step 6), uses a multi-octave band superposition algorithm to generate a two-dimensional noise field with natural texture characteristics, and generates a transparency fusion mask through threshold truncation and Gaussian blurring. This solves the data bottleneck problem of scarce and diverse defect samples in industrial quality inspection, and achieves the effect of generating synthetic training samples with natural edge transitions and visual realism under the condition of no real defect annotation, providing effective supervision information for model training.

[0103] 7. This invention solves the technical problems of model overfitting and feature drift in small sample training by performing hybrid forward propagation under gradient truncation (step 7), keeping the parameters of the frozen multi-scale feature extractor and non-parametric feature memory unchanged, and only updating the parameters of the multi-source feature parallel encoding network and decoder. It achieves the effect of keeping the feature space distribution benchmark stable while enabling the trainable module to focus on learning the mapping relationship from coarse prior to fine segmentation, which significantly improves the generalization ability of the model.

[0104] 8. This invention organically combines techniques such as frozen feature extractors, non-parametric feature memory, multi-source feature parallel encoding, attention-guided fusion, synthetic anomaly enhancement, and gradient truncation training, producing significant synergistic effects and resolving the long-standing core contradiction in industrial anomaly detection where "high-precision segmentation" and "few-sample generalization" are mutually exclusive. Specifically, the frozen feature extractor and memory, acting as a "teaching module," provide stable and reliable coarse anomaly localization capabilities, while the trainable filtering network, acting as a "learning module," focuses on fine-tuning. Synthetic anomaly data bridges the gap between unsupervised feature extraction and supervised pixel segmentation; the attention mechanism achieves deep coupling between prior knowledge and the parameterized network. This cascaded architecture combining "non-parametric coarse localization" and "parametric fine-tuning" not only retains the broad-spectrum capture capability of unsupervised methods for unknown anomalies but also achieves pixel-level segmentation accuracy close to that of fully supervised models, providing a practical solution for industrial quality inspection scenarios that combines high precision and strong generalization. Attached Figure Description

[0105] Figure 1 This is a simplified flowchart of the present invention;

[0106] Figure 2 Schematic diagram of self-supervised training process;

[0107] Figure 3 Overall solution architecture flowchart;

[0108] Figure 4 The output graph for the PatchCore algorithm inference;

[0109] Figure 5 This is the inference output diagram of the method proposed in this invention; Detailed Implementation

[0110] The embodiments of the present invention will be described in detail below. Although the present invention will be described and illustrated in conjunction with some specific embodiments, it should be noted that the present invention is not limited to these embodiments. On the contrary, any modifications or equivalent substitutions made to the present invention should be covered within the scope of the claims of the present invention.

[0111] Furthermore, to better illustrate the present invention, numerous specific details are set forth in the following detailed embodiments. Those skilled in the art will understand that the present invention can be practiced without these specific details.

[0112] This invention relates to the fields of computer vision and image processing technology, and is applicable to surface defect detection (such as scratches, foreign objects, stains, etc.) in industrial automated production. It can achieve high-precision pixel-level anomaly segmentation with small samples under unsupervised conditions. A system and method for industrial image anomaly detection based on feature memory prior and multi-scale attention fusion are proposed. Addressing the insufficient feature utilization and blurred edges in pixel-level segmentation of existing unsupervised detection algorithms, this scheme innovatively designs a cascaded deep learning architecture combining "non-parametric coarse localization" and "parametric fine-tuning." Logically, this architecture does not abandon existing feature embedding techniques, but rather uses them as a prior knowledge generator, deeply coupled with a fine-tuning filtering network built on a general semantic segmentation framework. By introducing a spatial attention mechanism, the system can effectively transform non-parametric distance metric information into guiding signals for the parametric network, thereby achieving high-precision, pixel-level segmentation of industrial surface defects under unsupervised (or minimally supervised) conditions.

[0113] The implementation process of this technical solution strictly includes the following three stages:

[0114] Model building phase: Construct a hybrid network topology that includes a frozen feature extractor, a normal sample memory, and a trainable multi-source feature fusion filter;

[0115] Model training phase: Design an online data augmentation strategy based on Perlin noise and illumination perturbation, and optimize the filter weight parameters through a self-supervised learning paradigm in the absence of real defect samples;

[0116] Forward inference stage: In actual detection scenarios, a complete pipeline is executed from multi-scale feature extraction, coarse prior calculation to fine feature decoding, and the final anomaly probability map is output.

[0117] The following section will elaborate on the specific implementation details of the above three stages.

[0118] Model building phase:

[0119] Step 1: Construct a frozen multi-scale feature extractor

[0120] The system first initializes a deep convolutional neural network (CNN) as the backbone feature extractor. The network structure uses Wide_ResNet_50_2 pre-trained on the ImageNet dataset. To obtain multi-level representations of the image, the system selects the intermediate layer (Layer 2) and deep layer (Layer 3) of the network as feature output nodes. For the input image tensor... ,feature The extraction process is formalized as shown in equation (1):

[0121]

[0122] in, This represents a Layer 2 layer feature containing rich texture details. This represents Layer 3 features containing semantic structure. All weight parameters of this feature extractor are used throughout the model building and subsequent training process. All were frozen. This is to ensure the stability of the feature space distribution and prevent the model from overfitting or feature collapse under small sample conditions.

[0123] Step 2: Construct a non-parametric feature memory

[0124] To describe the distribution manifold of normal samples, the system constructs a non-parametric feature memory bank, denoted as MemoryBank. Iterate through all normal training samples. Extract its in and The features of each layer are analyzed and locally aggregated in the spatial dimension to form a set of local feature vectors. To address the computational redundancy caused by storing all features, this invention introduces a Greedy Coreset Sampling algorithm. A most representative subset is selected from the pool to serve as the memory. This process aims to find an optimal subset. The objective function is shown in equation (2), which minimizes the distance from any point in the original set to the subset.

[0125]

[0126] in, This means that for each point in the large set... In the selected non-parametric feature memory Find the nearest eigenvector in the array. And calculate the distance between them, which measures the subset. For a single sample The degree of approximation. The complete collection Relative to subset The one-way Hausdorff distance represents the worst-case coverage radius of the current memory bank when covering the feature space distribution. Represents all possibilities, with a size of Find a specific subset from a set of subsets. This minimizes the coverage radius in the worst-case scenario.

[0127] Through this step, the system establishes a compact reference benchmark that covers the feature space of normal samples. This memory... This will serve as the core basis for subsequent anomaly detection.

[0128] Step 3: Generate coarse anomaly prior distribution

[0129] Based on the constructed memory, the system defines a non-parametric anomaly measurement mechanism to generate a coarse anomaly prior map. This mechanism is used for the local feature vectors of the test sample. The system calculates its relationship with the memory bank. Nearest neighbor Euclidean distance of all eigenvectors This is used to quantify the degree of anomaly at that location. The distance calculation formula is shown in equation (3).

[0130]

[0131] To enhance discriminative power, the system introduces cosine similarity as a penalty term to correct for distance. Subsequently, the scores of all spatial locations are reconstructed into a two-dimensional matrix. And through bilinear interpolation Upsample it to the original image size to generate a coarse anomaly prior map. .this It provides a global location prior for anomalous regions, but due to the low resolution of the feature layer, its edges are usually blurry and lack pixel-level geometric precision.

[0132] Step 4: Construct a multi-source feature parallel encoding network

[0133] To refine the coarse prior, this invention designs a trainable parameterized filtering network (ScoreMapFilter). This network contains four parallel encoding branches, each used to extract information from different modalities:

[0134] (i) Semantic coding branch: receives features from the backbone network respectively. and Through convolution operations and residual module By compressing and unifying the channel dimensions, semantic features are obtained. and .

[0135] (ii) Prior coding branch: receiving coarse anomalous prior graph Map it to high-dimensional features This is used to guide the network to focus on areas suspected of being abnormal.

[0136] (iii) Texture encoding branch: directly receives the original image. High-frequency edges and texture details are extracted using a shallow convolutional network to obtain the features of the original image. The unified representation of the calculation process for each branch is shown in equation (4):

[0137]

[0138] in, This represents the nonlinear mapping function for each branch. This design ensures that the network can simultaneously utilize deep semantic consistency, statistical priors from the memory bank, and the physical details of the original graph.

[0139] Step 5: Construct attention-guided feature fusion and decoder

[0140] This is the core innovation of this architecture, aiming to dynamically modulate feature responses using prior information. The system introduces a spatial attention gate mechanism, utilizing prior features... Generate a spatial attention map and perform element-wise product on semantic features.

[0141] First, through the Sigmoid activation function Prior features will be transformed into attention weights. Then, this weight is applied to the semantic features. .in, The Hadamard product represents the element-wise multiplication operation of two tensors at their spatial locations, i.e. This operation acts as a differentiable spatial filter, forcing the network to discard elements from the prior graph. The semantic features with low response are analyzed, while the feature responses of suspected abnormal regions are preserved or enhanced. Finally, the weighted semantic features are... Prior features Features of the original image The data is concatenated along the channel dimension and then input into a cascaded decoding network. The decoder restores spatial resolution through a series of upsampling and convolution operations, and finally outputs a detailed anomaly probability map through the sigmoid function. :

[0142]

[0143] Thus, the model has completed the construction process from "coarse estimation based on distance" to "fine segmentation based on multi-source information fusion".

[0144] Model training phase

[0145] The core task of this stage is to train the multi-source feature fusion filtering network (ScoreMapFilter). Since it is difficult to obtain a large amount of real defect data in industrial scenarios, this invention adopts a self-supervised learning strategy based on real anomaly data and synthetic data. The synthetic data is automatically synthesized into realistic simulated defects through an algorithm, forcing the network to learn how to reconstruct fine defect contours from coarse prior information. If reliable real data is available, real defect data and synthetic data can be mixed for training to enhance the model's adaptability to different scenarios. The specific implementation steps for synthetic data are as follows:

[0146] Step 1: Construct the synthetic anomaly sample space online

[0147] To enable the model to generalize to unknown defect morphologies, an online data augmentation pipeline was constructed to generate training samples in real time during training iterations. This pipeline abandons the simple geometric cut-and-paste approach used in traditional methods, instead employing a multi-octave stacking algorithm to generate a two-dimensional Perlin noise field. This is used to simulate the continuous, random, and irregular physical texture changes of fluids or object surfaces in nature. The mathematical generation process is achieved by superimposing basis noise functions of different frequencies and amplitudes, as defined in equation (6).

[0148]

[0149] in, Represents the basis noise function. It is the frequency multiplication factor. This is a persistence parameter, obtained by accumulating... The noise at each frequency layer generates a texture that contains both macroscopic structure and microscopic detail. After generating the noise field, the system performs threshold truncation to determine the binarized shape mask of the defects. To avoid overly obvious jagged edges due to artificial synthesis, the system... Gaussian blurring is applied to obtain a continuously varying transparency blending mask, denoted as . Based on this, images of the foreign object source were selected. By using a linear interpolation formula, it can be naturally integrated into normal industrial images. In the process, synthetic anomalous images are generated. The mathematical representation of the process is shown in equation (7).

[0150]

[0151] This process not only simulates foreign object attachment but also simulates uneven illumination by introducing a low-frequency noise field, thus constructing a model from the input image. To supervise the label The complete paired training data effectively solves the cold start problem of training data.

[0152] Step 2: Hybrid Forward Propagation with Gradient Truncation

[0153] After constructing the synthetic data, the system inputs the images into a hybrid network architecture to perform forward propagation with gradient truncation. The unique aspect of this process is the clear distinction between the instruction module and the learning module. Feature extraction backbone network. With memory bank As a teaching module, its parameter set By keeping the data frozen throughout training and not participating in gradient updates, the baseline distribution of the feature space is ensured not to drift due to the introduction of synthetic data. (Input image) First, the freezing module generates a coarse anomaly prior map based on memory retrieval. Subsequently, this prior image, along with the intermediate layer features of the backbone network and the original image, is input into the trainable filtering network (ScoreMapFilter). The filtering network, as a learning module, has parameters... Responsible for fitting precise segmentation results. The system's predicted output. This can be formally described as a nonlinear mapping of multi-source information by a filtering network:

[0154]

[0155] in, This indicates that the frozen backbone network is from the anomalous image. The features extracted from the image are shown in the formula. This formula indicates that the output of the filtering network depends not only on the image features, but also, more explicitly, on the prior guidance provided by the freezing module, which greatly reduces the difficulty of model convergence.

[0156] Step 3: Construct the binary segmentation objective function

[0157] To quantify the difference between the model's predictions and the synthesized ground truth, the system constructs a pixel-level binary segmentation objective function. Considering the extreme imbalance between positive and negative samples (defects and background) and numerical stability in the segmentation task, this invention employs a binary cross-entropy loss function with logits (BCEWithLogitsLoss). For any pixel in the image domain... Let its corresponding synthetic truth label be (Taken from binary mask) The unnormalized response values ​​(Logits) output by the model are: Then the average loss function of the entire graph Defined as:

[0158]

[0159] The physical meaning of this loss function is that in regions where the synthetic mask indicates defects, the model's output response is forced to approach 1; while in background regions, the response is forced to approach 0. Through this pixel-by-pixel penalty mechanism, the model is forced to focus on those areas indicated by defects. It indicates areas with blurred edges and uses the texture information of the original input image to correct the boundaries of these areas.

[0160] Step 4: Parameter Iteration and Optimization

[0161] Finally, the system performs parameter iteration and optimization based on the calculated loss gradient. An Adaptive Moment Estimation Optimizer (AdamW) is employed, utilizing the backpropagation algorithm to calculate the loss function relative to the filter network parameters. gradient Parameter updates follow the gradient descent principle, and the update rule is as follows:

[0162]

[0163] in For learning rate, and These are the first and second moments of the gradient, respectively. To ensure numerical stability and smoothness, a denominator of 0 is introduced at the beginning of training due to the gradient being close to 0. Since the gradients of the preceding modules are truncated, this update process only changes the weights of the filtering network. After multiple rounds of iterative training, the filtering network gradually learns a general "denoising and refinement" capability, that is, it can transform coarse, low-resolution anomalous prior images into fine-grained segmentation images with the same resolution as the original image and clear edges, thus realizing the transfer of capabilities from unsupervised feature extraction to supervised pixel segmentation.

[0164] (III) Forward Reasoning Stage:

[0165] The forward inference phase is the execution process of the technical solution of this invention on an actual industrial production line. In this phase, parameter updates are no longer performed; instead, the trained hybrid model is used to perform anomaly detection and fine segmentation on the real-time acquired images. The specific implementation process is as follows:

[0166] Step 1: Image Acquisition and Tensor Preprocessing

[0167] The system first acquires test images of the object to be inspected using an industrial camera. To adapt to the input specifications of deep neural networks, standardized preprocessing operations need to be performed on the original images. First, bicubic interpolation is used to adjust the images to a fixed resolution consistent with that used in the training phase. The processed image is obtained. Subsequently, the image data was normalized by subtracting the statistical mean of the ImageNet dataset. Divide by the standard deviation Map it to a numerically stable floating-point tensor The calculation formula is shown in equation (11).

[0168]

[0169] This step ensures numerical stability and consistency in the subsequent feature extraction process by eliminating low-frequency data drift caused by different lighting conditions or sensor gain differences.

[0170] Step 2: Multi-scale feature extraction and coarse prior generation

[0171] Preprocessed tensors Feature extraction backbone network fed into parameter-frozen network The system extracts the output tensors from the intermediate and deep layers of the network to construct a multi-scale feature pyramid containing texture and semantic information. Simultaneously, to obtain global anomaly priors for the image, the system performs optimal memory-based processing on the extracted local feature vectors. Non-parametric retrieval. For each spatial location on the feature map. The system extracts its corresponding local feature vectors. The minimum Euclidean distance between this vector and the feature vectors of all normal samples in the memory is calculated. This distance value is directly mapped to the anomaly confidence score at that location. The calculation formula is the same as that in equation (3). Subsequently, the scores of all spatial locations are reorganized into a two-dimensional matrix. And through bilinear interpolation Upsample it to the original image size to generate a coarse anomaly prior map. .

[0172] Step 3: Refined Segmentation Reasoning Based on Prior Guidance

[0173] To correct the coarse prior and restore pixel-level details, the system then activates the trained parameterized filtering network (ScoreMapFilter). This network simultaneously receives three data streams: backbone network features containing rich semantics, a coarse prior map indicating the probability distribution of anomalies, and a coarse prior map indicating the probability distribution of anomalies. and the preprocessed input tensor Within the network, the coarse prior image is transformed into spatial attention weights, which are used to weight the deep semantic features of the backbone network point by point, forcing the network to focus on suspected anomaly regions; simultaneously, the original image branches directly access the network through shallow convolutions. High-frequency edge information is extracted to supplement the spatial details lost in the deep features. These three information streams are non-linearly fused in the decoder, ultimately outputting a fine-grained anomaly probability prediction map with the same resolution as the original image. This process is described by the following mapping function:

[0174]

[0175] in, This represents the filter network function after training. The optimized network parameters are shown in the formula. This formula indicates that the final prediction result is the product of the deep coupling of the original physical texture, deep semantic features, and statistical distribution priors in the parameterized network.

[0176] Step 4: Binarization Segmentation and Anomaly Region Localization

[0177] To output intuitive quality inspection results, the system needs to transform continuous probability prediction maps into explicit defect location masks. The system introduces a preset confidence threshold. For fine probability maps Binarization truncation is performed. To further eliminate tiny isolated noise points caused by sensor noise or background texture, the system applies a structuring element. Morphological opening is used to filter the binary image to generate the final anomaly segmentation mask. :

[0178]

[0179] in, This is an indicator function, taking the value 1 if the condition is met and 0 otherwise. Based on this mask... The system further executes a connected component analysis algorithm to extract the topological contours of all independent abnormal regions in the mask and calculate their minimum bounding rectangle, thereby accurately framing the specific location of the defect on the original image and realizing the transformation from pixel-level probability prediction to instance-level defect localization.

[0180] Because of the adoption of the above technical solution, the present invention has the following characteristics:

[0181] 1. Cascaded Coupled Network Architecture of Parametric Prior Guidance and Parametric Fine Filtering

[0182] This application proposes a unique hybrid deep learning topology, using a frozen feature extractor and memory module as the front-end system and a trainable multi-source feature fusion filtering network as the back-end system, with the two deeply coupled sequentially. Logically, the front-end system generates coarse anomaly location priors based on non-parametric nearest neighbor search, while the back-end system refines these priors using parametric convolutional networks. This design significantly differs from traditional end-to-end fully supervised segmentation networks or purely unsupervised reconstruction networks. By explicitly freezing the weight parameters of the front-end backbone and memory during training, and only performing gradient updates on the back-end filtering network, it effectively decouples feature distribution stability from edge segmentation flexibility.

[0183] 2. Spatial Attention Gating Mechanism Based on Coarse Priors

[0184] This application designs a specific feature fusion component, namely a spatial attention gating unit (step 5). The core logic of this component lies in using the coarse anomaly prior map generated in the previous stage as a guiding signal, and transforming it into a spatial attention weight mask through a nonlinear activation function. In the feature fusion stage, this weight mask is multiplied element-wise with the deep semantic features extracted by the backbone network (Hadamard Product). This mechanism mathematically constructs a differentiable spatial filter that can dynamically suppress the feature response of the background region according to the prior distribution and significantly enhance the semantic expression of suspected anomaly regions, thereby solving the feature interference problem caused by simple splicing in traditional methods and ensuring that the filtering network can focus on statistically significant anomaly regions.

[0185] 3. Direct injection of original physical details and multimodal feature fusion strategy

[0186] To address the issue of spatial information loss caused by downsampling operations in existing feature embedding-based methods, this application designs an independent original image encoding branch in the filtering network. This branch directly receives the unsampled original high-resolution image tensor, extracts high-frequency physical texture and edge details through shallow convolution operations, and then concatenates and fuses them with attention-weighted deep semantic features and prior features along the channel dimension. This multimodal fusion strategy constructs a complete feature space encompassing semantic consistency, statistical anomalies, and physical geometric boundaries, enabling the decoder to accurately recover pixel-level contours of minute defects using directly connected original texture features, even in the absence of deep spatial information.

[0187] 5. An online self-supervised sample synthesis method based on Perlin noise.

[0188] This application proposes a cold-start training method that does not require real defect samples, constructing an online data augmentation pipeline based on Perlin noise. This method abandons simple geometric cut-and-paste, instead utilizing a multi-octave stacking algorithm to generate a two-dimensional noise field with continuous, random, and natural texture features. By thresholding and Gaussian blurring the noise field, a transparency fusion mask with gradient edges is generated, naturally blending foreign object textures or lighting perturbations into the normal image. This strategy can synthesize training data that statistically closely approximates real physical defects in real time, even with only normal samples. If usable real anomalous samples are available, the two can be mixed to further enhance the model's adaptability to the scene. Furthermore, a binary cross-entropy loss function drives the network for self-supervised learning, effectively solving the problem of small-sample generalization in industrial scenarios.

[0189] Compared with current mainstream unsupervised anomaly detection techniques based on feature embedding (such as PatchCore) and general fully supervised segmentation frameworks (such as MMSeg), this proposal has significant technical advantages in terms of detection accuracy, feature utilization, and deployment cost.

[0190] 1. Achieved an improvement from coarse heatmap localization to pixel-level fine segmentation.

[0191] Existing PatchCore technology is limited by the downsampling mechanism of convolutional neural networks (typically 1 / 8 or 1 / 16 resolution) and the Gaussian smoothing operation in the post-processing stage. The resulting anomalous heatmaps often have blurred and diffuse edges, making it difficult to accurately reconstruct the geometric boundaries of minute defects (such as scratches on wine bottles) or complex-shaped defects. In contrast, this application proposes to introduce a parameterized filtering network and direct-connection branches to the original image, utilizing the high-frequency texture information of the original image to perform pixel-level modification and reconstruction of the coarse prior heatmap. Figure 4 , Figure 5 The image shows a comparison of the output results of the original PatchCore and the method proposed in this invention after inference on the same image. The results show that the binarized mask output by the method proposed in this invention can closely fit the real physical contour of the defect, significantly improving the positioning accuracy and morphological restoration of the defect.

[0192] 2. Significantly improved the utilization rate of feature tensors and the ability to resist background interference.

[0193] Traditional unsupervised detection methods typically rely solely on the distance scalar between feature vectors as the sole criterion for anomaly detection, discarding the rich semantic and textural context information originally contained in the feature tensors of the intermediate layers of the backbone network. This leads to false positives when the model encounters workpieces with complex texture backgrounds. This proposal addresses this issue by employing a multi-source feature fusion mechanism to re-minimize and utilize deep and intermediate features of the backbone network, and organically combining these features with anomaly priors through a spatial attention mechanism. This enables the model to not only perceive distance but also understand texture structure, effectively distinguishing normal texture abrupt changes from genuine defects and significantly enhancing its robustness in complex industrial environments.

[0194] 3. It balances the cold-start capability of unsupervised learning with the segmentation accuracy of supervised learning.

[0195] In the field of industrial quality inspection, purely unsupervised methods have strong generalization but limited accuracy, while fully supervised segmentation methods have high accuracy but rely on massive amounts of annotation and cannot identify unknown defects. This application creatively combines the advantages of both: on the one hand, a frozen memory module ensures that the model does not forget the distribution characteristics of normal samples, guaranteeing a broad-spectrum capture capability for unknown anomalies; on the other hand, a filtering network trained on synthetic data endows the model with a keen ability to capture defect boundaries. This hybrid architecture enables the system to achieve segmentation performance close to that of a fully supervised model without requiring any real defect sample annotations, greatly reducing the deployment threshold and data maintenance costs on the production line.

[0196] 4. Modular decoupling and high scalability of the architecture

[0197] The hybrid architecture proposed in this application is highly modular and possesses excellent engineering scalability. Since the feature extraction module and the filtering module are decoupled during training, industrial users can flexibly replace different backbone networks (such as switching from ResNet to EfficientNet or ViT) according to the computing power limitations or accuracy requirements of the actual production line, without having to reconstruct the backend filtering network architecture.

Claims

1. An industrial image anomaly detection method based on multi-source feature fusion and synthetic anomaly enhancement, characterized in that, Includes the following steps: Step 1: Construct a frozen multi-scale feature extractor. Select a convolutional neural network pre-trained on a large-scale dataset as the backbone network, freeze all its weight parameters, and extract multi-scale feature maps from different levels of the backbone network. Step 2: Construct a non-parametric feature memory library, and use a greedy core set sampling algorithm to select the most representative feature subset from the feature set of normal samples as a reference benchmark for the distribution of normal samples; Step 3: Generate a coarse anomaly prior distribution, calculate the nearest neighbor distance between the local features of the test image and the features in the non-parametric feature memory, obtain the anomaly score map, and obtain a coarse anomaly prior map with the same size as the original image through upsampling operation; Step 4: Construct a multi-source feature parallel encoding network, including multiple parallel branches that process the multi-scale feature map, the coarse anomaly prior map, and the original input image respectively, to generate semantic features, prior features, and texture features; Step 5: Construct attention-guided feature fusion and decoder, generate spatial attention weights using the prior features, perform element-wise weighting on the semantic features, and then fuse them with the texture features. Output a detailed anomaly probability map through the decoding network. Step 6: Generate synthetic anomalous samples based on the Berlin noise field. A two-dimensional Berlin noise field is generated by multi-octave band superposition algorithm. After threshold truncation and Gaussian blurring, a transparency fusion mask is generated. The foreign object source image is fused with the normal industrial image to construct training data. Step 7: Perform hybrid forward propagation under gradient truncation, keeping the parameters of the frozen multi-scale feature extractor and non-parametric feature memory unchanged, and only updating the parameters of the multi-source feature parallel encoding network and attention-guided feature fusion and decoder, and optimizing the network weights through the binary segmentation objective function; Step 8: Perform forward inference, preprocess the test image, input it into the trained network, generate a detailed anomaly probability map, and obtain the final anomaly region localization result through threshold truncation and morphological operations.

2. The method according to claim 1, characterized in that, Step 1 includes the following sub-steps: Step 1.1: Initialize a Wide_ResNet_50_2 network pre-trained on the ImageNet dataset as the backbone feature extractor. The backbone feature extractor Φ is used to extract multi-scale features from the input image; Step 1.2: Select the middle and deep layers of the backbone feature extractor Φ as feature output nodes, for the input image tensor ,feature The extraction process is represented as follows: in, This represents the feature set of the input image I. This represents a Layer 2 layer feature containing rich texture details. This represents Layer 3 features containing semantic structure, where C is the number of channels in the input image, and H and W are the height and width of the input image, respectively. and These are the channel dimensions of the features in Layer2 and Layer3, respectively. Step 1.4: During the entire model building and subsequent training process, freeze all weight parameters of the backbone feature extractor. ,Right now This is to ensure the stability of the feature space distribution and prevent the model from overfitting or feature collapse under small sample conditions.

3. The method according to claim 1, characterized in that, Step 2 includes the following sub-steps: Step 2.1: Construct a non-parametric feature memory Iterate through all normal training samples Extract its in and The features of the layer are analyzed and locally aggregated in the spatial dimension to form a set of local feature vectors. ; Step 2.2: Employ a greedy core set sampling algorithm to sample the local feature vector set. The most representative subset is selected as the memory bank, and this process is achieved by solving the following mathematical optimization problem: in, This means that for each point in the large set... In the selected non-parametric feature memory Find the nearest eigenvector in the array. And calculate the distance between them, which measures the subset. For a single sample The degree of approximation; The complete collection Relative to subset The one-way Hausdorff distance represents the worst-case coverage radius of the current memory bank when covering the feature space distribution; Represents all possibilities, with a size of Find a specific subset from a set of subsets. This minimizes the coverage radius of the worst-case scenario. Step 2.3: Calculate the optimal subset obtained from the solution. As a non-parametric feature memory, it serves as a reference benchmark in the subsequent anomaly detection process.

4. The method according to claim 1, characterized in that, Step 3 includes the following sub-steps: Step 3.1: Based on the constructed memory Define a non-parametric anomaly measurement mechanism for the local feature vector of the sample to be tested. Calculate its relationship with the memory bank Nearest neighbor Euclidean distance of all feature vectors in This quantifies the degree of anomaly at that location. The distance calculation formula is as follows: in, Indicates the spatial location of the sample to be tested. Local feature vectors at that location Show memory bank The feature vector in Represents the Euclidean distance norm; Step 3.2: Introduce cosine similarity as a penalty term to correct the calculated distance, thereby enhancing the accuracy of anomaly detection; Step 3.3: Reorganize the corrected scores of all spatial locations into a two-dimensional matrix. ,in and These represent the height and width of the feature map, respectively. Step 3.4: Using bilinear interpolation The two-dimensional matrix S is upsampled to the original image size to generate a coarse anomaly prior map: in, It provides a global location prior for anomalous regions.

5. The method according to claim 1, characterized in that, Step 4 includes the following sub-steps: Step 4.1: Construct a multi-source feature parallel coding network, which is a trainable parameterized filtering network containing three parallel coding branches; Step 4.2: In the semantic coding branch, receive the multi-scale feature maps extracted by the backbone network. and Semantic features are generated by compressing and unifying the channel dimensions through convolution operations and residual modules. and ; Step 4.3: In the prior coding branch, receive the coarse anomaly prior map. Through nonlinear mapping functions Map it to high-dimensional features This is used to guide network attention to areas suspected of being abnormal. Step 4.4: In the texture coding branch, the original input image I is directly received, and high-frequency edges and texture details are extracted through a shallow convolutional network to generate texture features. ; Step 4.5: The calculation process for each branch is uniformly represented as follows: in, This represents the feature of the output of the k-th branch. This represents the nonlinear mapping function of the k-th branch. This represents the input data for the k-th branch.

6. The method according to claim 5, characterized in that, Step 5 includes the following sub-steps: Step 5.1: Construct an attention-guided feature fusion and decoder. The decoder introduces a spatial attention gating mechanism, uses prior features to generate spatial attention weights, and dynamically modulates semantic features. Step 5.2: Activate prior features using the Sigmoid activation function σ(∙). Transformed into attention weight α: Where α represents the spatial attention weight, with a value between 0 and 1, and H and W are the height and width of the input image, respectively; Step 5.3: Apply the attention weight α to the semantic feature Esem and perform element-wise weighting to obtain the weighted semantic feature. : Where ⨀ represents the Hadamard product, which is the element-wise multiplication of two tensors in space. The specific calculation method is as follows: , These represent the spatial coordinates of the feature map; Step 5.4: Weight the semantic features Prior features With texture features The data is spliced ​​and merged along the channel dimension to form a fusion feature; Step 5.5: Input the fused features into the cascaded decoding network. In the process, spatial resolution is restored through a series of upsampling and convolution operations, and finally a fine-grained anomaly probability map is output through the sigmoid function: in, This represents the anomaly probability map of the final output, where σ represents the Sigmoid activation function, Decoder represents the decoding network function, and [⋅,⋅,⋅] represents the concatenation operation along the channel dimensions.

7. The method according to claim 6, characterized in that, Step 6 also includes the following steps: Step 6.1: A two-dimensional Berlin noise field P(x,y) is generated using a multioctave superposition algorithm. This generation process involves superimposing fundamental noise functions of different frequencies and amplitudes. The mathematical expression is as follows: in, This represents the generated two-dimensional Berlin noise field. The base noise function is represented by f, the frequency multiplication factor is β, the persistence parameter is K, the number of superimposed noise layers is K, and x and y represent the spatial coordinates. Step 6.2: Process the generated Berlin noise field Threshold truncation is performed to determine the binary shape mask of the defect. ; Step 6.3: Perform Gaussian blurring on the binarized shape mask Mgt to generate a continuously varying transparency blending mask. ,in This represents the transparency value of the blending mask, ranging from 0 to 1; Step 6.4: Image of the foreign object source Compared with normal industrial images Through the transparency blending mask Perform natural fusion to generate synthetic anomalous images The mathematical expression for its fusion process is: in, This represents the generated synthetic anomalous image. This represents a normal industrial image. ⨀ represents the image of the foreign object source, and ⨀ represents the Hadamard product, which is the element-wise multiplication operation of two tensors in spatial position; Step 6.5: Combine the synthesized abnormal image and its corresponding binarized shape mask As training samples, a training dataset is constructed for subsequent model training.

8. The method according to claim 7, characterized in that, Step 6 includes the following steps: Step 7.1: Perform gradient-truncation hybrid forward propagation to synthesize the anomalous image. The input is fed into a hybrid network architecture, where the frozen multi-scale feature extractor Φ and the non-parametric feature memory M∗ serve as the teaching module, and its parameter set... The network remains frozen throughout training and does not participate in gradient updates; the multi-source feature parallel encoding network and the attention-guided feature fusion and decoder serve as learning modules, forming a trainable filtering network. Its parameters Participate in gradient update; Step 7.2: During the hybrid forward propagation process, the input image is processed... After normalization preprocessing, the data first passes through a frozen feature extraction module to generate multi-scale features. and rough anomaly prior map Then , and The common inputs are fed into a trainable filter network to generate the predicted output. : in, This represents a graph showing the anomaly probability predicted by the model. This represents the nonlinear mapping function of the filtering network. This indicates that the frozen backbone network is from the anomalous image. Features extracted from This represents the generated coarse anomaly prior map. Represents the set of trainable parameters for the filtering network; Step 7.3: Construct a binary segmentation objective function, and use a binary cross-entropy loss function with Logits to calculate the difference between the predicted result and the synthesized true value. Defined as: Where H and W are the height and width of the image, respectively. Indicates spatial location The synthesized truth label at the location is taken from the binarization mask. , σ(∙) represents the unnormalized response value output by the model at position (i,j), and σ(∙) represents the Sigmoid activation function. Step 7.4: Based on the calculated loss function, use the AdamW adaptive moment estimator to calculate the loss function relative to the filter network parameters. Find the gradient ∇θ and perform parameter updates: Where η is the learning rate. and These are the first and second moments of the gradient, respectively. For numerically stable smoothing terms; Step 7.5: Repeat steps 7.1 to 7.

4. Through multiple rounds of iterative training, the filtering network learns the ability to transform the coarse anomaly prior map into a fine anomaly segmentation map, thus completing the optimization of the network weights.

9. The method according to claim 8, characterized in that, Step 8 includes the following sub-steps: Step 8.1: Perform preprocessing on the test image. First, acquire the test image to be inspected using an industrial camera. A bicubic interpolation algorithm is used to adjust the image to a fixed resolution consistent with that used during the training phase. The processed image is obtained. ; then on Normalization is performed by subtracting the statistical mean μavg of the ImageNet dataset and dividing by the standard deviation σstandard to generate the preprocessed input tensor. : in, This represents the preprocessed input tensor. This represents the image after resolution adjustment. This represents the statistical mean of the ImageNet dataset. Indicates standard deviation; Step 8.2: Convert the preprocessed input tensor The input is fed into the parameter-frozen feature extraction backbone network Φ to extract multi-scale features, and then based on the non-parametric feature memory. Calculate the minimum Euclidean distance between the local feature vector and the feature vector of normal samples in the memory bank to generate a rough anomaly prior map. ; Step 8.3: Convert the input tensor Multi-scale features and rough anomaly prior map The input is fed into the trained filter network to generate a fine-grained anomaly probability map. : Where Ψ represents the trained filter network function. This represents the features extracted by the backbone network. The optimized network parameters; Step 8.4: Develop a detailed anomaly probability map Binarization segmentation and anomaly region localization are performed, and a preset confidence threshold τ is introduced. Perform binarization truncation and apply the structuring element as... The morphological opening operation is used to filter the binary image to generate the final anomaly segmentation mask. : in, This represents the final anomaly segmentation mask. This represents the morphological opening operation, where l is the indicator function, taking the value 1 if the condition is met and 0 otherwise, and τ is a preset confidence threshold. Structural elements for morphological operations; Step 8.5: Based on the aforementioned anomaly segmentation mask The connected component analysis algorithm is executed to extract the topological contours of all independent anomalous regions and calculate their minimum bounding rectangle, thereby accurately locating the anomalous regions on the original image.

10. An industrial image anomaly detection system based on multi-source feature fusion and synthetic anomaly enhancement, characterized in that, The system operates by implementing the method as described in any one of claims 1-8.