Class adaptive image anomaly detection method and system, terminal and medium

By constructing a category-adaptive image anomaly detection model based on a method driven jointly by input and reference, it solves the "identical shortcut" problem in multi-category detection in the existing technology, achieves efficient anomaly detection, is suitable for multi-category application scenarios, and reduces cost and computational overhead.

CN118587190APending Publication Date: 2024-09-03NINGBO HAITANG INFORMATION TECH CO LTD

Patent Information

Application Number
CN202410761768.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

It is difficult to implement category-adaptive multi-category image anomaly detection with existing technology, resulting in "identical shortcut" problems in the reconstruction network, resulting in anomaly detection failure, and single-category models cannot be effectively deployed in multi-category applications.

Method used

Adopting a method based on joint input and reference driving, through spatial alignment, encoder, suspected anomaly replacement and input-reference fusion module, a category-adaptive image anomaly detection model is constructed, using reference samples to enhance the characteristics of normal samples, reduce abnormal leakage, and achieve seamless operation. Reconstructed networks from unusual leaks.

Benefits of technology

It achieves category-adaptive multi-category anomaly detection, reduces storage and computing overhead, is suitable for industrial surface defect detection with diverse product types, and improves the decoder's reconstruction capability and anomaly detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118587190A
    Figure CN118587190A
Patent Text Reader

Abstract

The invention provides a category adaptive image anomaly detection method and system, and the method comprises the steps: providing an anomaly detection model, during training, selecting a category which is the same as an input sample from a prototype library as a reference sample, and enabling the reference sample to be aligned with a to-be-trained input through a space alignment module; extracting features of the input sample and the reference sample through an encoder; replacing potential abnormal features in the input sample through a suspected abnormal replacement module; fusing the features of the reference sample and the input sample through an input-reference fusion module; and inputting the fused features into a decoder to obtain reconstruction features of the input sample. During anomaly detection, the model does not need to be finely adjusted, the process is directly repeated to obtain reconstruction differences, and anomaly scores are obtained. According to the invention, the storage cost, the labor cost and the calculation overhead are greatly reduced, and the method is more suitable for application such as surface defect detection of industrial products with diversified and continuously updated product types.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a category adaptive anomaly detection technology in the field of image processing technology, and in particular to a category adaptive image anomaly detection method, system, terminal and medium based on input and reference joint drive. Background Art

[0002] Anomaly detection has been increasingly widely used in industrial surface defect detection, medical image analysis, hyperspectral image processing and other fields. In industrial defect detection, most unsupervised anomaly detection uses normal samples to build a reconstruction model, and then regards test samples with poor reconstruction results as anomalies. However, they can often only train one category on one model, and each category requires a dedicated model for training (single-category anomaly detection model). Considering the increasing variety of industrial products, the required models also increase, which will cause huge storage requirements and computational overhead. Therefore, category-adaptive multi-category anomaly detection models are in high demand and value in actual industrial applications. The key to achieving category-adaptive AD is to solve the "identical shortcut" problem of the reconstruction network.

[0003] In typical reconstruction-based unsupervised anomaly detection methods, the model only learns the ability to reconstruct the features of normal samples, so it has limited ability to reconstruct abnormal samples, and can distinguish between normal and abnormal. They are based on the assumption that the distribution of normal features is quite different from that of abnormal features, and the reconstruction network cannot reconstruct unknown abnormal samples. However, when the sample feature distribution is diverse, or there are multiple categories of samples, the reconstruction network often reconstructs both normal and abnormal samples without distinction. Because under the optimization of the loss function, the network tends to output a copy of the input to obtain a lower reconstruction error, which is the "identical shortcut" problem. When the test sample is abnormal, the network will also output a copy of the abnormality (abnormal leakage), resulting in failure of anomaly detection. In multi-category anomaly detection, the feature differences between classes are greater than the differences between normal and abnormal within a class. In order to obtain a lower reconstruction loss, the "identical shortcut" problem of the reconstruction network is more serious, so that most methods can reconstruct normal and abnormal samples at the same time, making it difficult to achieve multi-category anomaly detection.

[0004] In recent years, some anomaly detection methods have used masking strategies to build multi-class anomaly detection models (AUnifiedModel for Multi-class Anomaly Detection, 2022). They need to first roughly determine which content of the image is abnormal, then mask these contents, and then reconstruct the image. This masking strategy cannot guarantee that all anomalies in the image are masked, so there is still the "identical shortcut" problem caused by anomaly leakage.

[0005] These reconstruction-based anomaly detection methods only use a single input image as the decoder input, which limits the decoder's anomaly perception ability. Therefore, they often face a dilemma: on the one hand, in order to avoid "identical shortcuts" caused by anomaly leakage, it is necessary to fully filter out or shield suspected anomaly information in the input. On the other hand, in order to better reconstruct the input, it is necessary to retain sufficient information for reconstruction.

[0006] Therefore, how to solve the above-mentioned dilemma and realize a reconstruction network without abnormal leakage, thereby realizing a category-adaptive anomaly detection model, has extremely high research value and practical significance.

[0007] After searching, we found:

[0008] The Chinese invention patent application with publication number CN116485922A, "An Autoencoder and Its Training Method and Detection System for Image Processing", wherein the encoding module is used to encode the input image to obtain the features of the input image and pass it to the storage module; the storage module is used to store the features of multiple known normal image categories, and compare the stored features with the features of the input image to obtain the features of the normal image category similar to the features of the input image and pass it to the decoding module; the decoding module is used to decode the features passed by the storage module to obtain the reconstructed image of the input image, and output the difference between the reconstructed image and the input image. The patented technology introduces a storage module, controls the generalization of the autoencoder, and solves the problem in the prior art that the autoencoder cannot detect normal images and abnormal images well after training with a non-Gaussian distribution training set. However, the patented technology is still only a single-category anomaly detection model, that is, each category requires a dedicated model for training. This makes it difficult to deploy and use in many practical application scenarios such as clothing printing defect detection. For example, a clothing manufacturer usually has a variety of printed products and new printed patterns will be designed, requiring a category-adaptive multi-category anomaly detection model.

[0009] At present, no description or report of similar technology to the present invention has been found, and similar information at home and abroad has not been collected yet. Summary of the invention

[0010] In view of the above-mentioned deficiencies in the prior art, the present invention provides a category-adaptive image anomaly detection method, system, terminal and medium based on input and reference joint drive.

[0011] According to one aspect of the present invention, a method for class-adaptive image anomaly detection based on joint input and reference driving is provided, comprising:

[0012] Provide an image anomaly detection model, the model comprising: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder;

[0013] Get normal samples as training samples, and randomly select a small number of normal samples as prototype libraries;

[0014] Selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained through the spatial alignment module;

[0015] Extracting features of input samples and reference samples respectively by the encoder;

[0016] Replacing potential abnormal features in the input sample by the suspected abnormality replacement module;

[0017] The reference sample is fused with the input sample by the input-reference fusion module to obtain a fused feature;

[0018] Inputting the fused features into the decoder to obtain the reconstructed features of the input samples, completing the training of the image anomaly detection model, and obtaining a category-adaptive image anomaly detection model;

[0019] An image sample to be detected is obtained, and the image sample to be detected is input into the category adaptive image anomaly detection model for anomaly detection, a reconstruction difference is obtained, an anomaly score is obtained, and an abnormal image sample is detected.

[0020] Preferably, providing an image anomaly detection model comprises:

[0021] Construct a spatial alignment module, which uses an image spatial alignment algorithm to align the reference sample with the input sample to be trained;

[0022] Provide a visual model pre-trained on a large-scale dataset as a pre-trained encoder to extract features of input samples and reference samples;

[0023] Build a suspected anomaly replacement module, which is used to find potential abnormal areas in the input sample and replace them;

[0024] Construct an input-reference fusion module, which is used to fuse the features of multiple reference samples with the features of the input sample;

[0025] A decoder is constructed, wherein the architecture of the decoder is inversely symmetric to the architecture of the pre-trained encoder, and is used to reconstruct the fused features.

[0026] Preferably, the step of selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained by the spatial alignment module comprises:

[0027] Obtain a prototype sample of the same category as the input sample from the prototype library;

[0028] Select any one of the above-obtained prototype samples as reference samples;

[0029] The position and angle of the reference sample are adjusted by a spatial alignment module to align them with the input sample.

[0030] Preferably, replacing the potential abnormal features in the input sample by the suspected abnormality replacement module includes:

[0031] Define a hyperparameter λ as the potential anomaly threshold, with a value of 0 to 1;

[0032] The encoder extracts the features of the input sample and the reference sample respectively, that is, obtains an input feature map and a reference feature map;

[0033] For each feature of the input feature map, the distance between it and the most similar reference feature is calculated by distance metric. If the distance exceeds λ, the feature is identified as a potential abnormal feature and directly replaced by the reference feature.

[0034] Preferably, fusing the reference sample with the input sample through the input-reference fusion module to obtain fused features includes:

[0035] The extracted features of the input sample are spliced ​​with the features of multiple reference samples to obtain a spliced ​​graph;

[0036] The cross fusion layer is used to perform input-reference feature fusion on the spliced ​​image to obtain a fused feature map.

[0037] Preferably, the acquiring of the image sample to be detected, inputting the image sample to be detected into the category adaptive image anomaly detection model for anomaly detection, obtaining a reconstruction difference, obtaining an anomaly score, and detecting an abnormal image sample includes:

[0038] Obtain the image sample to be detected. If the image sample to be detected belongs to a new category, obtain an appropriate amount of normal samples of the same category and add them to the prototype library;

[0039] Passing the image sample to be detected through the category adaptive image anomaly detection model to obtain an input feature map and a feature map reconstructed by a decoder;

[0040] Calculating a difference map between the input feature map and the reconstructed feature map using a similarity metric;

[0041] Performing interpolation fitting on the difference map to obtain an image anomaly score map of the same scale as the image sample to be detected;

[0042] When the image anomaly score map is smaller than the set anomaly discrimination threshold, the image sample to be detected is determined to be a normal image; otherwise, the image sample to be detected is determined to be an abnormal image.

[0043] According to another aspect of the present invention, there is provided a class-adaptive image anomaly detection system based on joint input and reference driving, comprising:

[0044] An image anomaly detection model module, which is used to provide an image anomaly detection model, the model includes: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder;

[0045] A model training module, which is used to train the image anomaly detection model to obtain a category-adaptive image anomaly detection model; wherein the training includes:

[0046] Get normal samples as training samples, and randomly select a small number of normal samples as prototype libraries;

[0047] Selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained through the spatial alignment module;

[0048] Extracting features of input samples and reference samples respectively by the encoder;

[0049] Replacing potential abnormal features in the input sample by the suspected abnormality replacement module;

[0050] The reference sample is fused with the input sample by the input-reference fusion module to obtain a fused feature;

[0051] Inputting the fused features into the decoder to obtain reconstructed features of the input samples;

[0052] The anomaly detection module is used to obtain image samples to be detected, input the image samples to be detected into the category adaptive image anomaly detection model for anomaly detection, obtain reconstruction differences, obtain anomaly scores, and detect image anomaly samples.

[0053] According to a third aspect of the present invention, there is provided a computer terminal comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor can be used to execute any of the above-mentioned methods or to run the above-mentioned system when executing the program.

[0054] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can be used to execute any of the above methods, or to run the above system.

[0055] Compared with the prior art, the present invention has at least one of the following beneficial effects:

[0056] The present invention utilizes near-abnormal samples to implement a category-adaptive image anomaly detection technology based on joint input and reference drive, and can use a unified model to implement category-adaptive anomaly detection, which greatly reduces storage costs, labor costs and computing overhead, and is more suitable for applications in scenarios such as industrial surface defect detection with an increasing number of product types.

[0057] The present invention adopts input-reference fusion technology, which can use the splicing features of input samples and reference samples to introduce additional context information, effectively improving the reconstruction capability of the decoder.

[0058] The present invention adopts the suspected anomaly replacement technology to replace the abnormal features, which can achieve efficient anomaly filtering and real-time anomaly detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0060] Figure 1 The figure is a flowchart of a category-adaptive image anomaly detection method in a preferred embodiment of the present invention.

[0061] Figure 2 It is a schematic diagram of the working results and working process of image anomaly detection in a preferred embodiment of the present invention.

[0062] Figure 3It is a schematic diagram of the working structure and working process of the input-reference fusion module in a preferred embodiment of the present invention.

[0063] Figure 4 Schematic diagram of component modules of a category adaptive image anomaly detection system in a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0064] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several variations and improvements may be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.

[0065] An embodiment of the present invention provides a category-adaptive image anomaly detection method based on joint input and reference driving. The method combines input samples with reference samples so that the model can obtain more complete normal sample information from the reference samples, thereby achieving abnormality-free reconstruction of the input samples and ultimately achieving category-adaptive anomaly detection.

[0066] Specifically, Figure 1 As shown, the category-adaptive image anomaly detection method provided by this embodiment may include the following operations:

[0067] S1, providing an image anomaly detection model, the model comprising: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder;

[0068] S2, obtain normal samples as training samples, and randomly select a small number of normal samples as the prototype library;

[0069] S3, select multiple (preferably 3) samples of the same category as the input sample from the prototype library as reference samples, and align the reference samples with the input sample to be trained through the spatial alignment module;

[0070] S4, extracting the features of the input sample and the reference sample respectively through the encoder;

[0071] S5, replaces potential abnormal features in the input sample through the suspected abnormal replacement module;

[0072] S6, fusing the reference sample and the input sample through an input-reference fusion module;

[0073] S7, inputting the fused features into the decoder to obtain the reconstructed features of the input samples, completing the training of the image anomaly detection model, and obtaining a category-adaptive image anomaly detection model;

[0074] S8, obtaining an image sample to be detected, inputting the image sample to be detected into a category-adaptive image anomaly detection model for anomaly detection, obtaining a reconstruction difference (i.e., reconstruction loss), and obtaining an anomaly score, and detecting an abnormal image sample.

[0075] The category-adaptive image anomaly detection method provided by the above embodiment of the present invention does not need to fine-tune the model during anomaly detection. The reconstruction loss and the anomaly score can be obtained by directly repeating the above process to detect abnormal image samples.

[0076] In some preferred embodiments, the above S1 provides an image anomaly detection model, such as Figure 2 As shown, the model includes: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder, and may further include the following operations:

[0077] S11, constructing a spatial alignment module, which uses an image spatial alignment algorithm to align the reference sample with the input sample to be trained;

[0078] S12, select a visual model pre-trained on a large-scale dataset as the encoder network to extract features of input samples and reference samples;

[0079] S13, design a suspected anomaly replacement module, which is used to find potential abnormal areas in the input sample and replace them;

[0080] S14, designing an input-reference fusion module, which fuses the features of multiple (preferably 3) reference samples with the features of the input sample;

[0081] S15, construct a decoder network, the architecture of which is inversely symmetric to the architecture of the pre-trained encoder network.

[0082] In some preferred embodiments, the above S3, which selects a plurality of samples of the same category as the input sample from the prototype library as reference samples, and aligns the reference samples with the input sample to be trained through the spatial alignment module, may further include the following operations:

[0083] S31, obtain a prototype sample of the same category as the input sample from the prototype library;

[0084] S32, selecting any one of the prototype samples obtained as reference samples;

[0085] S33, adjusting the position and angle of the reference sample through the spatial alignment module to align it with the input sample.

[0086] In some preferred implementations, the spatial alignment module can select an image feature matching method SIFT as the image spatial alignment algorithm. Of course, in other embodiments, other methods can also be used, such as ORB matching method, SURF matching method, STN alignment network, etc., and are not limited to SIFT method.

[0087] In the spatial alignment module, the image feature matching method SIFT is used to first obtain the feature descriptors of the input sample and the reference sample, then SIFT uses the kd-tree algorithm to obtain the matching points, and finally the reference sample and the input sample are aligned according to the matching points; through alignment, the spatial positions of the reference sample and the input sample are made more consistent, which improves the effectiveness of subsequent operations such as anomaly replacement and input reference-fusion.

[0088] In some preferred implementations, in the above S4, the encoder can select a Wide-Resnet50 model pre-trained on ImageNet as the encoder network. Of course, in other embodiments, other models can also be used, such as DeiT, ViT, SwinTransformer model, etc., not limited to the Wide-Resnet50 model.

[0089] In some preferred implementations, the above S5, replacing the potential abnormal features in the input sample by the suspected abnormality replacement module, may further include the following operations:

[0090] S51, define a hyperparameter λ as a potential anomaly threshold, with a value ranging from 0 to 1;

[0091] S52, extracting features of the input sample and the reference sample respectively through an encoder, that is, obtaining an input feature map and a reference feature map;

[0092] S53, for each feature of the input feature graph, the feature distance is calculated by distance metric to obtain the distance between it and the most similar reference feature. If the distance is greater than λ, the feature is identified as a potential abnormal feature and directly replaced with the most similar reference feature.

[0093] In some preferred embodiments, in the above S53, the distance metric adopts the cosine metric, which is implemented by calculating the cosine similarity and negating it to obtain the cosine distance, and the above search and replace operation is performed separately for each feature of the input feature map. In this simple way, potential abnormal features in the input sample can be effectively filtered out, and the "identical shortcut" problem can be effectively avoided. When detecting anomalies, if it is a new category, this method can also be used to achieve abnormal filtering, which greatly improves the versatility of the model.

[0094] In some preferred embodiments, Figure 3 As shown, the above S6, fusing the reference sample with the input sample through the input-reference fusion module to obtain the fused feature, may further include the following operations:

[0095] S61, concatenating the input feature map obtained in S5 with multiple (preferably 3) reference feature maps to obtain a large concatenated map;

[0096] S62, sending the spliced ​​image to the cross fusion layer to achieve input-reference feature fusion and obtain a fused feature map.

[0097] In some preferred embodiments, the above S62, the cross-fusion layer can select a 4-layer cascaded Multi-head Attention. Of course, in other embodiments, other models can also be used, such as Squeeze-and-Excitation, Group Query Attention, etc., and are not limited to the Multi-head Attention model. It can use the attention mechanism to learn all the normal features of the input samples and reference samples, and provide subsequent decoders with information that is more conducive to reconstruction. In this preferred embodiment, the input-reference features are first spliced, and then the input features and reference features are fused through 4 fusion layers.

[0098] In some preferred implementations, the above S7, inputting the fused features into a decoder to obtain the reconstructed features of the input sample, may further include the following operations:

[0099] The fused features obtained in S6 are input into the decoder to obtain the reconstructed features of the input sample. In some preferred embodiments, the cosine similarity loss can be selected to calculate the reconstruction loss as a supervisory signal for model training. Of course, in other embodiments, other distance metrics such as Euclidean distance, Manhattan distance, SIMM, etc. can be used to calculate the reconstruction loss, and are not limited to the cosine similarity metric.

[0100] In some preferred implementations, the above S8, obtaining the image sample to be detected, inputting the image sample to be detected into the category adaptive image anomaly detection model for anomaly detection, obtaining the reconstructed difference, and obtaining the anomaly score, and detecting the image abnormal sample, may further include the following operations:

[0101] S81, obtaining a sample of an image to be detected; if the sample of the image to be detected is of a new category, adding a small number (preferably 3 to 10) of normal samples of the same category to the prototype library;

[0102] S82, passing the image sample to be detected through a category adaptive image anomaly detection model to obtain an input feature map and a feature map reconstructed by a decoder;

[0103] S83, using a similarity metric, calculating a difference map between the input feature map and the reconstructed feature map;

[0104] S84, performing interpolation fitting on the difference map to obtain an image anomaly score map of the same scale as the image sample to be detected, that is, obtaining an anomaly score;

[0105] S85, if the image abnormality score map is less than the set abnormality discrimination threshold, it is determined to be a normal image; otherwise, it is determined to be an abnormal image.

[0106] In some preferred implementations, in the above S83, the similarity measurement uses cosine similarity loss, and the reconstructed difference map is obtained by using the similarity of the feature map. Then, the anomaly score map of the same scale as the test sample is obtained by difference fitting. This method is simple and can realize anomaly location by using the two-dimensional characteristics of the anomaly score map.

[0107] The technical solution provided by the above embodiment of the present invention is further described below in conjunction with a specific application example.

[0108] In this specific application example, industrial printed fabrics are used as a specific application of the class-adaptive image anomaly detection method based on input and reference joint drive. The process of performing anomaly detection on industrial printed fabrics includes the following steps:

[0109] Step 1: Use an industrial camera to collect normal images of various printed products as training samples for the image anomaly detection model;

[0110] Step 2: Based on the training sample data set obtained in step 1, a category-adaptive image anomaly detection model based on joint input and reference drive is trained, and a small number (3 to 10) normal images of the printed product to be tested are collected using an industrial camera and added to the prototype library.

[0111] Step 3: Use the category-adaptive image anomaly detection model trained in step 2 to deploy and apply it in actual scenarios; the industrial camera collects the surface image of the printed sample to be tested in real time, and the image anomaly detection model obtains the reconstructed difference, interpolates and fits, and sums to obtain the anomaly score. The higher the anomaly score, the more likely it is an anomaly. If the printed product to be tested is a new category, a small number (3 to 10) of normal samples of the same category are added to the prototype library before testing.

[0112] Through the above specific application examples, it can be known that the category-adaptive image anomaly detection method provided by the above embodiment of the present invention, before training the model, first selects a small number of representative normal sample images for each type of target or product as a prototype library; during training, 3 samples of the same category as the input sample are selected from the prototype library as reference samples, and the reference samples are aligned with the input to be trained through the spatial alignment module. Then, the features of the input sample and the reference sample are extracted respectively through the encoder; the potential abnormal features in the input sample are replaced by the suspected abnormal replacement module; the reference sample and the input sample are fused by the input-reference fusion module; finally, the fused features are input into the decoder with rich feature retention to obtain the reconstructed features of the input sample. During anomaly detection, there is no need to fine-tune the model, and the above process is directly repeated to obtain the reconstruction loss and the anomaly score. The category-adaptive anomaly detection can be realized with a unified model, which greatly reduces the storage cost, labor cost and computing overhead, and is more suitable for applications such as surface defect detection of industrial products with diversified and constantly updated product types.

[0113] An embodiment of the present invention provides a category-adaptive image anomaly detection system based on joint drive of input and reference.

[0114] Specifically, Figure 4 As shown, the category-adaptive image anomaly detection system provided by this embodiment may include the following modules:

[0115] An image anomaly detection model module, which is used to provide an image anomaly detection model, the model includes: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder;

[0116] A model training module is used to train the image anomaly detection model to obtain a category-adaptive image anomaly detection model; wherein the training includes:

[0117] Get normal samples as training samples, and randomly select a small number of normal samples as prototype libraries;

[0118] Select multiple samples of the same category as the input samples from the prototype library as reference samples, and align the reference samples with the input samples to be trained through the spatial alignment module;

[0119] The features of the input sample and the reference sample are extracted respectively through the encoder;

[0120] Replace potential abnormal features in input samples through the suspected abnormal replacement module;

[0121] The reference sample is fused with the input sample through the input-reference fusion module to obtain the fused features;

[0122] The fused features are input into the decoder to obtain the reconstructed features of the input samples;

[0123] The anomaly detection module is used to obtain image samples to be detected, input the image samples to be detected into the category adaptive image anomaly detection model for anomaly detection, obtain the reconstructed difference, obtain the anomaly score, and detect the image abnormal samples.

[0124] In the above embodiment, the image anomaly detection model module includes:

[0125] A spatial alignment module, which aligns the reference sample to the input sample through an image spatial alignment algorithm;

[0126] The encoder module extracts features of the input sample and the reference sample;

[0127] A suspected anomaly replacement module that finds potential anomaly features from the input feature map using a distance metric and replaces them with the most similar reference features;

[0128] An input-reference fusion module, which concatenates and fuses the obtained input sample feature map with multiple (preferably 3) reference feature maps to obtain a fused feature map;

[0129] The decoder module uses the fused feature map to reconstruct the feature map of the input sample and obtain the final anomaly score map.

[0130] It should be noted that the steps in the method provided by the present invention can be implemented by using corresponding modules, devices, units, etc. in the system. Those skilled in the art can refer to the technical solution of the method to realize the composition of the system, that is, the embodiments in the method can be understood as preferred examples for constructing the system, which will not be elaborated here.

[0131] An embodiment of the present invention provides a computer terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the processor can be used to execute any method of the above-mentioned embodiments of the present invention, or to run any system of the above-mentioned embodiments of the present invention.

[0132] Optionally, the memory is used to store programs; the memory may include volatile memory (English: volatile memory), such as random-access memory (English: random-access memory, abbreviated: RAM), such as static random-access memory (English: static random-access memory, abbreviated: SRAM), double data rate synchronous dynamic random access memory (English: Double Data Rate Synchronous Dynamic Random Access Memory, abbreviated: DDR SDRAM), etc.; the memory may also include non-volatile memory (English: non-volatile memory), such as flash memory (English: flash memory). The memory is used to store computer programs (such as applications, functional modules, etc. that implement the above method), computer instructions, etc., and the above computer programs, computer instructions, etc. can be partitioned and stored in one or more memories. And the above computer programs, computer instructions, data, etc. can be called by the processor.

[0133] The above-mentioned computer programs, computer instructions, etc. may be stored in one or more memories in partitions, and the above-mentioned computer programs, computer instructions, data, etc. may be called by a processor.

[0134] The processor is used to execute the computer program stored in the memory to implement the various steps of the method or various modules of the system involved in the above embodiments. For details, please refer to the relevant descriptions in the above method and system embodiments.

[0135] The processor and the memory may be independent structures or integrated structures. When the processor and the memory are independent structures, the memory and the processor may be coupled and connected via a bus.

[0136] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can be used to execute any method of the above embodiments of the present invention, or to run any system of the above embodiments of the present invention.

[0137] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0138] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0139] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0140] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0141] The above-mentioned embodiments of the present invention provide a method, system, terminal and medium for category-adaptive image anomaly detection based on joint driving of input and reference, and use near-abnormal samples to implement category-adaptive image anomaly detection technology based on joint driving of input and reference. Category-adaptive anomaly detection can be implemented with a unified model, which greatly reduces storage costs, labor costs and computing overhead, and is more suitable for applications in scenarios such as industrial surface defect detection with an increasing number of product types. By using input-reference fusion technology, additional contextual information can be introduced by using the splicing features of input samples and reference samples, effectively improving the reconstruction capability of the decoder. By using suspected anomaly replacement technology to replace abnormal features, efficient anomaly filtering and real-time anomaly detection can be achieved.

[0142] All matters not covered in the above embodiments of the present invention are well known in the art.

[0143] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0144] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A category-adaptive image anomaly detection method, It is characterized in that include: Provide an image anomaly detection model, the model comprising: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder; Get normal samples as training samples, and randomly select a small number of normal samples as prototype libraries; Selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained through the spatial alignment module; Extracting features of input samples and reference samples respectively by the encoder; Replacing potential abnormal features in the input sample by the suspected abnormality replacement module; The reference sample is fused with the input sample by the input-reference fusion module to obtain a fused feature; Inputting the fused features into the decoder to obtain the reconstructed features of the input samples, completing the training of the image anomaly detection model, and obtaining a category-adaptive image anomaly detection model; An image sample to be detected is obtained, and the image sample to be detected is input into the category adaptive image anomaly detection model for anomaly detection, a reconstruction difference is obtained, an anomaly score is obtained, and an abnormal image sample is detected.

2. The class-adaptive image anomaly detection method according to claim 1, It is characterized in that The method provides an image anomaly detection model, comprising: Construct a spatial alignment module, which uses an image spatial alignment algorithm to align the reference sample with the input sample to be trained; Provide a visual model pre-trained on a large-scale dataset as a pre-trained encoder to extract features of input samples and reference samples; Build a suspected anomaly replacement module, which is used to find potential abnormal areas in the input sample and replace them; Construct an input-reference fusion module, which is used to fuse the features of multiple reference samples with the features of the input sample; A decoder is constructed, wherein the architecture of the decoder is inversely symmetric to the architecture of the pre-trained encoder, and is used to reconstruct the fused features.

3. The class-adaptive image anomaly detection method according to claim 1, It is characterized in that The step of selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained by the spatial alignment module comprises: Obtain a prototype sample of the same category as the input sample from the prototype library; Select any one of the above-obtained prototype samples as reference samples; The position and angle of the reference sample are adjusted by a spatial alignment module to align them with the input sample.

4. The class-adaptive image anomaly detection method according to claim 1, It is characterized in that The replacing potential abnormal features in the input sample by the suspected abnormality replacement module includes: Define a hyperparameter λ as the potential anomaly threshold, with a value of 0 to 1; The encoder extracts the features of the input sample and the reference sample respectively, that is, obtains an input feature map and a reference feature map; For each feature of the input feature map, the distance between it and the most similar reference feature is calculated by distance metric. If the distance exceeds λ, the feature is identified as a potential abnormal feature and directly replaced with the most similar reference feature.

5. The class-adaptive image anomaly detection method according to claim 1, It is characterized in that The step of fusing the reference sample with the input sample through the input-reference fusion module to obtain a fused feature includes: The extracted features of the input sample are spliced ​​with the features of multiple reference samples to obtain a spliced ​​graph; The cross fusion layer is used to perform input-reference feature fusion on the spliced ​​image to obtain a fused feature map.

6. The base class adaptive image anomaly detection method according to claim 1, It is characterized in that The step of obtaining an image sample to be detected, inputting the image sample to be detected into the category-adaptive image anomaly detection model for anomaly detection, obtaining a reconstruction difference, and obtaining an anomaly score, and detecting an abnormal image sample includes: Obtain the image sample to be detected. If the image sample to be detected belongs to a new category, obtain an appropriate amount of normal samples of the same category and add them to the prototype library; Passing the image sample to be detected through the category adaptive image anomaly detection model to obtain an input feature map and a feature map reconstructed by a decoder; Calculating a difference map between the input feature map and the reconstructed feature map using a similarity metric; Performing interpolation fitting on the difference map to obtain an image anomaly score map of the same scale as the image sample to be detected; When the image anomaly score map is smaller than the set anomaly discrimination threshold, the image sample to be detected is determined to be a normal image; otherwise, the image sample to be detected is determined to be an abnormal image.

7. A category-adaptive image anomaly detection system, It is characterized in that include: An image anomaly detection model module, which is used to provide an image anomaly detection model, the model includes: a spatial alignment module, a pre-trained encoder, a suspected anomaly replacement module, an input-reference fusion module and a decoder; A model training module, which is used to train the image anomaly detection model to obtain a category-adaptive image anomaly detection model; wherein the training includes: Get normal samples as training samples, and randomly select a small number of normal samples as prototype libraries; Selecting a plurality of samples of the same category as the input samples from the prototype library as reference samples, and aligning the reference samples with the input samples to be trained through the spatial alignment module; Extracting features of input samples and reference samples respectively by the encoder; Replacing potential abnormal features in the input sample by the suspected abnormality replacement module; The reference sample is fused with the input sample by the input-reference fusion module to obtain a fused feature; Inputting the fused features into the decoder to obtain reconstructed features of the input samples; The anomaly detection module is used to obtain image samples to be detected, input the image samples to be detected into the category adaptive image anomaly detection model for anomaly detection, obtain reconstruction differences, obtain anomaly scores, and detect image anomaly samples.

8. A computer terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, it can be used to execute the method described in any one of claims 1 to 6, or to run the system described in claim 7.

9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, it can be used to execute the method described in any one of claims 1 to 6, or to run the system described in claim 7.

Citation Information

Patent Citations

  • Auto-encoder applied to image processing and training method and detection system thereof

    CN116485922A

Cited By

  • Industrial image defect detection method and system based on reconstruction, storage medium and product

    CN121883482A

  • A reconstruction-based industrial image defect detection method, system, storage medium and product

    CN121883482B