A differentially trainable adaptive memory type defect detection and localization method

By employing a differentially trainable adaptive memory-based defect detection method, synthetic abnormal images are generated from normal image data and multi-level feature fusion is performed. This solves the problem of sample scarcity in unsupervised detection and achieves efficient defect detection and localization.

CN120672701BActive Publication Date: 2026-07-28BOHAI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BOHAI UNIV
Filing Date
2025-06-10
Publication Date
2026-07-28

AI Technical Summary

Technical Problem

Existing unsupervised surface defect detection methods are inefficient and unstable when there are few abnormal samples, and it is difficult to effectively capture the statistical information of abnormal patterns. Traditional methods have problems such as difficulty in feature representation learning, poor model interpretability, complex training process or information loss.

Method used

A differentially trainable adaptive memory-based defect detection method is adopted. By extracting features from normal image data, performing k-means clustering and memory feature storage, synthetic abnormal images are generated. Defect detection and localization are performed using a multi-level feature fusion and segmentation network. L1 loss and Focal loss are calculated for network training.

Benefits of technology

It improves the model's sample diversity and efficiency, enhances the model's reasoning and cognitive abilities, accurately predicts defect areas, and improves the accuracy of defect detection and localization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120672701B_ABST
    Figure CN120672701B_ABST
Patent Text Reader

Abstract

The application provides a difference trainable adaptive memory type defect detection and positioning method, and relates to the technical field of industrial defect detection. The method first acquires normal image data from an existing image data set; the acquired normal image data is subjected to selection and storage of memory characteristic information through a memory information construction module; an abnormal sample is generated through data enhancement, and the abnormal sample is subjected to feature extraction through an encoder; a feature matching and connection module matches the sample features extracted by the encoder with the memory characteristic information, and then connects the sample features extracted by the encoder to obtain connection information; the connection information is sent into a multi-level feature fusion module and a decoder; a difference calculation and segmentation network is used to obtain a final prediction segmentation map; finally, the prediction segmentation map is compared with a mask image to obtain a loss and training, so as to complete abnormal detection and positioning. The method has good defect positioning effect and can meet the needs of industrial production.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial defect detection technology, and in particular to a differentially trainable adaptive memory-based defect detection and localization method. Background Technology

[0002] In today's industrial production context, surface defect detection of products is increasingly important. Surface defect detection is a method for determining whether an abnormal region exists in an image and locating it. However, in reality, abnormal samples are very scarce and difficult to collect, lacking effectively usable supervised information. Furthermore, abnormal samples and patterns are often highly variable and lack stable statistical regularities. This makes it difficult for supervised learning models to capture sufficient statistical information or salient features about abnormal patterns. Therefore, most current anomaly detection methods are unsupervised, trained only on normal samples, which gives them a significant advantage in practical applications.

[0003] In unsupervised surface defect detection, models do not use any labels. Instead, they rely on features learned from the data itself. Unsupervised surface defect detection methods include image reconstruction, generative models, and deep feature embedding. Specifically, image reconstruction methods based on autoencoders reconstruct defect-free images from the original image and then identify defects by comparing the original and reconstructed images. Generative models based on generative adversarial networks use two neural networks: a generator and a discriminator. The generator learns to generate near-realistic samples from a potential noise distribution, while the discriminator learns to distinguish between its generated samples and real samples. Deep feature embedding methods generally reduce the dimensionality of the data while preserving its important features, and then perform anomaly detection and localization. However, deep feature embedding methods face difficulties in feature representation learning and have poor model interpretability; generative model methods have complex training processes and may suffer from instability during training; and image reconstruction methods may result in the loss or blurring of some information, leading to low model efficiency and instability. Therefore, research on industrial defect detection is still in its early stages, and the corresponding fundamental theories and methodological frameworks are still lacking. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a differentially trainable adaptive memory-based defect detection and localization method to achieve defect detection.

[0005] The technical solution adopted in this invention is:

[0006] A differentially trainable adaptive memory-based defect detection and localization method includes the following steps:

[0007] Step 1: Obtain normal image data, i.e. defect-free image data, from the existing image dataset;

[0008] The existing image dataset contains M image datasets of different categories, of which m are object categories and n are texture categories, m+n=M. Each category of image dataset is divided into a training set, a test set, and a label dataset. The training set contains only normal images, while the test set contains both normal and abnormal images, with abnormal images being defective images. The images in the label dataset are black and white images, and the defect locations of the abnormal images in the test set are labeled. Obtaining normal image data from the existing image dataset refers to obtaining normal image data I from the training set.

[0009] Step 2: The acquired normal image data is processed through the memory information construction module to select and store memory feature information;

[0010] Step 2-1: Use an encoder to extract features from the input normal image data;

[0011] The encoder consists of the first, second, and third layer features output by a pre-trained ResNet18 network, denoted by F1, F2, and F3, respectively.

[0012] Step 2-2: Perform k-means clustering on the features extracted by the encoder;

[0013] Steps 2-3: Obtain the optimal number of cluster centers;

[0014] Specifically, the contour coefficient is calculated on the results of k-means clustering to obtain the optimal number of cluster centers, thereby obtaining and storing the cluster center features. The contour coefficient describes the clarity of the contours of each category after clustering, and the formula for calculating the contour coefficient is as follows:

[0015]

[0016] Among them, S i f is the profile coefficient. j Representative and sample features f i Other sample features within the same class, a (i) It is cohesion, which is the average distance from an input sample feature to other features within the same category, b (i) It is the separation degree, which is the average distance from the input sample features to the features of other classes, where N is the number of samples within a class;

[0017] Steps 2-4: Obtain hard sample features and store the memory feature information;

[0018] The hard sample feature is the sample feature that is farthest from the cluster center point feature, calculated by Euclidean distance, in each class selected in steps 2-3.

[0019] The memory feature information includes hard sample features and cluster center point features;

[0020] Step 3: Perform data augmentation on the acquired normal image data I to obtain the synthesized abnormal image I. a ;

[0021] Step 3-1: Randomly generate two-dimensional Burmester noise, and binarize the randomly generated two-dimensional Burmester noise to obtain the initial mask image M. p ;

[0022] Step 3-2: In the initial mask image M p Two rectangular blocks of random size are randomly cropped from the top to obtain the final mask image.

[0023] Step 3-3: Compare the mask image (Mask) with a randomly selected texture image or structure image (I). n Multiply to obtain I n1 ;

[0024] The texture image is from the FMD texture dataset, and the structure image is from normal image data I. It is obtained by randomly adjusting normal image data I, where random adjustment includes one or more of the following: brightness, contrast, sharpness, color, and rotation.

[0025] Steps 3-4: After inverting the mask image (Mask) to black and white, multiply it with the normal image data (I) to obtain I1;

[0026] Steps 3-5: Introduce a transparency factor δ to diversify the defects, thereby obtaining the enhanced synthetic anomaly image I. a The specific formula is as follows:

[0027] I a =δI n1 +I1

[0028] Step 4: The synthesized anomalous image I obtained after data augmentation a The features are fed into the encoder for feature extraction, and the L2 distance between the extracted features and the stored memory feature information is calculated. The feature with the smallest distance is the best matching feature. Then, the best matching feature is concatenated with the features extracted by the encoder to obtain three levels of connection information CI1, CI2 and CI3.

[0029] Step 5: Perform multi-scale feature fusion on the connection information CI1, CI2 and CI3 at the three levels;

[0030] Step 5-1: The connection information CI3 is processed by two 3×3 convolutions to make its channel number 256, thus obtaining the fusion feature CI3′;

[0031] Step 5-2: The connection information CI2 is processed through two 3×3 convolutions to increase its channel count to 128, resulting in... Then upsample CI3′ and perform a 3×3 convolution to make its size and number of channels similar to each other. Align and add them to obtain the fused feature CI2′;

[0032] Step 5-3: The connection information CI1 is processed through two 3×3 convolutions to increase its channel count to 64, resulting in... Then Upsampling is performed, and a 3×3 convolution is applied to make its size and number of channels similar to... Align and add them to obtain the fused feature CI1′;

[0033] Step 6: Send the data to the decoder for decoding;

[0034] Step 6-1: Perform a 3×3 convolution on CI3′ to obtain F3′, which is the first layer feature of the decoder;

[0035] Step 6-2: Upsample F3′ and perform a 3×3 convolution to align it with the size of CI2′. Then add the two together and perform a 3×3 convolution to obtain F2′, which is the second layer feature of the decoder.

[0036] Step 6-3: Upsample F2′ and perform a 3×3 convolution to align it with the size of CI1′. Then add the two together and perform a 3×3 convolution to obtain F1′, which is the third layer feature of the decoder.

[0037] Step 7: Calculate the differences and feed them into the segmentation network to predict the final segmentation map;

[0038] Step 7-1: Subtract F3′ from the input feature F3, then perform a 3×3 convolution and upsampling to obtain the segment. Figure 1 ;

[0039] Step 7-2: Subtract F2′ from the input feature F2, and then subtract it from the segmentation feature. Figure 1 Multiply, then perform a 3×3 convolution and upsampling to obtain the segmentation. Figure 2 ;

[0040] Step 7-3: Subtract F1′ from the input feature F1, and then subtract it from the segmentation feature F1. Figure 2 The initial segmentation map is obtained by multiplying the segments, and then it is input into the segmentation network to obtain the final predicted segmentation map.

[0041] The segmentation network includes 5 batch modules, namely the first batch module to the fifth batch module, 2 LeakyRELU modules, namely the first LeakyRELU module and the second LeakyRELU module, and 2 upsampling modules, namely the first upsampling module and the second upsampling module;

[0042] The initial segmentation map is passed sequentially through the first batch module, the second batch module, and added to the output of the third batch module. The result of the addition is then passed through the first LeakyRELU module, the first upsampling module, and the fourth batch module. The output of the fourth batch module is added to the output of the first upsampling module. The result of the addition is then sent to the second LeakyRELU module, the second upsampling module, and the fifth batch module to output the predicted segmentation map.

[0043] The first to fourth batch modules consist of 3×3 convolutions, batch normalization layers, and LeakyRELU activation functions, while the fifth batch module consists of 3×3 convolutions, batch normalization layers, and Softplus activation functions.

[0044] Step 8: Calculate the loss and train the network;

[0045] The specific calculation of loss is as follows: calculate the L1 loss and Focal loss between the predicted segmentation map and the obtained mask image, and sum them by weight to obtain the total loss function. When the total loss is minimized, defect detection and localization are achieved.

[0046] The formula for the total loss function is as follows:

[0047] L 总 =λ1L1+λ f L f

[0048] Among them, L 总 L1 is the total loss function, L1 is the L1 loss, and L... f It is the Focal loss, λ1 and λ f These are the corresponding weights.

[0049] The beneficial effects of adopting the above technical solution are as follows:

[0050] This invention provides a differentially trainable adaptive memory-based defect detection and localization method. The differentially trainable adaptive memory-based defect detection and localization method provided by this invention (1) proposes a new enhancement method that generates defect samples in addition to the original normal samples, increases the diversity of samples, makes up for the current problem of scarce abnormal samples, and improves the efficiency of the model. (2) proposes a new memory module construction method, which is different from the traditional memory module construction method. It not only solves the problem that the traditional method lacks representativeness of the stored sample features and cannot cover the data distribution of the entire dataset or consumes a lot of memory resources, but also enhances the reasoning and cognitive ability of the model. (3) proposes a trainable differential calculation method that integrates multi-level information, which enhances feature expression and reduces information loss. Unlike the traditional image-level differential calculation, we perform differential calculation at the feature level and feed it into the segmentation network for training. It can accurately predict the segmented image and improve the model's ability to distinguish and locate defects. Attached Figure Description

[0051] Figure 1 A flowchart illustrating a differentially trainable adaptive memory-based defect detection and localization method provided in an embodiment of the present invention;

[0052] Figure 2 This is a diagram of the segmentation network structure provided in an embodiment of the present invention;

[0053] Figure 3 The image shows the effect of using the method of the present invention to perform defect detection on data in 15 categories of MVTec AD, as provided in an embodiment of the present invention. Detailed Implementation

[0054] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0055] A differentially trainable adaptive memory-based defect detection and localization method is presented in this embodiment, using the MVTec AD dataset as an example. Figure 1 As shown, it includes the following steps:

[0056] Step 1: Obtain normal image data, i.e. defect-free image data, from the existing image dataset;

[0057] This embodiment uses the MVTec AD dataset, which was proposed at the 2019 CVPR conference and is specifically designed to evaluate and test the performance of unsupervised image anomaly pattern detection and segmentation. It contains 15 different image datasets, including 10 object categories and 5 texture categories, totaling 5354 high-resolution images. Each dataset is divided into training, testing, and label datasets. The training set contains only normal images, while the testing set contains both normal images and real anomaly images; the anomaly images are defective images. The label dataset contains black-and-white images of the anomaly images in the testing set, with defect locations marked. Obtaining normal image data from the MVTec AD dataset refers to obtaining normal image data I from the training set.

[0058] The MVTec AD dataset has 10 object categories: Bottle, Cable, Capsule, Hazelnut, Screw, Toothbrush, Pill, Zipper, Transistor, and Metal Nut; and 5 texture categories: Carpet, Grid, Leather, Tile, and Wood.

[0059] Step 2: The acquired normal image data is processed through the memory information construction module to select and store memory feature information;

[0060] Step 2-1: Use an encoder to extract features from the input normal image data;

[0061] The encoder consists of the first, second, and third layer features output by a pre-trained ResNet18 network, denoted by F1, F2, and F3, respectively. In this embodiment, the sample feature sizes extracted from each layer are 64×64×64, 128×32×32, and 256×16×16, respectively.

[0062] Step 2-2: Perform k-means clustering on the features extracted by the encoder;

[0063] In this embodiment, the value of k ranges from 20 to 200;

[0064] Steps 2-3: Obtain the optimal number of cluster centers;

[0065] Specifically, the silhouette coefficient is calculated on the results of k-means clustering to evaluate the effectiveness of k-means clustering, thereby obtaining the optimal number of cluster centroids and acquiring and storing the cluster centroid features. The silhouette coefficient describes the clarity of the silhouettes of each category after clustering, and its magnitude is used to evaluate the quality of the clustering. The formula for calculating the silhouette coefficient is as follows:

[0066]

[0067] Among them, S i f is the profile coefficient. j Representative and sample features f i Other sample features within the same class, a (i) It is cohesion, which is the average distance from an input sample feature to other features within the same category, b (i) It is the separation degree, which is the average distance from the input sample features to the features of other classes, where N is the number of samples within a class;

[0068] Steps 2-4: Obtain hard sample features and store the memory feature information;

[0069] The hard sample feature is the sample feature that is farthest from the cluster center point feature, calculated by Euclidean distance, in each class selected in steps 2-3.

[0070] The memory feature information includes hard sample features and cluster center point features;

[0071] Step 3: Perform data augmentation on the acquired normal image data I to obtain the synthesized abnormal image I. a ;

[0072] Step 3-1: Randomly generate two-dimensional Burmester noise, and binarize the randomly generated two-dimensional Burmester noise to obtain the initial mask image M. p ;

[0073] Step 3-2: In the initial mask image M p Two rectangular blocks of random size are randomly cropped from the top to obtain the final mask image.

[0074] In this embodiment, the height and width of the cut rectangular block range from 30 to 50.

[0075] Step 3-3: Compare the mask image (Mask) with a randomly selected texture image or structure image (I). n Multiply to obtain I n1 ;

[0076] The texture image comes from the FMD texture dataset, and the structure image comes from normal image data I. It is obtained by randomly adjusting normal image data I, where random adjustment includes one or more of the following: brightness, contrast, sharpness, color, and rotation.

[0077] Steps 3-4: After inverting the mask image (Mask) to black and white, multiply it with the normal image data (I) to obtain I1;

[0078] Steps 3-5: Introduce a transparency factor δ to diversify the defects, thereby obtaining the enhanced synthetic anomaly image I. a The specific formula is as follows:

[0079] I a =δI n1 +I1

[0080] In this embodiment, the introduced transparency factor δ takes the value of a random number between 0.15 and 1;

[0081] Step 4: The synthesized anomalous image I obtained after data augmentation a The features are fed into the encoder for feature extraction, and the L2 distance between the extracted features and the stored memory feature information is calculated. The feature with the smallest distance is the best matching feature. Then, the best matching feature is concatenated with the features extracted by the encoder to obtain three levels of connection information CI1, CI2 and CI3.

[0082] In this embodiment, the sample feature sizes of the three levels of connection information CI1, CI2 and CI3 are 128×64×64, 256×32×32 and 512×16×16, respectively.

[0083] Step 5: Perform multi-scale feature fusion on the connection information CI1, CI2 and CI3 at the three levels;

[0084] Step 5-1: The connection information CI3 is processed by two 3×3 convolutions to make its channel number 256, thus obtaining the fusion feature CI3′;

[0085] Step 5-2: The connection information CI2 is processed through two 3×3 convolutions to increase its channel count to 128, resulting in... Then upsample CI3′ and perform a 3×3 convolution to make its size and number of channels similar to each other. Align and add them to obtain the fused feature CI2′;

[0086] Step 5-3: The connection information CI1 is processed through two 3×3 convolutions to increase its channel count to 64, resulting in... Then Upsampling is performed, and a 3×3 convolution is applied to make its size and number of channels similar to... Align and add them to obtain the fused feature CI1′;

[0087] In this embodiment, the sample feature sizes of CI1′, CI2′ and CI3′ are 64×64×64, 128×32×32 and 256×16×16, respectively;

[0088] Step 6: Send the data to the decoder for decoding;

[0089] Step 6-1: Perform a 3×3 convolution on CI3′ to obtain F3′, which is the first layer feature of the decoder;

[0090] Step 6-2: Upsample F3′ and perform a 3×3 convolution to align it with the size of CI2′. Then add the two together and perform a 3×3 convolution to obtain F2′, which is the second layer feature of the decoder.

[0091] Step 6-3: Upsample F2′ and perform a 3×3 convolution to align it with the size of CI1′. Then add the two together and perform a 3×3 convolution to obtain F1′, which is the third layer feature of the decoder.

[0092] Step 7: Calculate the differences and feed them into the segmentation network to predict the final segmentation map;

[0093] Step 7-1: Subtract F3′ from the input feature F3, then perform a 3×3 convolution and upsampling to obtain the segment. Figure 1 ;

[0094] Step 7-2: Subtract F2′ from the input feature F2, and then subtract it from the segmentation feature. Figure 1 Multiply, then perform a 3×3 convolution and upsampling to obtain the segmentation. Figure 2 ;

[0095] Step 7-3: Subtract F1′ from the input feature F1, and then subtract it from the segmentation feature F1. Figure 2 The initial segmentation map is obtained by multiplying the segments, and then it is input into the segmentation network to obtain the final predicted segmentation map.

[0096] The segmentation network structure is as follows: Figure 2 As shown, it includes 5 batch modules, namely the first batch module to the fifth batch module, 2 LeakyRELU modules, namely the first LeakyRELU module and the second LeakyRELU module, and 2 upsampling modules, namely the first upsampling module and the second upsampling module;

[0097] The initial segmentation map is passed sequentially through the first batch module, the second batch module, and added to the output of the third batch module. The result of the addition is then passed through the first LeakyRELU module, the first upsampling module, and the fourth batch module. The output of the fourth batch module is added to the output of the first upsampling module. The result of the addition is then sent to the second LeakyRELU module, the second upsampling module, and the fifth batch module to output the predicted segmentation map.

[0098] The first to fourth batch modules consist of 3×3 convolutions, batch normalization layers, and LeakyRELU activation functions, while the fifth batch module consists of 3×3 convolutions, batch normalization layers, and Softplus activation functions.

[0099] Step 8: Calculate the loss and train the network;

[0100] The specific calculation of loss is as follows: calculate the L1 loss and Focal loss between the predicted segmentation map and the obtained mask image, and sum them by weight to obtain the total loss function. When the total loss is minimized, defect detection and localization are achieved.

[0101] The formula for the total loss function is as follows:

[0102] L 总 =λ1L1+λ f L f

[0103] Among them, L 总 L1 is the total loss function, L1 is the L1 loss, and L... f It is the Focal loss, λ1 and λ f These are the corresponding weights.

[0104] In this embodiment, λ1 and λ f The values ​​are 0.6 and 0.4 respectively;

[0105] In this embodiment, the method of the present invention was compared with existing methods on the MVTec AD dataset. Tables 1 and 2 show the image-level and pixel-level AUC-ROC scores of different methods, and Table 3 shows the pixel-level PRO scores of different methods.

[0106] Table 1. Comparison of image-level AUC-ROC anomaly detection performance on the MVTec AD dataset.

[0107]

[0108]

[0109] Table 2. Performance comparison of pixel-level AUC-ROC anomaly detection on the MVTec AD dataset.

[0110]

[0111]

[0112] Table 3. Performance comparison of pixel-level AUC-PRO anomaly detection on the MVTec AD dataset

[0113]

[0114] As shown in Table 1, among the 15 categories, the image-level AUC-ROC score of this method is the highest in 7 categories, reaching 100%, and the average image-level AUC-ROC across the 15 categories reaches 97.8%, significantly outperforming other methods. Tables 2 and 3 show that compared with other methods, this method has the highest pixel-level AUC-ROC in 4 categories, and its PRO score is mostly superior. Furthermore, the overall average score of both methods is also the highest, confirming its accuracy in anomaly localization. The defect detection effect of this method is as follows: Figure 3 As shown in the image, from left to right, the categories are: carpet, mesh, leather, wood, tile, bottle, cable, capsule, hazelnut, metal nut, pill, screw, toothbrush, transistor, and zipper. The first row represents samples with anomalies, the second row shows the detection results of this method, and the third row shows the labels corresponding to the anomaly images. It can be seen that this method can effectively detect both large and small defects, lines and dots, and semantic and logical errors, fully demonstrating its effectiveness.

[0115] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.

Claims

1. A differentially trainable adaptive memory-based defect detection and localization method, characterized in that, Includes the following steps: Step 1: Obtain normal image data, i.e. defect-free image data, from the existing image dataset; The existing image dataset contains a total of M image datasets of different categories, of which m are object categories and n are texture categories, m+n=M; Step 2: The acquired normal image data is processed through the memory information construction module to select and store memory feature information; Step 2 includes the following steps: Step 2-1: Use an encoder to extract features from the input normal image data; The encoder consists of features from the first, second, and third layers output by a pre-trained ResNet18 network, respectively, using... express; Step 2-2: Perform k-means clustering on the features extracted by the encoder; Steps 2-3: Obtain the optimal number of cluster centers; Specifically, the contour coefficient is calculated on the results of k-means clustering to obtain the optimal number of cluster centers, thereby obtaining and storing the cluster center features. The contour coefficient describes the clarity of the contours of each category after clustering, and the formula for calculating the contour coefficient is as follows: ; Among them, S i f is the profile coefficient. j Representative and sample features f i Other sample features within the same class, a (i) It is cohesion, which is the average distance from an input sample feature to other features within the same category, b (i) It is the separation degree, which is the average distance from the input sample features to the features of other classes, where N is the number of samples within a class; Steps 2-4: Obtain hard sample features and store the memory feature information; The hard sample feature is the sample feature that is farthest from the cluster center point feature, calculated by Euclidean distance, in each class selected in steps 2-3. The memory feature information includes hard sample features and cluster center point features; Step 3, data augmentation is performed on the obtained normal image data I to obtain synthetic abnormal image I a ; Step 4: The synthesized anomalous image I obtained after data augmentation a The data is fed into the encoder for feature extraction, and the L2 distance between the extracted features and the stored memory features is calculated. The feature with the smallest distance is the best matching feature. Then, the best matching feature is concatenated with the features extracted by the encoder to obtain three levels of connection information. , and ; Step 5: Connect the three levels of information , and Perform multi-scale feature fusion; Step 6: Send the data to the decoder for decoding; Step 7: Calculate the differences and feed them into the segmentation network to predict the final segmentation map; Step 8: Calculate the loss and train the network to achieve defect detection and localization.

2. The differentially trainable adaptive memory-based defect detection and localization method according to claim 1, characterized in that, Step 1 specifically involves dividing the image datasets of each category into a training set, a test set, and a label dataset. The training set contains only normal images, while the test set contains both normal and abnormal images, with the abnormal images being defective images. The images in the label dataset are black and white images, and the defect locations of the abnormal images in the test set are labeled. Obtaining normal image data from the existing image dataset refers to obtaining normal image data I from the training set.

3. The differentially trainable adaptive memory-based defect detection and localization method according to claim 1, characterized in that, Step 3 includes the following steps: Step 3-1: Randomly generate two-dimensional Burmester noise, and binarize the randomly generated two-dimensional Burmester noise to obtain the initial mask image M. p ; Step 3-2: In the initial mask image M p Two rectangular blocks of random size are randomly cropped from the top to obtain the final mask image. Step 3-3: Compare the mask image (Mask) with a randomly selected texture image or structure image (I). n Multiply to obtain I n1 ; The texture image is from the FMD texture dataset, and the structure image is from normal image data I. It is obtained by randomly adjusting normal image data I, where random adjustment includes one or more of the following: brightness, contrast, sharpness, color, and rotation. Steps 3-4: After inverting the mask image (Mask) to black and white, multiply it with the normal image data (I) to obtain I1; Steps 3-5: Introduce a transparency factor δ to diversify the defects, thereby obtaining the enhanced synthetic anomaly image I. a The specific formula is as follows: 。 4. The differentially trainable adaptive memory-based defect detection and localization method according to claim 1, characterized in that, Step 5 includes the following steps: Step 5-1, Connection Information After two 3×3 convolutions, the number of channels is increased to 256, resulting in the fused features. ; Step 5-2, Connection Information After performing two 3×3 convolutions to increase its channel count to 128, we obtain... Then Upsampling is performed, and a 3×3 convolution is applied to make its size and number of channels similar to... Align and add them to obtain the fused features. ; Step 5-3, Connection Information After performing two 3×3 convolutions to increase its channel count to 64, we obtain... Then Upsampling is performed, and a 3×3 convolution is applied to make its size and number of channels similar to... Align and add them to obtain the fused features. .

5. The differentially trainable adaptive memory-based defect detection and localization method according to claim 4, characterized in that, Step 6 includes the following steps: Step 6-1, Perform a 3×3 convolution to obtain This refers to the first layer features of the decoder; Step 6-2, Perform upsampling and 3×3 convolution to make it consistent with... Align the sizes, add the two together, and then perform a 3×3 convolution to obtain the result. This is the second layer feature of the decoder; Step 6-3, Perform upsampling and 3×3 convolution to make it consistent with... Align the sizes, add the two together, and then perform a 3×3 convolution to obtain the result. This refers to the third layer of features in the decoder.

6. The differentially trainable adaptive memory-based defect detection and localization method according to claim 5, characterized in that, Step 7 includes the following steps: Step 7-1, and input features The difference is calculated, and then a 3×3 convolution and upsampling are performed to obtain the segmentation image 1; Step 7-2, the input feature is subtracted from the output feature of step 7-1, and then multiplied by the segmentation map 1 to obtain the segmentation map 2. and input features Subtracting, then multiplying by the segmentation map 1, and then performing 3x3 convolution and upsampling to obtain the segmentation map 2. Step 7-3, obtaining the preliminary segmentation map by subtracting the first segmentation map from the second segmentation map, and multiplying the preliminary segmentation map by the segmentation map of the second image to obtain a third segmentation map, and inputting the third segmentation map into the segmentation network to obtain the final predicted segmentation map. and input features obtaining the preliminary segmentation map by subtracting the first segmentation map from the second segmentation map, and multiplying the preliminary segmentation map by the segmentation map of the second image to obtain a third segmentation map The segmentation network includes 5 batch modules, namely the first batch module to the fifth batch module, 2 LeakyRELU modules, namely the first LeakyRELU module and the second LeakyRELU module, and 2 upsampling modules, namely the first upsampling module and the second upsampling module; The initial segmentation map is passed sequentially through the first batch module, the second batch module, and added to the output of the third batch module. The result of the addition is then passed through the first LeakyRELU module, the first upsampling module, and the fourth batch module. The output of the fourth batch module is added to the output of the first upsampling module. The result of the addition is then sent to the second LeakyRELU module, the second upsampling module, and the fifth batch module to output the predicted segmentation map. The first to fourth batch modules consist of 3×3 convolutions, batch normalization layers, and LeakyRELU activation functions, while the fifth batch module consists of 3×3 convolutions, batch normalization layers, and Softplus activation functions.

7. The differentially trainable adaptive memory-based defect detection and localization method according to claim 1, characterized in that, Step 8 specifically involves calculating the loss by calculating the L1 loss and Focal loss between the predicted segmentation map and the obtained mask image, and then summing them by weight to obtain the total loss function. When the total loss is minimized, defect detection and localization are achieved. The formula for the total loss function is as follows: ; in, It is the total loss function. It is L1 loss. It is the Focal loss, λ1 and λ f These are the corresponding weights.