Grain depot system generative adversarial network anomaly detection method based on multi-scale features
By using multi-scale feature generative adversarial networks for local and global coding in the grain storage system, combined with the adversarial training mechanism, the problem of difficulty in detecting local and global anomalies with existing technology is solved, and the security and detection efficiency of grain storage are improved. Overfitting problem is avoided.
Patent Information
- Application Number
- CN202410853067.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-22
AI Technical Summary
It is difficult for the existing technology to simultaneously detect local and global abnormal characteristics in the grain depot environment, resulting in low detection efficiency, and the deep learning algorithm based on reconstruction is prone to overfitting problems.
A generative adversarial network anomaly detection method based on multi-scale features is designed, which enhances data feature representation through local and global encoding, and uses the adversarial training mechanism of the generative adversarial network to combine reconstruction loss and contrast loss to alleviate the process in deep learning. fitting problem.
It effectively detects various abnormal conditions in the grain storage environment, improves the safety and reliability of grain storage, can take into account both local and global abnormal characteristics, and reduces the risk of over-fitting.
Smart Images

Figure CN118820945A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of anomaly detection and early warning of grain depot systems, and in particular to an anomaly detection method for grain depot monitoring data based on multi-scale features, namely local and global features, and a Generative Adversarial Networks (GANs). Background Art
[0002] During the grain storage process, grain depots need to monitor environmental parameters such as temperature, humidity, and gas composition in real time to prevent grain rotting, mold, and other problems. However, traditional monitoring methods usually rely on fixed thresholds and rules, lack flexibility, and are difficult to adapt to complex grain depot environments. With the development of deep learning, it has become possible to perform anomaly detection more intelligently and accurately.
[0003] Existing technologies are disclosed: Smart grain depots refer to the use of modern Internet of Things, big data and other technical means to conduct real-time monitoring and data analysis of grain storage, transportation, quality assurance and other links to improve the efficiency and quality of the grain industry. Real-time data analysis and decision support are important functions of smart grain depots, which can provide managers with accurate information and decision-making basis.
[0004] Real-time data analysis of smart grain depots can improve the management efficiency of grain depots: through real-time monitoring and data analysis, problems in grain depots can be discovered in time, and corresponding measures can be taken to improve management;
[0005] The core task of grain storage in a grain depot is to keep the grain in good condition to ensure that the quantity of grain stored does not decrease and the quality is intact. However, during the storage process, grain is easily affected by its own physiological activities such as respiration, ripening, germination, environmental factors such as heat, moisture, gas, and harmful organisms such as insects, mildew, rats, and birds. The abnormal performance of grain storage reflected by these influences is called abnormal grain condition.
[0006] Due to the small number of abnormal data in grain depots, supervised learning-based algorithms are difficult to apply effectively because they require a large amount of labeled data for training. However, abnormal data is often scarce and difficult to label in real scenarios. Therefore, reconstruction-based unsupervised algorithms have become mainstream. This type of algorithm does not rely on labeled data, but detects anomalies by learning the distribution of normal data. However, existing reconstruction-based deep learning algorithms are prone to overfitting problems due to their complexity, resulting in low detection efficiency.
[0007] In addition, abnormal data in the grain storage environment has local and global characteristics. Local anomalies usually manifest as drastic changes in a short period of time, such as instantaneous anomalies in temperature or humidity. Global anomalies manifest as long-term trend changes, such as continuous temperature increases caused by equipment failure. Existing methods often find it difficult to take into account both types of abnormal characteristics at the same time, so a new method is urgently needed to solve these problems.
[0008] To this end, the present invention locally and globally encodes the data in the grain storage system, enhances the feature representation of the data in the grain storage and expands the diversity of the data, and constrains the reconstruction loss based on the adversarial generative network. By combining these two methods, namely expanding the data and constraining the loss function, it is easier to alleviate the overfitting problem in deep learning. Summary of the invention
[0009] The present invention aims to provide a grain storage system adversarial generative network anomaly detection method based on multi-scale features. By mining the local and global features of data in the grain storage system and utilizing the adaptive characteristics of the generative adversarial network, various abnormal situations in the grain storage environment can be effectively detected, thereby improving the safety and reliability of grain storage.
[0010] To achieve the above purpose, the present invention designs a model including a generative network and a discriminative network. The model extracts and reconstructs the grain depot data through local and global coding, and uses the adversarial training mechanism of the generative adversarial network to perform anomaly detection. The following technical solutions are mainly adopted:
[0011] Step 1, data collection: Collect environmental parameter data in real time from multiple sensors deployed in the grain storage system, including temperature, humidity, gas composition, etc. These data form multi-dimensional time series data.
[0012] Step 2, data preprocessing: preprocess the collected data, such as normalization, denoising, etc., to meet the needs of model training.
[0013] Step 3: Build a generative adversarial network anomaly detection model based on multi-scale features, such as Figure 1 As shown in Figure 1, the model mainly consists of a generation network and a discrimination network.
[0014] 3.1 The main task of the generative network is to extract and reconstruct the input grain storage system data. The main framework of the generative network is based on the Autoencoder architecture of encoder and decoder, where the encoder consists of a local encoder and a global encoder.
[0015] 3.1.1 Local encoder: extract local features and capture data changes in a short period of time. Convolutional neural network (CNN) can be used to extract local features of input data.
[0016] 3.1.2 Global Encoder: Extract global features, capture long-term trends and global patterns, and use the Transformer network to extract global features of the input data.
[0017] 3.1.3 Mapping layer: Map and align local and global features. A fully connected layer can be used to align local features with global features.
[0018] 3.1.4 Decoder: Reconstruct the input data and generate pseudo data similar to the real grain storage system data. The features can be reconstructed using a multi-layer neural network.
[0019] 3.1.5 In order to strengthen the consistency of local and global features, the consistency of the reconstructed data can be constrained based on the multi-scale perceptual contrast loss of local and global features.
[0020] The autoencoder (AE) architecture is a data compression algorithm in which the compression and decompression functions are data-dependent, lossy, and automatically learned from samples. Autoencoders are often used to learn efficient encodings. In the form of neural networks, autoencoders can be used for dimensionality reduction and feature learning.
[0021] 3.2 The discriminant network mainly distinguishes the generated data from the real data and constrains the normal data reconstructed by the generative network, so that the reconstructed data is more distinguishable from the abnormal data and the accuracy of anomaly detection is improved. It mainly includes the feature representation layer and the feature layer.
[0022] 3.2.1 Feature representation layer: Use a multi-layer neural network to extract features from reconstructed data and real data.
[0023] 3.2.2 Discriminant layer: Use the fully connected layer to perform binary classification and output the probability value to determine whether the input data is reconstructed or real data.
[0024] Step 4, model training: The generator and discriminator compete with each other through adversarial training and continuously optimize:
[0025] Training steps:
[0026] 4.1 Initialize the parameters of the generator network and the discriminator network. Define an optimizer (such as Adam optimizer) to update the parameters of the generator network and the discriminator network.
[0027] 4.2 Extract a batch of data from the real data set and mark it as real samples; generate a batch of pseudo data through the generative network from the real data and mark it as reconstructed samples.
[0028] 4.3 Classify the real samples and reconstructed samples through the discriminant network and calculate the loss. Here, the loss of the discriminator adopts cross loss, and the parameters of the discriminant network are updated by gradient descent.
[0029] 4.5 Calculate the loss of the generated network. The loss of the generated network also includes reconstruction loss and contrast loss. Update the parameters of the generated network through gradient descent.
[0030] Step 5, anomaly detection process:
[0031] 5.1 Input the real-time collected grain storage system data into the trained generation network to obtain reconstructed data.
[0032] 5.2 Calculate the error between the reconstructed data and the real data. If it is higher than the preset threshold, it is considered an abnormal situation. The threshold here can be set by the value in the training process.
[0033] Step 6, alarm and processing:
[0034] For data judged to be abnormal, the system triggers an alarm mechanism and notifies management personnel.
[0035] Management personnel take corresponding measures based on the alarm information, such as adjusting environmental parameters, checking equipment, etc.
[0036] Beneficial effects: The present invention has local and global characteristics for abnormal data in a grain depot environment. Local anomalies usually manifest as drastic changes in a short period of time, such as instantaneous anomalies in temperature or humidity. Global anomalies manifest as long-term trend changes. The present invention needs to take into account both types of abnormal characteristics at the same time. By encoding the data in the grain depot system locally and globally, the data feature representation in the grain depot is enhanced while expanding the diversity of the data. Based on the adversarial generative network, the reconstruction loss is constrained. By combining these two methods, that is, expanding the data and constraining the loss function, it is easier to alleviate the overfitting problem in deep learning. By mining the local and global characteristics of the data in the grain depot system and utilizing the adaptive characteristics of the generative adversarial network, various abnormal situations in the grain depot environment can be effectively detected, thereby improving the safety and reliability of grain storage. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 Generative adversarial network anomaly detection model based on multi-scale features. DETAILED DESCRIPTION
[0038] In a grain storage system, multiple sensors are deployed to collect environmental data such as air temperature, air humidity, and grain temperature in real time. These data form multi-dimensional time series data. The system transmits the collected data to the central processing unit in real time through a wireless network.
[0039] 3) Data collection: Data is collected every hour. For example, the data includes air temperature, air humidity, grain temperature, etc., which can be expressed as X = {x1, x2, ..., x i ,...}, where x i ∈R d It represents the sensor data at time point i, and d is the feature dimension of the data.
[0040] 4) Data preprocessing: Perform maximum and minimum normalization processing on the collected data, such as
[0041]
[0042] 5) Construct a generative adversarial network anomaly detection model based on multi-scale features. Assume that the input data is of dimension X T ∈R T×d Where T is the length of the time series and d is the feature dimension at each time point.
[0043] 3.1.1 Local Encoder: Mining the Local Features F of Time Series Data by Gated Recurrent Unit (GRU) with 2D Convolution l , the 2D convolution layer Conv2d uses d filters, each of which has a size of k1×k2, representing the convolution kernel size in the time and feature dimensions respectively. The main process is as follows:
[0044] X' T =Conv2d(X T ) (2)
[0045] z t =σ(W z X' T +U z h t-1 +b z ) (3)
[0046] r t =σ(W r X' T +U r h t-1 +b r ) (4)
[0047]
[0048]
[0049] Among them, zt 是 Update gate, controlling the state h of the previous time step t-1 How much information will be retained, r tis the reset gate, which determines how much past information will be forgotten. is a candidate hidden state, representing a possible new state after forgetting some past information, h t is the hidden state of the current time step, which is obtained by mixing the previous hidden state and the current candidate hidden state in proportion. W, U, and b are learnable parameters. The local features obtained are implicit features, which can be understood as the relationship and changes between data in various dimensions in a short period of time, such as the temperature peak or the sharp change of humidity in a short period of time.
[0050] 3.1.2 Global Encoder: The global features of time series data are mined through the encoder layer of the transformer model. The main process is as follows:
[0051] First, the input data X T The data at each time point is mapped into a high-dimensional space:
[0052] E = embedding(X T ) (7)
[0053] And add position encoding to provide the position information of each time point in the sequence to supplement the global perception ability of the self-attention mechanism:
[0054] E pos =E+PositionalEncoding(E) (8)
[0055] Next, enter the encoded E pos Enter the self-attention layer:
[0056] Q=E pos W Q , K=E pos W K , V = E pos W V (9)
[0057]
[0058] Where W is a learnable parameter, d k is the dimension of K.
[0059] Next, input residual connection and layer normalization:
[0060] x norm =layernorm(E pos +Attention(Q,K,V)) (11)
[0061] Then enter the feedforward network layer:
[0062] x feed=max(0,x norm W1+b1)W2+b2 (12)
[0063] And further input residual connection and layer normalization, the final global feature F g It consists of the output of the Transformer encoder of L layers. The number of layers L is a model hyperparameter, and the output of each layer becomes the input of the next layer. Here, the L layer is the encoder, which is not involved in the setting and judgment of the abnormal threshold.
[0064] Unlike RNN, Transformer can be trained in parallel relatively well. Transformer itself cannot use the sequential information of data, so it is necessary to add position embedding to the input, otherwise Transformer will be a bag-of-words model. The focus of Transformer is the Self-Attention structure, in which the Q, K, and V matrices used are obtained by linear transformation of the output.
[0065] 3.1.3 Mapping layer: local features F l and the global feature F g The mapping layer is constructed by two layers of MLP to obtain the representation F' in the same space l and F' g , the process is as follows:
[0066] F l =Relu(Relu(W l1 F l +b l1 )W l2 +b l2 ) (13)
[0067] F′ g =Relu(Relu(W g1 F g +b g1 )W g2 +b g2 ) (14)
[0068] 3.1.4 Decoder: F' output from the mapping layer l and F' g The sum is used to form the new multi-scale feature data, and the original input data is reconstructed through two layers of MLP:
[0069] F lg =F' l +F' g (15)
[0070] X'=Relu(Relu(W lg1 Flg +b lg1 )W lg2 +b lg2 ) (16)
[0071] 3.2 Construct a discriminant network and use two layers of MLP to extract features from the reconstructed data X' and the original data X. The formulas are as follows:
[0072] F fake =Relu(Relu(W fake1 X'+b fake1 )W fake2 +b fake2 ) (17)
[0073] F real =Relu(Relu(W real1 X+b real1 )W real2 +b real2 ) (18)
[0074] The extracted features enter the discrimination layer of MLP to determine whether it is reconstructed (fake) or original (real) data. The formula is as follows:
[0075] D fake or real =sigmoid(W fin F+b fin ) (19)
[0076] 6) Model training. The model involves three types of loss functions, namely, the loss function of the adversarial network generation adversarial loss, reconstruction loss, and multi-scale perceptual contrast loss, which are as follows:
[0077] The loss function of the generated adversarial discriminator network is:
[0078]
[0079] The loss function of the generative adversarial network includes not only the adversarial loss of the generative network, but also the reconstruction loss and the contrast loss, where the reconstruction loss is the mean square error loss (MSE) and the contrast loss is the InfoNCE loss:
[0080]
[0081] The first term in the above formula is the adversarial loss, the second term is the reconstruction loss, and the third term is the contrast loss, where B is the batch data during training, and α and β are hyperparameters that can be set to 0.2 and 0.1. The training process adopts the training method of the production adversarial network, which is the process of step 4.
[0082] 7) Setting of abnormal threshold: Check whether the reconstruction error is abnormal. We can determine this standard based on the statistical properties of the training data, such as selecting the 95th or 99th percentile of the reconstruction error in the training set as the judgment standard. Then, use this threshold to compare with the reconstruction error to determine whether a sample is abnormal. For example, the reconstruction errors of air temperature and air humidity at a certain time point t are 0.2 and 0.4 respectively, then the MSE reconstruction error at time point t is The threshold is set to the 95% percentile reconstruction error in the training set. For example, 100 training data are sorted from large to small according to the reconstruction error. For example, the reconstruction errors of the last ten digits after sorting are [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]. The reconstruction error of the 95th digit is 0.5. Then 0.5 is taken as the threshold. If it exceeds the threshold, it is considered abnormal.
[0083] 8) Alarm and processing:
[0084] For data judged to be abnormal, the system triggers an alarm mechanism and notifies management personnel.
[0085] Management personnel take corresponding measures based on the alarm information, such as adjusting environmental parameters, checking equipment, etc.
[0086] Table 1 Data instance table
[0087]
[0088] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and modify the above embodiments within the scope of the present invention without departing from the principles and intent of the present invention.
Claims
1. A grain storage system adversarial generative network anomaly detection method based on multi-scale features, characterized in that: By mining the local and global features of the data in the grain storage system and utilizing the adaptive characteristics of the generative adversarial network, various abnormal situations in the grain storage environment can be effectively detected. The model built consists of two parts: a generative network and a discriminative network. The grain depot data is feature extracted and reconstructed through local and global encoding, and anomaly detection is performed using the adversarial training mechanism of the generative adversarial network. The following steps are adopted: Step 1, data collection: collect environmental parameter data in real time from multiple sensors deployed in the grain storage system, including temperature, humidity, gas composition, etc. These data form multi-dimensional time series data; Step 2, data preprocessing: preprocess the collected data, normalize and denoise it to meet the needs of model training; Step 3: Build a generative adversarial network anomaly detection model based on multi-scale features. The model mainly consists of a generative network and a discriminative network. 3.1 The task of the generative network is to extract and reconstruct the features of the input grain storage system data; the main framework of the generative network is based on the Autoencoder architecture of encoder and decoder, where the encoder is composed of a local encoder and a global encoder; 3.1.1 Local encoder: extract local features, capture data changes in a short period of time, and use convolutional neural network (CNN) to extract local features of input data; 3.1.2 Global Encoder: Extract global features, capture long-term trends and global patterns, and use the Transformer network to extract global features from input data; 3.1.3 Mapping layer: Map and align local and global features. The fully connected layer can be used to align local features with global features. 3.1.4 Decoder: Reconstruct the input data and generate pseudo data similar to the real grain storage system data. Multi-layer neural network can be used to reconstruct the features; 3.1.5 In order to strengthen the consistency of local and global features, the consistency of reconstructed data can be constrained based on the multi-scale perceptual contrast loss of local and global features; 3.2 The discriminant network mainly distinguishes the generated data from the real data and constrains the normal data reconstructed by the generative network, so that the reconstructed data is more distinguishable from the abnormal data and the accuracy of anomaly detection is improved; it mainly includes the feature representation layer and the feature layer; 3.2.1 Feature representation layer: Use a multi-layer neural network to extract features from reconstructed data and real data; 3.2.2 Discriminant layer: Use the fully connected layer to perform binary classification and output the probability value to determine whether the input data is reconstructed or real data; Step 4, model training: The generator and discriminator compete with each other through adversarial training and continuously optimize: Training steps: 4.1 Initialize the parameters of the generator network and the discriminator network; define an optimizer (such as Adam optimizer) to update the parameters of the generator network and the discriminator network; 4.2 Extract a batch of data from the real data set and mark it as real samples; The real data is passed through the generative network to generate a batch of pseudo data, which are marked as reconstructed samples; 4.3 Classify the real samples and reconstructed samples through the discriminant network and calculate the loss. Here, the loss of the discriminator adopts the cross loss, and the parameters of the discriminant network are updated by gradient descent; 4.4 Calculate the loss of the generated network. The loss of the generated network consists of adversarial loss, reconstruction loss and contrast loss. Update the parameters of the generated network by gradient descent. 4.5 Repeat steps 4.2-4.4, first update the parameters of the discriminant network, then update the parameters of the generative network, and train for multiple rounds until the loss function converges or reaches the predetermined number of training times; Step 5, anomaly detection process: 5.1 Input the real-time collected grain storage system data into the trained generation network to obtain a reconstructed data; 5.2 Calculate the error between the reconstructed data and the real data. If it is higher than the preset threshold, it is considered an abnormal situation. Here, the threshold is set by the value in the training process.
2. The method for detecting anomalies in a grain storage system adversarial generative network based on multi-scale features according to claim 1 is characterized in that: Alarm and processing: For data judged to be abnormal, the system triggers the alarm mechanism and notifies the management personnel; the management personnel take corresponding measures based on the alarm information, including adjusting environmental parameters and checking equipment.
3. The method for detecting anomalies in a grain storage system adversarial generative network based on multi-scale features according to claim 1 is characterized in that: 3.1.1 Local Encoder: Local Features F of Data Structure l , the 2D convolution layer Conv2d uses D filters, each of which has a size of k1×k2, representing the convolution kernel size in the time and feature dimensions respectively; The process is as follows: X' T =Conv2d(X T ) (2) z t =σ(W z X' T +U z h t-1 +b z ) (3) r t =σ(W r X' T +U r h t-1 +b r ) (4) Among them, z t is the update gate, controlling the state h of the previous time step t-1 How much information will be retained, r t is the reset gate, which determines how much past information will be forgotten. is a candidate hidden state, representing a possible new state after forgetting some past information, h t is the hidden state of the current time step, which is obtained by mixing the previous hidden state and the current candidate hidden state in proportion. W, U, and b are learnable parameters. The local features obtained are implicit features, which can be understood as the relationship and changes between data in various dimensions in a short period of time, such as the temperature peak or the sharp change of humidity in a short period of time. 3.1.2 Global Encoder: The global features of time series data are mined through the encoder layer of the transformer model. The process is as follows: First, the input data X T The data at each time point is mapped into a high-dimensional space: E = embedding(X T ) (7) And add position encoding to provide the position information of each time point in the sequence to supplement the global perception ability of the self-attention mechanism: E pos =E+PositionalEncoding(E) (8) Next, enter the encoded E pos Enter the self-attention layer: Q=E pos W Q , K=E pos W K , V = E pos W V (9) Where W is a learnable parameter, d k is the dimension of K. Next, input residual connection and layer normalization: x norm =layernorm(E pos +Attention(Q,K,V)) (11) Then enter the feedforward network layer: x feed =max(0,x norm W1+b1)W2+b2 (12) And further input residual connection and layer normalization, the final global feature F g It consists of the output of the Transformer encoder of L layers; the number of layers L is a model hyperparameter, and the output of each layer becomes the input of the next layer; The focus of Transformer is the Self-Attention structure, in which the Q, K, and V matrices used are obtained by linear transformation of the output; 3.1.3 Mapping layer: local features F l and the global feature F g The mapping layer is constructed by two layers of MLP to obtain the representation F' in the same space l and F' g , the process is as follows: F′ l=Relu(Relu(W l1 F l +b l1 )W l2 +b l2 ) (13) F′ g =Relu(Relu(W g1 F g +b g1 )W g2 +b g2 ) (14) 3.1.4 Decoder: F' output from the mapping layer l and F' g The sum is used to form the new multi-scale feature data, and the original input data is reconstructed through two layers of MLP: F lg =F' l +F' g (15) X'=Relu(Relu(W lg1 F lg +b lg1 )W lg2 +b lg2 ) (16) 3.2 Construct a discriminant network and use two layers of MLP to extract features from the reconstructed data X' and the original data X. The formulas are as follows: F fake =Relu(Relu(W fake1 X'+b fake1 )W fake2 +b fake2 ) (17) F real =Relu(Relu(W real1 X+b real1 )W real2 +b real2 ) (18) The extracted features enter the discrimination layer of MLP to determine whether it is reconstructed (fake) or original (real) data. The formula is as follows: D fake or real =sigmoid(W fin F+b fin ) (19) 1) Model training. The model involves three types of loss functions, namely, the loss function of the adversarial network generation adversarial loss, reconstruction loss, and multi-scale perceptual contrast loss, which are as follows: The loss function of the generated adversarial discriminator network is: The loss function of the generative adversarial network includes not only the adversarial loss of the generative network, but also the reconstruction loss and the contrast loss, where the reconstruction loss is the mean square error loss (MSE) and the contrast loss is the InfoNCE loss: The first term in the above formula is the adversarial loss, the second term is the reconstruction loss, and the third term is the contrast loss. B is the batch data during training, α and β are hyperparameters, which can be set to 0.2 and 0.1; The training process adopts the training method of production adversarial network, that is, step 4; 2) Setting of abnormal threshold: whether the reconstruction error is abnormal; determine this standard based on the statistical properties of the training data, and select the 95th or 99th percentile of the reconstruction error in the training set as the judgment standard; then, use this threshold to compare with the reconstruction error to determine whether a sample is abnormal.
Citation Information
Cited By
Method and system for detecting safety of motorcycle product processing workshop
CN119475395A
Multi-source sensor fused granary environment alarm method
CN120913357A
