Industrial surface anomaly detection method based on multi-scale difference perception

By employing a multi-scale difference perception method, the accuracy and robustness of industrial surface anomaly detection are enhanced. This method solves the problems of over-reconstruction and unclear localization in anomaly detection against complex texture backgrounds, and enables precise localization of subtle defects.

CN122368630APending Publication Date: 2026-07-10SOUTH CHINA UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SOUTH CHINA UNIV OF TECH
Filing Date
2026-04-27
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing industrial surface anomaly detection methods are prone to over-reconstruction in complex texture scenarios, making it difficult to take into account both local minor defects and global structural information, resulting in unclear anomaly detection results and insufficient positioning accuracy.

Method used

A multi-scale difference perception-based approach is adopted, which enhances the feature representation capability of abnormal regions, reduces background noise interference, and improves detection accuracy by using a parameter-frozen teacher encoder, student decoder, scale residual aggregation module, anomaly perception contrastive learning constraint, and multi-scale difference perception module.

Benefits of technology

It significantly improves the accuracy and robustness of anomaly detection against complex texture backgrounds, enabling precise localization of subtle defects, reducing background noise interference, and lowering development costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122368630A_ABST
    Figure CN122368630A_ABST
Patent Text Reader

Abstract

The present application mainly aims at the problems that the existing industrial surface anomaly detection method is easy to be interfered by background noise, the anomaly feature representation is insufficient and the positioning accuracy is not high in the complex texture background, and discloses an industrial surface anomaly detection method based on multi-scale difference perception, which comprises the following steps: (1) obtaining a normal image of an industrial surface, and constructing a synthetic abnormal image and a corresponding abnormal mask; (2) performing feature extraction on the normal image and the synthetic abnormal image obtained in step 1, obtaining multi-scale teacher features and enhancing the multi-scale teacher features; (3) inputting the enhanced features obtained in step 2 into a student decoder for reconstruction, and combining the abnormal mask obtained in step 1 to apply abnormal perception contrast constraint; (4) performing multi-scale difference fusion on the reconstructed features obtained in step 3 and completing segmentation network training; (5) using the trained model obtained in step 4 to infer the image to be detected, and outputting a pixel-level abnormal positioning result.
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, specifically to an industrial surface anomaly detection method based on multi-scale difference perception. Background Technology

[0002] With the continuous improvement of industrial intelligence, machine vision-based surface anomaly detection technology has been widely used in product quality inspection, defect identification, and production process monitoring. Most existing industrial surface anomaly detection methods are based on deep learning models, which learn the feature distribution of normal samples to detect and locate abnormal regions. Among them, the teacher-student architecture based on knowledge distillation is widely used in unsupervised anomaly detection tasks because it does not require a large number of anomaly samples.

[0003] However, existing technologies still have certain shortcomings in complex industrial surface texture scenarios. On the one hand, when the image to be detected contains fine-grained textures, periodic backgrounds, or high-frequency structural information, the student network is prone to over-reconstruction of anomalous regions, leading to a weakening of the feature differences between the teacher and student networks in anomalous regions, thus affecting the anomaly detection results. On the other hand, existing methods often use fixed rules for combination during multi-scale feature fusion, making it difficult to take into account both local subtle defects and global structural information, easily resulting in unclear boundaries of the anomaly response map and insufficient localization accuracy. Therefore, there is an urgent need to propose an industrial surface anomaly detection method that can enhance the ability to discriminate anomaly regions and improve the accuracy of anomaly localization. Summary of the Invention

[0004] The purpose of this invention is to overcome the shortcomings and deficiencies of the prior art and propose an industrial surface anomaly detection method based on multi-scale difference perception. This method enables effective detection and accurate localization of abnormal areas on industrial surfaces against complex texture backgrounds, effectively enhances the ability to characterize abnormal features, reduces background noise interference, and improves the accuracy and robustness of industrial surface anomaly detection.

[0005] This invention discloses an industrial surface anomaly detection method based on multi-scale difference perception. This method achieves anomaly detection on industrial surfaces based on an anomaly detection model. The anomaly detection model includes a parameter-frozen teacher encoder, a student decoder, a scale residual aggregation module with a bottleneck layer, anomaly perception contrastive learning constraints, a multi-scale difference perception module, and a segmentation network. The specific implementation of this method includes the following steps:

[0006] S1. Obtain a normal image of the industrial surface, and generate a synthetic abnormal image containing a pseudo-abnormal region based on the normal image, a pre-selected external texture image and random noise. At the same time, generate a corresponding synthetic abnormal mask, and construct a training set using the normal image, the synthetic abnormal image and the synthetic abnormal mask. S2. Input the training set into the anomaly detection model and train it. The training process is as follows: S21. The normal image and the synthetic abnormal image are respectively input into the teacher encoder with frozen parameters to extract multi-scale normal teacher features and multi-scale abnormal teacher features. S22. The multi-scale teacher anomaly features are enhanced using the scale residual aggregation module. The specific process includes: The multi-scale teacher anomaly features are preprocessed using spatial filtering via a coordinate attention mechanism. A projection layer maps the preprocessed features to a compact manifold space, and a cosine embedding loss is introduced as a normality alignment constraint. Feature residuals between adjacent scales are calculated to suppress background texture noise and enhance high-frequency anomaly-related information, resulting in preliminary enhanced teacher features. These preliminary enhanced teacher features are then input into the bottleneck layer within the module, where a residual mapping structure is used to perform feature compression and reconstruction, outputting a compact feature representation for use by the student decoder. S23. Input the enhanced teacher features output by the bottleneck layer into the student decoder for multi-scale feature reconstruction, and perform anomaly perception contrastive learning constraints based on the synthetic anomaly mask to drive the student decoder to fit multi-scale normal teacher features in normal regions and generate student features that differ from multi-scale teacher anomaly features in abnormal regions. S24. Calculate the cosine distance between teacher abnormal features and student abnormal features at the same scale using the multi-scale difference perception module, generate abnormal attention maps at each scale, and use the abnormal attention maps to perform weighted modulation on the spliced ​​features of teacher abnormal features and student abnormal features at the same scale to obtain fused multi-scale features. S25. Input the fused multi-scale features into the segmentation network to generate pixel-level anomaly localization results, and calculate the loss between the pixel-level anomaly localization results and the synthesized anomaly mask based on a preset multi-task objective function. Update the network parameters through backpropagation to complete the training of the anomaly detection model. S3. In the inference stage, the industrial image to be detected is input into the trained anomaly detection model, which can then output the pixel-level anomaly localization results of the industrial image to be detected.

[0007] The specific implementation method in step S1 is as follows: Given a normal image ,in Represents the set of real numbers. This represents the height, width, and channel dimensions of the input image tensor. This indicates that the input is normal; the foreground mask is obtained using the GrabCut background culling algorithm. Then generate a random Perlin noise mask. The intersection of the anomaly mask with the foreground mask is then used to obtain the final synthetic anomaly mask. : , in, Represents element-wise product. Indicates background, Indicates noise. Indicates an anomaly; Select the pre-selected external texture image Compared with normal images Perform linear interpolation to construct a synthetic anomalous image. : , in, This is the opacity coefficient, used to control the prominence of anomalies, and ; Indicates an anomaly. The name of the pre-selected external texture dataset.

[0008] The specific implementation method in step S21 is as follows: Synthesize abnormal images and normal image Input to the teacher encoder with the parameters frozen Extracting normal features of teachers at multiple scales and multi-scale abnormal characteristics of teachers .in, Wide_ResNet50 was used as the backbone network. This indicates that it is normal. Indicates an anomaly. This represents different network output scales. .

[0009] The specific implementation method in step S22 is as follows: In the designed scale residual aggregation module, the original multi-scale teacher anomaly features are first processed. A coordinate attention mechanism is applied as a spatial filter, and then a learnable projection layer is used to map the filtered features onto a compact manifold space to obtain the projected features. : , in, This indicates coordinate attention operations. This refers to the projection layer operation designed in the scale residual aggregation module, specifically, using... Convolutional layer followed by Normalization and The activation function is used to construct the projection layer, and its expression is: , in, for Convolution kernel parameters, For bias terms; In this process, cosine embedding loss is introduced. As a normality alignment constraint, abnormal texture patterns are forced to be repaired by forward normal patterns, thereby limiting the propagation of abnormal features. Its loss function is expressed as: , in, This represents the dot product operation. express Norm, This represents the normal characteristics of teachers. This represents the projected features of abnormal teacher characteristics after being projected through the projection layer. For projection features of two adjacent scales Let the deep-scale features be denoted as Shallow scale characteristics are Then, scale residual features are constructed and fused through upsampling and convolution: , in, Representing residual characteristics, This indicates the initial enhancement of teacher characteristics after fusing residual features. Indicates an upsampling operation. and These represent the kernel size as follows: and Convolution operations; Subsequently, the aforementioned preliminary enhancement of teacher characteristics will be implemented. The bottleneck layer within the scale residual aggregation module is input, and the classic ResNet bottleneck structure adopted by the bottleneck layer is used to perform feature compression and reconstruction to output a compact feature representation for use by the student decoder. The scale residual aggregation module significantly improves the model's ability to perceive subtle anomalies through the synergistic effect of the coordinate attention mechanism and the scale residual mechanism. First, by using the coordinate attention mechanism to capture long-distance spatial dependencies in the horizontal and vertical directions, it can accurately locate and filter out common periodic background textures or high-frequency structural noise in industrial images. Second, by calculating the feature residuals between adjacent scales, it can effectively cancel redundant background information that recurs at different resolutions, thereby highlighting local abnormal high-frequency signals such as tiny scratches and cracks. Finally, a bottleneck layer is introduced to perform nonlinear compression and reconstruction of the aggregated features. While eliminating redundant feature dimensions, the most core normal texture distribution semantics are preserved. This not only provides a high-quality feature benchmark for the lightweight reconstruction of the subsequent student network, but also further enhances the robustness of the model in complex industrial contexts.

[0010] The specific implementation method in step S23 is as follows: The compact feature representation output by the bottleneck layer is input into the student decoder. Multi-scale student abnormal features were obtained. The student decoder uses an inverted Wide_ResNet50 network as its backbone to perform multi-scale feature reconstruction on the compact feature representation, so that the student decoder fits the feature distribution of the teacher encoder in the normal region. In the design of the anomaly perception contrastive learning constraint, the synthetic anomaly mask will be used. Bilinear interpolation downsampling yields the first... Anomaly mask corresponding to feature resolution at each scale ; using the aforementioned anomaly mask As a spatial selector, it constrains multi-scale student anomalous features within the normal region. Normal characteristics of teachers at multiple scales Alignment; and in anomalous regions, apply negative constraints to penalize students' anomalous characteristics. Multiscale Teacher Abnormalities Overly similar feature reconstruction behavior; this process is constrained by anomaly-aware contrastive learning. Perform overall optimization: , in, This refers to Anomaly-Aware Contrastive Learning. To prevent smooth terms with a denominator of zero; The cosine similarity function is used to drive student features to fit teacher features in the normal region by minimizing the numerator, and to penalize student features for generating feature reconstruction behavior similar to teacher features in the abnormal region by maximizing the denominator. The anomaly-aware contrastive learning constraint introduces a synthetic anomaly mask as a spatial selector, enabling precise control over the feature distribution of different regions. Compared to traditional knowledge distillation methods that only apply alignment constraints to normal regions, this scheme drives the student decoder to accurately fit teacher features in normal regions while applying negative constraints to anomaly regions using the denominator. This effectively breaks the identity mapping trap that the student decoder is prone to when facing high-frequency, fine-grained textures. This differentiated supervision mechanism can significantly suppress the over-reconstruction of anomaly regions by the student decoder, thereby widening the semantic distance between teacher and student features in anomaly regions, enhancing the model's ability to discriminate subtle defects, and significantly improving the accuracy and stability of anomaly detection on industrial surfaces against complex texture backgrounds.

[0011] The specific implementation method in step S24 is as follows: In the designed multi-scale difference perception module, for the first... Teacher Abnormalities at Various Scales Abnormal characteristics of students First, the anomaly attention map for this layer is obtained by calculating the pixel-level cosine distance. The calculation formula is as follows: , in, This represents the dot product operation. express Norm, Indicates scale.

[0012] Subsequently, abnormal characteristics of teachers at the same level were identified. Abnormal characteristics of students It is obtained by splicing along the channel dimension. And using the above attention map Spatial modulation of the spliced ​​features allows the network to focus on feature response regions highly correlated with anomalies. The modulated feature representation is as follows: : , , in, This indicates splicing by channel. element-wise multiplication Indicates the kernel size as Convolution operation, This indicates splicing by channel dimension. Indicates the output of the first One scale; The multi-scale difference perception module introduces pixel-level cosine distance calculation to transform the directional differences between the teacher and student networks in the feature space into explicit anomalous attention weights. This design breaks away from the empirical inference limitation of previous methods that simply sum the distances of multiple layers of features, achieving adaptive integration of difference information. This is achieved using attention maps. Spatial modulation of the splicing features essentially serves as a form of "feature purification," enabling the segmentation network to shield against interference responses from background textures and suppress spurious response regions, resulting in clearer and sharper anomaly localization results at defect boundaries.

[0013] The specific implementation method in step S25 is as follows: Attention Modulation Individual scale features After being upsampled to a uniform spatial resolution, the data is then stitched together along the channel dimension to guide the segmentation network in achieving precise localization and obtaining pixel-level anomaly localization results. : , The segmentation head consists of the classic bottleneck structure of the ResNet network, dilated convolution, and spatial pyramid pooling modules. This represents the pixel-level anomaly localization results output by the segmentation network. This indicates that the computation has been performed using dilated convolution and spatial pyramid pooling modules. This indicates that the classic bottleneck structure of the ResNet network is used for computation. Features at three scales; The anomaly detection model is optimized using an end-to-end approach via a loss function. During the training phase, anomaly masks are synthesized. Anomaly mask obtained after bilinear interpolation downsampling As a monitoring signal, it is combined with the cosine embedding loss in the scale residual aggregation module. Anomaly perception contrastive learning constraints Focus loss and average absolute loss Construct a multi-task objective function to achieve collaborative optimization of network parameters. Multi-task objective function The calculation is as follows: , in, and They are defined as follows: , , in, Represents the height and width of the input image tensor. For pixels The predicted probability of belonging to the true category. This represents the x and y coordinates of a pixel. Specifically, when... hour, ;when hour, . This is a focusing parameter used to adjust the degree of attention given to difficult-to-classify samples; The trained anomaly detection model is obtained after training is completed.

[0014] Compared with the prior art, the present invention has the following advantages: 1. This invention can improve the ability to distinguish abnormal regions against complex texture backgrounds. By setting anomaly perception contrastive learning constraints, the model's ability to represent feature differences between abnormal and normal regions is enhanced, thereby helping to improve anomaly detection performance.

[0015] 2. This invention can enhance the expression of subtle anomaly features. By setting up a scale residual feature aggregation module, multi-scale features are enhanced, background texture interference is reduced, and local anomaly information such as minute scratches and cracks is highlighted.

[0016] 3. This invention can improve pixel-level anomaly localization accuracy. By setting up a multi-scale difference perception module, features at different scales are adaptively fused, enabling the model to simultaneously consider local detail information and deep semantic information, thereby improving the accuracy of anomaly region boundary localization.

[0017] 4. This invention relies only on normal samples during model training, eliminating the need for manual annotation of defective samples. This reduces manual involvement in data preparation, thereby lowering development costs and shortening the system development cycle to some extent. Attached Figure Description

[0018] Figure 1 This is a general framework diagram of the present invention; Figure 2 For each of the designed modules (including the scale residual aggregation module, the anomaly perception contrastive learning constraint and the multi-scale difference perception module). Figure 3 This is a schematic diagram of the detection results of the present invention. Detailed Implementation

[0019] The present invention will be further described below with reference to embodiments, but this does not constitute any limitation on the present invention. Any limited modifications made by any person within the scope of the claims of the present invention are still within the scope of the claims of the present invention.

[0020] See Figures 1-3This invention discloses an industrial surface anomaly detection method based on multi-scale difference perception. This method achieves anomaly detection on industrial surfaces based on an anomaly detection model. The anomaly detection model includes a parameter-frozen teacher encoder, a student decoder, a scale residual aggregation module with a bottleneck layer, anomaly perception contrastive learning constraints, a multi-scale difference perception module, and a segmentation network. The specific implementation of this method includes the following steps: S1. Obtain a normal image of the industrial surface, and generate a synthetic abnormal image containing a pseudo-abnormal region based on the normal image, a pre-selected external texture image and random noise. At the same time, generate a corresponding synthetic abnormal mask, and construct a training set using the normal image, the synthetic abnormal image and the synthetic abnormal mask. S2. Input the training set into the anomaly detection model and train it. The training process is as follows: S21. The normal image and the synthetic abnormal image are respectively input into the teacher encoder with frozen parameters to extract multi-scale normal teacher features and multi-scale abnormal teacher features. S22. The multi-scale teacher anomaly features are enhanced using the scale residual aggregation module. The specific process includes: The multi-scale teacher anomaly features are preprocessed using spatial filtering via a coordinate attention mechanism. A projection layer maps the preprocessed features to a compact manifold space, and a cosine embedding loss is introduced as a normality alignment constraint. Feature residuals between adjacent scales are calculated to suppress background texture noise and enhance high-frequency anomaly-related information, resulting in preliminary enhanced teacher features. These preliminary enhanced teacher features are then input into the bottleneck layer within the module, where a residual mapping structure is used to perform feature compression and reconstruction, outputting a compact feature representation for use by the student decoder. S23. Input the enhanced teacher features output by the bottleneck layer into the student decoder for multi-scale feature reconstruction, and perform anomaly perception contrastive learning constraints based on the synthetic anomaly mask to drive the student decoder to fit multi-scale normal teacher features in normal regions and generate student features that differ from multi-scale teacher anomaly features in abnormal regions. S24. Calculate the cosine distance between teacher abnormal features and student abnormal features at the same scale using the multi-scale difference perception module, generate abnormal attention maps at each scale, and use the abnormal attention maps to perform weighted modulation on the spliced ​​features of teacher abnormal features and student abnormal features at the same scale to obtain fused multi-scale features. S25. Input the fused multi-scale features into the segmentation network to generate pixel-level anomaly localization results, and calculate the loss between the pixel-level anomaly localization results and the synthesized anomaly mask based on a preset multi-task objective function. Update the network parameters through backpropagation to complete the training of the anomaly detection model. S3. In the inference stage, the industrial image to be detected is input into the trained anomaly detection model, which can then output the pixel-level anomaly localization results of the industrial image to be detected.

[0021] The specific implementation method in step S1 is as follows: Given a normal image ,in Represents the set of real numbers. This represents the height, width, and channel dimensions of the input image tensor. This indicates that the input is normal; the foreground mask is obtained using the GrabCut background culling algorithm. Then generate a random Perlin noise mask. The intersection of the anomaly mask with the foreground mask is then used to obtain the final synthetic anomaly mask. : , in, Represents element-wise product. Indicates background, Indicates noise. Indicates an anomaly; Select the pre-selected external texture image Compared with normal images Perform linear interpolation to construct a synthetic anomalous image. : , in, This is the opacity coefficient, used to control the prominence of anomalies, and ; Indicates an anomaly. The name of the pre-selected external texture dataset.

[0022] The specific implementation method in step S21 is as follows: Synthesize abnormal images and normal image Input to the teacher encoder with the parameters frozen Extracting normal features of teachers at multiple scales and multi-scale abnormal characteristics of teachers .in, Wide_ResNet50 was used as the backbone network. This indicates that it is normal. Indicates an anomaly. This represents different network output scales. .

[0023] The specific implementation method in step S22 is as follows: In the designed scale residual aggregation module, the original multi-scale teacher anomaly features are first processed. A coordinate attention mechanism is applied as a spatial filter, and then a learnable projection layer is used to map the filtered features onto a compact manifold space to obtain the projected features. : , in, This indicates coordinate attention operations. This refers to the projection layer operation designed in the scale residual aggregation module, specifically, using... Convolutional layer followed by Normalization and The activation function is used to construct the projection layer, and its expression is: , in, for Convolution kernel parameters, For bias terms; In this process, cosine embedding loss is introduced. As a normality alignment constraint, abnormal texture patterns are forced to be repaired by forward normal patterns, thereby limiting the propagation of abnormal features. Its loss function is expressed as: , in, This represents the dot product operation. express Norm, This represents the normal characteristics of teachers. This represents the projected features of abnormal teacher characteristics after being projected through the projection layer. For projection features of two adjacent scales Let the deep-scale features be denoted as Shallow scale characteristics are Then, scale residual features are constructed and fused through upsampling and convolution: , in, Representing residual characteristics, This indicates the initial enhancement of teacher characteristics after fusing residual features. Indicates an upsampling operation. and These represent the kernel size as follows: and Convolution operations; Subsequently, the aforementioned preliminary enhancement of teacher characteristics will be implemented. The bottleneck layer within the scale residual aggregation module is input, and the classic ResNet bottleneck structure adopted by the bottleneck layer is used to perform feature compression and reconstruction to output a compact feature representation for use by the student decoder. The scale residual aggregation module significantly improves the model's ability to perceive subtle anomalies through the synergistic effect of the coordinate attention mechanism and the scale residual mechanism. First, by using the coordinate attention mechanism to capture long-distance spatial dependencies in the horizontal and vertical directions, it can accurately locate and filter out common periodic background textures or high-frequency structural noise in industrial images. Second, by calculating the feature residuals between adjacent scales, it can effectively cancel redundant background information that recurs at different resolutions, thereby highlighting local abnormal high-frequency signals such as tiny scratches and cracks. Finally, a bottleneck layer is introduced to perform nonlinear compression and reconstruction of the aggregated features. While eliminating redundant feature dimensions, the most core normal texture distribution semantics are preserved. This not only provides a high-quality feature benchmark for the lightweight reconstruction of the subsequent student network, but also further enhances the robustness of the model in complex industrial contexts.

[0024] The specific implementation method in step S23 is as follows: The compact feature representation output by the bottleneck layer is input into the student decoder. Multi-scale student abnormal features were obtained. The student decoder uses an inverted Wide_ResNet50 network as its backbone to perform multi-scale feature reconstruction on the compact feature representation, so that the student decoder fits the feature distribution of the teacher encoder in the normal region. In the design of the anomaly perception contrastive learning constraint, the synthetic anomaly mask will be used. Bilinear interpolation downsampling yields the first... Anomaly mask corresponding to feature resolution at each scale ; using the aforementioned anomaly mask As a spatial selector, it constrains multi-scale student anomalous features within the normal region. Normal characteristics of teachers at multiple scales Alignment; and in anomalous regions, apply negative constraints to penalize students' anomalous characteristics. Multiscale Teacher Abnormalities Overly similar feature reconstruction behavior; this process is constrained by anomaly-aware contrastive learning. Perform overall optimization: , in, This refers to Anomaly-Aware Contrastive Learning. To prevent smooth terms with a denominator of zero; The cosine similarity function is used to drive student features to fit teacher features in the normal region by minimizing the numerator, and to penalize student features for generating feature reconstruction behavior similar to teacher features in the abnormal region by maximizing the denominator. The anomaly-aware contrastive learning constraint introduces a synthetic anomaly mask as a spatial selector, enabling precise control over the feature distribution of different regions. Compared to traditional knowledge distillation methods that only apply alignment constraints to normal regions, this scheme drives the student decoder to accurately fit teacher features in normal regions while applying negative constraints to anomaly regions using the denominator. This effectively breaks the identity mapping trap that the student decoder is prone to when facing high-frequency, fine-grained textures. This differentiated supervision mechanism can significantly suppress the over-reconstruction of anomaly regions by the student decoder, thereby widening the semantic distance between teacher and student features in anomaly regions, enhancing the model's ability to discriminate subtle defects, and significantly improving the accuracy and stability of anomaly detection on industrial surfaces against complex texture backgrounds.

[0025] The specific implementation method in step S24 is as follows: In the designed multi-scale difference perception module, for the first... Teacher Abnormalities at Various Scales Abnormal characteristics of students First, the anomaly attention map for this layer is obtained by calculating the pixel-level cosine distance. The calculation formula is as follows: , in, This represents the dot product operation. express Norm, Indicates scale.

[0026] Subsequently, abnormal characteristics of teachers at the same level were identified. Abnormal characteristics of students It is obtained by splicing along the channel dimension. And using the above attention map Spatial modulation of the spliced ​​features allows the network to focus on feature response regions highly correlated with anomalies. The modulated feature representation is as follows: : , , in, This indicates splicing by channel. element-wise multiplication Indicates the kernel size as Convolution operation, This indicates splicing by channel dimension. Indicates the output of the first One scale; The multi-scale difference perception module introduces pixel-level cosine distance calculation to transform the directional differences between the teacher and student networks in the feature space into explicit anomalous attention weights. This design breaks away from the empirical inference limitation of previous methods that simply sum the distances of multiple layers of features, achieving adaptive integration of difference information. This is achieved using attention maps. Spatial modulation of the splicing features essentially serves as a form of "feature purification," enabling the segmentation network to shield against interference responses from background textures and suppress spurious response regions, resulting in clearer and sharper anomaly localization results at defect boundaries.

[0027] The specific implementation method in step S25 is as follows: Attention Modulation Individual scale features After being upsampled to a uniform spatial resolution, the data is then stitched together along the channel dimension to guide the segmentation network in achieving precise localization and obtaining pixel-level anomaly localization results. : , The segmentation head consists of the classic bottleneck structure of the ResNet network, dilated convolution, and spatial pyramid pooling modules. This represents the pixel-level anomaly localization results output by the segmentation network. This indicates that the computation has been performed using dilated convolution and spatial pyramid pooling modules. This indicates that the classic bottleneck structure of the ResNet network is used for computation. Features at three scales; The anomaly detection model is optimized using an end-to-end approach via a loss function. During the training phase, anomaly masks are synthesized. Anomaly mask obtained after bilinear interpolation downsampling As a monitoring signal, it is combined with the cosine embedding loss in the scale residual aggregation module. Anomaly perception contrastive learning constraints Focus loss and average absolute loss Construct a multi-task objective function to achieve collaborative optimization of network parameters. Multi-task objective function The calculation is as follows: , in, and They are defined as follows: , , in, Represents the height and width of the input image tensor. For pixels The predicted probability of belonging to the true category. This represents the x and y coordinates of a pixel. Specifically, when... hour, ;when hour, . This is a focusing parameter used to adjust the degree of attention given to difficult-to-classify samples; The trained anomaly detection model is obtained after training is completed.

[0028] Combined with appendix Figure 3 The visualized detection results show that this solution demonstrates excellent detection performance and positioning accuracy in various complex industrial scenarios. The figure illustrates pixel-level anomaly localization results generated by this solution for a variety of challenging industrial surface samples, including metal parts, capsules, fabrics, and leather. Figure 3 Lines 3 and 6) and the real anomaly mask ( Figure 3 Lines 2 and 5 show a very high degree of consistency. The specific advancements are reflected in the following aspects: Effectively suppressing over-reconstruction: Addressing the problem mentioned in the background that existing technologies easily produce "over-reconstruction" under complex textures, leading to weakened differences, this solution successfully breaks the student network's identity mapping trap for anomalous regions by setting anomaly-aware contrastive learning constraints. From Figure 3 It is evident that for minor scratches or structural abrupt changes, the response values ​​generated by this scheme are significant and concentrated, with no voids in the center of the abnormal area, fully demonstrating a stronger anomaly detection capability. Strong resistance to background noise interference: Experimental results show that when facing samples with periodic backgrounds or high-frequency structural information (such as fabric, mesh, and other textures), the background area of ​​the localization map generated by this scheme is extremely clean. This is thanks to the effective filtering and residual enhancement of spatial features by the scale residual aggregation module, which successfully suppresses the spurious responses that may be generated by normal textures, significantly reducing the false alarm rate. High localization accuracy and clear boundaries: Compared to the common problems of blurred boundaries and insufficient localization accuracy in existing methods, this scheme utilizes a multi-scale difference perception module to achieve adaptive feature fusion and spatial modulation. Figure 3 The detection heatmap shows that the contours of the abnormal areas closely match the actual shapes, with sharp edges, enabling precise identification of the physical boundaries of minute defects and significantly improving the accuracy of pixel-level localization. Robustness and generalization ability: Whether facing large-area structural damage or extremely fine surface cracks, this solution maintains a stable high-performance response. This ability to handle anomalies at different semantic levels and scales demonstrates the strong engineering application value and technological advancement of this technical solution in complex and ever-changing industrial production environments.

[0029] The above description is only a preferred embodiment of the present invention. It should be noted that those skilled in the art can make several modifications and improvements without departing from the structure of the present invention, and these will not affect the effectiveness of the implementation of the present invention or the practicality of the patent.

Claims

1. An industrial surface anomaly detection method based on multi-scale difference perception, characterized in that, This method achieves anomaly detection on industrial surfaces based on an anomaly detection model. The anomaly detection model includes a parameter-frozen teacher encoder, a student decoder, a scale residual aggregation module with a bottleneck layer, an anomaly perception contrastive learning constraint, a multi-scale difference perception module, and a segmentation network. The specific implementation of this method includes the following steps: S1. Obtain a normal image of the industrial surface, and generate a synthetic abnormal image containing a pseudo-abnormal region based on the normal image, a pre-selected external texture image and random noise. At the same time, generate a corresponding synthetic abnormal mask, and construct a training set using the normal image, the synthetic abnormal image and the synthetic abnormal mask. S2. Input the training set into the anomaly detection model and train it. The training process is as follows: S21. The normal image and the synthetic abnormal image are respectively input into the teacher encoder with frozen parameters to extract multi-scale normal teacher features and multi-scale abnormal teacher features. S22. The multi-scale teacher anomaly features are enhanced using the scale residual aggregation module. The specific process includes: The multi-scale teacher anomaly features are preprocessed using spatial filtering via a coordinate attention mechanism. A projection layer maps the preprocessed features to a compact manifold space, and a cosine embedding loss is introduced as a normality alignment constraint. Feature residuals between adjacent scales are calculated to suppress background texture noise and enhance high-frequency anomaly-related information, resulting in preliminary enhanced teacher features. These preliminary enhanced teacher features are then input into the bottleneck layer within the module, where a residual mapping structure is used to perform feature compression and reconstruction, outputting a compact feature representation for use by the student decoder. S23. Input the enhanced teacher features output by the bottleneck layer into the student decoder for multi-scale feature reconstruction, and perform anomaly perception contrastive learning constraints based on the synthetic anomaly mask to drive the student decoder to fit multi-scale normal teacher features in normal regions and generate student features that differ from multi-scale teacher anomaly features in abnormal regions. S24. Calculate the cosine distance between teacher abnormal features and student abnormal features at the same scale using the multi-scale difference perception module, generate abnormal attention maps at each scale, and use the abnormal attention maps to perform weighted modulation on the spliced ​​features of teacher abnormal features and student abnormal features at the same scale to obtain fused multi-scale features. S25. Input the fused multi-scale features into the segmentation network to generate pixel-level anomaly localization results, and calculate the loss between the pixel-level anomaly localization results and the synthesized anomaly mask based on a preset multi-task objective function. Update the network parameters through backpropagation to complete the training of the anomaly detection model. S3. In the inference stage, the industrial image to be detected is input into the trained anomaly detection model, which can then output the pixel-level anomaly localization results of the industrial image to be detected.

2. The method according to claim 1, characterized in that, The specific implementation method in step S1 is as follows: Given a normal image ,in Represents the set of real numbers. This represents the height, width, and channel dimensions of the input image tensor. This indicates that the input is normal; Foreground mask is obtained using the GrabCut background culling algorithm. Then generate a random Perlin noise mask. The intersection of the anomaly mask with the foreground mask is then used to obtain the final synthetic anomaly mask. : , in, Represents element-wise product. Indicates background, Indicates noise. Indicates an anomaly; Select the pre-selected external texture image Compared with normal images Perform linear interpolation to construct a synthetic anomalous image. : , in, This is the opacity coefficient, used to control the prominence of anomalies, and ; Indicates an anomaly. The name of the pre-selected external texture dataset.

3. The method according to claim 1, characterized in that, In step S21: Synthesize abnormal images and normal image Input to the teacher encoder with the parameters frozen Extracting normal features of teachers at multiple scales and multi-scale abnormal characteristics of teachers ;in, Wide_ResNet50 was used as the backbone network. This indicates that it is normal. Indicates an anomaly. This represents different network output scales. .

4. The method according to claim 3, characterized in that, In step S22: In the designed scale residual aggregation module, the original multi-scale teacher anomaly features are first processed. A coordinate attention mechanism is applied as a spatial filter, and then a learnable projection layer is used to map the filtered features onto a compact manifold space to obtain the projected features. : , in, This indicates coordinate attention operations. This refers to the projection layer operation designed in the scale residual aggregation module, specifically, using... Convolutional layer followed by Normalization and The activation function is used to construct the projection layer, and its expression is: , in, for Convolution kernel parameters, For bias terms; In this process, cosine embedding loss is introduced. As a normality alignment constraint, abnormal texture patterns are forced to be repaired by forward normal patterns, thereby limiting the propagation of abnormal features. Its loss function is expressed as: , in, This represents the dot product operation. express Norm, This represents the normal characteristics of teachers. This represents the projected features of abnormal teacher characteristics after being projected through the projection layer. For projection features of two adjacent scales Let the deep-scale features be denoted as Shallow scale characteristics are Then, scale residual features are constructed and fused through upsampling and convolution: , in, Representing residual characteristics, This indicates the initial enhancement of teacher characteristics after fusing residual features. Indicates an upsampling operation. and These represent the kernel size as follows: and Convolution operations; Subsequently, the aforementioned preliminary enhancement of teacher characteristics will be implemented. The bottleneck layer within the scale residual aggregation module is input, and the classic ResNet bottleneck structure used in the bottleneck layer is used to perform feature compression and reconstruction to output a compact feature representation for use by the student decoder.

5. The method according to claim 4, characterized in that, In step S23: The compact feature representation output by the bottleneck layer is input into the student decoder. Multi-scale student abnormal features were obtained. The student decoder uses an inverted Wide_ResNet50 network as its backbone to perform multi-scale feature reconstruction on the compact feature representation, so that the student decoder fits the feature distribution of the teacher encoder in the normal region. In the design of the anomaly perception contrastive learning constraint, the synthetic anomaly mask will be used. Bilinear interpolation downsampling yields the first... Anomaly mask corresponding to feature resolution at each scale ; using the aforementioned anomaly mask As a spatial selector, it constrains multi-scale student anomalous features within the normal region. Normal characteristics of teachers at multiple scales Alignment; and in anomalous regions, apply negative constraints to penalize students' anomalous characteristics. Multiscale Teacher Abnormalities Overly similar feature reconstruction behavior; this process is constrained by anomaly-aware contrastive learning. Perform overall optimization: , in, This refers to Anomaly-Aware Contrastive Learning. To prevent smooth terms with a denominator of zero; The cosine similarity function is used to drive student features to fit teacher features in normal regions by minimizing the numerator, and to penalize student features for generating feature reconstruction behavior similar to teacher features in abnormal regions by maximizing the denominator.

6. The method according to claim 5, characterized in that, In step S24, the specific process of executing the multi-scale difference sensing module is as follows: In the designed multi-scale difference perception module, for the first... Teacher Abnormalities at Various Scales Abnormal characteristics of students First, the anomaly attention map for this layer is obtained by calculating the pixel-level cosine distance. The calculation formula is as follows: , in, This represents the dot product operation. express Norm, Indicates scale; Subsequently, abnormal characteristics of teachers at the same level were identified. Abnormal characteristics of students It is obtained by splicing along the channel dimension. And using the above attention map Spatial modulation of the spliced ​​features allows the network to focus on feature response regions highly correlated with anomalies. The modulated feature representation is as follows: : , , in, This indicates splicing by channel. element-wise multiplication Indicates the kernel size as Convolution operation, This indicates splicing by channel dimension. Indicates the output of the first Each scale.

7. The method according to claim 6, characterized in that, In step S25, the specific process for generating the pixel-level anomaly localization result is as follows: Attention Modulation Individual scale features After being upsampled to a uniform spatial resolution, the data is then stitched together along the channel dimension to guide the segmentation network in achieving precise localization and obtaining pixel-level anomaly localization results. : , The segmentation head consists of the classic bottleneck structure of the ResNet network, dilated convolution, and spatial pyramid pooling modules. This represents the pixel-level anomaly localization results output by the segmentation network. This indicates that the computation has been performed using dilated convolution and spatial pyramid pooling modules. This indicates that the classic bottleneck structure of the ResNet network is used for computation. Features at three scales; The anomaly detection model is optimized using an end-to-end approach through a loss function; during the training phase, anomaly masks are synthesized. Anomaly mask obtained after bilinear interpolation downsampling As a monitoring signal, it is combined with the cosine embedding loss in the scale residual aggregation module. Anomaly perception contrastive learning constraints Focus loss and average absolute loss Construct a multi-task objective function to achieve collaborative optimization of network parameters; multi-task objective function The calculation is as follows: , in, and They are defined as follows: , , in, Represents the height and width of the input image tensor. For pixels The predicted probability of belonging to the true category. This represents the x and y coordinates of a pixel. Specifically, when... hour, ;when hour, . This is a focusing parameter used to adjust the degree of attention given to difficult-to-classify samples; The trained anomaly detection model is obtained after training is completed.