Image anomaly detection method and device, computer equipment and storage medium

Through the combined decoding processing and attention feature extraction in the image anomaly detection method, the problem of difficulty in distinguishing normal areas and abnormal areas in the image is solved, and the detection accuracy is improved.

CN118608451AActive Publication Date: 2024-09-06TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Application Number
CN202410518003.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-26
Publication Date
2024-09-06
Estimated Expiration
2044-04-26

AI Technical Summary

Technical Problem

In existing image anomaly detection methods, it is difficult to effectively distinguish between normal areas and abnormal areas in the image, resulting in low detection accuracy.

Method used

By obtaining the original features of the image to be detected, the coding features are obtained, and combined with the features associated with the reference image excluding abnormalities for decoding processing. Attention feature extraction and cross-attention mechanisms are used to enhance feature expression capabilities and improve detection accuracy. .

Benefits of technology

The accuracy of image anomaly detection is improved, the feature expression ability of combined decoding features is enhanced, and the accuracy of anomaly detection results is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118608451A
    Figure CN118608451A
Patent Text Reader

Abstract

The invention relates to an image anomaly detection method and device, computer equipment, a storage medium and a computer program product. The method relates to an artificial intelligence technology, and comprises the following steps: encoding an image original feature of a to-be-detected image to obtain a detection encoding feature; encoding the prompt original feature associated with the to-be-detected image to obtain a prompt code feature; performing at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain combined decoding features, performing attention feature extraction for the input target detection coding features and the target prompt coding features in each level, and performing attention feature extraction for the output prompt coding features; performing attention feature extraction in combination with the target detection coding feature to obtain an output detection coding feature; and obtaining an anomaly detection result based on a reconstruction difference between the image reconstruction feature obtained according to the combined decoding feature and the image original feature. By adopting the method, the accuracy of image anomaly detection can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an image anomaly detection method, apparatus, computer equipment, storage medium and computer program product, as well as an image anomaly detection model processing method, apparatus, computer equipment, storage medium and computer program product. Background Art

[0002] With the development of computer technology, computer vision is increasingly used in various fields, including autonomous driving, medical image analysis, retail, security, games, etc., realizing various tasks such as image classification, target detection, semantic segmentation, face recognition, image anomaly detection, etc., greatly improving image processing efficiency. Among them, image anomaly detection aims to identify abnormal images, which has high research significance and application value in the fields of industrial appearance defect detection, medical image analysis, hyperspectral image processing, etc.

[0003] However, in the current image anomaly detection process, because there is often a high consistency between the abnormal area and the adjacent area in the image, the normal area and the abnormal area in the image cannot be effectively distinguished, resulting in low accuracy of image anomaly detection. Summary of the invention

[0004] Based on this, it is necessary to provide an image anomaly detection method, device, computer equipment, computer-readable storage medium and computer program product, as well as an image anomaly detection model processing method, device, computer equipment, storage medium and computer program product, which can improve the accuracy of image anomaly detection in response to the above-mentioned technical problems.

[0005] In a first aspect, the present application provides an image anomaly detection method. The method comprises:

[0006] Acquire an image to be detected, and encode the original image features of the image to be detected to obtain detection coding features of the image to be detected;

[0007] Determine the prompt original feature associated with the image to be detected, and encode the prompt original feature to obtain the prompt encoding feature; the prompt original feature is extracted from the reference image that does not include anomalies corresponding to the image to be detected;

[0008] Perform at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features output by the combined decoding processing of at least one level, and in the combined decoding processing of each level, perform attention feature extraction on the target detection coding features and the target prompt coding features input by the level to obtain the prompt coding features output by the level, and perform attention feature extraction on the prompt coding features and the target detection coding features output by the level to obtain the detection coding features output by the level;

[0009] Obtaining image reconstruction features for the image to be detected according to the combined decoding features;

[0010] Based on the reconstructed difference between the image reconstructed features and the image original features, an abnormality detection result for the image to be detected is obtained.

[0011] In a second aspect, the present application also provides an image anomaly detection device. The device comprises:

[0012] The image processing module to be detected is used to obtain the image to be detected, and encode the original image features of the image to be detected to obtain the detection coding features of the image to be detected;

[0013] The prompt feature acquisition module is used to determine the prompt original feature associated with the image to be detected, and encode the prompt original feature to obtain the prompt encoding feature; the prompt original feature is extracted from the reference image that does not include anomalies corresponding to the image to be detected;

[0014] A combined decoding processing module, used for performing at least one level of combined decoding processing based on the detection coding features and the prompt coding features, obtaining the combined decoding features output by the combined decoding processing of at least one level, and in the combined decoding processing of each level, performing attention feature extraction on the target detection coding features and the target prompt coding features inputted at the level, obtaining the prompt coding features outputted at the level, and performing attention feature extraction on the prompt coding features and the target detection coding features outputted at the level, obtaining the detection coding features outputted at the level;

[0015] A reconstruction feature acquisition module, used for obtaining image reconstruction features for the image to be detected according to the combined decoding features;

[0016] The reconstruction difference processing module is used to obtain an abnormality detection result for the image to be detected based on the reconstruction difference between the image reconstruction feature and the image original feature.

[0017] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the above image anomaly detection method are implemented.

[0018] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above-mentioned image anomaly detection method are implemented.

[0019] In a fifth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the above image anomaly detection method are implemented.

[0020] The above-mentioned image anomaly detection method, apparatus, computer equipment, storage medium and computer program product encode the original image features of the image to be detected to obtain detection coding features, encode the prompt original features associated with the image to be detected and extracted from the reference image that does not include the anomaly to obtain prompt coding features, perform at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain combined decoding features, in the combined decoding processing of each level, perform attention feature extraction on the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and perform attention feature extraction on the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level, obtain image reconstruction features for the image to be detected based on the combined decoding features, and obtain the anomaly detection result of the image to be detected based on the reconstruction difference between the image reconstruction features and the original image features. During image anomaly detection processing, in the combined decoding processing of each level, attention features are extracted through the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and attention features are extracted from the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level. The image context information of the reference image that does not include anomalies and the corresponding dynamic prompt coding features of each level can be comprehensively utilized to construct a combined decoding feature, thereby enhancing the feature expression ability of the combined decoding feature, thereby improving the accuracy of image anomaly detection based on the reconstructed features obtained from the combined decoding feature.

[0021] In a sixth aspect, the present application provides an image anomaly detection model processing method. The method comprises:

[0022] Acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image;

[0023] Performing feature extraction on the normal sample image, the reference sample image and the abnormal sample image respectively, to obtain the normal image original features of the normal sample image, the reference image original features of the reference sample image and the abnormal image original features of the abnormal sample image;

[0024] By using the image anomaly detection model to be trained, the original features of the normal image, the original features of the reference image, and the original features of the abnormal image are respectively encoded to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image;

[0025] By using the image anomaly detection model to be trained, performing at least one level of combined decoding processing based on the normal sample coding features and the prompt sample coding features, obtaining a first combined decoding feature output by the at least one level of combined decoding processing, and obtaining a normal sample reconstruction feature for the normal sample image according to the first combined decoding feature;

[0026] By using the image anomaly detection model to be trained, performing at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features, obtaining a second combined decoding feature output by the at least one level of combined decoding processing, and obtaining an abnormal sample recovery feature for the abnormal sample image according to the second combined decoding feature;

[0027] The image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then training is continued until the training is completed to obtain a trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on the input image.

[0028] In one of the embodiments, the image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and the training is continued until the training is completed to obtain a trained image anomaly detection model, including: determining the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features; determining the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features; and the image anomaly detection model to be trained is updated based on the sample reconstruction loss and the sample recovery loss and the training is continued until the training is completed to obtain a trained image anomaly detection model.

[0029] In one of the embodiments, the image anomaly detection model processing method also includes: respectively determining a first feature difference between a normal sample reconstructed feature and an original feature of a normal image, and a second feature difference between an abnormal sample restored feature and an original feature of an abnormal image; performing at least one level of pixel feature extraction for the first feature difference and the second feature difference, respectively, through the image anomaly detection model to be trained, to obtain a first pixel anomaly result and a second pixel anomaly result; determining a pixel anomaly detection loss according to the abnormal area label carried by the abnormal sample image, the first pixel anomaly result and the second pixel anomaly result; updating the image anomaly detection model to be trained based on the sample reconstruction loss and the sample recovery loss, and continuing to train until the training is completed, to obtain a trained image anomaly detection model, including: fusing the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to obtain a model target loss; updating the image anomaly detection model to be trained based on the model target loss, and continuing to train until the training is completed, to obtain a trained image anomaly detection model.

[0030] In a seventh aspect, the present application also provides an image anomaly detection model processing device. The device comprises:

[0031] A sample image acquisition module, used to acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image;

[0032] A sample feature extraction module is used to extract features from the normal sample image, the reference sample image and the abnormal sample image, respectively, to obtain the normal image original features of the normal sample image, the reference image original features of the reference sample image and the abnormal image original features of the abnormal sample image;

[0033] A sample feature encoding module is used to encode the original features of the normal image, the original features of the reference image, and the original features of the abnormal image respectively through the image anomaly detection model to be trained, so as to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image;

[0034] A normal sample reconstruction module is used to perform at least one level of combined decoding processing based on the normal sample coding features and the prompt sample coding features through the image anomaly detection model to be trained, obtain a first combined decoding feature output by the at least one level of combined decoding processing, and obtain a normal sample reconstruction feature for the normal sample image according to the first combined decoding feature;

[0035] An abnormal sample recovery module is used to perform at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features through the image abnormality detection model to be trained, obtain a second combined decoding feature output by the at least one level of combined decoding processing, and obtain an abnormal sample recovery feature for the abnormal sample image according to the second combined decoding feature;

[0036] The model updating module is used to update the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then continue training until the training is completed to obtain the trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on the input image.

[0037] In an eighth aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the above image anomaly detection model processing method are implemented.

[0038] In a ninth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above image anomaly detection model processing method are implemented.

[0039] In a tenth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the above image anomaly detection model processing method are implemented.

[0040] The above-mentioned image anomaly detection model processing method, device, computer equipment, storage medium and computer program product, for normal sample images, reference sample images associated with normal sample images and abnormal sample images, respectively encode the original image features of each of them through the image anomaly detection model to be trained to obtain normal sample encoding features, prompt sample encoding features and abnormal sample encoding features, and perform at least one level of combined decoding processing based on the normal sample encoding features and the prompt sample encoding features through the image anomaly detection model to be trained to construct normal sample reconstruction features for normal sample images, and perform at least one level of combined decoding processing based on the abnormal sample encoding features and the prompt sample encoding features through the image anomaly detection model to be trained to construct abnormal sample recovery features for abnormal sample images, and then continue to train the image anomaly detection model to be trained after updating based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features to obtain a trained image anomaly detection model for image anomaly detection on the input image. By introducing the hint sample coding features and combining them with the normal sample coding features to perform at least one level of combined decoding processing to reconstruct the features of the normal sample image, and introducing the hint sample coding features and combining them with the abnormal sample coding features to perform at least one level of combined decoding processing to restore the features of the abnormal sample image, the image anomaly detection capability of the image anomaly detection model can be enhanced by utilizing the image context information of the reference sample image and the corresponding dynamic hint coding features of each level, thereby improving the accuracy of image anomaly detection for the input image by the trained image anomaly detection model. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0042] Figure 1 A diagram showing an application environment of an image anomaly detection method in one embodiment;

[0043] Figure 2 1 is a flow chart of an image anomaly detection method according to an embodiment;

[0044] Figure 3 is a flowchart of an image anomaly detection method in yet another embodiment;

[0045] Figure 4 A schematic diagram of a flow chart of feature extraction and encoding processing in one embodiment;

[0046] Figure 5 A schematic diagram of a combined decoding process in one embodiment;

[0047] Figure 6 A schematic diagram of a flow chart of combined decoding processing within a certain layer in one embodiment;

[0048] Figure 7 A schematic diagram of a process for obtaining a prompt coding feature in one embodiment;

[0049] Figure 8 A schematic diagram of a process for obtaining a detection coding feature in one embodiment;

[0050] Fig. 9 A schematic diagram of a process of updating a model in one embodiment;

[0051] Fig.10 A schematic diagram of a process of an image anomaly detection model processing method in one embodiment;

[0052] Fig.11 is a framework diagram of image anomaly detection in one embodiment;

[0053] Fig.12 is a comparison table of detection results of different image anomaly detection methods in one embodiment;

[0054] Fig.13 is a structural block diagram of an image anomaly detection device in one embodiment;

[0055] Fig.14 is a structural block diagram of an image anomaly detection model processing device in one embodiment;

[0056] Fig.15 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0058] The image anomaly detection method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 104 through a network. The data storage system can store data that the server 104 needs to process. The data storage system can be set up separately, integrated on the server 104, or placed on the cloud or other servers.

[0059] The terminal 102 can perform image acquisition, such as industrial product image acquisition, medical image acquisition, etc. The terminal 102 can send the acquired image to be detected to the server 104 through the network. The server 104 obtains the image to be detected sent by the terminal 102, and encodes the original image features of the image to be detected to obtain the detection coding features of the image to be detected. The server 104 determines the prompt original features associated with the image to be detected and extracted from the reference image corresponding to the image to be detected and not including abnormalities, and encodes the prompt original features to obtain the prompt coding features. The server 104 performs at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features output by the combined decoding processing of at least one level. In the combined decoding processing of each level, the attention feature extraction is performed for the target detection coding features and the target prompt coding features input at the level, and the prompt coding features output at the level are obtained. Attention feature extraction is performed for the prompt coding features and the target detection coding features output at the level, and the detection coding features output at the level are obtained. The server 104 obtains the image reconstruction feature for the image to be detected based on the combined decoding feature, and obtains the abnormality detection result for the image to be detected based on the reconstruction difference between the image reconstruction feature and the original feature of the image. The server 104 can also feed back the abnormality detection result to the terminal 102. In some embodiments, the image abnormality detection method can also be implemented by the server 104 or the terminal 102 alone, such as the server 104 can directly obtain the image to be detected from the data storage system, and perform image abnormality detection processing on the image to be detected; for example, after the terminal 102 collects the image to be detected, the image abnormality detection processing can be directly performed on the image to be detected through the terminal 102.

[0060] The image anomaly detection model processing method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Specifically, the server 104 can obtain a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image. The normal sample image, the reference sample image, and the abnormal sample image can be sent by the terminal 102 to the server 104. The server 104 can perform feature extraction on the normal sample image, the reference sample image, and the abnormal sample image to obtain the original features of each image. The server 104 encodes the original features of each image through the image abnormality detection model to be trained to obtain the normal sample encoding feature, the prompt sample encoding feature, and the abnormal sample encoding feature. The server 104 performs at least one level of combined decoding processing based on the normal sample encoding feature and the prompt sample encoding feature through the image abnormality detection model to be trained to construct the normal sample reconstruction feature for the normal sample image, and performs at least one level of combined decoding processing based on the abnormal sample encoding feature and the prompt sample encoding feature through the image abnormality detection model to be trained to construct the abnormal sample recovery feature for the abnormal sample image. The server 104 then updates the image abnormality detection model to be trained based on the normal sample reconstruction feature, the abnormal sample recovery feature, and the normal image original feature and continues to train, and obtains a trained image abnormality detection model for image abnormality detection for the input image. After obtaining the trained image anomaly detection model, the user can send the image to be detected to the server 104 through the terminal 102. The server 104 can input the image to be detected sent by the terminal 102 into the trained image anomaly detection model to perform image anomaly detection, and feed back the anomaly detection result output by the image anomaly detection model to the terminal 102.

[0061] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal 102 and the server 104 can be directly or indirectly connected via wired or wireless communication, which is not limited here.

[0062] Among them, cloud technology refers to a hosting technology that unifies hardware, software, network and other resources in a wide area network or local area network to realize data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which is used on demand and flexible and convenient. Cloud computing technology will become an important support. The background services of technical network systems require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the background system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.

[0063] Cloud computing refers to the delivery and use model of IT infrastructure, which means obtaining required resources through the network in an on-demand and easily scalable manner; in a broad sense, cloud computing refers to the delivery and use model of services, which means obtaining required services through the network in an on-demand and easily scalable manner. This service can be related to IT and software, the Internet, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing. With the development of the Internet, real-time data streams, and the diversification of connected devices, as well as the promotion of search services, social networks, mobile commerce, and open collaboration, cloud computing has developed rapidly. Different from the previous parallel distributed computing, the emergence of cloud computing will promote revolutionary changes in the entire Internet model and enterprise management model from a conceptual perspective.

[0064] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making. Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level technology and software-level technology. The basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, pre-trained model technology, operation / interaction system, mechatronics, etc. Among them, the pre-trained model is also called the large model or basic model. After fine-tuning, it can be widely used in downstream tasks in various major directions of artificial intelligence. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0065] Computer Vision (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to machine vision such as using cameras and computers to replace human eyes to identify and measure targets, and further processing graphics to make computer processing into images that are more suitable for human eye observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data. Large model technology has brought important changes to the development of computer vision technology. Pre-trained models in the visual field such as swin-transformer, ViT, V-MOE, and MAE can be quickly and widely applied to downstream specific tasks after fine tuning. Computer vision technology usually includes image processing, image recognition, image semantic understanding, image retrieval, OCR, video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and mapping, and other technologies, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.

[0066] Machine Learning (ML) is a multi-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning by induction. The pre-trained model is the latest development of deep learning, which integrates the above technologies.

[0067] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, driverless cars, autonomous driving, drones, digital twins, virtual humans, robots, artificial intelligence generated content (AIGC), conversational interaction, smart medical care, smart customer service, game AI, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.

[0068] The so-called artificial intelligence cloud service is generally also called AIaaS (AI as a Service, Chinese for "AI as a Service"). This is the service mode of a mainstream artificial intelligence platform. Specifically, the AIaaS platform will split several common AI services and provide independent or packaged services in the cloud. This service model is similar to opening an AI theme mall: all developers can access and use one or more artificial intelligence services provided by the platform through the API interface. Some senior developers can also use the AI ​​framework and AI infrastructure provided by the platform to deploy and operate their own cloud artificial intelligence services.

[0069] The solutions provided in the embodiments of the present application involve artificial intelligence technologies such as computer vision, machine learning, and deep learning, which are specifically illustrated by the following embodiments.

[0070] In an exemplary embodiment, Figure 2 As shown, a method for detecting anomalies in an image is provided. The method is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the embodiment of the present application, the method is applied to Figure 1 The server in the example is used to illustrate, including the following steps 202 to 210. Among them:

[0071] Step 202: Acquire the image to be detected, and encode the original image features of the image to be detected to obtain the detection coding features of the image to be detected.

[0072] Among them, image anomaly detection technology has a wide range of applications in multiple fields. For example, in the medical field, image anomaly detection can be used for disease diagnosis; in the field of autonomous driving, this technology can help vehicles identify abnormal objects on the road; in the retail industry, image anomaly detection can be used to identify abnormal behavior; in the agricultural field, it can be used for crop health monitoring and pest detection. The image to be detected is an image that needs to be detected for anomalies, and can be acquired by an image acquisition device. In different image anomaly detection application scenarios, the image to be detected may include different image contents. The original image features may be preliminary image features extracted from the image to be detected, such as the original image features extracted from the image to be detected by a pre-trained feature extraction network. The feature extraction network can be trained based on various neural network algorithms, which may include but are not limited to at least one of convolutional neural networks (CNN), recurrent neural networks (RNN), transformers, feedforward neural networks, generative adversarial networks (GANs) or autoencoders. The detection coding features are obtained by encoding the original features of the image. Specifically, the original features of the image can be encoded by the encoding network to obtain the detection coding features of the image to be detected. In a specific implementation, the encoding network can be obtained based on various neural network model architectures, such as being constructed based on an attention mechanism.

[0073] Exemplarily, the server may obtain an image to be detected that needs to be detected for image anomaly detection, and the server may determine the original image features of the image to be detected. Specifically, the server may call a pre-trained feature extraction network to extract features of the image to be detected to obtain the original image features. The server may encode the original image features, and specifically, may call an encoding network to perform at least one level of encoding processing on the original image features to obtain the detection encoding features of the image to be detected. By decoding the detection encoding features of the image to be detected, feature reconstruction of the image to be detected may be achieved, so that the obtained reconstructed features may be used for anomaly detection processing.

[0074] Step 204, determining the prompt original features associated with the image to be detected, and encoding the prompt original features to obtain prompt encoded features; the prompt original features are extracted from the reference image that does not include anomalies and corresponds to the image to be detected.

[0075] Among them, the prompt original feature is associated with the image to be detected, which can be specifically the preliminary image feature extracted from the reference image corresponding to the image to be detected. The reference image does not include abnormalities, and is a normal image relative to the image to be detected, that is, there is no abnormality in the reference image. For example, in the abnormality detection processing scenario for medical images, the image to be detected can be a collected medical image that needs to be detected, and the reference image can be a medical image that has been confirmed in advance to be a normal image, that is, a medical image that does not include abnormalities. The higher the similarity between the image to be detected and the reference image, such as the higher the feature matching degree between the image features of the image to be detected and the image features of the reference image, the more the image to be detected tends to the reference image, that is, the more likely the image to be detected is a normal image that does not include abnormalities; and the less similar the image to be detected is to the reference image, the more likely the image to be detected is an abnormal image that includes abnormal content. For example, various abnormal contents such as foreign matter, scratches, and missing may exist in the image to be detected.

[0076] In a specific application, the server may pre-acquire each reference image that does not include anomalies, and perform feature extraction for each reference image, such as performing feature extraction through a pre-trained feature extraction network, to obtain the prompt original features of each reference image. After obtaining the image to be detected, the server may determine the prompt original features associated with the image to be detected from the prompt original features of each reference image. The prompt coding feature is obtained by encoding based on the prompt original feature, and specifically, the prompt original feature may be encoded through an encoding network to obtain the prompt coding feature.

[0077] Optionally, the server can determine the prompt original features associated with the image to be detected. In a specific implementation, the server can pre-store the prompt original features of each reference image, and the prompt original features of each reference image can be obtained by the server in advance through a feature extraction network for each reference image. The server can directly determine the prompt original features associated with the image to be detected from the stored prompt original features. For example, the server can match the image original features of the image to be detected with the stored prompt original features respectively, and determine the prompt original features associated with the image to be detected according to the matching result, and specifically can use the prompt original features with the highest matching degree represented by the matching result as the prompt original features associated with the image to be detected. In certain embodiments, the server can also first determine the reference image corresponding to the image to be detected, and perform feature extraction for the reference image corresponding to the image to be detected, so as to obtain the prompt original features associated with the image to be detected. The server can encode the prompt original features, and specifically can call the encoding network to perform at least one level of encoding processing for the prompt original features to obtain the prompt encoding features. In some embodiments, the original image features and the hint original features of the image to be detected can be respectively extracted through the same feature extraction network, and the encoding of the original image features and the hint original features can also be implemented based on the same encoding network.

[0078] Step 206, performing at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features output by at least one level of combined decoding processing, and in the combined decoding processing at each level, performing attention feature extraction on the target detection coding features and the target prompt coding features input at the level to obtain the prompt coding features output at the level, and performing attention feature extraction on the prompt coding features and the target detection coding features output at the level to obtain the detection coding features output at the level.

[0079] Among them, the input of the combined decoding process is the detection coding features of the image to be detected and the prompt coding features obtained by encoding the prompt original features; the output of the combined decoding process can also include the corresponding detection coding features and prompt coding features, that is, the combined decoding features output by the combined decoding process of at least one level may include the detection coding features and prompt coding features corresponding to the output of the last level. In the multi-level combined decoding process, the combined decoding process of the first level can be directly implemented based on the detection coding features of the image to be detected and the prompt coding features obtained by encoding the prompt original features; and starting from the second level of combined decoding process, the detection coding features and prompt coding features corresponding to the output of the combined decoding process of the previous level can be used as the input of this level, so as to perform multiple iterations of combined decoding process until the combined decoding process of the last level is completed and the combined decoding features are output.

[0080] In the combined decoding process of each level, the target detection coding features and the target prompt coding features are the input of the combined decoding process of this level, and specifically can be the output of the combined decoding process of the previous level. Attention feature extraction can be based on the feature extraction process implemented by the attention mechanism. There is a certain connection between the target detection coding features and the target prompt coding features. The attention mechanism can establish the correlation between the target detection coding features and the target prompt coding features, so that features with stronger representation capabilities can be obtained, that is, the attention mechanism can enhance the expression of the correlation between the target detection coding features and the target prompt coding features. The prompt coding features output by the level are obtained by extracting the attention features based on the target detection coding features and the target prompt coding features input by the level; the detection coding features output by the level are obtained by extracting the attention features based on the prompt coding features and the target detection coding features output by the level.

[0081] Specifically, the server can perform at least one level of combined decoding processing based on the detection coding features and prompt coding features obtained by encoding to obtain combined decoding features. In the combined decoding processing of each level, the server can determine the target detection coding features and target prompt coding features input at the level, and extract features for the target detection coding features and target prompt coding features based on the attention mechanism to obtain the prompt coding features output at the level. Further, the server extracts features from the prompt coding features and target detection coding features output at the level based on the attention mechanism to obtain the detection coding features output at the level. The server can use the output of the combined decoding processing of this level as the input of the combined decoding processing of the next level, that is, the server can input the prompt coding features and detection coding features output by the combined decoding processing of this level to the next level to perform the combined decoding processing of the next level. In some embodiments, at least one level of combined decoding processing can be implemented based on the combined decoding processing layer structure, and each layer structure can implement a level of combined decoding processing, so that at least one level of combined decoding processing is implemented by setting at least one layer structure.

[0082] Step 208: Obtain image reconstruction features for the image to be detected according to the combined decoding features.

[0083] Among them, the image reconstruction feature is a feature obtained by reconstructing the features of the image to be detected, and can be obtained by performing feature mapping on the combined decoding features, such as performing feature mapping on the combined decoding features based on the attention mechanism to obtain the image reconstruction features of the image to be detected. Specifically, the server can obtain the image reconstruction features of the image to be detected based on the combined decoding features, such as the server can perform feature mapping on the combined decoding features through the feature mapping layer to obtain the image reconstruction features of the image to be detected. In a specific implementation, the feature mapping for the combined decoding features can be implemented according to actual needs, such as further attention feature extraction can be performed on the combined decoding features to obtain the image reconstruction features of the image to be detected.

[0084] Step 210: Obtain an abnormality detection result for the image to be detected based on the reconstruction difference between the image reconstructed features and the image original features.

[0085] Among them, the reconstruction difference is used to characterize the feature difference between the image reconstruction feature and the image original feature. Specifically, the image reconstruction feature and the image original feature can be compared to obtain the feature. According to the reconstruction difference, the abnormality detection result of the image to be detected can be determined. Exemplarily, the server can determine the reconstruction difference between the image reconstruction feature and the image original feature. Specifically, the server can compare the image reconstruction feature and the image original feature to obtain the reconstruction difference. The server determines the abnormality detection result for the image to be detected based on the reconstruction difference. For example, the server can map the reconstruction difference to obtain the abnormality detection parameters for the image to be detected, and the abnormality detection result of the image to be detected can be obtained according to the abnormality detection parameters. In some embodiments, the abnormality detection parameters may include an abnormality detection score. The abnormality detection result can be determined based on the abnormality detection score and the score threshold. If the abnormality detection score exceeds the score threshold, it can be considered that there is an abnormality in the image to be detected, that is, the image to be detected is an abnormal image.

[0086] In some embodiments, Figure 3 As shown, after the server obtains the image to be detected, it extracts the original features of the image to be detected, and encodes the original features of the image to be detected to obtain the detection coding features of the image to be detected; the server obtains the prompt original features associated with the image to be detected, and the prompt original features are obtained by feature extraction based on the reference image corresponding to the image to be detected that does not include abnormalities, and the server encodes the prompt original features to obtain the prompt coding features. The server performs at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features. The server determines the image reconstruction features based on the combined decoding features, and obtains the reconstruction difference based on the image reconstruction features and the original features of the image, and the server determines the abnormality detection result of the image to be detected based on the reconstruction difference.

[0087] In some embodiments, Figure 4As shown, for the image to be detected and the reference image, feature extraction can be performed respectively through the same feature extraction network. The specific server can input the image to be detected and the reference image into the same feature extraction network respectively, and the feature extraction network outputs the original features of the image and the original features of the prompt respectively. The encoding of the original features of the image and the original features of the prompt can also be implemented through the same encoding network. The specific server can input the original features of the image and the original features of the prompt into the same encoding network respectively, and the encoding network outputs the detection encoding features and the prompt encoding features respectively.

[0088] In some embodiments, Figure 5 As shown, at least one level of combined decoding processing may include N levels of combined decoding processing. For the first level, the first level of combined decoding processing can be directly performed on the detection coding features and prompt coding features of the image to be detected, that is, in the first level, the detection coding features of the image to be detected are directly used as the target detection coding features of this level, and the prompt coding features obtained by encoding the prompt original features are used as the target prompt coding features of this level, so as to obtain the detection coding features and prompt coding features output by the first level. The detection coding features and prompt coding features output by the first level can be input into the second level for combined decoding processing of the second level. The detection coding features and prompt coding features output by the second level can be input into the next level for combined decoding processing of the next level. Until the last level, that is, for the Nth level, the detection coding features and prompt coding features output by the N-1th level can be used as input for combined decoding processing of the Nth level, and the combined decoding features are output.

[0089] In some embodiments, Figure 6 As shown, in the combined decoding process of each level, such as in the combined decoding process of the Kth level, the server can use the prompt coding features and detection coding features output by the K-1th level as the input of the Kth level, that is, use the prompt coding features output by the K-1th level as the target prompt coding features of the Kth level, and use the detection coding features output by the K-1th level as the target detection coding features of the Kth level. The server extracts attention features based on the target detection coding features and the target prompt coding features to obtain the prompt coding features output by the level; the server extracts attention features based on the prompt coding features and the target detection coding features output by the level to obtain the detection coding features output by the level. The server outputs the prompt coding features and the detection coding features through the Kth level, and the server can use the prompt coding features and the detection coding features output by the Kth level as the input of the K+1th level to perform combined decoding process for the K+1th level.

[0090] In the above-mentioned image anomaly detection method, the original image features of the image to be detected are encoded to obtain detection coding features, the prompt original features associated with the image to be detected and extracted from the reference image that does not include the anomaly are encoded to obtain prompt coding features, and at least one level of combined decoding processing is performed based on the detection coding features and the prompt coding features to obtain combined decoding features. In the combined decoding processing of each level, attention features are extracted for the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and attention features are extracted for the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level. Image reconstruction features for the image to be detected are obtained based on the combined decoding features, and the anomaly detection result of the image to be detected is obtained based on the reconstruction difference between the image reconstruction features and the original image features. During image anomaly detection processing, in the combined decoding processing of each level, attention features are extracted through the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and attention features are extracted from the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level. The image context information of the reference image that does not include anomalies and the corresponding dynamic prompt coding features of each level can be comprehensively utilized to construct a combined decoding feature, thereby enhancing the feature expression ability of the combined decoding feature, thereby improving the accuracy of image anomaly detection based on the reconstructed features obtained from the combined decoding feature.

[0091] In an exemplary embodiment, attention feature extraction is performed on the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, including: obtaining the first key feature and the first value feature according to the target detection coding features input at the level, and obtaining the first query feature according to the target prompt coding features input at the level; cross-attention feature extraction is performed on the first key feature, the first value feature and the first query feature to obtain the prompt coding features output at the level.

[0092] Among them, in the attention mechanism, Q (Query), K (Key) and V (Value) are three core concepts. The basic idea of ​​Q, K, and V is to calculate the correlation between the Query and each Key, obtain the weight of each Key corresponding to the Value, and then perform weighted summation on the Value to obtain the final attention value. This mechanism can adaptively select and focus on the Key and Value most relevant to the Query according to the needs of the Query when processing information. The key feature can be used as the key vector in the attention mechanism, the value feature can be used as the value vector in the attention mechanism, and the query feature can be used as the query vector in the attention mechanism.

[0093] Cross-Attention is a variation of the neural network attention mechanism, which is mainly used to process the correlation information between multiple input sequences or features. In the traditional self-attention mechanism, attention is calculated between the input sequences or features themselves, but in the cross-attention mechanism, in addition to calculating the self-attention within the input sequence or feature, the attention between different input sequences or features is also calculated. The cross-attention mechanism can selectively focus on specific areas or features in the image, thereby generating more discriminative feature representations, so that the image content can be more accurately recognized and understood. Moreover, different levels of attention modules can capture different levels of features, thereby achieving incremental performance improvements. This mechanism makes the model more flexible and efficient when processing complex image tasks.

[0094] Specifically, in the combined decoding process of each level, the server can determine the input of the level, including the target detection coding features and the target prompt coding features, and the input of the level can be specifically the output of the previous level. The server constructs the parameters under the attention mechanism according to the input of the level, including key features, value features and query features. In specific applications, the server can obtain the first key feature and the first value feature according to the target detection coding feature, such as directly using the target detection coding feature as the first key feature and the first value feature respectively. The server can obtain the first query feature according to the target prompt coding feature input at the level, such as directly using the target prompt coding feature as the first query feature. The server performs cross-attention feature extraction based on the obtained first key feature, first value feature and first query feature, and specifically can perform feature extraction on the first key feature, the first value feature and the first query feature based on the cross-attention mechanism to obtain the prompt coding feature output at the level.

[0095] In one embodiment, Figure 7As shown, in the combined decoding process of a certain level, the target detection coding features of the input level are used as the key vector (K) and the value vector (V), respectively, and the target prompt coding features of the input level are used as the query vector (Q). Cross-attention features are extracted through the key vector (K), the value vector (V) and the query vector (Q) to obtain the prompt coding features of the output level.

[0096] In this embodiment, in the combined decoding processing of each level, the server obtains the first key feature and the first value feature according to the target detection coding feature input at the level, obtains the first query feature according to the target prompt coding feature input at the level, and performs cross-attention feature extraction based on the determined first key feature, first value feature and first query feature. This can implement cross-attention processing from target prompt coding features to target detection coding features, enhance the feature expression capability of the prompt coding features output at the level, and thus help improve the accuracy of image anomaly detection.

[0097] In an exemplary embodiment, cross-attention feature extraction is performed on the first key feature, the first value feature and the first query feature to obtain a prompt coding feature output at the level, including: performing cross-attention feature extraction based on the attention mechanism according to the first key feature, the first value feature and the first query feature to obtain a first cross-attention feature; performing residual fusion on the first cross-attention feature and the first query feature to obtain a fused feature; performing feature mapping on the fused feature at least once to obtain a mapping feature; performing residual fusion on the mapping feature and the fused feature to obtain a prompt coding feature output at the level.

[0098] Among them, the cross-attention feature is a feature directly obtained by extracting cross-attention features based on the attention mechanism, and is obtained according to the corresponding value features, key features, and query features. The fusion feature is obtained by fusing the first cross-attention feature with the first query feature. In specific implementation, the first cross-attention feature and the first query feature can be weighted fused. The mapping feature is obtained by mapping the fusion feature. Specifically, the fusion feature can be mapped through a mapping layer structure, such as mapping the fusion feature through an MLP (Multilayer Perceptron) layer structure to obtain the mapping feature.

[0099] Exemplarily, based on the attention mechanism, the server can directly perform cross-attention feature extraction on the first key feature, the first value feature and the first query feature to obtain the first cross-attention feature. The server can perform residual fusion on the first cross-attention feature and the first query feature to obtain a fused feature. Feature information of different layers or information of different modalities are fused through residual fusion to obtain a richer feature representation. The server can perform feature mapping on the fused feature at least once, such as mapping the fused feature through at least one mapping layer structure to obtain a mapping feature. The server further performs residual fusion on the mapping feature and the fused feature, and specifically can perform weighted fusion on the mapping feature and the fused feature to obtain the prompt coding feature output at the level.

[0100] In this embodiment, the server performs residual fusion on the obtained first cross-attention feature and the first query feature, and after performing feature mapping on the fused feature at least once, performs residual fusion on the mapped feature and the fused feature. This can fuse image feature information at different levels and enhance the feature expression capability of the prompt coding feature output at the level, thereby helping to improve the accuracy of image anomaly detection.

[0101] In an exemplary embodiment, attention feature extraction is performed on the prompt coding features and target detection coding features output by the level at which the user is located to obtain the detection coding features output by the level at which the user is located, including: obtaining a second key feature and a second value feature based on the prompt coding features output by the level at which the user is located, and obtaining a second query feature based on the target detection coding features input by the level at which the user is located; and cross-attention feature extraction is performed on the second key feature, the second value feature, and the second query feature to obtain the detection coding features output by the level at which the user is located.

[0102] Exemplarily, in the combined decoding process of each level, the server can construct parameters under the attention mechanism, including key features, value features and query features, according to the target detection coding features input by the level and the prompt coding features output by the level. In a specific application, the server can obtain the second key feature and the second value feature according to the prompt coding features output by the level, such as directly using the prompt coding features output by the level as the second key feature and the second value feature, respectively. The server can obtain the second query feature according to the target detection coding features input by the level, such as directly using the target detection coding features as the second query feature. The server performs cross-attention feature extraction based on the obtained second key feature, second value feature and second query feature, and specifically can perform feature extraction on the second key feature, second value feature and second query feature based on the cross-attention mechanism to obtain the detection coding features output by the level.

[0103] In one embodiment, Figure 8As shown, in the combined decoding process of a certain level, the prompt coding features output by the level are used as the key vector (K) and the value vector (V), respectively, and the target detection coding features input by the level are used as the query vector (Q). Cross-attention feature extraction is performed through the key vector (K), the value vector (V) and the query vector (Q) to obtain the detection coding features output by the level.

[0104] In this embodiment, in the combined decoding processing of each level, the server obtains the second key feature and the second value feature according to the prompt coding feature output by the level, obtains the second query feature according to the target detection coding feature input by the level, and performs cross-attention feature extraction based on the determined second key feature, second value feature and second query feature. This can realize cross-attention processing from target detection coding feature to target prompt coding feature, enhance the feature expression ability of the prompt coding feature output by the level, and thus help improve the accuracy of image anomaly detection.

[0105] In an exemplary embodiment, cross-attention feature extraction is performed on the second key feature, the second value feature, and the second query feature to obtain the detection coding feature output at the level, including: performing cross-attention feature extraction based on the attention mechanism according to the second key feature, the second value feature, and the second query feature to obtain the second cross-attention feature; residually fusing the second cross-attention feature with the second query feature to obtain the detection coding feature output at the level.

[0106] Optionally, the server can directly perform cross-attention feature extraction on the second key feature, the second value feature, and the second query feature based on the attention mechanism to obtain a second cross-attention feature. The server can perform residual fusion on the second cross-attention feature and the second query feature to obtain the detection coding feature output at the level. In this embodiment, the server performs residual fusion on the obtained second cross-attention feature and the second query feature, which can fuse image feature information at different levels, and can enhance the feature expression ability of the detection coding feature output at the level, thereby facilitating improving the accuracy of image anomaly detection.

[0107] In an exemplary embodiment, at least one level includes multiple levels; combined decoding processing of at least one level is performed based on detection coding features and prompt coding features to obtain combined decoding features output by the combined decoding processing of at least one level, including: in the combined decoding processing of the first level among the multiple levels, attention feature extraction is performed on the detection coding features and prompt coding features inputted into the first level to obtain prompt coding features outputted from the first level, and attention feature extraction is performed on the prompt coding features and detection features outputted from the first level to obtain detection coding features outputted from the first level; for each level starting from the second level among the multiple levels, combined decoding processing of the level is performed based on the prompt coding features and detection coding features outputted from the previous level to obtain the prompt coding features and detection coding features outputted from the level, until the combined decoding processing of the last level among the multiple levels outputs combined decoding features of multiple levels.

[0108] When the combined decoding process includes multiple levels, for the combined decoding process of the first level, the detection coding features of the image to be detected and the hint coding features obtained by hinting the original feature coding are directly used as input for combined decoding process. Starting from the second level, the output of the previous level is used as the input of this level for combined decoding process.

[0109] Exemplarily, for the combined decoding processing of the first level among multiple levels, the server can directly perform attention feature extraction on the detection coding features and prompt coding features inputted by the first level, and obtain the prompt coding features outputted by the first level. The server performs attention feature extraction on the prompt coding features and detection features outputted by the first level, and obtains the detection coding features outputted by the first level. For each level starting from the second level, the server uses the prompt coding features and detection coding features outputted by the previous level as the target detection coding features and target prompt coding features inputted by this level. In specific implementation, the server can determine the prompt coding features and detection coding features outputted by the previous level, and perform combined decoding processing of the level based on the prompt coding features and detection coding features outputted by the previous level, and obtain the prompt coding features and detection coding features outputted by the level, until the combined decoding processing is completed at the last level, and the combined decoding features of multiple levels are obtained according to the output of the combined decoding processing of the last level.

[0110] In this embodiment, the server performs multi-level combined decoding processing based on the detection coding features and the prompt coding features, and can perform deep attention feature extraction based on the detection coding features and the prompt coding features, which is beneficial to enhancing the feature expression ability of the combined decoding features, thereby improving the accuracy of image anomaly detection based on the combined decoding features.

[0111] In an exemplary embodiment, image reconstruction features for the image to be detected are obtained based on the combined decoding features, including: performing cross-attention feature extraction on the detection coding features and prompt coding features included in the combined decoding features to obtain image reconstruction features for the image to be detected.

[0112] The combined decoding feature is obtained according to the output of the combined decoding process of the last level in at least one level of combined decoding process, and the combined decoding feature may include the prompt coding feature and the detection coding feature output by the combined decoding process of the last level.

[0113] Specifically, for the combined decoding features output by at least one level of combined decoding processing, the server can perform cross-attention feature extraction based on the detection coding features and prompt coding features included in the combined decoding features. For example, cross-attention feature extraction can be performed on the detection coding features and prompt coding features included in the combined decoding features based on the attention mechanism to obtain image reconstruction features of the image to be detected.

[0114] In this embodiment, the server performs cross-attention feature extraction on the detection coding features and prompt coding features included in the combined decoding features, and thereby reconstructs the image reconstruction features of the image to be detected using the combined decoding features based on the attention mechanism. The information carried by the detection coding features and the prompt coding features can be further integrated, and the feature expression capability of the image reconstruction features can be enhanced, thereby facilitating the accuracy of image anomaly detection.

[0115] In an exemplary embodiment, based on the reconstruction difference between the image reconstructed features and the image original features, an abnormality detection result for the image to be detected is obtained, including: determining the reconstruction difference between the image reconstructed features and the image original features; mapping the reconstruction difference to obtain abnormality mapping parameters; and determining the abnormality detection result for the image to be detected based on the abnormality mapping parameters.

[0116] The reconstruction difference is used to indicate the similarity between the image reconstruction feature and the image original feature, and can reflect the error caused by the reconstruction of the image to be detected. The abnormal mapping parameter is obtained based on the reconstruction difference mapping, and can be specifically implemented by mapping the reconstruction difference through a preset mapping relationship.

[0117] Exemplarily, the server may determine the reconstruction difference between the image reconstruction feature and the image original feature, and specifically may compare the image reconstruction feature with the image original feature to obtain the reconstruction difference. For example, the server may perform absolute element-by-element subtraction between the image reconstruction feature and the image original feature to determine the reconstruction difference. The server may map the reconstruction difference, and specifically may map the reconstruction difference according to a preset mapping relationship to obtain an abnormal mapping parameter. For example, the server may perform L2 norm mapping on the reconstruction difference to obtain the L2 norm of the reconstruction difference, and use the L2 norm as the abnormal mapping parameter. The server obtains an abnormal detection result of the image to be detected based on the abnormal mapping parameter, such as the server may directly obtain the abnormal detection result according to the abnormal mapping parameter, or may obtain the abnormal detection result of the image to be detected after performing an abnormal determination on the abnormal mapping parameter. For example, the server may compare the abnormal mapping parameter with a preset threshold value, and when the abnormal mapping parameter exceeds the preset threshold value, it is considered that the image to be detected belongs to an abnormal image, and then an abnormal detection result indicating that the image to be detected is an abnormal image may be obtained.

[0118] In this embodiment, the server maps the reconstructed differences between the image reconstructed features and the image original features, and determines the anomaly detection result according to the anomaly mapping parameters obtained by mapping, so as to make quantitative anomaly judgments on the image to be detected, which is beneficial to ensure the accuracy of image anomaly detection.

[0119] In an exemplary embodiment, the image anomaly detection method further includes: performing at least one level of pixel feature extraction on the reconstruction difference to obtain a pixel anomaly result.

[0120] Among them, the pixel anomaly result is obtained by performing pixel feature extraction on the reconstructed difference. Pixel feature extraction refers to feature extraction based on the pixel level for the reconstructed difference, which may specifically include various feature extraction processes such as convolution, normalization, and linear rectification. Exemplarily, the server may further perform pixel feature extraction on the reconstructed difference. Specifically, the server may perform at least one level of pixel feature extraction on the reconstructed difference, such as performing at least one level of convolution operation, normalization, linear rectification, deconvolution, and other pixel feature extraction on the reconstructed difference to obtain the pixel anomaly result. The pixel anomaly result may reflect the anomaly detection result of the image to be detected at the pixel level, and may specifically include an anomaly map, which may be an image area where an anomaly is detected in the image to be detected.

[0121] Furthermore, determining an anomaly detection result for the image to be detected based on the anomaly mapping parameter includes: weighted fusion of the anomaly mapping parameter and the pixel anomaly result to obtain an anomaly fusion result; and determining an anomaly detection result for the image to be detected based on the anomaly fusion result.

[0122] Among them, the abnormal fusion result is obtained by weighted fusion of the abnormal mapping parameters and the pixel abnormal results. Specifically, the server can fuse the abnormal mapping parameters with the pixel abnormal results, and specifically can fuse the abnormal mapping parameters with the pixel abnormal results according to the preset weighted weights to obtain the abnormal fusion result. The server obtains the abnormal detection result for the image to be detected based on the abnormal fusion result. In a specific application, the abnormal fusion result can include a quantization parameter, and the server can perform a quality comparison of the abnormal fusion result with the threshold parameter to determine the abnormal detection result of the image to be detected according to the numerical comparison result.

[0123] In this embodiment, the server performs at least one level of pixel feature extraction on the reconstructed difference to obtain a pixel anomaly result, and determines the anomaly detection result of the image to be detected by weighted fusion of the anomaly mapping parameters and the pixel anomaly result. Anomaly detection can be performed on the image to be detected from different dimensions, which can improve the accuracy of image anomaly detection.

[0124] In an exemplary embodiment, the original image features of the image to be detected are encoded to obtain the detection coding features of the image to be detected, including: extracting the original image features of the image to be detected, and performing at least one level of attention feature encoding on the original image features to obtain the detection coding features of the image to be detected.

[0125] Among them, the original features of the image can be extracted from the image to be detected through a pre-trained feature extraction network, and the original features of the image are used as preliminary image features extracted from the image to be detected. Feature encoding is performed based on the attention mechanism for the original features of the image to obtain detection encoding features. In order to encode deep features, multiple attention feature encodings can be performed on the original features of the image to obtain detection encoding features.

[0126] Specifically, the server can perform feature extraction on the acquired image to be detected, such as calling a pre-trained feature extraction network to perform feature extraction on the image to be detected to obtain the original features of the image. The server performs attention feature encoding on the original features of the image, specifically, it can perform at least one level of attention feature encoding on the original features of the image by calling an encoding network to obtain the detection coding features of the image to be detected. In a specific application, the server can perform at least one level of attention feature encoding on the original features of the image based on the self-attention mechanism, that is, perform at least one level of self-attention feature extraction on the original features of the image, so as to obtain the detection coding features of the image to be detected. In some embodiments, various processing such as residual fusion and feature mapping can also be introduced for the attention feature encoding to enrich the information carried by the detection coding features and ensure the feature expression capability of the detection coding features.

[0127] Furthermore, the prompt original features associated with the image to be detected are determined, and the prompt original features are encoded to obtain prompt coded features, including: determining the prompt original features associated with the image to be detected from a prompt feature pool, the prompt feature pool including at least one candidate prompt original feature extracted based on a reference image; performing at least one level of attention feature encoding on the prompt original features to obtain prompt coded features.

[0128] The prompt feature pool is used to store candidate prompt original features, which are image original features extracted based on reference images. The reference image can be a normal image that has been confirmed in advance, that is, an image that does not contain abnormalities. The prompt original features can be feature encoded based on the attention mechanism to obtain prompt encoded features.

[0129] Specifically, the server can determine the prompt original feature associated with the image to be detected from the prompt feature pool, and the prompt feature pool includes at least one candidate prompt original feature extracted based on the reference image, and the candidate prompt original feature is obtained by pre-extracting features for the reference image. In some embodiments, the server can query the preset prompt feature pool, and match in the prompt feature pool based on the original features of the image to obtain the prompt original feature associated with the image to be detected. The server can perform at least one level of attention feature encoding for the prompt original feature by calling the encoding network to obtain the prompt encoding feature. In a specific application, the server can perform at least one level of attention feature encoding for the prompt original feature based on the self-attention mechanism, that is, perform at least one level of self-attention feature extraction on the prompt original feature, thereby prompting the encoding feature. In some embodiments, various processing such as residual fusion and feature mapping can also be introduced for the attention feature encoding to enrich the information carried by the prompt encoding feature and ensure the feature expression ability of the prompt encoding feature.

[0130] In this embodiment, the server performs at least one level of attention feature encoding for the original features of the image and the original features of the prompt respectively. Based on the attention mechanism, the server can enrich the information of the detection coding features and the prompt coding features, thereby ensuring the feature expression ability of the detection coding features and the prompt coding features, which is conducive to improving the accuracy of image anomaly detection.

[0131] In an exemplary embodiment, a prompt original feature associated with an image to be detected is determined from a prompt feature pool, including: determining the prompt feature pool; performing feature matching on the image original feature and each candidate prompt original feature in the prompt feature pool to obtain a feature matching result; and determining the candidate prompt original feature corresponding to the feature matching result indicating feature matching as the prompt original feature associated with the image to be detected.

[0132] The prompt feature pool is used to store the candidate prompt original features extracted based on each reference image. The feature matching result is used to characterize the feature matching degree between the original features of the image and the corresponding candidate prompt original features.

[0133] Specifically, the server can query the preset prompt feature pool, and perform feature matching between the original features of the image and each candidate prompt original feature in the prompt feature pool. For example, the server can calculate the feature similarity between the original features of the image and each candidate prompt original feature, thereby obtaining a feature matching result. The feature matching result can be used to characterize the degree of feature similarity between the original features of the image and the candidate prompt original features, thereby reflecting whether the original features of the image match the candidate prompt original features. The server can determine the feature matching result indicating feature matching, and determine the candidate prompt original feature corresponding to the feature matching result as the prompt original feature associated with the image to be detected.

[0134] In this embodiment, the server performs feature matching on the original features of the image with each candidate prompt original feature in the prompt feature pool, and determines the prompt original features according to the feature matching results. This can quickly and accurately obtain the prompt original features associated with the image to be detected for anomaly detection processing, which is beneficial to improving the processing efficiency and accuracy of image anomaly detection.

[0135] In an exemplary embodiment, an image anomaly detection method is implemented by an image anomaly detection model; the training steps of the image anomaly detection model include: obtaining a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image; performing feature extraction on the normal sample image, the reference sample image, and the abnormal sample image, respectively, to obtain normal image original features of the normal sample image, reference image original features of the reference sample image, and abnormal image original features of the abnormal sample image; encoding the normal image original features, the reference image original features, and the abnormal image original features, respectively, through the image anomaly detection model to be trained, to obtain normal sample encoded features of the normal sample image, prompt sample encoded features of the reference sample image, and abnormal sample encoded features of the abnormal sample image; and extracting features of the normal sample image, the reference sample image, and the abnormal sample image through the image anomaly detection model to be trained. A detection model is provided, wherein at least one level of combined decoding processing is performed based on the normal sample coding features and the prompt sample coding features to obtain a first combined decoding feature output by at least one level of combined decoding processing, and a normal sample reconstruction feature for a normal sample image is obtained according to the first combined decoding feature; through an image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the abnormal sample coding features and the prompt sample coding features to obtain a second combined decoding feature output by at least one level of combined decoding processing, and an abnormal sample recovery feature for an abnormal sample image is obtained according to the second combined decoding feature; the image anomaly detection model to be trained is updated based on the normal sample reconstruction feature, the abnormal sample recovery feature and the normal image original feature, and then training is continued until the training is completed to obtain a trained image anomaly detection model.

[0136] Among them, the image anomaly detection model can be constructed based on various artificial neural network algorithms and used to detect anomalies for input images. The normal sample image is a sample image that does not include image anomalies. The reference sample image is associated with the normal sample image. The reference sample image is used as a reference sample image. The image features carried by the reference sample image are used as prompt features to guide the training of the image anomaly detection model. The abnormal sample image is a sample image that includes image anomalies. The normal sample image, the reference sample image, and the abnormal sample image are specifically sample images belonging to the same application scenario, and the only difference is whether there are anomalies in the image content, such as whether there are missing, scratched, rotten, and other abnormal contents.

[0137] Specifically, the server may obtain sample images for the image anomaly detection model, including normal sample images, reference sample images, and abnormal sample images. For the normal sample images, reference sample images, and abnormal sample images, the server may perform feature extraction respectively, such as pre-trained feature extraction networks to perform feature extraction on the normal sample images, reference sample images, and abnormal sample images, respectively, to obtain respective original image features, specifically including normal image original features of the normal sample images, reference image original features of the reference sample images, and abnormal image original features of the abnormal sample images. The server may construct an image anomaly detection model to be trained, and the image anomaly detection model to be trained may be constructed based on at least one of a convolutional neural network, a recurrent neural network, a transformer, a feedforward neural network, a generative adversarial network, or an autoencoder. The server may encode the sample images through the image anomaly detection model to be trained to obtain respective encoding features. Specifically, the server may obtain the normal image original features of the normal sample images, the reference image original features of the reference sample images, and the abnormal image original features of the abnormal sample images, respectively, and the original image features of the various sample images may be extracted based on the same pre-trained feature extraction network. The server can encode the original features of the normal image, the original features of the reference image, and the original features of the abnormal image through the image anomaly detection model to be trained, and obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image. In a specific implementation, the image anomaly detection model to be trained may include an encoder network, and the encoder network can encode the input image original features to output corresponding encoding features.

[0138] The server can perform at least one level of combined decoding processing based on the normal sample coding features and the prompt sample coding features through the image anomaly detection model to be trained, obtain the corresponding first combined decoding features, and obtain the normal sample reconstruction features according to the first combined decoding features. The server can perform at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features through the image anomaly detection model to be trained, obtain the corresponding second combined decoding features, and obtain the abnormal sample recovery features according to the second combined decoding features. In a specific implementation, the server can perform combined decoding processing respectively using the feature combinations of normal sample coding features + prompt sample coding features and abnormal sample coding features + prompt sample coding features through the image anomaly detection model to be trained, so as to obtain the corresponding normal sample reconstruction features and abnormal sample recovery features according to their respective combined decoding features. In the combined decoding processing at each level, the image anomaly detection model to be trained performs attention feature extraction on the target detection coding features and target prompt coding features input at the level, obtains the prompt coding features output at the level, and performs attention feature extraction on the prompt coding features and target detection coding features output at the level, obtains the detection coding features output at the level.

[0139] The server updates the image anomaly detection model to be trained based on the normal sample reconstruction features, abnormal sample recovery features and normal image original features, without the need to introduce manually pre-labeled labels, thereby realizing unsupervised training for the image anomaly detection model. For example, the model target loss can be constructed through the normal sample reconstruction features, abnormal sample recovery features and normal image original features, and the model parameters of the image anomaly detection model to be trained are updated based on the model target loss, and then the training is continued until the training is completed to obtain the trained image anomaly detection model. The training end condition can be set according to actual needs, such as when the training reaches a preset number of times, the accuracy of the image anomaly detection model meets the end condition, or all sample images are trained.

[0140] In this embodiment, the server reconstructs features based on a feature combination of normal sample coding features and prompt sample coding features through the image anomaly detection model to be trained to obtain normal sample reconstructed features, recovers features based on a feature combination of abnormal sample coding features and prompt sample coding features to obtain abnormal sample recovered features, and updates the image anomaly detection model based on the normal sample reconstructed features, the abnormal sample recovered features and the normal image original features. By introducing abnormal sample images and reference sample images for model training, the generalization ability of the image anomaly detection model can be enhanced, and the accuracy of image anomaly detection based on the image anomaly detection model can be improved.

[0141] In an exemplary embodiment, Fig. 9As shown, the model update process, that is, updating the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then continuing the training until the training is completed to obtain the trained image anomaly detection model, includes:

[0142] Step 902: Determine the sample reconstruction loss according to the sample reconstruction difference between the normal sample reconstruction feature and the normal image original feature.

[0143] The sample reconstruction difference represents the feature difference between the normal sample reconstruction feature and the normal image original feature. The sample reconstruction loss is obtained based on the sample reconstruction difference and is used to adjust the influence of the normal sample reconstruction feature on the model update.

[0144] Specifically, the server may determine the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction feature and the normal image original feature. Specifically, the server may determine the sample reconstruction difference between the normal sample reconstruction feature and the normal image original feature, such as performing feature comparison between the normal sample reconstruction feature and the normal image original feature to obtain the sample reconstruction difference, and construct the sample reconstruction loss based on the sample reconstruction difference. The form of the sample reconstruction loss may be set according to actual needs, and may specifically include but is not limited to at least one or a combination of Mean Squared Error (MSE), Cross-Entropy Loss (CE), Logarithmic Loss (LogLoss) or L1 loss (Mean Absolute Error, MAE, mean absolute error).

[0145] Step 904: Determine the sample recovery loss according to the sample recovery difference between the abnormal sample recovery feature and the normal image original feature.

[0146] The sample recovery difference represents the feature difference between the abnormal sample recovery feature and the normal image original feature. The sample recovery loss is obtained based on the sample recovery difference and is used to adjust the influence of the abnormal sample recovery feature on the model update.

[0147] Specifically, the server can determine the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features. Specifically, the server can determine the sample recovery difference between the abnormal sample recovery features and the normal image original features. For example, the abnormal sample recovery features and the normal image original features can be compared to obtain the sample recovery difference, and the sample recovery loss can be constructed based on the sample recovery difference. The form of the sample recovery loss can be set according to actual needs.

[0148] Step 906 , the image anomaly detection model to be trained is updated based on the sample reconstruction loss and the sample recovery loss, and then training is continued until the training is completed, thereby obtaining a trained image anomaly detection model.

[0149] Specifically, the server updates the model parameters of the image anomaly detection model to be trained based on the sample reconstruction loss and the sample recovery loss, and continues training with the updated image anomaly detection model until the training is completed, thereby obtaining the trained image anomaly detection model. In specific applications, the server can obtain the model target loss based on the sum or weighted sum of the sample reconstruction loss and the sample recovery loss, and update the image anomaly detection model to be trained based on the model target loss. Among them, the sample reconstruction loss and the sample recovery loss are directly calculated based on the normal sample reconstruction features, abnormal sample recovery features, and normal image original features obtained during the training process, without the need to introduce artificial pre-labeled labels, and can perform unsupervised training on the image anomaly detection model.

[0150] In this embodiment, the server determines the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features, determines the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features, and updates the model based on the comprehensive sample reconstruction loss and sample recovery loss. The model can be trained from two dimensions: feature reconstruction and feature recovery, which can ensure the generalization ability of the image anomaly detection model for image anomaly detection, thereby improving the accuracy of image anomaly detection.

[0151] In an exemplary embodiment, the image anomaly detection method also includes: determining a first feature difference between a normal sample reconstructed feature and an original feature of a normal image, and determining a second feature difference between an abnormal sample restored feature and an original feature of an abnormal image; performing at least one level of pixel feature extraction for the first feature difference and the second feature difference, respectively, through an image anomaly detection model to be trained, to obtain a first pixel anomaly result and a second pixel anomaly result; and determining a pixel anomaly detection loss based on the abnormal area label carried by the abnormal sample image, the first pixel anomaly result, and the second pixel anomaly result.

[0152] Among them, the first feature difference represents the feature difference between the reconstructed feature of the normal sample and the original feature of the normal image, which can be obtained by absolutely subtracting the reconstructed feature of the normal sample from the original feature of the normal image. The second feature difference represents the feature difference between the restored feature of the abnormal sample and the original feature of the abnormal image, which can be obtained by absolutely subtracting the restored feature of the abnormal sample from the original feature of the abnormal image. The pixel abnormality result is obtained by performing pixel feature extraction on the feature difference. The pixel feature extraction refers to feature extraction based on the pixel level for the feature difference, which can specifically include various feature extraction processes such as convolution, normalization, and linear rectification. The pixel abnormality result may include a first pixel abnormality result and a second pixel abnormality result. The first pixel abnormality result is obtained by performing at least one level of pixel feature extraction on the first feature difference, and the second pixel abnormality result is obtained by performing at least one level of pixel feature extraction on the second feature difference. The abnormal area label can be obtained by pre-marking the abnormal sample image, and is used to characterize the image abnormality area included in the abnormal sample image.

[0153] Specifically, the server can determine the first feature difference based on the reconstructed features of the normal sample and the original features of the normal image, and determine the second feature difference based on the restored features of the abnormal sample and the original features of the abnormal image, such as performing absolute element-by-element subtraction between the reconstructed features of the normal sample and the original features of the normal image, and performing absolute element-by-element subtraction between the restored features of the abnormal sample and the original features of the abnormal image, to obtain the first feature difference and the second feature difference. The server further extracts pixel features for the first feature difference and the second feature difference through the image anomaly detection model to be trained, and specifically can perform at least one level of pixel feature extraction, such as performing at least one level of convolution operation, normalization processing, linear rectification, deconvolution and other pixel feature extraction for the first feature difference and the second feature difference, respectively, to obtain the first pixel anomaly result and the second pixel anomaly result. The server can obtain the abnormal area label carried by the abnormal sample image, and the abnormal area label can be manually annotated for the abnormal sample image in advance to characterize the image abnormal area in the abnormal sample image. The server constructs the pixel anomaly detection loss by combining the abnormal area label, the first pixel anomaly result and the second pixel anomaly result. In some embodiments, the server can construct a pixel anomaly detection loss according to the abnormal area label, the first pixel abnormal result and the second pixel abnormal result in accordance with the selected loss function form. The loss function form can be flexibly set according to actual needs. The pixel anomaly detection loss is obtained by combining the abnormal area label, the first pixel abnormal result and the second pixel abnormal result, that is, it is necessary to introduce the abnormal area label pre-annotated for the abnormal sample image, and the calculation optimization of the pixel anomaly detection loss belongs to supervised training.

[0154] In some embodiments, the first pixel abnormality result is obtained based on the first feature difference between the normal sample reconstruction feature and the normal image original feature, and there is no image abnormality area in the normal sample image corresponding to the normal image original feature, that is, it can be considered that the image abnormality area represented by the abnormal area label of the normal sample image is empty, and the server can directly determine the first pixel abnormality detection loss for the normal sample image based on the first pixel abnormality result. For the second pixel abnormality result, it is obtained based on the second feature difference between the abnormal sample recovery feature and the abnormal image original feature, and the image abnormality area in the abnormal sample image corresponding to the abnormal image original feature is represented by the carried abnormal area label. The server can compare the abnormal area according to the abnormal area label carried by the abnormal sample image and the second pixel abnormality result, and obtain the second pixel abnormality detection loss for the abnormal sample image according to the comparison result. The server can combine the first pixel abnormality detection loss and the second pixel abnormality detection loss to obtain the pixel abnormality detection loss, such as summing the first pixel abnormality detection loss and the second pixel abnormality detection loss to obtain the pixel abnormality detection loss.

[0155] Furthermore, the image anomaly detection model to be trained is updated based on the sample reconstruction loss and the sample recovery loss, and the training is continued until the training is completed to obtain a trained image anomaly detection model, including: fusing the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to obtain the model target loss; the image anomaly detection model to be trained is updated based on the model target loss and the training is continued until the training is completed to obtain a trained image anomaly detection model.

[0156] Among them, the pixel anomaly detection loss reflects the anomaly detection result at the pixel level, and the model target loss is obtained by integrating the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss. The model target loss is used to update the image anomaly detection model. Specifically, the server can fuse the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss. For example, the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss can be weighted and fused according to the set weights to obtain the model target loss. The server updates the model parameters of the image anomaly detection model to be trained based on the model target loss, and continues training based on the updated image anomaly detection model until the training is completed, thereby obtaining a trained image anomaly detection model.

[0157] In this embodiment, the server further constructs a pixel anomaly detection loss at the pixel level based on the first feature difference and the second feature difference, and obtains a model target loss by integrating the abnormal area label carried by the abnormal sample image, the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to update the image anomaly detection model. The model can be trained from three dimensions: feature reconstruction, feature recovery and pixel-level anomaly detection, which can ensure the generalization ability of the image anomaly detection model for image anomaly detection, thereby improving the accuracy of image anomaly detection.

[0158] In an exemplary embodiment, Fig.10 As shown, a method for processing an image anomaly detection model is provided. The method is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the embodiment of the present application, the method is applied to Figure 1 The server in the example is used to illustrate, including the following steps 1002 to 1012. Among them:

[0159] Step 1002: Acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image.

[0160] Among them, the image anomaly detection model can be constructed based on various artificial neural network algorithms. The normal sample image is a sample image that does not include image anomalies. The reference sample image is associated with the normal sample image. The reference sample image is used as a reference sample image. The image features carried by the reference sample image are used as prompt features to provide training guidance for the image anomaly detection model. The abnormal sample image is a sample image that includes image anomalies. The normal sample image, the reference sample image, and the abnormal sample image are specifically sample images belonging to the same application scenario, and the only difference is whether there are anomalies in the image content, such as whether there are abnormal contents such as missing, scratched, and rotten. Specifically, the server can obtain sample images for the image anomaly detection model, including normal sample images, reference sample images, and abnormal sample images.

[0161] Step 1004 , feature extraction is performed on the normal sample image, the reference sample image and the abnormal sample image respectively to obtain normal image original features of the normal sample image, reference image original features of the reference sample image and abnormal image original features of the abnormal sample image.

[0162] Exemplarily, for normal sample images, reference sample images and abnormal sample images, the server can perform feature extraction respectively, such as a pre-trained feature extraction network can perform feature extraction on normal sample images, reference sample images and abnormal sample images respectively to obtain their respective original image features, specifically including normal image original features of normal sample images, reference image original features of reference sample images, and abnormal image original features of abnormal sample images.

[0163] Step 1006, through the image anomaly detection model to be trained, the original features of the normal image, the original features of the reference image, and the original features of the abnormal image are encoded respectively to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image.

[0164] Specifically, the server can encode the sample images through the image anomaly detection model to be trained to obtain respective encoding features, including normal sample encoding features of normal sample images, prompt sample encoding features of reference sample images, and abnormal sample encoding features of abnormal sample images.

[0165] Step 1008, through the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the normal sample coding features and the prompt sample coding features, a first combined decoding feature output by at least one level of combined decoding processing is obtained, and a normal sample reconstruction feature for the normal sample image is obtained based on the first combined decoding feature.

[0166] Optionally, the server can perform combined decoding processing using the feature combination of normal sample coding features + prompt sample coding features through the image anomaly detection model to be trained, so as to obtain the corresponding normal sample reconstruction features. In the combined decoding processing at each level, the image anomaly detection model to be trained performs attention feature extraction on the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and performs attention feature extraction on the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level.

[0167] Step 1010, using the image anomaly detection model to be trained, performing at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features, obtaining a second combined decoding feature output by at least one level of combined decoding processing, and obtaining an abnormal sample recovery feature for the abnormal sample image based on the second combined decoding feature.

[0168] Optionally, the server can use the image anomaly detection model to be trained to perform combined decoding processing using the feature combination of abnormal sample coding features + prompt sample coding features to obtain corresponding abnormal sample recovery features. In the combined decoding processing at each level, the image anomaly detection model to be trained performs attention feature extraction on the target detection coding features and target prompt coding features input at the level to obtain the prompt coding features output at the level, and performs attention feature extraction on the prompt coding features and target detection coding features output at the level to obtain the detection coding features output at the level.

[0169] Step 1012, the image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then the training is continued until the training is completed to obtain a trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on the input image.

[0170] Specifically, the server can construct a model target loss through normal sample reconstruction features, abnormal sample recovery features and normal image original features, update the model parameters of the image anomaly detection model to be trained based on the model target loss, and then continue training until the training is completed to obtain a trained image anomaly detection model. The training end condition can be set according to actual needs, such as when the training reaches a preset number of times, the accuracy of the image anomaly detection model meets the end condition, or all sample images are trained.

[0171] The above-mentioned image anomaly detection model processing method, for normal sample images, reference sample images associated with normal sample images, and abnormal sample images, respectively encodes the original image features of each of them through the image anomaly detection model to be trained to obtain normal sample encoding features, prompt sample encoding features, and abnormal sample encoding features, and performs at least one level of combined decoding processing based on the normal sample encoding features and the prompt sample encoding features through the image anomaly detection model to be trained to construct normal sample reconstruction features for normal sample images, and performs at least one level of combined decoding processing based on the abnormal sample encoding features and the prompt sample encoding features through the image anomaly detection model to be trained to construct abnormal sample recovery features for abnormal sample images, and then updates the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features, and the normal image original features and continues to train, to obtain a trained image anomaly detection model for image anomaly detection on the input image. By introducing the hint sample coding features and combining them with the normal sample coding features to perform at least one level of combined decoding processing to reconstruct the features of the normal sample image, and introducing the hint sample coding features and combining them with the abnormal sample coding features to perform at least one level of combined decoding processing to restore the features of the abnormal sample image, the image anomaly detection capability of the image anomaly detection model can be enhanced by utilizing the image context information of the reference sample image and the corresponding dynamic hint coding features of each level, thereby improving the accuracy of image anomaly detection for the input image by the trained image anomaly detection model.

[0172] In an exemplary embodiment, the image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and the training is continued until the training is completed to obtain a trained image anomaly detection model, including: determining the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features; determining the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features; and the image anomaly detection model to be trained is updated based on the sample reconstruction loss and the sample recovery loss and the training is continued until the training is completed to obtain a trained image anomaly detection model.

[0173] Specifically, the server can determine the sample reconstruction difference between the normal sample reconstruction feature and the normal image original feature, such as performing feature comparison between the normal sample reconstruction feature and the normal image original feature to obtain the sample reconstruction difference, and constructing the sample reconstruction loss based on the sample reconstruction difference. Similarly, the server can perform feature comparison between the abnormal sample recovery feature and the normal image original feature to obtain the sample recovery difference, and construct the sample recovery loss based on the sample recovery difference. Among them, the form of the sample reconstruction loss and the sample recovery loss can be set according to actual needs. The server can obtain the model target loss based on the sum or weighted sum of the sample reconstruction loss and the sample recovery loss, and update the image anomaly detection model to be trained based on the model target loss.

[0174] In this embodiment, the server determines the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features, determines the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features, and updates the model based on the comprehensive sample reconstruction loss and sample recovery loss. The model can be trained from two dimensions: feature reconstruction and feature recovery, which can ensure the generalization ability of the image anomaly detection model for image anomaly detection, thereby improving the accuracy of image anomaly detection.

[0175] In an exemplary embodiment, the image anomaly detection model processing method also includes: respectively determining a first feature difference between a normal sample reconstructed feature and an original feature of a normal image, and a second feature difference between an abnormal sample restored feature and an original feature of an abnormal image; performing at least one level of pixel feature extraction for the first feature difference and the second feature difference, respectively, through the image anomaly detection model to be trained, to obtain a first pixel anomaly result and a second pixel anomaly result; determining a pixel anomaly detection loss according to the abnormal area label carried by the abnormal sample image, the first pixel anomaly result and the second pixel anomaly result; updating the image anomaly detection model to be trained based on the sample reconstruction loss and the sample recovery loss, and continuing the training until the training is completed, to obtain a trained image anomaly detection model, including: fusing the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to obtain the model target loss; updating the image anomaly detection model to be trained based on the model target loss, and continuing the training until the training is completed, to obtain a trained image anomaly detection model.

[0176] Exemplarily, the server may perform an absolute element-by-element subtraction of the normal sample reconstruction feature from the normal image original feature, and an absolute element-by-element subtraction of the abnormal sample recovery feature from the abnormal image original feature to obtain a first feature difference and a second feature difference. The server performs at least one level of convolution operation, normalization processing, linear rectification, deconvolution and other pixel feature extraction on the first feature difference and the second feature difference through the image anomaly detection model to be trained, and obtains a first pixel anomaly result and a second pixel anomaly result, respectively. The server constructs a pixel anomaly detection loss based on the abnormal area label, the first pixel anomaly result and the second pixel anomaly result. In some embodiments, the server can construct a pixel anomaly detection loss according to the abnormal area label, the first pixel anomaly result and the second pixel anomaly result in accordance with the selected loss function form. Among them, the loss function form can be flexibly set according to actual needs.

[0177] Furthermore, the server can perform weighted fusion of the sample reconstruction loss, sample recovery loss and pixel anomaly detection loss according to the set weights to obtain the model target loss, and update the model parameters of the image anomaly detection model to be trained based on the model target loss, and continue training based on the updated image anomaly detection model until the training is completed, thereby obtaining a trained image anomaly detection model.

[0178] In this embodiment, the server further constructs a pixel-level pixel anomaly detection loss based on the first feature difference and the second feature difference, and obtains a model target loss based on the abnormal area label carried by the abnormal sample image, the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to update the image anomaly detection model. The model can be trained from three dimensions: feature reconstruction, feature recovery and pixel-level anomaly detection, which can ensure the generalization ability of the image anomaly detection model for image anomaly detection, thereby improving the accuracy of image anomaly detection. The present application also provides an application scenario, which applies the above-mentioned image anomaly detection method. Specifically, the application of the image anomaly detection method in this application scenario is as follows:

[0179] For image anomaly detection processing, there are currently reconstruction-based unsupervised anomaly detection methods and text-cue-based anomaly detection methods. For reconstruction-based unsupervised anomaly detection methods, it is assumed that abnormal image regions or features should not be able to be reconstructed correctly because they do not exist in normal training samples. Some methods use generative models such as autoencoders and generative adversarial networks to reconstruct normal images. RGI (Robust GAN-Inversion) proposes a robust GAN (Generative Adversarial Networks) inversion that can restore any input image (even if severely damaged) to a clean image and identify damaged area masks by solving its optimization problem. Some methods regard anomaly detection as an image repair problem in which patches of the image are partially masked. RIAD (Region-based Image Anomaly Detection) randomly deletes parts of the image area and uses a convolutional neural network to reconstruct the image of the deleted area using the undeleted part. SSPCAB (Spatial and Channel-wise Pixel-wise Anomaly Block) learns to reconstruct the masked area using contextual information with masked convolution kernels. In order to enhance the diversity of reconstruction while avoiding undesired anomaly generalization, a pyramid deformation module is proposed to model different normals and measure the severity of anomalies. However, these methods tend to be computationally expensive because they involve reconstruction in the original image space. UniAD (Unified model for Anomaly Detection) extracts features from a pre-trained model and reconstructs the features, which implements unified anomaly detection and balances efficiency and performance. However, UniAD is still unsatisfactory for pixel-level anomaly segmentation.

[0180] For anomaly detection methods based on text prompts, their use of large pre-trained visual language models (such as CLIP, Contrastive Language–Image Pre-training) has shown unprecedented versatility and has achieved impressive performance on various tasks such as few-shot image classification, open word target detection, and text-to-image generation. Using multiple text prompts on the powerful CLIP model can produce excellent performance in zero-shot and few-shot anomaly detection. In addition, the application of multi-round dialogue AnomalyGPT (Anomaly GenerativePre-Trained Transformer, anomaly detection model based on generative pre-training) not only indicates the presence and location of anomalies, but also provides a detailed description of anomalies in test images. However, these methods mainly rely on text prompts to identify anomalies, and the workload of constructing text prompts for images is large, which affects the processing efficiency of image anomaly detection. The image anomaly detection method provided in this embodiment detects anomalies by using normal images as visual prompts, which is more intuitive and conducive to improving the accuracy and processing efficiency of image anomaly detection.

[0181] For the processing of image anomaly detection, the unsupervised reconstruction method of Transformer based on the self-attention mechanism has achieved the best results in unified (single model multi-category) anomaly detection. However, these self-attention-based reconstruction models mainly operate on the target features themselves, while there may be a high consistency between the anomaly itself and the context, resulting in the perfect reconstruction of both normal features and abnormal features, which makes the true anomaly detection fail. In order to ensure the efficiency of the reconstruction process, the reconstruction network is usually performed in a low-resolution latent space, but this makes the model generally poor in anomaly positioning performance. In order to make the reconstruction model maintain high efficiency while enhancing its generalization ability for anomaly detection, the image anomaly detection method provided in this embodiment only needs one normal image prompt to reconstruct normal features for normal samples and restore their abnormal features to normal for abnormal samples. The image anomaly detection method provided in this embodiment allows reconstruction or restoration of anomalies with only one normal image prompt, which effectively improves the anomaly detection performance. In addition, the image anomaly detection method provided in this embodiment also includes a supervised fine-tuning module, which regresses the reconstruction error by using real normal images and synthetic abnormal images, which significantly improves the performance of pixel-level anomaly segmentation. The image anomaly detection method provided in this embodiment outperforms previous methods on three anomaly detection benchmark datasets: MVTec, BTAD, and ViSA.

[0182] Specifically, Fig.11As shown in FIG. 1 , a unified unsupervised anomaly detection framework diagram is used in the image anomaly detection method provided in this embodiment. For input (Input) including normal images (normal, )、prompt image(prompt, ) and pseudo anomalies, ) Three types of images are obtained through the feature extraction network (Backbone) to obtain their respective original image features, including the image features corresponding to the normal image , the image features corresponding to the prompt image And the image features corresponding to the abnormal image . The solid line segment is the unsupervised reconstruction process, the dotted line segment is the unsupervised restoration process, and the dotted box is the supervised refinement process. The image features corresponding to the normal image, the image features corresponding to the prompt image, and the image features corresponding to the abnormal image are encoded by N encoders. In each encoder, a self-attention layer (self-attn) and a multi-layer perceptron layer (MLP) are connected in sequence to obtain the encoded features corresponding to the normal image. , the encoding features of the prompt image And the encoding features corresponding to the abnormal images .

[0183] For unsupervised reconstruction, the coded features corresponding to the normal image and the coded features of the prompt image are decoded by N decoders, each of which includes a cross-attn layer, a multi-layer perceptron layer (MLP), and a cross-attn layer. For the cross-attn layer, the prompt coded features output by the previous decoder are decoded. As the query vector (q), the normal encoding features output by the previous decoder The output of the crisscross attention layer 1 is fed into the multilayer perceptron layer as the key vector (k) and value vector (v); for the crisscross attention layer 2, the normal encoded features output by the previous decoder are As the query vector, the output of the multi-layer perceptron layer is used as the key vector and value vector, and the output of the cross attention layer 2 is the prompt encoding feature output by the decoder of this layer , the output of the multi-layer perceptron layer is used as the normal encoding feature of the decoder output of this layer , the output of the last decoder is reconstructed after the cross-attn layer . Reconstruction features Image features corresponding to normal images The reconstruction error between them is refined to obtain the final output.

[0184] For unsupervised recovery processing, the input to the decoder is the encoding features of the prompt image and the encoding features corresponding to the abnormal image. The output of the last decoder is obtained after the cross attention layer to obtain the restored features. The restored features correspond to the image features of the normal image The recovery error between them is fine-tuned to obtain the final output.

[0185] Furthermore, during the training phase, both normal images and synthetic images are fed into the pre-trained backbone network to extract multi-level representations. Under the guidance of the normal image cues, the normal features of the normal samples are reconstructed in the unsupervised reconstruction stream, and the synthetic abnormal samples are restored to normal features in the unsupervised recovery stream. In addition, the supervised fine-tuning module is used to regress the reconstruction errors of the normal images and the synthetic abnormal images. It is worth noting that the unsupervised recovery stream will be cleared during inference, so it does not bring additional computational overhead.

[0186] Furthermore, for the processing of reconstruction based on normal image cues. The image anomaly detection method provided in this embodiment focuses on unified anomaly detection, which means that a model is required to process data of multiple categories. Compared with the anomaly detection method of one category and one model, the data to be processed by unified anomaly detection has a more complex distribution and is therefore more challenging. Using the encoder-decoder architecture UniAD is a powerful and state-of-the-art unified unsupervised anomaly detection solution. UniAD consists of a neighbor masked attention (NMA) and a layered query decoder (LQD). NMA restricts a feature from seeing itself and its neighborhood, so its contextual features (long dependencies) are used for reconstruction. On the other hand, query embedding can be learned First embed with the encoder Fusion, then with the output Integrated The experiments show that the learned query embeddings can alleviate overfitting.

[0187] For simplicity, we omit the MLP (Multilayer Perceptron), residual connection, layer normalization, and dropout in LQD. In each module, the corresponding two important steps are as shown in equations (1) and (2).

[0188] (1)

[0189] (2)

[0190] in, is the attention feature fusion processing, for The transposed matrix of yes The dimension of By the first block in LQD Initialization is obtained, For the The above LQD can be implemented by multi-head self-attention. It should be noted that in each sub-block of LQD, is parameterized and learnable, while Keeping it fixed and unchanged, i.e., LQD only reconstructs the features by itself, which may fail in the face of challenging scenarios such as disguised anomalies.

[0191] The image anomaly detection method provided in this embodiment expects that feature reconstruction not only relies on its own structure and features, but also can be guided by normal prompts, aiming to reduce the difficulty of reconstruction and improve the performance of anomaly detection. A simple way is to directly use ordinary image prompts The encoder output Replace the query embedded in LQD , thus enabling the interaction between the cue and target features. Therefore, the LQD is transformed as shown in Equations (3) and (4):

[0192] (3)

[0193] (4)

[0194] This change is simple but has completely different implications and can significantly improve the performance of anomaly detection. In the above modification, the hint encoding statically interacts with the target features in a unidirectional manner, so it is called a unidirectional decoder with static hints. However, this unidirectional model may not be flexible enough, especially when the target features are constantly updated and may not be aligned with the target features.

[0195] Different from the static prompts in the unidirectional decoder, the image anomaly detection method provided in this embodiment uses a pair of bidirectional cross attention to dynamically update the prompt and target features, as shown in the following equations (5) and (6):

[0196] (5)

[0197] (6)

[0198] in, and The encoder module and Initialization is obtained. The above-mentioned bidirectional decoder with dynamic prompts simulates bidirectional feature interactions, including prompt to feature and feature to prompt, where the first interaction performs a cross-attention from the prompt (as a query) to the target feature, and the second interaction performs another cross-attention from the target feature (as a query) to the prompt. The next decoder block obtains the updated prompt and target feature from the previous block. In this way, the target feature reconstruction not only utilizes its contextual information, but also dynamically utilizes the corresponding normal prompt. It is worth noting that this bidirectional modeling method also enhances the flexibility of the prompt feature and can adapt to the distribution changes of the target feature to a certain extent. Finally, a cross attention is used to update the prompt on the output of the bidirectional decoder, and its output is regarded as the original feature The reconstruction features ( ). The reconstruction loss function calculates the mean square error (MSE) between the reconstructed features and the original features, as shown in the following formula (7):

[0199] (7)

[0200] in, To rebuild the losses, is the image channel, is the image height, is the image width.

[0201] Furthermore, for the processing of restoration based on normal image prompts. Unsupervised reconstruction learning is only performed on normal training images, which may cause the model to rely more on its own contextual information and weaken the participation of image prompts in the reconstruction process. In order to further enhance the guidance of image prompts, one expected way is to increase the difficulty of the reconstruction task, forcing the network to rely not only on its own contextual information, but also on the prompt information of normal image prompts. To achieve this goal, the image anomaly detection method provided in this embodiment introduces artificially synthesized pseudo-abnormal images. , which can be done by It can be easily generated by adding damage or destruction to the image, such as CutPaste and DRAEM (Discriminatively trained Reconstruction Anomaly Embedding Model). Based on the pseudo-anomaly image, the previous reconstruction can be transformed into a restoration problem, hoping to find the normal image prompt Under the guidance of Return to normal characteristics This recovery is consistent with the expectations of the rebuilt model during the testing phase.

[0202] Similar to the reconstruction process, the image anomaly detection method provided in this embodiment first transforms a pair of images ( and ) is input into the pre-trained backbone to extract offline features ( and ), and then obtain the final repaired features , and apply the offline paired features to the self-attention encoder and the bidirectional cross-attention decoder in turn. Specifically, the self-attention encoder parallelizes and As input, the output is and Next, the bidirectional decoder is composed of and Initialize and dynamically update. In the block, dynamic features and prompts are represented as and , which can be easily obtained by replace Different from the objective function in unsupervised reconstruction, the restoration loss function calculates the restored features ( ) and the corresponding original normal features ( ), as shown in the following formula (8):

[0203] (8)

[0204] in, To recover the losses.

[0205] For the supervised fine-tuning module, given a normal training image and the corresponding exception mask (all elements are zero), anomaly images can be synthesized , and its exception mask is represented as Then, the normal image and the synthetic image are fed into the pre-trained backbone network and their offline representations are derived as . Then use the proposed reconstruction flow to convert the normal Reconstructed as , and use the recommended recovery flow to return the exception Restore to Here, the absolute element-by-element subtraction of the original features and the reconstructed (restored) features is used to measure their differences, as shown in the following formula (9):

[0206] (9)

[0207] In fact, the difference in the equation of The norm can be used to roughly locate the abnormal region. However, in this way, since the feature reconstruction or recovery is performed in a low-resolution (i.e., 1 / 16 of the original input) latent space, it is difficult to accurately locate the abnormal region.

[0208] Note that the synthetic abnormal image Naturally with pixel-level anomaly masks The image anomaly detection method provided in this embodiment is expected to make full use of Further refine the reconstruction error from low resolution to high resolution. To this end, the image anomaly detection method provided in this embodiment designs a lightweight pixel-level fine-tuning module based on reconstruction error to perform anomaly segmentation. The module consists of several transposed convolution blocks followed by a 1x1 convolution layer. Here, each transposed convolution block reconstructs the error Upsampling by 2 times, it consists of 3x3 convolution, BatchNorm (Batch Normalization), ReLU (Rectified Linear Unit) and 2x2 deconvolution. In the experiment, the image anomaly detection method provided in this embodiment uses two transposed convolution blocks to increase the reconstruction error from 1 / 16 to 1 / 4 relative to the input image. Finally, the 1x1 convolution layer transforms the number of channels of the amplified reconstruction error to 1 and obtains the estimated anomaly map In order to calculate and the true value The loss between Adjust to Considering that abnormal pixels usually account for a minority in anomaly detection, the Dice loss function is used to optimize the model, which is very effective for learning from extremely unbalanced data. Specifically, it is shown in the following formula (10):

[0209] (10)

[0210] in, express or The spatial position in To fine tune the loss, for or Height, for or Width.

[0211] For training and inference processing, considering that the proposed scheme involves three objectives, including unsupervised reconstruction, unsupervised recovery, and supervised fine-tuning, the overall training loss function is shown in the following formula (11):

[0212] (11)

[0213] in, It is a balance between the two types of loss functions and At inference time, offline hint features of all categories are pre-extracted and stored in the hint pool. Given a test image and its characteristics , the best cue feature is selected using the cosine similarity of the feature and cue pool. For unsupervised reconstruction, the anomaly score map is calculated as the reconstruction error The norm is shown in the following formula (12):

[0214] (12)

[0215] in, Anomaly score map for unsupervised reconstruction.

[0216] For the supervised refiner, the anomaly score map is predicted to be Finally, (resized to native resolution) and Combined together, as the final abnormal segmentation map, it is specifically shown in the following formula (13):

[0217] (13)

[0218] in, is a weight, and abnormal classification is intended to detect whether an image contains an abnormal area. The image abnormality detection method provided in this embodiment is The maximum value of is taken as the image-level anomaly score.

[0219] In a specific application, the ROC (Receiver Operating Characteristic) / PR (Precision-Recall) metrics for image-level anomaly classification and pixel-level anomaly segmentation are compared for datasets such as MVTec, BTAD, and VisA. All methods are evaluated in a unified setting, where the results are averaged across multiple classes.

[0220] like Fig.12 As shown in the figure, it is a comparison table of image anomaly detection results on three different datasets, specifically, it is the result of comprehensive evaluation of current representative methods on image-level classification and pixel-level segmentation on three anomaly detection datasets (MVTec, BTAD and VisA). Among them, the metric includes image-level indicators and pixel-level indicators. The image-level indicators can include ROC / PR indicators (I-ROC / PR) for image-level anomaly classification, and the pixel-level indicators can include ROC / PR indicators (P-ROC / PR) for pixel-level anomaly segmentation; each reference image anomaly detection method can include image anomaly detection methods based on embedding features (Embedding-based), discriminator-based, and reconstruction-based. The image anomaly detection method based on embedding features can include reference 1 (CS-Flow, Cross-Scale Flow, cross-scale flow), reference 2 (PaDiM, Patch Distribution Modeling, patch distribution modeling), reference 3 (DFM, Distribution-based Feature Matching, distribution-based feature matching), reference 4 (PatchCore, patch core) and reference 5 (CFA, contextual feature analysis, context feature analysis), discriminator-based image anomaly detection methods may include reference 6 (DRAEM) and reference 7 (SimpleNet, simple network), and reconstruction-based image anomaly detection methods include those based on reference 8 (UniAD) and the image anomaly detection method in this scheme. Specifically, some important observations are summarized as follows:

[0221] When extending the single-model single-class method to single-model multi-class, most state-of-the-art methods suffer significant performance degradation in both image-level classification and pixel-level segmentation, which is also consistent with the observations of UniAD. For example, the state-of-the-art SimpleNet drops by about 21% (from 99.6% to 78.2%) on the I-ROC metric and about 17% (from 98.1% to 81.0%) on the P-ROC metric;

[0222] The image anomaly detection method provided in this embodiment beats all competitors and significantly outperforms the state-of-the-art UniAD in pixel-level anomaly segmentation on all three datasets, for example, from 44.7% to 63.7% on MVTec, from 50.9% to 56.8% on BTAD, and from 33.6% to 43.3% on VisA.

[0223] Some methods are not robust for different application scenarios, but the image anomaly detection method provided in this embodiment is always better than the best current method. For example, DRAEM achieves 49.6% P-PR on MVTec, but only 12.3% on BTAD and 15.1% on VisA.

[0224] For image-level anomaly classification, the image anomaly detection method provided in this embodiment also surpasses UniAD in most cases, for example, improving the I-ROC performance on MVTec from 96.5% to 97.9%, and improving the I-ROC performance on VisA from 90.8% to 92.5%.

[0225] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0226] Based on the same inventive concept, the embodiment of the present application also provides an image anomaly detection device for implementing the above-mentioned image anomaly detection method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in one or more image anomaly detection device embodiments provided below can refer to the limitations of the image anomaly detection method above, and will not be repeated here.

[0227] In an exemplary embodiment, Fig.13 As shown, an image anomaly detection device 1300 is provided, comprising: an image processing module 1302 to be detected, a prompt feature acquisition module 1304, a combined decoding processing module 1306, a reconstruction feature acquisition module 1308 and a reconstruction difference processing module 1310, wherein:

[0228] The image processing module 1302 is used to obtain the image to be detected, and encode the original image features of the image to be detected to obtain the detection coding features of the image to be detected;

[0229] The prompt feature acquisition module 1304 is used to determine the prompt original feature associated with the image to be detected, and encode the prompt original feature to obtain the prompt encoding feature;

[0230] The combined decoding processing module 1306 is used to perform at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features output by the combined decoding processing of at least one level, and in the combined decoding processing of each level, perform attention feature extraction on the target detection coding features and the target prompt coding features inputted at the level to obtain the prompt coding features outputted at the level, and perform attention feature extraction on the prompt coding features and the target detection coding features outputted at the level to obtain the detection coding features outputted at the level;

[0231] A reconstruction feature acquisition module 1308, used to obtain an image reconstruction feature for the image to be detected according to the combined decoding feature;

[0232] The reconstruction difference processing module 1310 is used to obtain an abnormality detection result for the image to be detected based on the reconstruction difference between the image reconstruction feature and the image original feature.

[0233] In one embodiment, the combined decoding processing module 1306 is also used to obtain the first key feature and the first value feature according to the target detection coding feature input at the level, and to obtain the first query feature according to the target prompt coding feature input at the level; cross-attention feature extraction is performed on the first key feature, the first value feature and the first query feature to obtain the prompt coding feature output at the level.

[0234] In one embodiment, the combined decoding processing module 1306 is also used to perform cross-attention feature extraction based on the attention mechanism according to the first key feature, the first value feature and the first query feature to obtain a first cross-attention feature; perform residual fusion on the first cross-attention feature and the first query feature to obtain a fused feature; perform feature mapping on the fused feature at least once to obtain a mapping feature; perform residual fusion on the mapping feature and the fused feature to obtain a prompt coding feature output at the level.

[0235] In one embodiment, the combined decoding processing module 1306 is also used to obtain the second key feature and the second value feature according to the prompt coding feature output by the level, and to obtain the second query feature according to the target detection coding feature input by the level; cross-attention feature extraction is performed on the second key feature, the second value feature and the second query feature to obtain the detection coding feature output by the level.

[0236] In one embodiment, the combined decoding processing module 1306 is also used to extract cross-attention features based on the attention mechanism according to the second key feature, the second value feature and the second query feature to obtain a second cross-attention feature; and to perform residual fusion on the second cross-attention feature and the second query feature to obtain the detection coding feature output at the level.

[0237] In one embodiment, at least one level includes multiple levels; the combined decoding processing module 1306 is also used to perform attention feature extraction on the detection coding features and prompt coding features inputted into the first level in the combined decoding processing of the first level among the multiple levels, so as to obtain the prompt coding features outputted by the first level, and perform attention feature extraction on the prompt coding features and detection features outputted from the first level, so as to obtain the detection coding features outputted by the first level; for each level starting from the second level among the multiple levels, combined decoding processing of the level is performed based on the prompt coding features and detection coding features outputted from the previous level, so as to obtain the prompt coding features and detection coding features outputted from the level, until the combined decoding processing of the last level among the multiple levels outputs the combined decoding features of the multiple levels.

[0238] In one embodiment, the reconstruction feature acquisition module 1308 is also used to perform cross-attention feature extraction on the detection coding features and the prompt coding features included in the combined decoding features based on the attention mechanism, so as to obtain image reconstruction features for the image to be detected.

[0239] In one embodiment, the reconstruction difference processing module 1310 is further used to determine the reconstruction difference between the image reconstructed features and the image original features; map the reconstruction difference to obtain abnormal mapping parameters; and determine the abnormality detection result for the image to be detected based on the abnormal mapping parameters.

[0240] In one embodiment, it also includes a pixel feature processing module for performing at least one level of pixel feature extraction on the reconstruction difference to obtain a pixel anomaly result; the reconstruction difference processing module 1310 is also used to weightedly fuse the anomaly mapping parameters with the pixel anomaly result to obtain an anomaly fusion result; and determine the anomaly detection result for the image to be detected based on the anomaly fusion result.

[0241] In one embodiment, the image processing module 1302 is further used to extract the original image features of the image to be detected, and perform at least one level of attention feature encoding on the original image features to obtain detection coding features of the image to be detected; the prompt feature acquisition module 1304 is further used to determine the prompt original features associated with the image to be detected from the prompt feature pool, the prompt feature pool includes at least one candidate prompt original feature extracted based on the reference image; perform at least one level of attention feature encoding on the prompt original features to obtain prompt coding features.

[0242] In one embodiment, the prompt feature acquisition module 1304 is also used to determine a prompt feature pool; perform feature matching on the image original features and each candidate prompt original feature in the prompt feature pool to obtain a feature matching result; and determine the candidate prompt original feature corresponding to the feature matching result indicating feature matching as the prompt original feature associated with the image to be detected.

[0243] In one embodiment, the method is implemented by an image anomaly detection model; it also includes a model training module, which is used to obtain a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image; through the image anomaly detection model to be trained, the normal image original features of the normal sample image, the reference image original features of the reference sample image, and the abnormal image original features of the abnormal sample image are respectively encoded to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image; through the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the normal sample encoding features and the prompt sample encoding features. Processing is performed to obtain a first combined decoding feature of at least one level of combined decoding processing output, and a normal sample reconstruction feature for a normal sample image is obtained according to the first combined decoding feature; through the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the abnormal sample encoding feature and the prompt sample encoding feature, to obtain a second combined decoding feature of at least one level of combined decoding processing output, and an abnormal sample recovery feature for the abnormal sample image is obtained according to the second combined decoding feature; the image anomaly detection model to be trained is updated based on the normal sample reconstruction feature, the abnormal sample recovery feature and the normal image original feature, and then the training is continued until the training is completed, so as to obtain a trained image anomaly detection model.

[0244] In one embodiment, the model training module is also used to determine the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features; determine the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features; based on the sample reconstruction loss and the sample recovery loss, the image anomaly detection model to be trained is updated and the training is continued until the training is completed, thereby obtaining a trained image anomaly detection model.

[0245] In one embodiment, the model training module is also used to perform at least one level of pixel feature extraction for sample reconstruction difference and sample recovery difference through the image anomaly detection model to be trained, to obtain a first pixel anomaly result and a second pixel anomaly result; determine the pixel anomaly detection loss according to the first pixel anomaly result and the second pixel anomaly result; fuse the sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss to obtain the model target loss; update the image anomaly detection model to be trained based on the model target loss and continue training until the training is completed, so as to obtain a trained image anomaly detection model.

[0246] Each module in the above-mentioned image anomaly detection device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0247] Based on the same inventive concept, the embodiment of the present application also provides an image anomaly detection model processing device for implementing the image anomaly detection model processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in the one or more image anomaly detection model processing device embodiments provided below can refer to the limitations of the image anomaly detection model processing method above, and will not be repeated here.

[0248] In an exemplary embodiment, Fig.14 As shown, an image anomaly detection model processing device 1400 is provided, comprising: a sample image acquisition module 1402, a sample feature extraction module 1404, a sample feature encoding module 1406, a normal sample reconstruction module 1408, an abnormal sample recovery module 1410 and a model updating module 1412, wherein:

[0249] The sample image acquisition module 1402 is used to acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image;

[0250] The sample feature extraction module 1404 is used to extract features from the normal sample image, the reference sample image and the abnormal sample image, respectively, to obtain the normal image original features of the normal sample image, the reference image original features of the reference sample image and the abnormal image original features of the abnormal sample image;

[0251] The sample feature encoding module 1406 is used to encode the original features of the normal image, the original features of the reference image, and the original features of the abnormal image respectively through the image abnormality detection model to be trained, so as to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image;

[0252] The normal sample reconstruction module 1408 is used to perform at least one level of combined decoding processing based on the normal sample coding features and the prompt sample coding features through the image abnormality detection model to be trained, obtain a first combined decoding feature output by the at least one level of combined decoding processing, and obtain a normal sample reconstruction feature for the normal sample image according to the first combined decoding feature;

[0253] The abnormal sample recovery module 1410 is used to perform at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features through the image abnormality detection model to be trained, obtain a second combined decoding feature output by the at least one level of combined decoding processing, and obtain an abnormal sample recovery feature for the abnormal sample image according to the second combined decoding feature;

[0254] The model updating module 1412 is used to update the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then continue training until the training is completed to obtain a trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on the input image.

[0255] In one embodiment, the model updating module 1412 is further used to determine the sample reconstruction loss based on the sample reconstruction difference between the normal sample reconstruction features and the normal image original features; determine the sample recovery loss based on the sample recovery difference between the abnormal sample recovery features and the normal image original features; update the image anomaly detection model to be trained based on the sample reconstruction loss and the sample recovery loss, and continue training until the training is completed, so as to obtain a trained image anomaly detection model.

[0256] In one embodiment, the model updating module 1412 is further used to respectively determine the first feature difference between the reconstructed features of the normal sample and the original features of the normal image, and the second feature difference between the restored features of the abnormal sample and the original features of the abnormal image; through the image anomaly detection model to be trained, at least one level of pixel feature extraction is performed for the first feature difference and the second feature difference, respectively, to obtain a first pixel anomaly result and a second pixel anomaly result; the pixel anomaly detection loss is determined according to the abnormal area label carried by the abnormal sample image, the first pixel anomaly result and the second pixel anomaly result; the sample reconstruction loss, the sample restoration loss and the pixel anomaly detection loss are integrated to obtain the model target loss; the image anomaly detection model to be trained is updated based on the model target loss and then the training is continued until the training is completed, so as to obtain a trained image anomaly detection model.

[0257] Each module in the above-mentioned image anomaly detection model processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0258] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Fig.15 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store image anomaly detection data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an image anomaly detection method or an image anomaly detection model processing method is implemented.

[0259] Those skilled in the art will understand that Fig.15 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0260] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

[0261] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0262] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0263] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0264] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0265] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0266] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for detecting anomalies in an image, characterized in that: The method comprises: Acquire an image to be detected, and encode original image features of the image to be detected to obtain detection coding features of the image to be detected; Determine the prompt original feature associated with the image to be detected, and encode the prompt original feature to obtain the prompt encoding feature; the prompt original feature is extracted from the reference image that does not include anomalies corresponding to the image to be detected; Perform at least one level of combined decoding processing based on the detection coding features and the prompt coding features to obtain the combined decoding features output by the at least one level of combined decoding processing; in the combined decoding processing of each level, perform attention feature extraction on the target detection coding features and the target prompt coding features input by the level to obtain the prompt coding features output by the level; perform attention feature extraction on the prompt coding features output by the level and the target detection coding features to obtain the detection coding features output by the level; Obtaining an image reconstruction feature for the image to be detected according to the combined decoding feature; Based on the reconstruction difference between the image reconstruction feature and the image original feature, an abnormality detection result for the image to be detected is obtained.

2. The method according to claim 1, characterized in that The attention feature extraction is performed on the target detection coding feature and the target prompt coding feature input at the level to obtain the prompt coding feature output at the level, including: Obtaining a first key feature and a first value feature according to the target detection coding feature input at the level, and obtaining a first query feature according to the target prompt coding feature input at the level; Cross-attention feature extraction is performed on the first key feature, the first value feature, and the first query feature to obtain prompt coding features output at the corresponding level.

3. The method according to claim 2, characterized in that The performing cross-attention feature extraction on the first key feature, the first value feature, and the first query feature to obtain the prompt coding feature output at the level includes: According to the first key feature, the first value feature and the first query feature, cross-attention feature extraction is performed based on the attention mechanism to obtain a first cross-attention feature; Perform residual fusion on the first cross-attention feature and the first query feature to obtain a fused feature; Performing feature mapping at least once on the fused features to obtain mapping features; The mapping feature and the fusion feature are residually fused to obtain the prompt coding feature output at the level.

4. The method according to claim 1, characterized in that: The attention feature extraction is performed on the prompt coding feature output at the level and the target detection coding feature to obtain the detection coding feature output at the level, including: Obtain a second key feature and a second value feature according to the prompt coding feature output by the level, and obtain a second query feature according to the target detection coding feature input by the level; Cross-attention feature extraction is performed on the second key feature, the second value feature and the second query feature to obtain the detection coding feature output at the corresponding level.

5. The method according to claim 4, characterized in that The performing cross-attention feature extraction on the second key feature, the second value feature, and the second query feature to obtain the detection coding feature output at the level includes: According to the second key feature, the second value feature and the second query feature, cross-attention feature extraction is performed based on the attention mechanism to obtain a second cross-attention feature; The second cross-attention feature is residually fused with the second query feature to obtain the detection coding feature output at the level.

6. The method according to claim 1, characterized in that The at least one level includes a plurality of levels; the performing at least one level of combined decoding processing based on the detection coding feature and the prompt coding feature to obtain the combined decoding feature output by the at least one level of combined decoding processing includes: In the combined decoding process of a first layer among the multiple layers, performing attention feature extraction on the detection coding features and the prompt coding features input by the first layer to obtain the prompt coding features output by the first layer, and performing attention feature extraction on the prompt coding features and the detection features output by the first layer to obtain the detection coding features output by the first layer; At each level starting from the second level among the multiple levels, combined decoding processing of the level is performed based on the prompt coding features and detection coding features output by the previous level to obtain the prompt coding features and detection coding features output by the level, until the combined decoding processing of the last level among the multiple levels outputs the combined decoding features of the multiple levels.

7. The method according to claim 1, characterized in that The step of obtaining an image reconstruction feature for the image to be detected according to the combined decoding feature comprises: Cross-attention feature extraction is performed on the detection coding features and the prompt coding features included in the combined decoding features to obtain image reconstruction features for the image to be detected.

8. The method according to claim 1, characterized in that The obtaining, based on the reconstruction difference between the image reconstruction feature and the image original feature, an abnormality detection result for the image to be detected includes: Determining a reconstruction difference between the reconstructed features of the image and the original features of the image; Mapping is performed on the reconstruction difference to obtain abnormal mapping parameters; An abnormality detection result for the image to be detected is determined based on the abnormality mapping parameter.

9. The method according to claim 8, characterized in that The method further comprises: Performing at least one level of pixel feature extraction on the reconstructed difference to obtain a pixel anomaly result; The determining, based on the abnormality mapping parameters, an abnormality detection result for the image to be detected includes: Weightedly fusing the abnormal mapping parameter with the pixel abnormal result to obtain an abnormal fusion result; An abnormality detection result for the image to be detected is determined according to the abnormality fusion result.

10. The method according to claim 1, characterized in that The encoding of the original image features of the image to be detected to obtain the detection coding features of the image to be detected includes: Extracting original image features of the image to be detected, and performing at least one level of attention feature encoding on the original image features to obtain detection coding features of the image to be detected; The determining of the prompt original feature associated with the image to be detected and encoding the prompt original feature to obtain the prompt encoding feature includes: Determining a prompt original feature associated with the image to be detected from a prompt feature pool, wherein the prompt feature pool includes at least one candidate prompt original feature extracted based on a reference image; At least one level of attention feature encoding is performed on the prompt original feature to obtain a prompt encoding feature.

11. The method according to claim 10, characterized in that The step of determining the prompt original feature associated with the image to be detected from the prompt feature pool includes: Determine the prompt feature pool; Perform feature matching on the original features of the image and each candidate prompt original feature in the prompt feature pool to obtain a feature matching result; The candidate prompt original feature corresponding to the feature matching result indicating feature matching is determined as the prompt original feature associated with the image to be detected.

12. The method according to any one of claims 1 to 11, characterized in that: The method is implemented by an image anomaly detection model; the training steps of the image anomaly detection model include: Acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image; Performing feature extraction on the normal sample image, the reference sample image and the abnormal sample image respectively to obtain normal image original features of the normal sample image, reference image original features of the reference sample image and abnormal image original features of the abnormal sample image; By using the image anomaly detection model to be trained, encoding the original features of the normal image, the original features of the reference image, and the original features of the abnormal image respectively, to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image; By means of the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the normal sample encoding features and the prompt sample encoding features to obtain a first combined decoding feature output by at least one level of combined decoding processing, and a normal sample reconstruction feature for the normal sample image is obtained according to the first combined decoding feature; By means of the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the abnormal sample coding features and the prompt sample coding features to obtain a second combined decoding feature output by at least one level of combined decoding processing, and an abnormal sample recovery feature for the abnormal sample image is obtained according to the second combined decoding feature; The image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then training is continued until the training is completed, thereby obtaining the trained image anomaly detection model.

13. The method according to claim 12, characterized in that The updating of the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features and continuing the training until the training is completed to obtain the trained image anomaly detection model includes: Determining a sample reconstruction loss according to a sample reconstruction difference between the normal sample reconstruction feature and the normal image original feature; Determining a sample recovery loss according to a sample recovery difference between the abnormal sample recovery feature and the normal image original feature; The image anomaly detection model to be trained is updated based on the sample reconstruction loss and the sample recovery loss, and then training is continued until the training is completed, thereby obtaining the trained image anomaly detection model.

14. The method according to claim 13, characterized in that The method further comprises: Determine a first feature difference between the reconstructed feature of the normal sample and the original feature of the normal image, and determine a second feature difference between the restored feature of the abnormal sample and the original feature of the abnormal image; By using the image anomaly detection model to be trained, performing at least one level of pixel feature extraction for the first feature difference and the second feature difference, respectively, to obtain a first pixel anomaly result and a second pixel anomaly result; Determine a pixel anomaly detection loss according to the abnormal region label carried by the abnormal sample image, the first pixel anomaly result, and the second pixel anomaly result; The updating of the image anomaly detection model to be trained based on the sample reconstruction loss and the sample recovery loss and continuing the training until the training is completed to obtain the trained image anomaly detection model include: The sample reconstruction loss, the sample recovery loss and the pixel anomaly detection loss are integrated to obtain a model target loss; The image anomaly detection model to be trained is updated based on the model target loss and then continued to be trained until the training is completed, thereby obtaining the trained image anomaly detection model.

15. A method for processing an image anomaly detection model, characterized in that: The method comprises: Acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image; Performing feature extraction on the normal sample image, the reference sample image and the abnormal sample image respectively to obtain normal image original features of the normal sample image, reference image original features of the reference sample image and abnormal image original features of the abnormal sample image; By using the image anomaly detection model to be trained, encoding the original features of the normal image, the original features of the reference image, and the original features of the abnormal image respectively, to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image, and the abnormal sample encoding features of the abnormal sample image; By means of the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the normal sample encoding features and the prompt sample encoding features to obtain a first combined decoding feature output by at least one level of combined decoding processing, and a normal sample reconstruction feature for the normal sample image is obtained according to the first combined decoding feature; By means of the image anomaly detection model to be trained, at least one level of combined decoding processing is performed based on the abnormal sample coding features and the prompt sample coding features to obtain a second combined decoding feature output by at least one level of combined decoding processing, and an abnormal sample recovery feature for the abnormal sample image is obtained according to the second combined decoding feature; The image anomaly detection model to be trained is updated based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then training is continued until the training is completed to obtain a trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on the input image.

16. An image anomaly detection device, characterized in that: The device comprises: The image processing module to be detected is used to obtain the image to be detected, and encode the original image features of the image to be detected to obtain the detection coding features of the image to be detected; A prompt feature acquisition module is used to determine the prompt original feature associated with the image to be detected, and encode the prompt original feature to obtain the prompt encoding feature; the prompt original feature is extracted from the reference image that does not include anomalies corresponding to the image to be detected; A combined decoding processing module, used for performing at least one level of combined decoding processing based on the detection coding features and the prompt coding features, obtaining the combined decoding features output by the at least one level of combined decoding processing, and in the combined decoding processing of each level, performing attention feature extraction on the target detection coding features and the target prompt coding features input at the level, obtaining the prompt coding features output at the level, and performing attention feature extraction on the prompt coding features output at the level and the target detection coding features, obtaining the detection coding features output at the level; A reconstruction feature acquisition module, used for obtaining an image reconstruction feature for the image to be detected according to the combined decoding feature; The reconstruction difference processing module is used to obtain an abnormality detection result for the image to be detected based on the reconstruction difference between the image reconstruction feature and the image original feature.

17. An image anomaly detection model processing device, characterized in that: The device comprises: A sample image acquisition module, used to acquire a normal sample image, a reference sample image associated with the normal sample image, and an abnormal sample image; A sample feature extraction module, used to perform feature extraction on the normal sample image, the reference sample image and the abnormal sample image respectively, to obtain normal image original features of the normal sample image, reference image original features of the reference sample image and abnormal image original features of the abnormal sample image; A sample feature encoding module, used to encode the original features of the normal image, the original features of the reference image and the original features of the abnormal image respectively through the image abnormality detection model to be trained, so as to obtain the normal sample encoding features of the normal sample image, the prompt sample encoding features of the reference sample image and the abnormal sample encoding features of the abnormal sample image; a normal sample reconstruction module, configured to perform at least one level of combined decoding processing based on the normal sample encoding features and the prompt sample encoding features through the image anomaly detection model to be trained, obtain a first combined decoding feature output by at least one level of combined decoding processing, and obtain a normal sample reconstruction feature for the normal sample image according to the first combined decoding feature; an abnormal sample recovery module, used to perform at least one level of combined decoding processing based on the abnormal sample coding features and the prompt sample coding features through the image abnormality detection model to be trained, obtain a second combined decoding feature output by at least one level of combined decoding processing, and obtain an abnormal sample recovery feature for the abnormal sample image according to the second combined decoding feature; A model updating module is used to update the image anomaly detection model to be trained based on the normal sample reconstruction features, the abnormal sample recovery features and the normal image original features, and then continue training until the training is completed to obtain a trained image anomaly detection model; the trained image anomaly detection model is used to perform image anomaly detection on an input image.

18. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 15 are implemented.

19. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 15 are implemented.

20. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 15 are implemented.

Citation Information

Patent Citations

  • Product surface defect segmentation method, defect segmentation model learning method and device

    CN111754513A

  • Image processing method and device, computer-readable storage medium, and electronic equipment

    CN113920208A

  • 3D printing workpiece defect identification method and system based on image detection

    CN116843685A

  • Image processing method and device, equipment, storage medium and computer program product

    CN117710301A

  • Novel peptide for specific detection of thrombin and Uses Thereof

    KR1020230057075A

Cited By

  • Lightweight beef quality evaluation method based on unsupervised feature learning

    CN119418330A

  • Zero sample surface defect segmentation method based on text guidance

    CN119785026A

  • Product defect detection method and device, medium and program product

    CN120543544A

  • Product defect detection method, apparatus, medium, and program product

    CN120543544B

  • Abnormality detection method and device, electronic equipment, storage medium and program product

    CN120805005A