An anomaly detection method, device, storage medium and electronic device
By employing a parallel teacher model and a dynamic multi-scale attention mechanism, the problem of missed detection in cross-domain anomaly detection by traditional diffusion models is solved, achieving high-performance anomaly detection applicable to industrial quality inspection and medical imaging diagnosis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XIAN AERONAUTICAL POLYTECHNIC INST
- Filing Date
- 2026-04-29
- Publication Date
- 2026-07-14
AI Technical Summary
Traditional diffusion models lack effective semantic guidance during the denoising and reconstruction process, resulting in the "perfect reconstruction" of abnormal regions, which reduces the discriminative power of the reconstruction residuals. They perform poorly, especially in cross-domain anomaly detection, and are prone to missing detections, particularly in the detection of fine cracks or early lesions.
We employ a parallel first-teacher model and a second-teacher model to reinforce basic semantic features and guide student models in learning mappings, respectively. Anomaly detection is performed through diffusion reconstruction branches. Prior constraints of high-level semantics are introduced to ensure that the model does not lose its way during the learning process. Furthermore, we improve the accuracy of feature representation and discrimination through dynamic multi-scale attention modules and polarization processing.
It significantly reduces the false negative rate of subtle lesions and industrial micro-cracks, achieves good detection performance across fields, eliminates the need to retrain the model, and improves the versatility and accuracy of the detection model.
Smart Images

Figure CN122391741A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence technology, specifically relating to an anomaly detection method, device, storage medium, and electronic device. Background Technology
[0002] Anomaly detection (AD) aims to identify data that deviates from normal patterns and has core application value in industrial quality inspection (such as chip scratches and fabric damage) and medical imaging diagnosis (such as tumor screening and tissue lesions). When dealing with cross-domain (industrial + medical) unified anomaly detection tasks, traditional diffusion models often lack effective semantic guidance during the denoising and reconstruction process. This sometimes leads to the "perfect reconstruction" of abnormal regions (i.e., overgeneralization), thereby masking abnormal signals, reducing the discriminative power of the reconstruction residuals, and causing missed detections. This is especially true in the detection of fine cracks or early lesions, making the detection model unable to be directly applied across domains. Summary of the Invention
[0003] In order to overcome the shortcomings of the prior art, the present invention aims to provide an anomaly detection method, device, storage medium and electronic device.
[0004] To achieve the above objectives, the present invention employs the following technical solution: In a first aspect, embodiments of the present invention provide an anomaly detection method, comprising the following steps: Acquire the image to be detected; The image to be detected is input into the anomaly detection model, and the target detection image is output. The feature extraction layer of the anomaly detection model includes a parallel first teacher model and a second teacher model. The first teacher model and the second teacher model are used to guide the student model to learn the mapping and strengthen the basic semantic features, respectively, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
[0005] In one possible implementation of the first aspect, before inputting the image to be detected into the anomaly detection model and outputting the target detection image, the method further includes: Feature extraction is performed on the sample images based on the first teacher model and the second teacher model to obtain sample features; Guided by the first teacher model, the student model learns to map the sample features to obtain student features; Using the second teacher model as a prior constraint, the diffusion reconstruction branch reconstructs student features to obtain reconstructed features; Anomaly detection models are established by identifying anomalies based on reconstructed features and student characteristics.
[0006] In one possible implementation of the first aspect, the first teacher model is a target view teacher model, the second teacher model is a source view teacher model, the target view teacher model is used to guide the student model to learn the mapping based on its knowledge distillation loss, and the source view teacher model is used to freeze to retain basic general semantic features.
[0007] In one possible implementation of the first aspect, after extracting features from the sample images based on the first teacher model and the second teacher model to obtain the sample features, the method further includes: The sample features extracted by the first teacher model and the second teacher model are fused to obtain the fused features; Enhanced features are obtained by strengthening the fused features at the bottleneck layer; Guided by the first teacher model, the student model learns to map sample features to obtain student features, including: Guided by the first teacher model, the student model learns and maps the enhanced features to obtain student features.
[0008] In one possible implementation of the first aspect, the fused features are enhanced at the bottleneck layer to obtain enhanced features, including: The fused features are bisected at the bottleneck layer to obtain the first bisected feature and the second bisected feature. Perform local convolution on the first bisecting feature to obtain the local convolution feature; Perform dilated convolution on the second bisecting feature to obtain dilated convolution features; Local convolutional features and dilated convolutional features are connected and weighted and fused to enhance the features, resulting in enhanced features.
[0009] In one possible implementation of the first aspect, anomaly detection is established by judging anomalies based on reconstruction features and student features, including: Anomaly detection is performed based on reconstructed features and student features, and low-level candidate features and high-level semantic guidance flow are obtained; Flatten the low-level candidate features into vectors to generate weight vectors; Driven by high-level semantic guidance flow, domain selection is performed based on weight vectors and low-level candidate features, and the low-level candidate features are polarized. The polarized domain features are obtained to build an anomaly detection model.
[0010] In one possible implementation of the first aspect, obtaining polarized domain features to build an anomaly detection model includes: Obtain polarized domain features and, based on these features, obtain feature scatter distribution data and multi-scale scoring maps; Connected component labeling is performed on the binarized multi-scale scoring map, and the area and intensity data of the connected regions are obtained based on the feature scatter distribution data; An anomaly heatmap is obtained based on the area and intensity data of the connected regions to establish an anomaly detection model.
[0011] Secondly, embodiments of the present invention provide an anomaly detection device, comprising: The acquisition module is used to acquire the image to be detected; The output module is used to input the image to be detected into the anomaly detection model and output the target detection image. The feature extraction layer of the anomaly detection model includes a parallel first teacher model and a second teacher model. The first teacher model and the second teacher model are used to guide the student model to learn the mapping and strengthen the basic semantic features, respectively, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
[0012] Thirdly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when loaded and executed by a processor, implements the anomaly detection method provided in any of the first aspects above.
[0013] Fourthly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein: Memory is used to store computer programs; The processor is used to load and execute computer programs to cause the electronic device to perform anomaly detection methods as provided in any of the first aspects above.
[0014] Compared with the prior art, the present invention has the following beneficial effects: This invention proposes an anomaly detection method, apparatus, storage medium, and electronic device. The method utilizes an anomaly detection model to identify anomalies in the image to be detected. This model employs a teacher-student model, but its feature extraction layer consists of two parallel teacher models. One teacher model strengthens basic semantic features, while the other guides the student model to learn the mapping, ensuring accurate simulation and preventing the model from losing its way during learning. This guarantees high-performance reconstruction while providing a reliable data foundation for subsequent processing. The diffusion reconstruction branch achieves anomaly detection through diffusion reconstruction, introducing semantic guidance from the teacher model. Through prior constraints of high-level semantics, the model is forced to locate itself on the manifold distribution of normal data during denoising and reconstruction, effectively suppressing erroneous reconstruction of abnormal textures and widening the numerical gap between normal and abnormal regions in the reconstruction residual. This significantly reduces the false negative rate of subtle lesions and industrial micro-cracks, enabling the detection model to achieve cross-domain applications and good detection performance without retraining. Attached Figure Description
[0015] Figure 1 This is a schematic diagram of the electronic device structure for the hardware operating environment involved in this invention; Figure 2 A flowchart illustrating the anomaly detection method provided by the present invention; Figure 3 This is a schematic diagram of a framework for an anomaly detection model in the anomaly detection method provided by the present invention. Figure 4 This is a schematic diagram of the dynamic multi-scale attention module in the anomaly detection method provided by the present invention; Figure 5 This is a schematic diagram illustrating semantic guidance and relevant feature selection in the anomaly detection method provided by the present invention. Figure 6 This is a schematic diagram of the module of the anomaly detection device provided by the present invention.
[0016] Wherein: 101-processor, 102-communication bus, 103-network interface, 104-user interface, 105-memory. Detailed Implementation
[0017] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0018] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0019] See attached document Figure 1 , attached Figure 1This is a schematic diagram of the electronic device structure of the hardware operating environment involved in the embodiments of the present invention. The electronic device may include: a processor 101, such as a central processing unit (CPU), a communication bus 102, a user interface 104, a network interface 103, and a memory 105. The communication bus 102 is used to realize the connection and communication between these components. The user interface 104 may include a display screen and an input unit such as a keyboard. Optionally, the user interface 104 may also include a standard wired interface or a wireless interface. The network interface 103 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 105 may be a storage device independent of the aforementioned processor 101. The memory 105 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as at least one disk storage device. The processor 101 may be a general-purpose processor, including a central processing unit, a network processor, etc., or it may be a digital signal processor, an application-specific integrated circuit, a field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component.
[0020] Those skilled in the art will understand that the appendix Figure 1 The structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0021] As attached Figure 1 As shown, the memory 105, which serves as a storage medium, may include an operating system, a network communication module, a user interface module, and an anomaly detection device.
[0022] In the appendix Figure 1 In the electronic device shown, the network interface 103 is mainly used for data communication with the network server; the user interface 104 is mainly used for data interaction with the user; the processor 101 and the memory 105 in this invention can be set in the electronic device, and the electronic device calls the anomaly detection device stored in the memory 105 through the processor 101 and executes the anomaly detection method provided in the embodiment of this invention.
[0023] Anomaly detection (AD) aims to identify data that deviates from normal patterns and has core application value in industrial quality inspection (such as chip scratches and fabric damage) and medical imaging diagnosis (such as tumor screening and tissue lesions). Because anomalous samples are extremely difficult to obtain in reality and their types are unpredictable, current mainstream technologies primarily employ unsupervised or self-supervised learning. Knowledge Distillation (KD): Locating anomalies by leveraging feature differences between a strong teacher network (pre-trained model) and a weak student network; this is currently the mainstream strategy for unified anomaly detection. Reconstructive Models: Attempting to reconstruct the input image using AutoEncoders or GANs, assuming the model cannot reconstruct unseen anomalies, and discovering anomalies through reconstruction residuals. Diffusion Models: As a new generation of generative models, exhibiting extremely powerful distribution modeling capabilities through noise addition and denoising processes, they are beginning to be introduced into the reconstruction branch to improve the fidelity of image reconstruction. Feature Selection and Attention Mechanisms: To handle lesions or defects of different sizes, researchers have introduced multi-scale feature fusion and attention weight adjustment techniques. Despite significant progress in existing technologies, the following core shortcomings still exist when handling cross-domain (industrial + medical) unified anomaly detection tasks: Traditional diffusion models often lack effective semantic guidance during denoising and reconstruction, sometimes resulting in the "perfect reconstruction" of anomalous regions (i.e., overgeneralization), thus masking abnormal signals. This reduces the discriminative power of the reconstruction residuals, leading to missed detections, especially in detecting fine cracks or early lesions. Existing bottleneck layers often use convolutional kernels with fixed receptive fields and static feature selection mechanisms. Industrial samples (typically with repetitive textures) and medical samples (with complex anatomical structures) have vastly different spatial scale requirements. Static models struggle to simultaneously accommodate the feature distributions of both types of data without fine-tuning, resulting in poor cross-domain generality. Most existing algorithms generate anomaly scoring maps based solely on pixel-level feature distances or cosine similarity, representing isolated "pixel-by-pixel" decision-making. This makes them susceptible to noise (such as image noise and uneven illumination), generating numerous false positives (FPs). Furthermore, they cannot identify regions composed of multiple pixels with specific shapes or topological structures (such as linear cracks or clump-like tumors), leading to overly simplistic decision-making dimensions.
[0024] Therefore, based on the hardware device of the foregoing embodiments, embodiments of the present invention provide an anomaly detection method to solve the above problems, comprising the following steps: S10: Acquire the image to be detected.
[0025] In the specific implementation process, the image to be detected is the image that will be input into the anomaly detection model for anomaly detection. Taking the field mentioned in the background technology as an example, the image to be detected can be an industrial image or a medical image. Acquiring the image to be detected can be done by directly acquiring the aforementioned real-time captured image for detection, or by saving the captured image to a dataset and retrieving it from the dataset during unified detection.
[0026] S20: Input the image to be detected into the anomaly detection model and output the target detection image; wherein, the feature extraction layer of the anomaly detection model includes a parallel first teacher model and a second teacher model. The first teacher model and the second teacher model are used to guide the student model to learn the mapping and strengthen the basic semantic features, respectively, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
[0027] In the specific implementation process, the image to be detected is processed by the anomaly detection model, and the output image is the target detection image. The anomaly detection model uses the classic teacher-student framework: the teacher model extracts features, and the student model learns the mapping and reconstructs it in the diffusion reconstruction branch. Anomaly detection is achieved by comparing the student model's learned features with the teacher model's learned features. The anomaly detection model of this invention designs a parallel dual-teacher model, where one teacher model is used to strengthen basic semantic features, and the other teacher model is used to guide the student model to learn the mapping. This ensures that the student model accurately simulates the mapping and does not lose its way during the learning process, guaranteeing high-performance reconstruction while providing a reliable data foundation for subsequent processing. The diffusion reconstruction branch achieves anomaly detection through diffusion reconstruction, which introduces semantic guidance from the teacher model. Through high-level semantic prior constraints, the model is forced to locate itself on the manifold distribution of normal data during the denoising and reconstruction process, effectively suppressing erroneous reconstruction of abnormal textures.
[0028] This invention implements an anomaly detection model to identify anomalies in images. The anomaly detection model adopts a teacher-student model, but its feature extraction layer consists of two parallel teacher models. One teacher model is used to strengthen basic semantic features, and the other teacher model is used to guide the student model to learn the mapping, enabling the student model to accurately simulate and ensuring that the model does not lose its way during the learning process. This guarantees high-performance reconstruction while providing a reliable data foundation for subsequent steps. The diffusion reconstruction branch achieves anomaly detection through diffusion reconstruction, which introduces semantic guidance from the teacher model. Through the prior constraints of high-level semantics, the model is forced to locate itself on the manifold distribution of normal data during the denoising and reconstruction process, effectively suppressing erroneous reconstruction of abnormal textures, widening the numerical gap between normal and abnormal regions in the reconstruction residual, and significantly reducing the false negative rate of subtle lesions and industrial micro-cracks. This allows the detection model to achieve cross-domain applications and good detection performance without retraining.
[0029] In one embodiment, before inputting the image to be detected into the anomaly detection model and outputting the target detection image, the method further includes: S101: Extract features from the sample images based on the first teacher model and the second teacher model to obtain sample features; S102: Guided by the first teacher model, the student model learns and maps the sample features to obtain student features; S103: Using the second teacher model as a prior constraint, the diffusion reconstruction branch reconstructs the student features to obtain the reconstructed features; S104: Based on the reconstructed features and student features, perform anomaly judgment to establish an anomaly detection model.
[0030] In practical implementation, the anomaly detection model can be established through pre-training on sample images. First, feature extraction is performed using a parallel dual-teacher model to obtain sample features. Specifically, within the framework of the anomaly detection model, the dual-teacher model can employ a Target view and a Source-view dual-teacher model, as shown in the attached figure. Figure 3 As shown, the first teacher model is the target view teacher model, and the second teacher model is the source view teacher model. The target view teacher model is used to guide the student model to learn the mapping based on its knowledge distillation loss, while the source view teacher model is used to freeze and retain basic, general semantic features. By freezing the source view teacher model, basic, general semantic features are preserved, while simultaneously utilizing... Knowledge distillation loss guides the student model to perform accurate simulations, ensuring that the model does not lose its way during the learning process. While guaranteeing high-performance reconstruction, it maintains the rigor and academic consistency of feature representations, laying a reliable data foundation for subsequent discrimination logic. On the one hand, it strengthens feature extraction; on the other hand, through high-level semantic prior constraints, it forces the model to be positioned on the manifold distribution of normal data during the denoising process.
[0031] Assume the input image, i.e., the sample image, has a size of... Let C be the number of channels, B be the batch size (a hyperparameter in deep learning training representing the number of samples used to calculate the gradient in one iteration), and d be the number of feature channels. Then the sample image is represented as... Images are fed into a dual-teacher model in parallel, and multi-scale features of the intermediate layer are extracted to output the target view features respectively: and Source view characteristics: , k This represents the downsampling ratio.
[0032] In one embodiment, after extracting features from the sample image based on a first teacher model and a second teacher model to obtain the sample features, the method further includes: The sample features extracted by the first teacher model and the second teacher model are fused to obtain the fused features; Enhanced features are obtained by strengthening the fusion features at the bottleneck layer.
[0033] In practice, the sample features output by the teacher model are fused features obtained by splicing or weighting. (in ), and enhance it at the bottleneck layer to strengthen feature representation.
[0034] Based on the aforementioned steps, guided by the first teacher model, the student model learns and maps the sample features to obtain student features, including: Guided by the first teacher model, the student model learns and maps the enhanced features to obtain student features.
[0035] Enhancement processing can focus on minute features through convolution or through multi-scale feature fusion. This invention provides a dynamic multi-scale attention embedding mechanism, specifically: enhancing the fused features at the bottleneck layer to obtain enhanced features, including: The fused features are bisected at the bottleneck layer to obtain the first bisected feature and the second bisected feature. Perform local convolution on the first bisecting feature to obtain the local convolution feature; Perform dilated convolution on the second bisecting feature to obtain dilated convolution features; Local convolutional features and dilated convolutional features are connected and weighted and fused to enhance the features, resulting in enhanced features.
[0036] In the specific implementation process, a parallel dual-convolutional dynamic multi-scale attention module is adopted, as shown in the attached diagram. Figure 4 As shown, the fused features are first divided into two equal parts, each with a dimension of [dimension value missing]. The local convolutional features are obtained by outputting the local convolutional path (3*3). The dilated convolution feature is obtained from the output of the dilated convolution path. Then, spatial attention fusion is performed to concatenate the two feature streams and obtain the desired result. Through attention maps Weighted fusion is performed, and the final output enhanced features are: This invention addresses the difference between repetitive textures in industrial images and complex anatomical structures in medical images. The DAME (Dynamic Multi-Scale Attention Module) abandons the fixed receptive field design, capturing microscopic textures through "local convolution" and obtaining macroscopic structures through "dilated convolution," while utilizing "dynamic spatial attention" to allocate weights in real time based on input features. This allows a single model to flexibly switch between high-precision industrial quality inspection and complex medical image analysis without retraining, enhancing the architecture's versatility and robustness of feature representation.
[0037] In one embodiment, anomaly detection is performed based on reconstructed features and student features to establish an anomaly detection model, including: Anomaly detection is performed based on reconstructed features and student features, and low-level candidate features and high-level semantic guidance flow are obtained; Flatten the low-level candidate features into vectors to generate weight vectors; Driven by high-level semantic guidance flow, domain selection is performed based on weight vectors and low-level candidate features, and the low-level candidate features are polarized. The polarized domain features are obtained to build an anomaly detection model.
[0038] In the specific implementation process, the student model learns and maps sample features to obtain student features. DRB diffusion reconstruction branch receiving student characteristics Inject Gaussian noise and perform T-step denoising and reconstruction to output student features. Reconstructing features Abnormal scores can be identified through... Implementation. The low-level candidate features extracted in the aforementioned process are: High-level semantic guidance flow is To achieve semantically guided domain-related feature selection, as shown in the appendix... Figure 5 As shown, the low-level candidate features are first flattened into vectors to generate channel / domain weight vectors. Then perform adaptive gating. and superimposed learning parameters The final output is the polarized domain features. By employing an "adaptive domain gating" mechanism, high-level semantics are used to polarize low-level features. This allows for the automatic suppression of irrelevant background features and the amplification of key identifying features based on the input's domain, enabling automatic feature filtering within a specific domain. It clearly delineates the boundaries between normal and abnormal features in the feature space (as shown in the attached figure). Figure 3 The gap and range shown in the figure solve the semantic drift problem, enabling the model to have extremely high discrimination accuracy when processing heterogeneous data.
[0039] In one embodiment, obtaining polarized neighborhood features to establish an anomaly detection model includes: Obtain polarized domain features and, based on these features, obtain feature scatter distribution data and multi-scale scoring maps; Connected component labeling is performed on the binarized multi-scale scoring map, and the area and intensity data of the connected regions are obtained based on the feature scatter distribution data; An anomaly heatmap is obtained based on the area and intensity data of the connected regions to establish an anomaly detection model.
[0040] In practical implementation, unlike existing technologies where independent pixel-level decision-making is susceptible to noise interference, this invention introduces spatial topology analysis through connectivity-aware decision-making, using a multi-scale scoring map. Using feature scatter distribution data as output, the binarized scoring map is first labeled with connected components, and then cross-scale scoring is performed based on the area of the connected regions. and intensity Weighted summaries are applied to output the final anomaly heatmap. (Real numbers between 0 and 1), category labels are (Normal or Abnormal). The decision-making method described above combines pixel-level anomaly scores with spatial topology for a comprehensive weighted decision. It not only examines the anomaly scores of individual pixels but also assesses whether these points constitute physically meaningful clumps or stripes through regional connectivity analysis. This greatly filters out false positive scores caused by random noise, making the detection results more consistent with actual physical morphology (such as the continuity of tumor clumps) and improving the accuracy of anomaly localization.
[0041] See attached document Figure 6 Based on the same inventive concept as in the foregoing embodiments, this embodiment of the invention also provides an anomaly detection device, comprising: The acquisition module is used to acquire the image to be detected; The output module is used to input the image to be detected into the anomaly detection model and output the target detection image. The feature extraction layer of the anomaly detection model includes a parallel first teacher model and a second teacher model. The first teacher model and the second teacher model are used to guide the student model to learn the mapping and strengthen the basic semantic features, respectively, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
[0042] Those skilled in the art should understand that the division of the various modules in the embodiments is merely a logical functional division. In actual applications, they can be fully or partially integrated into one or more actual carriers. These modules can be implemented entirely in software through processing unit calls, entirely in hardware, or a combination of software and hardware. It should be noted that each module in the anomaly detection device in this embodiment corresponds one-to-one with each step in the anomaly detection method in the aforementioned embodiments. Therefore, the specific implementation of this embodiment can refer to the implementation of the aforementioned anomaly detection method, which will not be repeated here.
[0043] Based on the same inventive concept as in the foregoing embodiments, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when loaded and executed by a processor, implements the anomaly detection method provided in the embodiments of the present invention.
[0044] Based on the same inventive concept as in the foregoing embodiments, embodiments of the present invention also provide an electronic device, including a processor and a memory, wherein: Memory is used to store computer programs; The processor is used to load and execute computer programs to cause the electronic device to perform the anomaly detection method provided in the embodiments of the present invention.
[0045] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a device including one or any combination of the above-mentioned memories. The computer may be a variety of computing devices, including smart terminals and servers.
[0046] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0047] As an example, executable instructions may, but do not necessarily, correspond to files in the file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple collaborative files (e.g., a file that stores one or more modules, subroutines, or code sections).
[0048] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.
[0049] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as read-only memory / random access memory, magnetic disk, optical disk) and includes several instructions to cause a multimedia terminal device (which may be a mobile phone, computer, television receiver, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0050] The above content is only for illustrating the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solution based on the technical concept proposed in this invention shall fall within the scope of protection of the claims of this invention.
Claims
1. An anomaly detection method, characterized in that, Includes the following steps: Acquire the image to be detected; The image to be detected is input into the anomaly detection model, and the target detection image is output. The feature extraction layer of the anomaly detection model includes a first teacher model and a second teacher model in parallel. The first teacher model and the second teacher model are used to guide the student model to learn the mapping and strengthen the basic semantic features, respectively, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
2. The anomaly detection method according to claim 1, characterized in that, Before inputting the image to be detected into the anomaly detection model and outputting the target detection image, the method further includes: The sample features are obtained by extracting features from the sample images based on the first teacher model and the second teacher model; Guided by the first teacher model, the student model learns and maps the sample features to obtain student features; Using the second teacher model as a prior constraint, the diffusion reconstruction branch reconstructs the student features to obtain reconstructed features; Anomaly detection model is established by performing anomaly assessment based on the reconstructed features and the student features.
3. The anomaly detection method according to claim 2, characterized in that, The first teacher model is a target view teacher model, and the second teacher model is a source view teacher model. The target view teacher model is used to guide the student model to learn the mapping based on its knowledge distillation loss, and the source view teacher model is used to freeze to retain basic general semantic features.
4. The anomaly detection method according to claim 2, characterized in that, After extracting features from the sample image based on the first teacher model and the second teacher model to obtain the sample features, the method further includes: The sample features extracted by the first teacher model and the second teacher model are fused to obtain fused features; The fusion features are enhanced at the bottleneck layer to obtain enhanced features; Guided by the first teacher model, the student model learns and maps the sample features to obtain student features, including: Guided by the first teacher model, the student model learns and maps the enhanced features to obtain student features.
5. The anomaly detection method according to claim 4, characterized in that, The enhancement of the fused features at the bottleneck layer to obtain enhanced features includes: The fused features are bisected at the bottleneck layer to obtain a first bisected feature and a second bisected feature. Perform local convolution on the first bisecting feature to obtain local convolution features; Perform dilated convolution on the second bisecting feature to obtain dilated convolution features; The local convolutional features and the dilated convolutional features are connected and weighted and fused to enhance the features, thereby obtaining the enhanced features.
6. The anomaly detection method according to claim 2, characterized in that, The step of determining anomalies based on the reconstructed features and the student features to establish the anomaly detection model includes: Anomaly detection is performed based on the reconstructed features and the student features, and low-level candidate features and high-level semantic guidance flow are obtained; Flatten the low-level candidate features into vectors to generate weight vectors; Driven by the high-level semantic guidance flow, domain filtering is performed based on the weight vector and the low-level candidate features, and the low-level candidate features are subjected to polarization processing. The polarized domain features are obtained to establish the anomaly detection model.
7. The anomaly detection method according to claim 6, characterized in that, The process of obtaining polarized domain features to establish the anomaly detection model includes: The polarized domain features are obtained, and based on these features, feature scatter distribution data and multi-scale scoring maps are obtained. Connected component labeling is performed on the binarized multi-scale scoring map, and the area and intensity data of the connected regions are obtained based on the feature scatter distribution data. Based on the area and intensity data of the connected regions, an anomaly heatmap is obtained to establish the anomaly detection model.
8. An anomaly detection device, characterized in that, include: The acquisition module is used to acquire the image to be detected; The output module is used to input the image to be detected into the anomaly detection model and output the target detection image; wherein, the feature extraction layer of the anomaly detection model includes a parallel first teacher model and a second teacher model, the first teacher model and the second teacher model are respectively used to guide the student model to learn the mapping and strengthen the basic semantic features, and the extracted sample features are used as the prior constraints of the diffusion reconstruction branch.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is loaded and executed by the processor, it implements the anomaly detection method as described in any one of claims 1-7.
10. An electronic device, characterized in that, Including processor and memory, of which: The memory is used to store computer programs; The processor is used to load and execute the computer program to cause the electronic device to perform the anomaly detection method as described in any one of claims 1-7.