An industrial image anomaly detection method based on domain adaptation

By training the anomaly detector using a domain adaptation method and utilizing synthetic anomaly maps and pseudo-labels for self-supervised training, the problem of insufficient generalization ability of models trained on synthetic data is solved, and efficient anomaly detection in real data is achieved.

CN116433634BActive Publication Date: 2026-01-06TSINGHUA SHENZHEN INTERNATIONAL GRADUATE SCHOOL
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310412596.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-10
Publication Date
2026-01-06
Estimated Expiration
2043-04-10

AI Technical Summary

Technical Problem

Existing industrial image anomaly detection models trained on synthetic data have limited generalization ability in practical applications and lack efficient methods for generalizing to real data.

Method used

By using a domain adaptation method, an anomaly detector is trained using a synthetic anomaly map to generate an anomaly segmentation prediction map. The distance between normal and anomalous features is narrowed using a prototype domain adaptation paradigm. The detector is then optimized through self-supervised training using a pseudo-labeled anomaly prediction map and transferred to real industrial image data.

Benefits of technology

It significantly improves the model's performance on real data, enhances the accuracy and robustness of anomaly detection, and can effectively adapt to anomaly distributions in real data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116433634B_ABST
    Figure CN116433634B_ABST
Patent Text Reader

Abstract

The application discloses an industrial image anomaly detection method based on domain adaptation, comprising the following steps: mixing patches in a source image into a target image, creating a synthetic anomaly map and a corresponding binary anomaly mask map from normal image data; training an anomaly detector using the synthetic anomaly map, locating an abnormal area to generate an anomaly segmentation prediction map; generating normal and abnormal feature prototypes on real samples using the trained anomaly detector; constructing a prototype domain adaptation paradigm to narrow the distance between the predicted normal area in the anomaly segmentation prediction map and the normal feature prototype, and the distance between the predicted abnormal area in the anomaly segmentation prediction map and the abnormal feature prototype, and to widen the distance between the predicted abnormal area and the normal feature prototype, and the distance between the predicted normal area and the abnormal feature prototype; and self-supervised training and optimization of the anomaly detector using the pseudo-label anomaly prediction map of the real sample data set predicted by the anomaly detector, so as to make the anomaly detector migrate to real industrial image data.
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 a domain-adaptive method for detecting anomalies in industrial images. Background Technology

[0002] Industrial anomaly detection is a crucial means of improving the quality, efficiency, and safety of manufacturing, preventing accidents and losses caused by manufacturing defects. Traditional manual anomaly detection relies on visual inspection or the use of simple tools, resulting in inconsistent detection results that are difficult to meet the needs of large-scale automated production. The latest anomaly detection methods primarily employ generative models, achieving anomaly detection through high-precision reconstruction of normal regions. However, these models are trained only on anomaly-free images and typically require additional manual post-processing steps to identify anomalies, limiting the optimization of feature extraction and thus impacting anomaly detection capabilities.

[0003] To improve the accuracy and robustness of anomaly detection models, a large amount of real-world anomaly data is typically required. However, in practical applications, obtaining sufficient real-world anomaly data is often difficult and expensive. Recent works have employed methods to simulate real-world anomalies using fabricated data for model training and evaluation. However, there are significant differences between synthetic and real anomalies, and models trained using synthetic data may have limited generalization ability in real-world applications. Therefore, current technology lacks an anomaly detection method that can efficiently generalize to real-world data. Summary of the Invention

[0004] The main objective of this invention is to overcome the limitation of the generalization ability of existing models trained on synthetic data in practical applications, and to provide a domain-adaptive industrial image anomaly detection method.

[0005] To achieve the above objectives, the present invention proposes the following technical solution:

[0006] A domain-adaptive industrial image anomaly detection method includes the following steps: S1, randomly selecting two samples from normal image data as the source image and the target image respectively, and mixing patches from the source image into the target image to create a synthetic anomaly map and a corresponding binary anomaly mask map from the normal image data; S2, using the synthetic anomaly map to train an anomaly detector, locating anomaly regions and generating an anomaly segmentation prediction map; S3, using the anomaly detector trained in step S2 to generate normal feature prototypes and anomaly feature prototypes on real samples; S4, constructing a prototype domain-adaptive paradigm to shorten the distance between the predicted normal region and the normal feature prototype in the anomaly segmentation prediction map, and to lengthen the distance between the predicted anomaly region and the normal feature prototype, and to lengthen the distance between the predicted normal region and the anomaly feature prototype; S5, using the pseudo-label anomaly prediction map of the real sample dataset predicted by the anomaly detector for self-supervised training to optimize the anomaly detector, enabling the anomaly detector to be transferred to real industrial image data.

[0007] Further, step S1 specifically includes: S11, randomly generating a rectangular patch from the source image; S12, randomly adjusting the size and different center positions of the patch; S13, seamlessly blending the patch into the target image; S14, repeating steps S11 to S13 to add multiple patches to the same target image to obtain a synthetic anomaly map; S15, using the local intensity of the introduced external patch to indicate whether there is a difference to create a pixel-by-pixel label to obtain the binary anomaly mask map.

[0008] Furthermore, the anomaly detector includes a reconstruction subnetwork and a discrimination subnetwork; in step S2, the reconstruction subnetwork reconstructs the input synthetic anomaly map into an anomaly-free reconstruction map; the discrimination subnetwork takes the stitched image obtained by connecting the reconstruction map and the synthetic anomaly map in the channel dimension as input, and outputs the anomaly segmentation prediction map of the same size as the synthetic anomaly map.

[0009] Further, in step S2, when training the anomaly detector using the synthetic anomaly map, the l2 loss and SSIM loss between the target image and the reconstructed map are selected as the constraint loss of the reconstructed sub-network; the FocalLoss loss function is used as the constraint loss of the discriminative sub-network; where SSIM is the structural similarity index.

[0010] Furthermore, the constraint loss of the reconstructed subnetwork is:

[0011] L rec (I,I r ) = L SSIM (I,I r )+l2(I,Ir )

[0012] Among them, L SSIM (I,I r ) represents the target image I and the reconstructed image I. r SSIM loss between l2(I,I) r ) represents the target image I and the reconstructed image I. r L2 loss between;

[0013] The total loss function of the anomaly detector in step S2 is:

[0014] L(I,I r ,M,M P ) = L rec (I,I r )+L focal (M,M P )

[0015] Among them, L focal (M,M P ) represents the constraint loss of the discriminant subnetwork, M and M P These represent the binary anomaly mask image and the anomaly segmentation prediction image, respectively.

[0016] Further, step S3 specifically includes: using the anomaly detector trained in step S2 to extract features of real normal samples in the layer before the classifier as the normal feature prototype, and extracting the abnormal region of the synthetic anomaly map and the features of the classifier in the layer before the classifier where real abnormal samples are predicted as abnormal regions as the abnormal feature prototype.

[0017] Further, step S4 specifically includes: for the predicted normal region, narrowing the distance between it and the normal feature prototype, and widening the distance between it and the abnormal feature prototype, expressed as:

[0018]

[0019] For the predicted abnormal region, the distance between it and the abnormal feature prototype is reduced, and the distance between it and the normal feature prototype is increased, which is expressed as:

[0020]

[0021] Among them, L N L represents the domain adaptation loss of the predicted normal region. A The domain adaptation loss represents the predicted anomaly region; k = 1, 2, ..., K represents the index of the normal and anomaly feature prototypes; f represents the real scene features given the anomaly detector to the input. These represent the k-th normal feature prototype and the abnormal feature prototype, respectively; This indicates taking the k largest middle values; [] + This indicates that negative values ​​are discarded, and only positive values ​​are retained; the total constraint loss of the prototype domain adaptive paradigm is L. pro =L N +L A .

[0022] Further, in step S5, the step of the anomaly detector predicting the pseudo-label anomaly prediction map of the real sample dataset includes: for the normal category and the anomaly category, the set of prediction confidence scores corresponding to each prediction point on the real sample data is θ. c =[θ c,n ,θ c,a ], where θ c,n θ c,a θ represents the confidence levels for the normal category and the anomaly classification, respectively, and the sum of the two confidence levels is 1; to obtain the pseudo-label anomaly prediction map, θ is set. c,a A value greater than 0.9 indicates an anomaly, with a pixel label of 1; θ c,n A value greater than 0.9 indicates a normal category with a pixel label of 0; the numerical labels for the remaining predicted points are set to 255.

[0023] Further, step S5, which involves using the pseudo-label anomaly prediction map to self-supervisedly train and optimize the anomaly detector, includes: using the pseudo-label anomaly prediction map as the ground-truth to train and optimize the anomaly detector, inputting real sample data, and using Focal Loss as the loss function for the anomaly detector's output prediction, expressed as:

[0024] L self (M s M P ) = focal loss(M s M P )

[0025] Among them, M s and M P These represent the pseudo-label anomaly prediction map and the anomaly segmentation prediction map, respectively.

[0026] The present invention also proposes a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the steps of the aforementioned industrial image anomaly detection method.

[0027] Compared with the prior art, the beneficial effects of the technical solution of the present invention include:

[0028] This paper presents an industrial image anomaly detection method based on domain adaptation. The anomaly detector is trained using a synthetic anomaly map and adaptively trained using unlabeled real data. By fully utilizing the characteristics of unlabeled real data, the predicted anomaly region is brought closer to the corresponding anomaly feature prototype, while the predicted normal region is brought closer to the normal feature prototype and farther away from the anomaly feature prototype. This adapts to the anomaly distribution in the real data and can significantly improve the model performance. It also performs well on unlabeled real sample data and has good practicality and application prospects. Attached Figure Description

[0029] Figure 1 This is a flowchart of the industrial image anomaly detection method based on domain adaptation according to an embodiment of the present invention.

[0030] Figure 2 yes Figure 1 A schematic diagram of the specific process of step S1 in the industrial image anomaly detection method.

[0031] Figure 3 yes Figure 1 The diagram illustrates the process of training the anomaly detector using a synthetic anomaly map in step S2 of the industrial image anomaly detection method.

[0032] Figure 4 yes Figure 1 The diagram illustrates the process of prototype domain adaptive training and optimization of the anomaly detector in steps S3 and S4 of the industrial image anomaly detection method.

[0033] Figure 5 yes Figure 1 The diagram illustrates the process of self-supervised training and optimization of the anomaly detector in step S5 of the industrial image anomaly detection method. Detailed Implementation

[0034] To make the technical problems, technical solutions, and beneficial effects of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the following description is merely exemplary and not intended to limit the scope of protection or application of this invention.

[0035] There are three main reasons why industrial image anomaly detection fails:

[0036] First, there is a lack of labeled data. On the one hand, anomalies in industrial images are usually quite complex, and manual labeling requires a lot of time and effort, so labeled data is often scarce, which limits the training and testing capabilities of anomaly detection algorithms. On the other hand, in industrial production processes, anomalies may be rare or unevenly distributed, which can lead to a small proportion of anomaly data or an indistinct distribution of anomaly data points, and the anomaly morphology cannot be estimated.

[0037] Secondly, feature extraction is difficult. Industrial images typically contain a large amount of complex visual information, such as texture, shape, and color. How to extract appropriate features to describe this information is a crucial issue in anomaly detection. Inaccurate feature extraction or insufficient feature representation will cause anomaly detection algorithms to fail.

[0038] Third, the generalization ability of models trained on synthetic data is limited in practical applications. Due to differences in the size, shape, and location of anomalous regions, the generated anomalous images cannot fully reflect the anomalous features in the real world, thus affecting the model's performance and generalization ability.

[0039] In view of this, embodiments of the present invention propose an industrial image anomaly detection method based on domain adaptation, such as... Figure 1 As shown, the industrial image anomaly detection method includes the following steps S1 to S5:

[0040] Step S1: Randomly select two samples from the normal image data as source images I. s And the target image I, the source image I s The patch is mixed into the target image I, thereby creating a synthetic anomalous image I from normal image data. a And the corresponding binary anomaly mask image M.

[0041] During training, since only normal data is available, we need to use a surrogate task. We set the task to locate image anomalies introduced by synthetic anomalies. Therefore, as... Figure 2 As shown, step S1 may include the following specific steps S11 to S15:

[0042] S11, From source image I s A rectangular patch is randomly generated. Preferably, two normal training images are used as source images I. s Given the target image I, we select a random rectangular patch p from the truncated Gamma distribution. s And select from the uniform distribution in the source image I s center point (c x ,c y Generate random patches as follows:

[0043] w = W min(max(w) min ,0.06+r w ),w max (1)

[0044] h = H min(max(h) min ,0.06+r h ),h max(2)

[0045]

[0046] Where W and H represent the width and height of the training image, respectively, and w and h represent the height of the patch p. s Width and height; r w and r h r is a random number sampled from a truncated Gamma distribution. w ~Gamma(2,0.1), r h ~Gamma(2,0.1); w min w max h min h max represents the parameters representing the maximum and minimum values ​​of the set random rectangle, and U represents a uniform distribution.

[0047] S12. Randomly adjust the size and center position of the patch. Preferably, we adjust the size of the patch to obtain a rectangular patch p with a width w' = sw and a height h' = sh. s ', specifically:

[0048]

[0049]

[0050] Where, r s It is a random number that follows a normal distribution, r s ~N(1,0.25). (c x ',c y ') represents the center point of the source image after the patch is adjusted.

[0051] S13. Seamlessly blend the patch into the target image I. Preferably, the adjusted patch p s Seamlessly blend to the center point located at (c x ',c y In the target image I, to obtain the synthetic anomaly map (i.e., the training sample) I. a .

[0052] S14. Optionally, repeat steps S11 to S13 to add multiple patches to the same target image. After mixing the first patch, a decision on whether to add a new patch can be made by selecting n-1 random numbers, with a maximum of n-1 additional patches. That is, only one patch can be added, or two or more patches (including the number of patches) can be added.

[0053] S15. A pixel-by-pixel label is created using the local intensity representation of the introduced external patch to indicate the presence of differences, thereby obtaining the binary anomaly mask image. Specifically, in this embodiment of the invention, a pixel-by-pixel label (i.e., a binary anomaly mask image) is created using the local intensity representation of the introduced external patch to indicate the presence of differences, and the label value M for each pixel q is... (q) The calculation is as follows:

[0054]

[0055] in, I (q) Representing the synthetic anomaly diagram I a And the pixel q of the target image I. If the synthesized anomalous image I a If a pixel q is different from the target image I, then pixel q is considered abnormal and its label value is 1; otherwise, pixel q is considered normal and its label value is 0. Thus, pixel-by-pixel labels are obtained, i.e., a binary anomaly mask image is created.

[0056] Step S2: Use the synthetic anomaly map I created in step S1 a Train the anomaly detector, locate the anomaly region, and generate an anomaly segmentation prediction map M. P From the anomaly segmentation prediction map M P This allows for the differentiation between predicted normal and predicted abnormal regions. For example... Figure 3 As shown, the anomaly detector includes a reconstruction subnetwork and a discrimination subnetwork. The reconstruction subnetwork is an encoder-decoder architecture used to process the input synthetic anomaly map I. a The reconstructed image without anomalies is denoted as I. r The subnetwork uses the U-Net architecture to reconstruct Figure I. r Synthetic Anomaly Diagram I a The concatenation along the channel (C) dimension serves as input, and the output is the composite anomaly map I. a Anomaly segmentation prediction map M of the same size P .

[0057] Preferably, in step S2, the synthetic anomaly map I is used. a When training the anomaly detector, the target image I and the reconstructed image I are selected. r The l2 loss between l2(I,I) r ) and SSIM (structural similarity index) loss L SSIM (I,I r The constraint loss for reconstructing the subnetwork is L, where the SSIM loss is L. SSIM (I,I r ) is represented as:

[0058]

[0059] Where, N P SSIM(I,I) represents the number of pixels in the target image I. r ) (i,j) The images I and I centered at (i,j) r The SSIM (Structural Similarity Index) results of the patches are used. Therefore, the constraint loss for reconstructing the subnetwork is L. rec (I,I r ) = L SSIM (I,I r )+l2(I,I r ).

[0060] Simultaneously, a binary anomaly mask map M and anomaly segmentation prediction map M are selected. P FocalLoss loss L focal (M,M P The loss function used for the output prediction of the discriminant subnetwork is used to improve the accuracy of segmenting hard negative examples. Therefore, the total loss function for training the anomaly detector in step S2 is L(I,I) r ,M,M P ) = L rec (I,I r )+L focal (M,M P ).

[0061] S3. Use the anomaly detector trained in step S2 to generate normal feature prototypes and anomalous feature prototypes on real samples.

[0062] Specifically, refer to Figure 4 The anomaly detector trained in step S2 is used to extract the feature set of real normal samples in the layer before the classifier. As the prototype of the normal features, the abnormal regions of the synthetic abnormal samples and the feature set of the classifier layer before the real abnormal samples that are predicted to be abnormal regions are extracted. This serves as the prototype of the aforementioned abnormal feature. Wherein, P A , Among them, H p and W p These represent the height and width of the feature prototype, respectively. C represents the channel dimension of the feature prototype, and K represents the number of feature prototypes (K is the number of both normal and abnormal feature prototypes). This represents the feature of the nth real normal sample at position (i,j) in the layer preceding the classifier. The feature represents the position (i,j) of the layer preceding the classifier where the nth synthetic anomaly map or a real anomaly sample is predicted as an anomaly region; n represents the index of the real normal sample, the synthetic anomaly sample, and the real anomaly sample. When representing real normal samples, n has a minimum of 1 and a maximum of Ns; when representing synthetic anomaly samples and real anomaly samples, n has a minimum of 1 and a maximum of Na; N s N represents the number of true normal samples. a This represents the sum of the number of synthetic anomaly maps and the number of real anomaly samples.

[0063] In this embodiment of the invention, feature prototypes are constructed in step S3 to describe normal and abnormal patterns, and multiple prototypes are used to describe these patterns in more detail, thereby enhancing the representational power of the prototypes. Next, adaptive training is performed using unlabeled real data, bringing abnormal data points closer to the corresponding abnormal prototypes, while moving normal data points closer to normal prototypes and further away from abnormal prototypes, to adapt to the abnormal distribution in the real data.

[0064] Step S4: Construct a prototype domain adaptive paradigm to shorten the distance between the predicted normal region and the normal feature prototype, and the distance between the predicted abnormal region and the abnormal feature prototype, and to widen the distance between the predicted abnormal region and the normal feature prototype, and the distance between the predicted normal region and the abnormal feature prototype.

[0065] Those skilled in the art should understand that an anomaly detector can also be viewed as consisting of a feature extractor and a classifier. Based on this, given the input real-world scene features f, an anomaly detector is synthesized into an anomaly map I. a The anomaly detector trained on it can produce pixel-level pseudo-labels. Preliminary prediction of whether the feature belongs to the normal or abnormal category. Continue referencing... Figure 4 For features predicted as normal (i.e., the predicted normal region), the distance between them and the normal feature prototypes is reduced, while the distance between them and the abnormal feature prototypes is increased. This can be expressed by the following formula:

[0066]

[0067] For features predicted as an anomalous category (i.e., the predicted anomalous region), the distance between the feature and the prototype of the anomalous feature is minimized, while the distance between the feature and the prototype of the normal feature is increased. This can be expressed by the following formula:

[0068]

[0069] Among them, L N L represents the domain adaptation loss of the predicted normal region. AThe domain adaptation loss represents the predicted anomaly region; k = 1, 2, ..., K represents the index of the normal and anomaly feature prototypes; f represents the real scene features given the anomaly detector to the input. These represent the k-th normal feature prototype and the abnormal feature prototype, respectively; This indicates taking the k largest middle values; [] + This means discarding negative values ​​and keeping only positive values.

[0070] Therefore, the total constraint loss of the prototype domain adaptive paradigm is L. pro =L N +L A .

[0071] Step S5: The anomaly detector is optimized through self-supervised training using the pseudo-label anomaly prediction map of the real sample dataset predicted by the anomaly detector, enabling the anomaly detector to be applied to real industrial image data. Preferably, for both normal and anomaly categories, the set of prediction confidence scores for each prediction point on the real sample data is θ. c =[θ c,n ,θ c,a ], where θ c,n θ c,a θ represents the confidence levels for the normal category and the anomaly classification, respectively, and the sum of the two confidence levels is 1; to obtain the pseudo-label anomaly prediction map, θ is set. c,a A value greater than 0.9 indicates an anomaly, with a pixel label of 1; θ c,n A value greater than 0.9 indicates a normal category with a pixel label of 0; the numerical labels for the remaining predicted points are set to 255, meaning that this pixel is ignored when calculating the loss.

[0072] Preferably, please refer to Figure 5 When using the pseudo-label anomaly prediction map for self-supervised training to optimize the anomaly detector, the pseudo-label anomaly prediction map is used as the ground-truth to train and optimize the anomaly detector. Real sample data is input, and FocalLoss is used as the loss function for the anomaly detector's output prediction during training. Specifically, the loss function for self-supervised training and optimization of the anomaly detector in step S5 is expressed as follows:

[0073] L self (M s M P ) = focal loss(M s M P (8)

[0074] Among them, M s This represents the anomaly prediction graph of the pseudo-label.

[0075] This invention utilizes a neural network model to predict real data and converts the prediction results into pseudo-labels, thereby generating pseudo-pixel-level annotations. These pseudo-labels are then used as supervisory signals for self-supervised training, further improving model performance. This method effectively utilizes unlabeled real data, thus maximizing data utilization and enhancing the model's generalization ability.

[0076] In one specific embodiment, the method described above was used for experimentation. First, normal samples from the MVTecAD dataset were selected as target images, and the model was tested on anomalous samples from the MVTecAD dataset. An anomaly detector was trained using synthetic anomaly maps, iterating for 100k steps to obtain the initial model trained on synthetic samples. Then, unlabeled real samples were used for comparative prototype adaptation adjustments, iterating for 10k steps. Pseudo-pixel level labels were used for adaptive training adjustments, iterating for 10k steps. Anomaly detection was then performed on the test set. We compared the localization AP (average accuracy) experimental results of four anomaly detection methods on the MVTecAD dataset, as shown in Table 1. The method of this embodiment outperformed other methods in 10 categories and the average across all categories. Specifically, the method of this embodiment performed best in the categories of bottles, capsules, metal mesh, floor tiles, zippers, cables, hazelnuts, metal nuts, screws, and wood. Although other methods may achieve better results in some categories, overall, the method of this embodiment demonstrates strong performance in the localization AP experiment on the MVTecAD dataset. Experiments have shown that the industrial image anomaly detection method adapted to the domain of this invention effectively improves the model's ability to locate anomalies, increasing the localization accuracy (AP) by 6.4 points without increasing the number of model parameters.

[0077] Table 1. Experimental results of MVTecAD dataset for AP localization

[0078]

[0079]

[0080] Another embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the steps of the aforementioned industrial image anomaly detection method.

[0081] The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disc, or compact disc read-only memory (CD-ROM); magnetic surface memory can be disk storage or magnetic tape storage. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), Sync Link Dynamic Random Access Memory (SLDRAM), and Direct Rambus Random Access Memory (DRRAM). The storage media described in the embodiments of the present invention are intended to include, but are not limited to, these and any other suitable types of memory.

[0082] This invention also provides a control device, including a processor and a storage medium for storing a computer program; wherein, when the processor executes the computer program, it at least executes the industrial image anomaly detection method as described above.

[0083] This application also provides a processor that executes a computer program to perform at least the industrial image anomaly detection method described above.

[0084] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, several equivalent substitutions or obvious modifications can be made without departing from the concept of the present invention, and all such modifications, achieving the same performance or purpose, should be considered within the scope of protection of the present invention.

Claims

1. A domain adaptation based industrial image anomaly detection method, characterized in that, The method comprises the following steps: S1, randomly selecting two samples from normal image data as a source image and a target image, mixing patches in the source image into the target image, and creating a synthetic abnormal image and a corresponding binary abnormal mask image from the normal image data; S2, training an anomaly detector using the synthetic abnormal image to locate abnormal regions and generate an abnormal segmentation prediction image; S3, using the anomaly detector trained in step S2 to generate normal feature prototypes and abnormal feature prototypes on real samples; S4, constructing a prototype domain adaptation paradigm to narrow the distance between the predicted normal regions in the abnormal segmentation prediction image and the normal feature prototypes, and the distance between the predicted abnormal regions in the abnormal segmentation prediction image and the abnormal feature prototypes, and to widen the distance between the predicted abnormal regions and the normal feature prototypes, and the distance between the predicted normal regions and the abnormal feature prototypes; S5, using the pseudo-label abnormal prediction image of the real sample data set predicted by the anomaly detector for self-supervised training to optimize the anomaly detector, and migrating the anomaly detector to real industrial image data; Step S1 specifically comprises: S11, randomly generating a rectangular patch from the source image; S12, randomly adjusting the size and different center positions of the rectangular patch; S13, seamlessly mixing the adjusted patch into the target image; S14, repeating steps S11-S13 to add multiple patches in the same target image to obtain the synthetic abnormal image; S15, using the local intensity representation of the introduced external patch to create a pixel-by-pixel label to obtain the binary abnormal mask image.

2. The industrial image anomaly detection method of claim 1, wherein, The anomaly detector comprises a reconstruction subnetwork and a discrimination subnetwork; In step S2, the reconstruction subnetwork reconstructs the input synthetic abnormal image into an abnormal-free reconstructed image; the discrimination subnetwork takes as input a splicing image obtained by connecting the reconstructed image and the synthetic abnormal image in the channel dimension, and outputs an abnormal segmentation prediction image of the same size as the synthetic abnormal image.

3. The industrial image anomaly detection method of claim 2, wherein, In step S2, when training the anomaly detector using the synthetic anomaly map, the difference between the target image and the reconstructed image is selected as the loss function loss and SSIM loss as the constraint loss of the reconstruction subnetwork; and using a Focal Loss loss function as the constraint loss of the discriminator subnetwork; wherein SSIM is a structural similarity index.

4. The industrial image anomaly detection method of claim 3, wherein, The constraint loss of the reconstruction subnetwork is: ; wherein, is a SSIM loss between the target image I and the reconstructed image , is a L1 loss between the target image I and the reconstructed image , is a L2 loss between the target image and the reconstructed image. The total loss function of the anomaly detector in step S2 is: ; wherein, is a constraint loss for the discriminative subnetwork, M and M P respectively represent the binary anomaly mask map and the anomaly segmentation prediction map.

5. The industrial image anomaly detection method of claim 1, wherein, Step S3 specifically comprises: Using the anomaly detector trained in step S2 to extract the features of real normal samples before the classifier as the normal feature prototypes, and extracting the features of the abnormal regions of the synthetic abnormal image and the real abnormal samples predicted as abnormal regions before the classifier as the abnormal feature prototypes.

6. The industrial image anomaly detection method of claim 1, wherein, Step S4 specifically comprises: For the predicted normal regions, the distance between them and the normal feature prototypes is narrowed, and the distance between them and the abnormal feature prototypes is widened, represented as: ; For the predicted abnormal regions, the distance between them and the abnormal feature prototypes is narrowed, and the distance between them and the normal feature prototypes is widened, represented as: ; wherein, represents the domain adaptation loss of the predicted normal region, represents the domain adaptation loss of the predicted abnormal region; represents the index of normal and abnormal feature prototypes; f represents the true scene feature of the given input of the anomaly detector; respectively represents the first k normal feature prototype and the abnormal feature prototype; represents taking k the maximum value in the middle; represents discarding negative values and only keeping positive values; The total constraint loss of the prototype domain adaptation paradigm is .

7. The industrial image anomaly detection method of claim 1, wherein, In step S5, the steps of predicting the pseudo-label abnormal prediction image of the real sample data set by the anomaly detector comprise: For normal and abnormal categories, the corresponding prediction confidence set of each prediction point on the real sample data is , wherein respectively represent the confidence of normal and abnormal discrimination, and the sum of the two confidences is 1; in order to obtain the pseudo-label abnormal prediction map, it is set that greater than 0.9 is an abnormal category, and the pixel label is 1; greater than 0.9 is a normal category, and the pixel label is 0; the remaining prediction point value label is set to 255.

8. The industrial image anomaly detection method of claim 1, wherein, The steps of step S5 using the pseudo-label abnormal prediction image for self-supervised training to optimize the anomaly detector comprise: The pseudo-label anomaly prediction map is used as ground-truth to train and optimize the anomaly detector, real sample data is input, and Focal Loss is used as a loss function of prediction output of the anomaly detector, and is expressed as: ; wherein, and respectively represent the pseudo-label anomaly prediction map and the anomaly segmentation prediction map.

9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, can implement the steps of the industrial image anomaly detection method of any one of claims 1-8. The computer program, when executed by a processor, can implement the steps of the industrial image anomaly detection method of any one of claims 1-8.

Citation Information

Patent Citations

  • Training method of abnormal region image generation network and related products

    CN110751187A

  • Two-stage anomaly detection method for attitude diversity object defects

    CN115565036A