Anomaly detection method and system based on generative model

Low-dimensional feature extraction and reconstruction through the generative model, combined with discriminator judgment, the problems of large sample demand and unbalanced categories in abnormal detection are solved, and detection accuracy and efficiency are improved.

CN114707600BActive Publication Date: 2025-08-26XIDIAN UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210339922.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-01
Publication Date
2025-08-26
Estimated Expiration
2042-04-01

AI Technical Summary

Technical Problem

The prior art requires a large number of samples in abnormal detection, the defect sample data is small, and the labeling is time-consuming and labor-intensive, resulting in high cost of abnormal detection and poor detection effect.

Method used

Anomaly detection method based on the generative model is adopted, low-dimensional feature extraction and reconstruction are performed through the generator, authenticity judgment is performed by combining the discriminator, and abnormality detection is performed by using residual values.

Benefits of technology

It reduces the demand for sample data volume, alleviates the problem of category imbalance, improves the accuracy and efficiency of abnormal detection, and controls time and labor costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114707600B_ABST
    Figure CN114707600B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for anomaly detection based on a generative model, which includes obtaining a first sample data set; constructing a generator, inputting the first sample data set into the generator, performing low-dimensional feature extraction of the first sample data set through a first encoder, constraining the low-dimensional feature vector of the first low-dimensional feature extraction result through a second encoder, decoding the constrained first low-dimensional feature extraction result through a decoder, and judging the authenticity of the first reconstructed sample set through a discriminator to obtain first data to be detected; inputting the first data to be detected into the generator to obtain first reconstructed data, and performing anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data. The method solves the technical problems of the prior art in the process of anomaly detection, such as the large sample demand, the small amount of defective sample data, and the time-consuming and labor-intensive labeling, which leads to high anomaly detection cost and poor detection effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of anomaly detection, and in particular to an anomaly detection method and system based on a generative model. Background Art

[0002] With the rapid development of science and technology, product production and manufacturing processes are constantly being improved and upgraded, and higher quality requirements are being placed on products. Substandard products can have a significant impact on a company's reputation and profitability, as well as the safety of users' lives and property. Therefore, accurate product quality testing is crucial.

[0003] Currently, supervised learning-based target detection methods are commonly used in anomaly detection, achieving good performance. However, these methods have high data requirements. In actual industrial production scenarios, the number of defects is relatively small, making acquiring and labeling defects time-consuming and labor-intensive. Furthermore, there is an imbalance between defective and normal samples. Due to these data constraints, supervised learning-based target detection methods face numerous challenges in solving defect detection tasks.

[0004] However, in the process of implementing the technical solution of the invention in this application, it was found that the above technology has at least the following technical problems:

[0005] In the process of anomaly detection, existing technologies have a large demand for samples, a small amount of defect sample data, and labeling is time-consuming and labor-intensive, resulting in high anomaly detection costs and poor detection results. Summary of the Invention

[0006] This application provides an anomaly detection method and system based on a generative model, which solves the technical problems of the prior art in the process of anomaly detection, such as large sample demand, small amount of defective sample data, and time-consuming and labor-intensive labeling, which leads to high anomaly detection cost and poor detection effect. The application achieves the technical effect of reducing the demand for sample data volume, alleviating the problem of category imbalance, and improving the accuracy of anomaly detection while controlling time and labor costs.

[0007] In view of the above problems, the present application proposes a method and system for anomaly detection based on a generative model.

[0008] In the first aspect, the present application provides an anomaly detection method based on a generative model, the method comprising: obtaining a first sample data set; constructing a generator, wherein the generator comprises a first encoder and a decoder; inputting the first sample data set into the generator, performing low-dimensional feature extraction of the first sample data set through the first encoder, and obtaining a first low-dimensional feature extraction result; performing low-dimensional feature vector constraints on the first low-dimensional feature extraction result through the second encoder, decoding the constrained first low-dimensional feature extraction result through the decoder, and obtaining a first reconstructed sample set; performing authenticity judgment of the first reconstructed sample set through a discriminator, and obtaining a first judgment result; when the output result of the first judgment result meets a first preset threshold, obtaining first data to be detected; inputting the first data to be detected into the generator, obtaining first reconstructed data, and performing anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data.

[0009] On the other hand, the present application also provides an anomaly detection system based on a generative model, the system comprising: a first obtaining unit, the first obtaining unit being used to obtain a first sample data set; a first constructing unit, the first constructing unit being used to construct a generator, wherein the generator comprises a first encoder and a decoder; a second obtaining unit, the second obtaining unit being used to input the first sample data set into the generator, and performing low-dimensional feature extraction of the first sample data set through the first encoder to obtain a first low-dimensional feature extraction result; a third obtaining unit, the third obtaining unit being used to constrain the low-dimensional feature vector of the first low-dimensional feature extraction result through the second encoder, and decoding the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set; a first discriminant unit, the first discriminant unit being used to perform authenticity judgment of the first reconstructed sample set through the discriminator to obtain a first judgment result; a fourth obtaining unit, the fourth obtaining unit being used to obtain first data to be detected when the output result of the first judgment result meets a first preset threshold; a first detection unit, the first detection unit being used to input the first data to be detected into the generator, obtain first reconstructed data, and perform anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data.

[0010] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods described in the first aspect when executing the program.

[0011] One or more technical solutions provided in this application have at least the following technical effects or advantages:

[0012] By adopting the following methods: obtaining a first sample data set; inputting the first sample data set into a generator; performing low-dimensional feature extraction on the first sample data set through a first encoder in the generator; constraining the low-dimensional feature extraction result vector through a second encoder; decoding the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set; performing authenticity judgment on the first reconstructed sample set through a discriminator to obtain a first judgment result; and when the output result of the generation model stabilizes, inputting the first data to be detected into the generator to obtain first reconstructed data, and performing anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data. This method reduces the demand for sample data volume, alleviates the problem of category imbalance, and achieves the technical effect of improving the accuracy of anomaly detection while controlling time and labor costs.

[0013] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 This is a flowchart of an anomaly detection method based on a generative model in this application;

[0015] Figure 2 This is a schematic diagram of the architecture of a first encoder of a generative model-based anomaly detection method of the present application;

[0016] Figure 3 This is a schematic diagram of the structure of a decoder of an anomaly detection method based on a generative model in this application;

[0017] Figure 4 This is a schematic diagram of the architecture of a discriminator for an anomaly detection method based on a generative model in this application;

[0018] Figure 5 This is a schematic diagram of the structure of an anomaly detection system based on a generative model in this application;

[0019] Figure 6 This is a structural diagram of an electronic device in this application.

[0020] Explanation of the accompanying drawings: first obtaining unit 11, first constructing unit 12, second obtaining unit 13, third obtaining unit 14, first distinguishing unit 15, fourth obtaining unit 16, first detecting unit 17, electronic device 50, processor 51, memory 52, input device 53, output device 54. DETAILED DESCRIPTION

[0021] This application solves the technical problems of the prior art in the process of anomaly detection, such as the large demand for samples, the small amount of defective sample data, and the time-consuming and labor-intensive labeling, which leads to high anomaly detection costs and poor detection results, by providing an anomaly detection method and system based on a generative model. This reduces the demand for sample data volume, alleviates the problem of category imbalance, and achieves the technical effect of improving the accuracy of anomaly detection while controlling time and labor costs. The embodiments of this application are described below in conjunction with the accompanying drawings. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided by this application are also applicable to similar technical problems.

[0022] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged under appropriate circumstances. This is merely a way of distinguishing when describing objects with the same properties in the embodiments of the present application. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, so that a process, method, system, product or apparatus that includes a series of units is not necessarily limited to those units, but may include other units not expressly listed or inherent to these processes, methods, products or apparatuses.

[0023] Application Overview

[0024] Currently, the mainstream technology for intelligent defect detection in the industrial sector is still based on supervised learning methods, such as Faster-RCNN and MSCNN. However, these supervised learning methods require a large amount of data, and acquiring and labeling data is extremely time-consuming and labor-intensive, making them unsuitable for large-scale application. Generative methods based on autoencoders (AE) and their variants reconstruct blurry images. Anomaly detection algorithms based on generative adversarial networks (GANs), such as AnoGAN, GANomaly, and ALAD, although they have low data requirements, are slow and have low recognition rates. Therefore, there is an urgent need for anomaly detection methods that require less data, have fast detection speeds, and high recognition rates. Existing anomaly detection technologies suffer from high sample requirements, small amounts of defect sample data, and time-consuming and labor-intensive labeling, resulting in high anomaly detection costs and poor results.

[0025] In response to the above technical problems, the overall idea of ​​the technical solution provided by this application is as follows:

[0026] The present application provides an anomaly detection method based on a generative model, which obtains a first sample data set; inputs the first sample data set into a generator, performs low-dimensional feature extraction on the first sample data set through a first encoder in the generator, constrains a vector of the low-dimensional feature extraction result through a second encoder, decodes the constrained first low-dimensional feature extraction result through the decoder, and obtains a first reconstructed sample set; performs authenticity judgment on the first reconstructed sample set through a discriminator to obtain a first judgment result; when the output result of the generative model stabilizes, inputs the first data to be detected into the generator to obtain first reconstructed data, and performs anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data.

[0027] After introducing the basic principles of the present application, various non-limiting implementation methods of the present application will be specifically introduced in conjunction with the drawings in the specification.

[0028] Example 1

[0029] like Figure 1 As shown, the present application provides an anomaly detection method based on a generative model, the method comprising:

[0030] Step S100: obtaining a first sample data set;

[0031] Step S200: constructing a generator, wherein the generator includes a first encoder and a decoder;

[0032] Specifically, the first sample data set is a set of real sample data, and all sample data in the first sample data set are normal samples, and the first sample data set is an image data set. The generator is a model for image reconstruction, which includes a first encoder and a decoder. The feature extractor of the first encoder is a residual network ResNet (Residual Network, ResNet), which has a more powerful feature extraction capability. The first layer and the second layer of the first encoder each have only one convolution layer and a LeakyReLU function. Through the construction of the generator, the reconstruction processing of the sample data based on the constructed generator provides data support for subsequent accurate anomaly detection.

[0033] Step S300: inputting the first sample data set into the generator, performing low-dimensional feature extraction on the first sample data set through the first encoder, and obtaining a first low-dimensional feature extraction result;

[0034] Step S400: constraining the low-dimensional feature vector of the first low-dimensional feature extraction result by a second encoder, decoding the constrained first low-dimensional feature extraction result by the decoder to obtain a first reconstructed sample set;

[0035] Furthermore, the first encoder is composed of a residual network, and each of the first two layers of the first encoder structure only includes one convolutional layer and a LeakyReLU function, and the network structure and parameters of the second encoder are consistent with those of the first encoder.

[0036] Specifically, the architecture of the first encoder is as follows Figure 2 As shown, it is composed of a residual network, and each of the first two layers of the first encoder structure contains only one convolution layer and a LeakyReLU function, followed by 5 residual blocks. After the first sample data set (image sample) is input into the generator, the image is processed by the first encoder in the generator. After the processing, after passing through 5 residual blocks, the output result is a feature map of size 4×4. The 4×4 feature map is then convolved with a convolution kernel size of 4 and the LeakyReLU function to obtain a low-dimensional feature vector of size 1×1. In order to force the reconstructed sample to be close to the low-dimensional features of the real sample, a second encoder is added, and the network structure and parameters of the second encoder are exactly the same as those of the first encoder. The second encoder constrains the low-dimensional feature vector of the first low-dimensional feature extraction result, and the constrained result is input into the decoder for decoding to obtain the first reconstructed sample set.

[0037] Further, such as Figure 3 As shown in the figure, the decoder structure is Skip Generator. By adding a second encoder, the low-dimensional feature vectors of the feature map can be constrained to improve the consistency of the low-dimensional features of the reconstructed image and the sample image, generating high-quality images. The decoder's structural design prevents the network model from simply learning the identity mapping from image space to feature space. When generating higher-resolution images, the decoder can better integrate the image's low-dimensional information to adapt to the aforementioned low-dimensional features, resulting in higher-quality reconstructed images and providing data support for subsequent accurate model training and anomaly detection.

[0038] Step S500: performing authenticity judgment on the first reconstructed sample set by a discriminator to obtain a first judgment result;

[0039] Furthermore, each of the first two layers of the discriminator structure only contains one convolutional layer and a LeakyReL U function, and is then connected to five DeBlock blocks.

[0040] Step S600: when the output result of the first judgment result meets a first preset threshold, obtaining first data to be detected;

[0041] Step S700: inputting the first data to be detected into the generator to obtain first reconstructed data, and performing abnormality detection and judgment based on the residual value between the first data to be detected and the first reconstructed data.

[0042] Specifically, the discriminator is a model used to judge the true probability of a sample, and its architecture is as follows: Figure 4 As shown, the first two layers of the discriminator are also convolution and activation functions, and then connected to 5 DeBlock blocks, namely the convolution layer Conv, batch normalization BN and activation function. When the size of the feature map is 4×4, the convolution and activation function with a convolution kernel size of 4 are directly used, and finally the result is output through a fully connected layer. The final output result of the discriminator is a scalar, which is used to evaluate the probability that the input image belongs to a real sample. The first preset threshold is a preset threshold for determining whether the discriminator's judgment result is stable. In essence, the first preset threshold is a threshold for evaluating whether the generator's reconstructed image result is stable. When the output result of the first judgment result meets the first preset threshold, it indicates that the generator has mastered the characteristic distribution law of normal data. At this time, the generator can perform the anomaly detection task.

[0043] Furthermore, the data in the anomaly detection task, i.e., the first data to be detected, is input into the generator, and the first reconstructed data is obtained through the generator. Once the generator has mastered the characteristic distribution pattern of normal data, when the input is an abnormal sample, the generator will force the input abnormal sample to approach the characteristics of the normal sample. Finally, the residual value between the input sample and the reconstructed sample is used to determine whether the anomaly detection is complete. This reduces the demand for sample data volume, alleviates the problem of class imbalance, and achieves the technical effect of improving the accuracy of anomaly detection while controlling time and labor costs.

[0044] Furthermore, this application also includes:

[0045] Calculate the reconstruction loss of the generator, and the calculation formula is as follows:

[0046] L recon =‖x,G De (G en (x))‖1

[0047] Among them, L recon is the reconstruction loss, G De is the decoder, G en For the first encoder, optimization compensation of the generator is performed according to the reconstruction loss obtained by calculation.

[0048] Specifically, in order to improve the accuracy of the generator in continuously optimizing the reconstructed image, a reconstruction loss function of the generator is constructed for optimization compensation. The definition formula is as follows:

[0049] L recon =‖x,G De (G en (x))‖1

[0050] Among them, L recon is the reconstruction loss, G De is the decoder, G en The first encoder optimizes and compensates the generator based on the calculated reconstruction loss. The reconstruction loss in this application is calculated using the L1 loss rather than the mean squared error (MSE). The L1 loss produces a clearer image, while the MSE loss produces a blurrier image. When the MSE loss is used as the reconstruction error function, it imposes a greater penalty on portions of the image with large reconstruction errors, while imposing a lighter penalty on portions of the image with small reconstruction errors. This is particularly susceptible to large deviations. If the reconstruction error is too large, it can easily cause gradient explosion during backpropagation. On the other hand, when the reconstruction error is small, the MSE gradient is also small, resulting in poor convergence performance and affecting the overall convergence speed of the model. Therefore, the L1 loss has better convergence performance than the MSE loss, improving the convergence speed of the model. Furthermore, the MSE loss only focuses on the relationship between corresponding pixels in the original and reconstructed images, not the correlation between image neighborhoods. This can easily result in the reconstructed image being only pixel-wise similar to the input image, but failing to achieve a realistic effect. This results in a very small residual value between the input and reconstructed images, resulting in a very poor visual experience. Since there is a strong correlation between adjacent pixels in an image, the basic features of the image can be considered in the L1 loss function, the neighborhood information of the composite component can be considered in the loss function, the global features of the image can be obtained from the neighborhood, and the pixel-level loss can be considered at the same time. The combination of the two can make the reconstruction result closer to the real result.

[0051] Furthermore, this application also includes:

[0052] Calculate the encoding loss of the generator as follows:

[0053]

[0054] Among them, L latent is the encoding loss, z is the low-dimensional feature vector of the first sample data set, is the low-dimensional feature vector of the first reconstructed sample set;

[0055] According to the reconstruction loss and the encoding loss, the total loss function of the generator is calculated and the calculation formula is as follows:

[0056] L G =λ recon L recon +λ ssim (1-L ssim )+λ latent L latent

[0057] Among them, L G is the total loss function, L ssim is the structural similarity loss, λ recon is the weight of the reconstruction loss, λ ssim is the weight of the structural similarity loss, λ latent The weight of the encoding loss is used to optimize and compensate the generator through the total loss function.

[0058] Specifically, the loss of the generator consists of three parts, namely reconstruction loss, structural similarity loss and encoding loss. The encoding loss L latent Used to measure the input sample x and the reconstructed sample The similarity of low-dimensional features ensures that the input sample x and the reconstructed sample Semantic consistency in high-level space. Where z is the low-dimensional feature vector of the first sample data set, is the low-dimensional feature vector of the first reconstructed sample set, encoding loss, and the calculation formula is as follows:

[0059]

[0060] According to the reconstruction loss and the encoding loss, the total loss function of the generator is calculated and the calculation formula is as follows:

[0061] L G =λ recon L recon +λ ssim (1-L ssim )+λ latent L latent

[0062] Among them, L G is the total loss function, L ssim is the structural similarity loss, λ recon is the weight of the reconstruction loss, λ ssim is the weight of the structural similarity loss, λ latentThe weight of the encoding loss is used to optimize and compensate the generator through the total loss function. By constructing the reconstruction loss, encoding loss, and structural similarity loss functions in the generator and optimizing and compensating the generator based on the constructed results, the convergence speed of the model can be improved, making the reconstruction result closer to the real result.

[0063] Furthermore, as shown, this application also includes:

[0064] Calculate the loss of the discriminator as follows:

[0065]

[0066] Among them, L D is the loss of the discriminator, and the discriminator is optimized and compensated according to the loss of the discriminator.

[0067] Specifically, the loss of the discriminator uses the traditional GAN ​​loss, which is calculated as follows:

[0068]

[0069] Among them, L D is the loss of the discriminator, G is the generator, and D is the discriminator. The discriminator is optimized and compensated according to its loss.

[0070] In summary, the anomaly detection method based on a generative model provided by this application has the following technical effects:

[0071] 1. By adopting the method of obtaining a first sample data set; inputting the first sample data set into a generator, performing low-dimensional feature extraction on the first sample data set through a first encoder in the generator, constraining the low-dimensional feature extraction result vector through a second encoder, decoding the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set; performing authenticity judgment on the first reconstructed sample set through a discriminator to obtain a first judgment result; and when the output result of the generation model stabilizes, inputting the first data to be detected into the generator to obtain first reconstructed data, and performing anomaly detection judgment based on the residual value between the first data to be detected and the first reconstructed data, the demand for sample data volume is reduced, the problem of class imbalance is alleviated, and the technical effect of improving the accuracy of anomaly detection while controlling time and labor costs is achieved.

[0072] 2. By adding a second encoder, the low-dimensional feature vectors of the feature map can be constrained to improve the consistency of the low-dimensional features of the reconstructed image and the sample image, generating high-quality images. The structural design of the decoder can prevent the network model from simply learning the identity mapping from image space to feature space. When generating higher-resolution images, the decoder can better combine the low-dimensional information of the image to adapt to the above-mentioned low-dimensional features, obtain higher-quality reconstructed images, and provide data support for subsequent accurate model training and anomaly detection.

[0073] 3. The basic features of the image can be considered in the L1 loss function, the neighborhood information of the composite component can be considered in the loss function, the global features of the image can be obtained from the neighborhood, and the pixel-level loss can be considered at the same time. The combination of the two can make the reconstruction result closer to the real result.

[0074] 4. By constructing the reconstruction loss, encoding loss and structural similarity loss functions in the generator and optimizing and compensating the generator based on the construction results, the convergence speed of the model can be improved, making the reconstruction results closer to the real results.

[0075] Example 2

[0076] Based on the same inventive concept as the anomaly detection method based on a generative model in the aforementioned embodiment, the present invention also provides an anomaly detection system based on a generative model, such as Figure 5 As shown, the system includes:

[0077] A first obtaining unit 11, wherein the first obtaining unit 11 is used to obtain a first sample data set;

[0078] A first construction unit 12, wherein the first construction unit 12 is used to construct a generator, wherein the generator includes a first encoder and a decoder;

[0079] A second obtaining unit 13, configured to input the first sample data set into the generator, perform low-dimensional feature extraction on the first sample data set through the first encoder, and obtain a first low-dimensional feature extraction result;

[0080] a third obtaining unit 14, configured to constrain the low-dimensional feature vector of the first low-dimensional feature extraction result through a second encoder, and decode the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set;

[0081] A first discriminant unit 15, configured to perform authenticity judgment on the first reconstructed sample set through a discriminator to obtain a first judgment result;

[0082] a fourth obtaining unit 16, configured to obtain first data to be detected when an output result of the first judgment result satisfies a first preset threshold;

[0083] The first detection unit 17 is used to input the first data to be detected into the generator to obtain first reconstructed data, and perform abnormality detection and judgment based on the residual value of the first data to be detected and the first reconstructed data.

[0084] Furthermore, the first encoder is composed of a residual network, and each of the first two layers of the first encoder structure only includes one convolutional layer and a LeakyReLU function, and the network structure and parameters of the second encoder are consistent with those of the first encoder.

[0085] Furthermore, each of the first two layers of the discriminator structure only contains one convolutional layer and a LeakyReL U function, and is then connected to five DeBlock blocks.

[0086] Furthermore, the system further comprises:

[0087] The first calculation unit is used to calculate the reconstruction loss of the generator, and the calculation formula is as follows:

[0088] L recon =‖x,G De (G en (x))‖1

[0089] Among them, L recon is the reconstruction loss, G De is the decoder, G en For the first encoder, optimization compensation of the generator is performed according to the reconstruction loss obtained by calculation.

[0090] Furthermore, the system further comprises:

[0091] The second calculation unit is used to calculate the encoding loss of the generator, and the calculation formula is as follows:

[0092]

[0093] Among them, L latent is the encoding loss, z is the low-dimensional feature vector of the first sample data set, is the low-dimensional feature vector of the first reconstructed sample set;

[0094] The third calculation unit is used to calculate the total loss function of the generator according to the reconstruction loss and the encoding loss. The calculation formula is as follows:

[0095] LG =λ recon L recon +λ ssim (1-L ssim )+λ latent L latent

[0096] Among them, L G is the total loss function, L ssim is the structural similarity loss, λ recon is the weight of the reconstruction loss, λ ssim is the weight of the structural similarity loss, λ latent The weight of the encoding loss is used to optimize and compensate the generator through the total loss function.

[0097] Furthermore, the system further comprises:

[0098] The fourth calculation unit is used to calculate the loss of the discriminator. The calculation formula is as follows:

[0099]

[0100] Among them, L D is the loss of the discriminator, and the discriminator is optimized and compensated according to the loss of the discriminator.

[0101] Furthermore, the structure of the decoder is Skip Generator.

[0102] The foregoing Figure 1 The various variations and specific examples of the anomaly detection method based on a generative model in Example 1 are also applicable to the anomaly detection system based on a generative model in this embodiment. Through the above detailed description of the anomaly detection method based on a generative model, those skilled in the art can clearly understand the implementation method of the anomaly detection system based on a generative model in this embodiment, so for the sake of brevity of the specification, it will not be described in detail here.

[0103] Exemplary electronic devices

[0104] Reference below Figure 6 To describe the electronic device of this application.

[0105] Figure 6 The figure shows a schematic structural diagram of an electronic device according to the present application.

[0106] Based on the inventive concept of the anomaly detection method based on the generative model in the above embodiment, the present invention also provides an electronic device, Figure 6The electronic device according to the present application is described below. The electronic device may be a mobile device itself, or a stand-alone device independent of the mobile device, and may store a computer program thereon, which, when executed by a processor, implements the steps of any of the above-described methods.

[0107] like Figure 6 As shown, the electronic device 50 includes one or more processors 51 and a memory 52 .

[0108] The processor 51 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 50 to perform desired functions.

[0109] The memory 52 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 51 may execute the program instructions to implement the methods of the various embodiments of the present application described above and / or other desired functions.

[0110] In one example, the electronic device 50 may further include an input device 53 and an output device 54 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0111] An embodiment of the present invention provides a method for anomaly detection based on a generative model, the method comprising: obtaining a first sample data set; constructing a generator, wherein the generator includes a first encoder and a decoder; inputting the first sample data set into the generator, performing low-dimensional feature extraction on the first sample data set by the first encoder to obtain a first low-dimensional feature extraction result; constraining the low-dimensional feature vector of the first low-dimensional feature extraction result by a second encoder, decoding the constrained first low-dimensional feature extraction result by the decoder to obtain a first reconstructed sample set; performing authenticity judgment on the first reconstructed sample set by a discriminator to obtain a first judgment result; obtaining first data to be detected when the output of the first judgment result meets a first preset threshold; inputting the first data to be detected into the generator to obtain first reconstructed data, and performing anomaly detection judgment based on the residual value of the first data to be detected and the first reconstructed data. The method solves the technical problems of the prior art in the process of anomaly detection, such as the large sample requirement, the small amount of defective sample data, and the time-consuming and labor-intensive labeling, which leads to high anomaly detection cost and poor detection effect. The method reduces the demand for sample data, alleviates the problem of class imbalance, and achieves the technical effect of improving the accuracy of anomaly detection while controlling time and labor costs.

[0112] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general-purpose hardware, and of course can also be implemented by dedicated hardware including application-specific integrated circuits, dedicated CPUs, dedicated memories, dedicated components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits, or dedicated circuits. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions for enabling a computer device to execute the methods described in each embodiment of the present application.

[0113] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0114] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in this application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from a computer-readable storage medium to another computer-readable storage medium. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0115] It should be understood that the “one embodiment” or “an embodiment” mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, the “in one embodiment” or “in an embodiment” appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the sequence numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the present application.

[0116] Additionally, the terms "system" and "network" are often used interchangeably. The term "and / or" is simply used to describe a relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. Furthermore, the character " / " generally indicates an "or" relationship between the related objects.

[0117] It should be understood that in this application, "B corresponding to A" means that B is associated with A and B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B based solely on A; B can also be determined based on A and / or other information.

[0118] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0119] In short, the above description is only a preferred embodiment of the technical solution of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this application shall be included in the scope of protection of this application.

Claims

1. A generative model-based anomaly detection method, characterized in that: The method comprises: Obtaining a first sample data set; Constructing a generator, wherein the generator includes a first encoder and a decoder; Inputting the first sample data set into the generator, performing low-dimensional feature extraction on the first sample data set through the first encoder, and obtaining a first low-dimensional feature extraction result; Performing low-dimensional feature vector constraints on the first low-dimensional feature extraction result through a second encoder, and decoding the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set; Performing authenticity judgment on the first reconstructed sample set by a discriminator to obtain a first judgment result; When the output result of the first judgment result meets the first preset threshold, obtaining first data to be detected; Inputting the first data to be detected into the generator to obtain first reconstructed data, and performing anomaly detection and judgment based on the residual value of the first data to be detected and the first reconstructed data; Calculate the reconstruction loss of the generator, and the calculation formula is as follows: L recon =‖x,G De (G en (x))‖1 Among them, L recon is the reconstruction loss, G De is the decoder, G en For the first encoder, performing optimization compensation on the generator according to the reconstruction loss obtained by calculation; Calculate the encoding loss of the generator as follows: Among them, L latent is the encoding loss, z is the low-dimensional feature vector of the first sample data set, is the low-dimensional feature vector of the first reconstructed sample set; According to the reconstruction loss and the encoding loss, the total loss function of the generator is calculated and the calculation formula is as follows: L G =λ recon L recon +λ ssim (1-L ssim )+λ latent L latent Among them, L G is the total loss function, L ssim is the structural similarity loss, λ recon is the weight of the reconstruction loss, λ ssim is the weight of the structural similarity loss, λ latent The weight of the encoding loss is used to optimize and compensate the generator through the total loss function.

2. The method according to claim 1, wherein The first encoder is composed of a residual network, and each of the first two layers of the first encoder structure only includes one convolutional layer and a LeakyReLU function. The network structure and parameters of the second encoder are consistent with those of the first encoder.

3. The method according to claim 1, wherein Each of the first two layers of the discriminator structure contains only one convolutional layer and a LeakyReLU function, followed by five DeBlock blocks.

4. The method according to claim 1, wherein The method further comprises: Calculate the loss of the discriminator as follows: Among them, L D is the loss of the discriminator, and the discriminator is optimized and compensated according to the loss of the discriminator.

5. A generative model-based anomaly detection system, characterized in that: The system comprises: A first obtaining unit, configured to obtain a first sample data set; A first construction unit, wherein the first construction unit is used to construct a generator, wherein the generator includes a first encoder and a decoder; a second obtaining unit, configured to input the first sample data set into the generator, perform low-dimensional feature extraction on the first sample data set through the first encoder, and obtain a first low-dimensional feature extraction result; a third obtaining unit, configured to constrain the low-dimensional feature vector of the first low-dimensional feature extraction result through a second encoder, and decode the constrained first low-dimensional feature extraction result through the decoder to obtain a first reconstructed sample set; a first discriminant unit, configured to perform authenticity judgment on the first reconstructed sample set through a discriminator to obtain a first judgment result; a fourth obtaining unit, configured to obtain first data to be detected when an output result of the first judgment result meets a first preset threshold; a first detection unit, configured to input the first data to be detected into the generator, obtain first reconstructed data, and perform anomaly detection and judgment based on a residual value between the first data to be detected and the first reconstructed data; The system further comprises: The first calculation unit is used to calculate the reconstruction loss of the generator, and the calculation formula is as follows: L recon =‖x,G De (G en (x))‖1 Among them, L recon is the reconstruction loss, G De is the decoder, G en For the first encoder, performing optimization compensation on the generator according to the reconstruction loss obtained by calculation; The second calculation unit is used to calculate the encoding loss of the generator, and the calculation formula is as follows: Among them, L latent is the encoding loss, z is the low-dimensional feature vector of the first sample data set, is the low-dimensional feature vector of the first reconstructed sample set; The third calculation unit is used to calculate the total loss function of the generator according to the reconstruction loss and the encoding loss. The calculation formula is as follows: L G =λ recon L recon +λ ssim (1-L ssim )+λ latent L latent Among them, L G is the total loss function, L ssim is the structural similarity loss, λ recon is the weight of the reconstruction loss, λ ssim is the weight of the structural similarity loss, λ latent The weight of the encoding loss is used to optimize and compensate the generator through the total loss function.

6. An electronic device, characterized in that: The method comprises a processor and a memory; the memory is used for storing; and the processor is used for executing the method according to any one of claims 1 to 4 by calling.

Citation Information

Patent Citations

  • Image anomaly detection method based on variational auto-encoder

    CN111598881A

  • Anomaly detection method and device based on unsupervised learning and storage medium

    CN113643292A

  • Image anomaly detection method based on deep convolutional generative adversarial network

    CN113658115A