Anomaly detection method and system based on collaborative training and generative adversarial network
Through the collaborative training and generative adversarial network methods, the collaborative training of the autoencoder group and the encoder group is utilized to automatically select data with small reconstruction error for training, and a generative adversarial network model is constructed, which solves the problem of the influence of noise data in the existing technology and achieves the effect of accurately detecting abnormal data in a noisy environment.
Patent Information
- Application Number
- CN202210847783.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-19
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2042-07-19
AI Technical Summary
In the prior art, existing anomaly detection methods require a large amount of labeled data when processing large amounts of data, and are easily affected by noisy data, resulting in an inability to accurately detect anomaly data.
A method based on collaborative training and generative adversarial networks is adopted. Through the collaborative training of autoencoder groups and encoder groups, data with smaller reconstruction errors are automatically selected for training, a generative adversarial network model is constructed, normal data distribution is learned, noise interference is avoided, and the adversarial mechanism of the generator and discriminator is used for anomaly detection.
It achieves accurate detection of abnormal data in noisy data environments, improves the accuracy and robustness of anomaly detection, reduces dependence on labeled data, effectively learns normal data distribution, and improves detection efficiency.
Smart Images

Figure CN115186756B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to an anomaly detection method and system based on collaborative training and generative adversarial networks. Background Art
[0002] One of the most common applications of machine learning is anomaly detection. Anomaly detection in machine learning is the process of detecting data instances that significantly deviate from the norm. It has widespread demand and application in areas such as risk management, security, financial monitoring, and healthcare. Unlike most conventional problems, anomalies are unpredictable and uncertain. Therefore, the core idea of anomaly detection is to learn the distribution of normal data in order to detect anomalous data by its degree of deviation.
[0003] In recent years, deep learning has been widely used in the field of anomaly detection. Numerous methods exist that use neural networks to learn representations of complex data for anomaly detection. Current anomaly detection methods primarily train models using normal data, typically using large amounts of normal data to learn their distribution. However, in practical applications, such methods have certain drawbacks:
[0004] On the one hand, the amount of data in the world is exploding. Labeling data is a huge expense and can even lead to misclassification. To address this issue, an unsupervised learning model is currently being developed to enable learning without the use of labeled data. This involves using an autoencoder as a common network structure for learning data distribution. An autoencoder, consisting of an encoder and a decoder, is a neural network that compresses input data into a latent code and then decompresses the code to generate reconstructed data. The autoencoder can automatically learn the distribution of data from samples.
[0005] On the other hand, the data distribution itself has a certain degree of variability. Normal data may contain instances that are similar to anomalies, and normal datasets may also contain instances that are similar to anomalies or misclassified anomalies. When learning the data distribution of such noisy datasets, commonly used autoencoder networks are often susceptible to these factors because they can also fit anomaly data, resulting in a small reconstruction error for the anomaly data. This means that the reconstruction of anomaly data will produce a very small error, making it impossible to accurately detect anomalies. Therefore, while autoencoders can automatically learn the data distribution from samples, they cannot avoid the influence of noise. In other words, current methods of using autoencoders to learn data distributions for anomaly detection cannot accurately detect anomalies. Summary of the Invention
[0006] The purpose of the present invention is to provide an anomaly detection method and system based on collaborative training and generative adversarial networks to accurately detect abnormal data.
[0007] To achieve the above object, the present invention provides the following solutions:
[0008] A method for anomaly detection based on collaborative training and generative adversarial networks, the method comprising:
[0009] Acquire a training data set; the training data set includes color images of multiple types of objects; the color image of one type of object in the color images of the multiple types of objects is used as abnormal data;
[0010] Inputting the training data set into a first autoencoder and a second autoencoder respectively to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes reconstruction errors corresponding to each color image data output by the first autoencoder; and the second reconstruction error sequence includes reconstruction errors corresponding to each color image data output by the second autoencoder;
[0011] sorting the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence;
[0012] Selecting the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously selecting the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence;
[0013] obtaining a first filtered training data set and a second filtered training data set based on the first filtered reconstruction error sequence and the second filtered reconstruction error sequence; the first filtered training data set including the color image data corresponding to each reconstruction error in the first filtered reconstruction error sequence; and the second filtered training data set including the color image data corresponding to each reconstruction error in the second filtered reconstruction error sequence;
[0014] Inputting the first filtered training data set into the second autoencoder, inputting the second filtered training data set into the first autoencoder, and using the first filtered training data set and the second filtered training data set to train and optimize a generative adversarial network model to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes the first autoencoder, the second autoencoder, a first encoder, and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; and the first encoder and the second encoder are both connected to the discriminator;
[0015] Acquire a data set to be detected; the data set to be detected includes multiple color images of objects;
[0016] The data set to be detected is input into the optimized generative adversarial network model, and the optimized generative adversarial network model is used to perform anomaly detection on the data set to be detected to obtain a color image of the abnormal object in the data set to be detected.
[0017] Optionally, the first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure.
[0018] Optionally, the first autoencoder and the second autoencoder each include an encoder and a decoder;
[0019] The encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure;
[0020] The decoder includes a convolutional transpose layer, batch-norm, ReLU() activation and tanh structure;
[0021] The first encoder and the second encoder each include a convolutional layer, a batch-norm, and a leakyReLU() activation structure.
[0022] Optionally, the discriminator includes an encoder with an additional Softmax layer; the encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure.
[0023] The present invention also provides the following solution:
[0024] An anomaly detection system based on collaborative training and generative adversarial networks, the system comprising:
[0025] A training data set acquisition module is used to acquire a training data set; the training data set includes color images of multiple types of objects; the color image of one type of object in the color images of the multiple types of objects is used as abnormal data;
[0026] a reconstruction error sequence obtaining module, configured to input the training data set into a first autoencoder and a second autoencoder, respectively, to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes reconstruction errors corresponding to each color image data output by the first autoencoder; and the second reconstruction error sequence includes reconstruction errors corresponding to each color image data output by the second autoencoder;
[0027] a reconstruction error sorting module, configured to sort the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence;
[0028] a reconstruction error screening module, configured to select the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously select the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence;
[0029] a training data set screening module, configured to obtain a first screened training data set and a second screened training data set based on the first screened reconstruction error sequence and the second screened reconstruction error sequence; the first screened training data set includes the color image data corresponding to each reconstruction error in the first screened reconstruction error sequence; and the second screened training data set includes the color image data corresponding to each reconstruction error in the second screened reconstruction error sequence;
[0030] a model training and optimization module, configured to input the first screened training data set into the second autoencoder, input the second screened training data set into the first autoencoder, and train and optimize a generative adversarial network model using the first screened training data set and the second screened training data set to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes the first autoencoder, the second autoencoder, a first encoder, and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; and the first encoder and the second encoder are both connected to the discriminator;
[0031] The module for acquiring a data set to be detected is used to acquire a data set to be detected; the data set to be detected includes a plurality of color images of objects;
[0032] The anomaly detection module is used to input the data set to be detected into the optimized generative adversarial network model, use the optimized generative adversarial network model to perform anomaly detection on the data set to be detected, and obtain a color image of the abnormal objects in the data set to be detected.
[0033] Optionally, the first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure.
[0034] Optionally, the first autoencoder and the second autoencoder each include an encoder and a decoder;
[0035] The encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure;
[0036] The decoder includes a convolutional transpose layer, batch-norm, ReLU() activation and tanh structure;
[0037] The first encoder and the second encoder each include a convolutional layer, a batch-norm, and a leakyReLU() activation structure.
[0038] Optionally, the discriminator includes an encoder with an additional Softmax layer; the encoder includes a convolutional layer, batch-norm and leakyReLU() activation structure.
[0039] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0040] The present invention discloses an anomaly detection method and system based on collaborative training and generative adversarial networks. The method and system utilize a first autoencoder and a second autoencoder to obtain a first reconstruction error sequence and a second reconstruction error sequence corresponding to a training data set. The reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence are sorted from small to large to obtain color image data corresponding to smaller reconstruction errors. The method enables the generator to automatically select samples according to the reconstruction error during the process of learning the normal data distribution, so that the generator is free from interference from noise data, thereby learning the normal data distribution. Since each autoencoder selects data with smaller reconstruction error and exchanges it with other autoencoders, the exchanged data is then used to train a generative adversarial network model, and the network parameters are updated to optimize the generative adversarial network model, thereby gradually discarding high reconstruction error data and training and optimizing the generative adversarial network model with low reconstruction error data. The network structure of the generative adversarial network model can effectively learn the normal data distribution without interference from noise data, thereby accurately detecting abnormal data. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0042] Figure 1 Flowchart of an embodiment of an anomaly detection method based on collaborative training and generative adversarial networks of the present invention;
[0043] Figure 2 Schematic diagram of the process of anomaly detection method based on collaborative training and generative adversarial network of the present invention;
[0044] Figure 3 A schematic diagram of the model structure constructed for the present invention;
[0045] Figure 4 This is a structural diagram of an embodiment of the anomaly detection system based on collaborative training and generative adversarial networks of the present invention. DETAILED DESCRIPTION
[0046] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0047] The purpose of the present invention is to provide an anomaly detection method and system based on collaborative training and generative adversarial networks to accurately detect abnormal data.
[0048] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0049] Figure 1 This is a flow chart of an embodiment of an anomaly detection method based on collaborative training and generative adversarial networks of the present invention. Figure 1 , the anomaly detection method based on collaborative training and generative adversarial network includes:
[0050] Step 101: Acquire a training data set; the training data set includes color images of multiple types of objects; and the color images of one type of objects in the color images of the multiple types of objects are used as abnormal data.
[0051] Step 102: Input the training data set into the first autoencoder and the second autoencoder respectively to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes the reconstruction errors corresponding to each color image data output by the first autoencoder; the second reconstruction error sequence includes the reconstruction errors corresponding to each color image data output by the second autoencoder.
[0052] Step 103: sorting the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence.
[0053] Step 104: Select the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously select the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence.
[0054] In step 104, N is an integer greater than 1, and N is smaller than the total number of reconstruction errors in the first sorted reconstruction error sequence, and N is smaller than the total number of reconstruction errors in the second sorted reconstruction error sequence.
[0055] Step 105: Obtain a first filtered training data set and a second filtered training data set based on the first filtered reconstruction error sequence and the second filtered reconstruction error sequence; the first filtered training data set includes color image data corresponding to each reconstruction error in the first filtered reconstruction error sequence; the second filtered training data set includes color image data corresponding to each reconstruction error in the second filtered reconstruction error sequence.
[0056] Step 106: Input the first filtered training data set into the second autoencoder, input the second filtered training data set into the first autoencoder, and use the first filtered training data set and the second filtered training data set to train and optimize the generative adversarial network model to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes a first autoencoder, a second autoencoder, a first encoder, and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; and the first encoder and the second encoder are both connected to the discriminator.
[0057] Step 107: Acquire a dataset to be detected; the dataset to be detected includes multiple color images of objects.
[0058] Step 108: Input the dataset to be detected into the optimized generative adversarial network model, use the optimized generative adversarial network model to perform anomaly detection on the dataset to be detected, and obtain color images of abnormal objects in the dataset to be detected.
[0059] Specifically, the first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure. The first autoencoder and the second autoencoder both include an encoder and a decoder. The encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure. The decoder includes a convolutional transpose layer, batch-norm, ReLU() activation and a tanh structure. The first encoder and the second encoder both include a convolutional layer, batch-norm and leaky ReLU() activation structure. The encoder in the present invention (the encoder in the present invention also includes the first encoder and the second encoder) adopts an existing encoder, and the encoder in the present invention does not improve the structure of the existing encoder. The decoder in the present invention adopts an existing decoder, and the decoder in the present invention does not improve the structure of the existing decoder.
[0060] The discriminator includes an encoder with an additional Softmax layer; the encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure. The discriminator in the present invention adopts an existing discriminator, and the discriminator in the present invention does not improve the structure of the existing discriminator.
[0061] The technical solution of the present invention is described below with a specific embodiment:
[0062] Figure 2 The figure is a flow chart of the anomaly detection method based on collaborative training and generative adversarial networks of the present invention. Figure 2 The basic process of abnormality detection in the present invention is shown. Figure 2 The anomaly detection method based on collaborative training and generative adversarial network of the present invention is as follows:
[0063] The CIFAR10 dataset contains color image data of ten categories of objects. This paper considers one category of data as abnormal. After dividing the dataset into training set and test set, the abnormal data in the training set are transferred to the test set, thus obtaining the noisy training set Dn train and the test set Dn testThe present invention is based on a generative adversarial network framework (generative adversarial network model) comprising a generator G and a discriminator D. Unlike traditional methods, the present invention uses a collaboratively trained autoencoder group (the first autoencoder and the second autoencoder constitute a collaboratively trained autoencoder group) and an additional encoder group (the first encoder and the second encoder constitute an additional encoder group) to generate data. This structure can automatically select samples, so that the generator is not interfered by noisy data and learns normal data distribution. The generative adversarial network model uses Dn train During training, the generator G automatically selects samples based on the reconstruction error (reconstruction error) while learning the normal data distribution, generating data similar to the input. The discriminator D distinguishes whether the data is real or generated. Ultimately, the generator G and the discriminator D reach a Nash equilibrium. Because the generator automatically selects normal data for training, the reconstruction effect of anomalies is worse than that of normal data. This is the anomaly detection method of the present invention. This model (generative adversarial network model) has been verified to have good anomaly detection performance.
[0064] This paper conducts a specific study on anomaly detection in noise-contaminated datasets. The following are specific steps to verify the effectiveness of the present invention:
[0065] Step 1: Divide the data set. Divide the CIFAR10 data set into a training set and a test set. Select one type of data as an anomaly and transfer all the anomaly data in the training set to the test set to obtain a pure data set Dc. Transfer part of the anomaly data to the test set to obtain a noisy data set Dn.
[0066] In order to prove that the present invention can avoid noise interference in Dn and can efficiently learn the distribution of normal data in Dc, the following steps will be performed on two datasets respectively. The training sets of the two datasets will be collectively referred to as D train , the test set is collectively referred to as D test .
[0067] Step 2: Construct the model of the present invention, such as Figure 3 As shown. The main structure of this model (generative adversarial network model) is divided into three modules:
[0068] The first module consists of two sets of autoencoders (the first and second autoencoders). Since the training set uses image data, a convolutional layer, batch-norm, and leaky ReLU() activation structure are selected as the encoder to generate the latent code of the input data. Subsequently, a convolutional transpose layer, batch-norm, ReLU() activation, and tanh are used as the decoder to reconstruct the input data. The autoencoder groups (the two sets of autoencoders) reconstruct the input data in a collaborative training manner.
[0069] The second module, connected to the autoencoder group (the first module), is an encoder with the same structure. It compresses the output data of the first module and outputs a latent code that reconstructs the data. This network structure enables the calculation of anomaly scores based on the lower-dimensional latent code.
[0070] The third module, the Discriminator Network (Discriminator), consists of an encoder with an additional Softmax layer. Its main task is to classify the received data and distinguish between real data and generated data.
[0071] Step 3: Use the Dc and Dn datasets for training respectively. The model established by the present invention does not directly learn the input data because the data may contain noise. If the autoencoder fits the noisy data, it will not be possible to clearly separate the abnormal scores of normal data and abnormal data. To solve this problem, the autoencoder group uses the sample selection method. The generator will D train The data x in the first module is fed into the two autoencoders (autoencoders) in the first module. A forward pass is performed, and the reconstruction error for each data point is calculated. A ratio is then set that decreases to a fixed value over the training process. Data with lower reconstruction error are proportionally selected from the input data of the two autoencoders and exchanged with the other set. Each autoencoder uses the low reconstruction error data from the other set to update its parameters. Finally, the latent vector between the autoencoders and the reconstructed data are output.
[0072] Step 4: The reconstructed data output from step 3 is used as the input of the second module. The encoder with the same structure compresses the reconstructed data and outputs the latent vector of the reconstructed data. Steps 3 and 4 constitute the generator of the generative adversarial network. During the training process, it is necessary to define an appropriate objective function to minimize the error between the reconstructed data and the original data and update the network parameters. The generator selects the following function as the objective function:
[0073] Reconstruction loss L con:The collaborative autoencoder group (co-trained autoencoder group) calculates the distance between the input data and the output data as the reconstruction error, and optimizes the process of the generator learning to generate real data. The objective function is:
[0074]
[0075] Coding loss L enc Compared with the traditional encoder-decoder structure, the present invention uses an additional encoder loss L _enc To minimize the distance between the potential vectors output by the first two modules, the objective function is:
[0076] In formula (1) and formula (2), represents the reconstruction loss, represents the coding loss, x1 and x2 represent the two data input into the collaborative autoencoder group respectively, G(x1) represents the generated data corresponding to the original data x1, G(x2) represents the generated data corresponding to the original data x2, G E (x1) represents the potential vector corresponding to the original data x1, G E (x2) represents the potential vector corresponding to the original data x2, E(G(x1)) represents the potential vector corresponding to the reconstructed data G(x1), and E(G(x2)) represents the potential vector corresponding to the reconstructed data G(x2). It is used to indicate that the data x1 is in the distribution px. There are no specific steps in the operation. It is used to indicate that the data x2 is in the distribution px. There are no specific steps in the operation. ||x1-G(x1)||1 is used to calculate the average absolute value of the difference between the data x1 and G(x1). ||x2-G(x2)||1 is used to calculate the average absolute value of the difference between the data x2 and G(x2). E (x1)-E(G(x1))||2 is used to calculate the latent vector G E (x1),E(G(x1))The sum of the squares of the differences between each element is taken as the root,||G E (x2)-E(G(x2))||2 is used to calculate the latent vector G E Take the root of the sum of the squares of the differences between (x1) and E(G(x1)).
[0077] Step 5: The original data and the reconstructed data output by the generator are used as input to the third module. As the discriminator of the generative adversarial network, this module compresses the input data to obtain their latent vectors. The final output represents whether the data is real or generated. The discriminator uses a feature matching method, and the objective function set for it is:
[0078] Adversarial loss Ladv : Assume a function f, which takes input x and outputs the corresponding latent vector at the middle layer of the discriminator D. The adversarial loss calculates the L2 distance between the latent vectors corresponding to the original image and the generated image. The objective function is:
[0079]
[0080] In formula (3), represents the adversarial loss, x1 and x2 represent the two data input into the collaborative autoencoder group respectively, G(x) represents the generated data corresponding to the original data x, f(x1,x2) represents the potential vector obtained by inputting the discriminator with data x1 and x2, and f(G(x1),G(x2)) represents the potential vector obtained by inputting the discriminator with data G(x1) and G(x2). Used to indicate that data x1, x2 are in the distribution px.
[0081] Step 6: Select Adam optimizer for generator and discriminator optimization. Follow the above steps to get a stable model.
[0082] Step 7: Testing phase, D test The data in is passed into the model. All data passes through the first module to output the latent space vector and reconstructed data. The reconstructed data is input into the second module to obtain the corresponding latent vector. Since the distribution of normal data is learned through sample selection during model training, the latent vector of abnormal data will show greater differences. The present invention outputs the anomaly score A(x) of each test sample based on the latent vector:
[0083]
[0084] In formula (4), G E (x) represents the potential vector corresponding to the original data x, G(x) represents the generated data corresponding to the original data x, and E(G(x)) represents the potential vector corresponding to the reconstructed data G(x). represents the anomaly score.
[0085] Suppose the set of all outliers is S = {s i :A(x i ), x i ∈D test}, the anomaly score of the data is mapped to the probability range of [0,1], and the obtained anomaly score set is used to evaluate the effect of anomaly detection. The new anomaly value set is composed of s i 'composition:
[0086]
[0087] In formula (5), min(S) represents the minimum value in the set S, max(S) represents the maximum value in the set S, and s i represents the i-th outlier in the set S, A(x i ) represents x i The anomaly score, x i Representative D test The i-th data in .
[0088] After experiments, this anomaly score calculation method has achieved better results and optimized the anomaly assessment work. The area under the receiver operating characteristic (ROC) curve (AUC) is used as the main evaluation indicator during the detection process. The relevant concepts are as follows:
[0089] False Positive Rate: The probability of detecting an abnormality when it is not.
[0090] True Positive Rate: The probability that a detected anomaly is actually an anomaly.
[0091] ROC curve: Setting different thresholds can obtain different false positive rates and true positive rates. The curve with the false positive rate as the horizontal axis and the true positive rate as the vertical axis is the ROC curve.
[0092] AUC: The area under the ROC curve and the coordinate axis is AUC. The closer the AUC is to 1.0, the higher the authenticity of the detection method.
[0093] The generative adversarial network structure containing a collaborative autoencoder group in this invention achieves good results in anomaly detection. It does not require completely normal training data and can automatically handle noise interference. The present invention refers to this anomaly detection method based on collaborative training and generative adversarial networks as RCGAD. Compared with traditional anomaly detection methods, this invention introduces a collaborative training network structure (a collaborative training autoencoder group), combines the adversarial mechanism of the generator and the discriminator, and compares the anomaly scores based on reconstruction loss and latent space features to improve the anomaly detection rate.
[0094] In the detection phase, the present invention mainly reports the results based on the area under the curve (AUC) of the receiver operating characteristic (ROC). To prove that the use of the collaborative training structure in the present invention to automatically select the data learning distribution with smaller reconstruction loss can improve the model's ability to handle noisy data, the adversarial mechanism can optimize the effect of model-generated data, and the anomaly score based on latent space features can more efficiently distinguish anomalies, the present invention compares the anomaly detection effects of the robust collaborative autoencoder (RCA) using the reconstruction error anomaly score, the generative adversarial network anomaly detection model (GANomaly), the method used in the present invention (RCGAD), and the RCGAD method without the adversarial mechanism (RCGwithoutD) on different data sets.
[0095] Taking a class of data from the CIFAR10 dataset as anomalies, the present invention transfers different proportions of anomaly data from the training set to the test set. This yields two different datasets: a clean dataset Dc and a noisy dataset Dn. These datasets are then used for testing to verify the anomaly detection effectiveness of the present invention. The following describes in detail the test results of the present invention on these datasets. For these two datasets, the present invention is compared with other anomaly detection methods described above, as shown in Table 1:
[0096] Table 1 Datasets with different anomaly ratios
[0097]
[0098] Existing generative adversarial network anomaly detection models have proven that adversarial mechanisms and anomaly scores based on latent space features have good detection effects when using normal data. However, this paper applies the collaborative training strategy of multi-view learning to learn the data distribution of single-view data. In order to verify the learning effect of this method on data without noise interference, the clean dataset Dc is used for training in the first stage.
[0099] Table 2 shows the comparison results of the first phase. Columns 0-9 represent the ten types of data in the dataset. The table records the AUC of anomaly detection for different models when this type of data is considered an anomaly. The bold data represents the highest score of each method for this type of anomaly. When the data is not affected by noise, the network structure of the present invention can achieve similar or even better results than the above experiments. In the process of learning the data distribution, the collaborative encoder group selects samples with smaller reconstruction errors in a certain proportion, and the generator selects more suitable samples to determine the distribution of the input data, which can better learn the latent space characteristics of normal data.
[0100] Table 2 Comparative experiments using clean datasets
[0101] 0 1 2 3 4 5 6 7 8 9 RCA 0.919 0.627 0.527 0.590 0.650 0.609 0.815 0.639 0.746 0.683 GANomaly 0.935 0.608 0.591 0.582 0.724 0.622 0.886 0.560 0.760 0.681 RCGwithoutD 0.949 0.682 0.546 0.609 0.728 0.736 0.878 0.632 0.865 0.703 RCGAD 0.958 0.652 0.589 0.628 0.736 0.730 0.904 0.647 0.874 0.691
[0102] In the second stage, the present invention uses a noisy dataset such as Dn for training. The main problem addressed by the present invention is to prevent the model from being affected by noisy data. The results of the following comparative experiments can demonstrate the advantages of the present invention in processing noisy data.
[0103] Table 3 shows the comparison results of the second stage. Like the first stage, columns 0-9 represent ten types of data. The table records the AUC of different models when this type of data is anomaly, where bold data represents the highest score of each method in this type of anomaly. The training set is no longer pure at this stage. The abnormality ratio of the training set actually used is 6.25%. The lowest proportion of samples selected by the collaborative autoencoder is 90%, which means that the autoencoder group selects all samples of a batch of input data at the beginning of training, and gradually reduces to 90% as training progresses. The RCGAD method of the present invention achieved the best results in most cases, which fully demonstrates that the combination of collaborative training structure, adversarial mechanism and anomaly score based on latent space features can effectively improve the detection effect of the model when facing noisy data.
[0104] Table 3 Comparative experiments based on different LSTM autoencoders
[0105] 0 1 2 3 4 5 6 7 8 9 RCA 0.928 0.658 0.509 0.596 0.738 0.675 0.896 0.653 0.855 0.662 GANomaly 0.945 0.685 0.544 0.594 0.755 0.698 0.872 0.636 0.880 0.701 RCGwithoutD 0.953 0.688 0.519 0.607 0.745 0.688 0.896 0.656 0.869 0.731 RCGAD 0.961 0.746 0.539 0.628 0.772 0.740 0.891 0.667 0.926 0.793
[0106] Comparisons between different methods in the two stages above demonstrate the impact of different network components on anomaly detection. A comparison of the GANomaly and RCGAD methods demonstrates the robustness of the collaborative training strategy in the presence of noisy data. A comparison of the RCGwithoutD and RCGAD methods demonstrates that adversarial mechanisms are more effective than simply reconstructing the input to generate data. A comparison of the RCA and RCGwithoutD methods demonstrates that anomaly scores based on latent space features generally outperform those based on traditional reconstruction losses.
[0107] In summary, multiple comparative experiments have been conducted to verify the improvement of the anomaly detection effect of each module of the model. It can be seen from the above experimental results that the solution proposed by the present invention is novel, reliable and effective.
[0108] Compared with the prior art, the advantages of the present invention are:
[0109] The present invention is based on the fact that the commonly used network structure for learning data distribution is an autoencoder, which consists of an encoder and a decoder. As a neural network that compresses input data into potential codes and then decompresses the codes to generate reconstructed data, the autoencoder automatically learns the distribution of data from samples and cannot avoid the influence of noise. In order to enable the model to learn the distribution of normal data in a contaminated data set, the present invention uses a collaborative training strategy, which is a learning strategy that combines multiple learners to fully explore the common attributes of the data. It was originally designed for multi-view data. Multi-view data refers to data objects with multiple attribute sets, each of which can be regarded as a view. Although the training set of the present invention is single-view data, the normal data that accounts for the majority of it is the information that the present invention hopes to capture.
[0110] This invention is based on the fact that existing anomaly detection methods generally use a large amount of normal data for training. However, in practical applications, normal datasets can also contain instances that resemble anomalies or misclassified anomaly data. For such noisy datasets, the present invention uses an unsupervised method with an adversarial mechanism for anomaly detection. The present invention constructs a generative adversarial network architecture, comprising a generator G and a discriminator D. G, consisting of a collaborative autoencoder group and an encoder, is tasked with learning the distribution of normal data. D is an encoder that distinguishes whether the data is real or generated. During training, a sample enters the generator. The input data first undergoes a forward propagation to calculate the reconstruction loss. Each autoencoder selects data with a lower reconstruction loss and exchanges it with the other autoencoders. The resulting data is then used to update the network parameters. Furthermore, the present invention sets coefficients for the sample selection process, allowing the collaborative training process to gradually discard data with high reconstruction loss, allowing the present network architecture to effectively learn the distribution of normal data. After the collaborative autoencoder group outputs the reconstructed data, additional encoders fit the generated data and then map it back to a latent feature representation. After the generator G completes its task, the discriminator D attempts to distinguish between real and generated data until G and D reach a Nash equilibrium. At this point, due to sample selection, the model only learns the distribution of normal data. Reconstructing abnormal data will result in significant errors, and the magnitude of the loss value can be used to determine whether it is an anomaly. Thus, the present invention successfully completes anomaly detection when the training set is contaminated by noise data. Based on the generative adversarial network framework, the present invention includes a generator G and a discriminator D. Unlike traditional methods, the present invention uses a collaboratively trained autoencoder group and encoder to generate data. This structure can automatically select samples, preventing the generator from being interfered with by noise data and allowing it to learn the normal data distribution.
[0111] Figure 4 This is a structural diagram of an embodiment of an anomaly detection system based on collaborative training and generative adversarial networks of the present invention. Figure 4, the anomaly detection system based on collaborative training and generative adversarial networks includes:
[0112] The training data set acquisition module 401 is used to acquire a training data set; the training data set includes color images of multiple types of objects; the color images of one type of objects in the color images of the multiple types of objects are used as abnormal data.
[0113] The reconstruction error sequence obtaining module 402 is used to input the training data set into the first autoencoder and the second autoencoder respectively to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes the reconstruction errors corresponding to each color image data output by the first autoencoder; the second reconstruction error sequence includes the reconstruction errors corresponding to each color image data output by the second autoencoder.
[0114] The reconstruction error sorting module 403 is configured to sort the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence.
[0115] The reconstruction error screening module 404 is configured to select the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously select the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence.
[0116] The training data set screening module 405 is used to obtain a first screened training data set and a second screened training data set based on the first screened reconstruction error sequence and the second screened reconstruction error sequence; the first screened training data set includes the color image data corresponding to each reconstruction error in the first screened reconstruction error sequence; the second screened training data set includes the color image data corresponding to each reconstruction error in the second screened reconstruction error sequence.
[0117] The model training and optimization module 406 is used to input the first filtered training data set into the second autoencoder, and input the second filtered training data set into the first autoencoder, and use the first filtered training data set and the second filtered training data set to train and optimize the generative adversarial network model to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes a first autoencoder, a second autoencoder, a first encoder and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; the first encoder and the second encoder are both connected to the discriminator.
[0118] The to-be-detected data set acquisition module 407 is configured to acquire the to-be-detected data set; the to-be-detected data set includes a plurality of color images of objects.
[0119] The anomaly detection module 408 is used to input the data set to be detected into the optimized generative adversarial network model, use the optimized generative adversarial network model to perform anomaly detection on the data set to be detected, and obtain color images of abnormal objects in the data set to be detected.
[0120] Specifically, the first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure. The first autoencoder and the second autoencoder both include an encoder and a decoder; the encoder includes a convolutional layer, batch-norm, and a leaky ReLU() activation structure; the decoder includes a convolutional transpose layer, batch-norm, ReLU() activation, and a tanh structure. The first encoder and the second encoder both include a convolutional layer, batch-norm, and a leaky ReLU() activation structure.
[0121] The discriminator consists of an encoder with an additional Softmax layer; the encoder consists of a convolutional layer, batch-norm, and leaky ReLU() activation structure.
[0122] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.
[0123] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The above examples are only intended to help understand the method and core concept of the present invention. At the same time, those skilled in the art will find that the specific implementation methods and application scopes may vary based on the concept of the present invention. In summary, the contents of this specification should not be construed as limiting the present invention.
Claims
1. A method for anomaly detection based on collaborative training and generative adversarial networks, characterized in that: The method comprises: Acquire a training data set; the training data set includes color images of multiple types of objects; the color image of one type of object in the color images of the multiple types of objects is used as abnormal data; Inputting the training data set into a first autoencoder and a second autoencoder respectively to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes reconstruction errors corresponding to each of the color images output by the first autoencoder; and the second reconstruction error sequence includes reconstruction errors corresponding to each of the color images output by the second autoencoder; sorting the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence; Selecting the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously selecting the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence; obtaining a first filtered training data set and a second filtered training data set based on the first filtered reconstruction error sequence and the second filtered reconstruction error sequence; the first filtered training data set including the color image corresponding to each reconstruction error in the first filtered reconstruction error sequence; and the second filtered training data set including the color image corresponding to each reconstruction error in the second filtered reconstruction error sequence; Inputting the first filtered training data set into the second autoencoder, inputting the second filtered training data set into the first autoencoder, and using the first filtered training data set and the second filtered training data set to train and optimize a generative adversarial network model to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes the first autoencoder, the second autoencoder, a first encoder, and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; and the first encoder and the second encoder are both connected to the discriminator; Acquire a data set to be detected; the data set to be detected includes multiple color images of objects; The data set to be detected is input into the optimized generative adversarial network model, and the optimized generative adversarial network model is used to perform anomaly detection on the data set to be detected to obtain a color image of the abnormal object in the data set to be detected.
2. The anomaly detection method based on collaborative training and generative adversarial network according to claim 1 is characterized in that The first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure.
3. The anomaly detection method based on collaborative training and generative adversarial network according to claim 2 is characterized in that The first autoencoder and the second autoencoder each include an encoder and a decoder; The encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure; The decoder includes a convolutional transpose layer, batch-norm, ReLU() activation and tanh structure; The first encoder and the second encoder both include convolutional layers, batch-norm, and leakyReLU() activation structures.
4. The anomaly detection method based on collaborative training and generative adversarial network according to claim 1 is characterized in that The discriminator includes an encoder with an additional Softmax layer; the encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure.
5. An anomaly detection system based on collaborative training and generative adversarial networks, characterized in that The system comprises: A training data set acquisition module is used to acquire a training data set; the training data set includes color images of multiple types of objects; the color image of one type of object in the color images of the multiple types of objects is used as abnormal data; a reconstruction error sequence obtaining module, configured to input the training data set into a first autoencoder and a second autoencoder, respectively, to obtain a first reconstruction error sequence and a second reconstruction error sequence; the first reconstruction error sequence includes reconstruction errors corresponding to each of the color images output by the first autoencoder; and the second reconstruction error sequence includes reconstruction errors corresponding to each of the color images output by the second autoencoder; a reconstruction error sorting module, configured to sort the reconstruction errors in the first reconstruction error sequence and the second reconstruction error sequence from small to large, respectively, to obtain a first sorted reconstruction error sequence and a second sorted reconstruction error sequence; a reconstruction error screening module, configured to select the first N reconstruction errors in the first sorted reconstruction error sequence to obtain a first screened reconstruction error sequence; and simultaneously select the first N reconstruction errors in the second sorted reconstruction error sequence to obtain a second screened reconstruction error sequence; a training data set screening module, configured to obtain a first screened training data set and a second screened training data set based on the first screened reconstruction error sequence and the second screened reconstruction error sequence; the first screened training data set includes the color image corresponding to each reconstruction error in the first screened reconstruction error sequence; and the second screened training data set includes the color image corresponding to each reconstruction error in the second screened reconstruction error sequence; a model training and optimization module, configured to input the first screened training data set into the second autoencoder, input the second screened training data set into the first autoencoder, and train and optimize a generative adversarial network model using the first screened training data set and the second screened training data set to obtain an optimized generative adversarial network model; the generative adversarial network model includes a generator and a discriminator; the generator includes the first autoencoder, the second autoencoder, a first encoder, and a second encoder; the first autoencoder is connected to the first encoder; the second autoencoder is connected to the second encoder; and the first encoder and the second encoder are both connected to the discriminator; The module for acquiring a data set to be detected is used to acquire a data set to be detected; the data set to be detected includes a plurality of color images of objects; The anomaly detection module is used to input the data set to be detected into the optimized generative adversarial network model, use the optimized generative adversarial network model to perform anomaly detection on the data set to be detected, and obtain a color image of the abnormal objects in the data set to be detected.
6. The anomaly detection system based on collaborative training and generative adversarial network according to claim 5, characterized in that The first autoencoder and the second autoencoder have the same structure; the first encoder and the second encoder have the same structure.
7. The anomaly detection system based on collaborative training and generative adversarial network according to claim 6, characterized in that: The first autoencoder and the second autoencoder each include an encoder and a decoder; The encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure; The decoder includes a convolutional transpose layer, batch-norm, ReLU() activation and tanh structure; The first encoder and the second encoder both include convolutional layers, batch-norm, and leakyReLU() activation structures.
8. The anomaly detection system based on collaborative training and generative adversarial network according to claim 5, characterized in that: The discriminator includes an encoder with an additional Softmax layer; the encoder includes a convolutional layer, batch-norm and leaky ReLU() activation structure.
Citation Information
Patent Citations
Abnormal image detection method combining attention mechanism and information entropy minimization
CN111079805A
Heterogeneous bidirectional generative adversarial network model and time sequence anomaly detection method
CN113127705A