A method and system for image anomaly detection based on masked image autoencoder
By using mask map autoencoder in hyperspectral image anomaly detection, the shortcomings of traditional methods in complex backgrounds and sparse anomaly detection are solved, the accuracy and robustness of the detection are improved, and the calculation overhead is reduced.
Patent Information
- Application Number
- CN202411721104.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2044-11-28
AI Technical Summary
Traditional hyperspectral image anomaly detection methods perform poorly when dealing with complex backgrounds and sparse anomalies, and the computational efficiency and accuracy are limited by high-dimensional characteristics and graph autoencoder.
The graph abnormality detection method based on the mask graph autoencoder is adopted. The node feature matrix and edge index matrix are obtained by preprocessing the input hyperspectral image, and the node feature matrix is randomly masked, and the masked feature matrix and edge index matrix are input to the autoencoder for encoding, the reconstruction error is calculated and the exception score is obtained, and the abnormal pixel is marked.
It improves the accuracy and robustness of image anomaly detection, reduces computational overhead, and enhances the autoencoder's ability to express high-dimensional features and distinguishes real anomalies and noise.
Smart Images

Figure CN119206253B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method and system for detecting anomalies in a graph based on a masked graph autoencoder, and belongs to the technical field of anomaly detection in a graph. Background Art
[0002] Hyperspectral images contain hundreds of continuous narrow bands, which can provide detailed spectral information of objects. In hyperspectral images, anomaly detection aims to identify pixels or targets that have significant spectral differences from the surrounding environment.
[0003] Although traditional anomaly detection methods can detect anomalies to a certain extent, they still have some limitations. For example, methods such as the RX algorithm often assume that the background follows a Gaussian distribution, which is not always true in practical applications. When dealing with complex backgrounds and sparse anomalies, the performance of traditional methods is often not ideal. The high-dimensional characteristics of hyperspectral images make traditional methods face challenges in terms of computational efficiency and accuracy. There are also certain limitations in graph autoencoders. For example, existing GAEs usually choose to reconstruct the structural information of the graph (adjacency matrix) rather than node features. Traditional GAEs often use MLP as a decoder, which has limited ability to reconstruct node features of continuous vectors. Most GAEs use mean square error (MSE) as a loss function, which may not be sufficient for meaningful feature reconstruction. Summary of the invention
[0004] The purpose of the present invention is to overcome the deficiencies in the prior art and provide a method and system for image anomaly detection based on mask image autoencoder, so as to overcome the limitations of traditional methods and improve the accuracy and robustness of image anomaly detection.
[0005] In order to achieve the above purpose / solve the above technical problems, the present invention is implemented by adopting the following technical solutions:
[0006] In a first aspect, the present invention provides a method for detecting anomalies in a graph based on a mask graph autoencoder, the method comprising:
[0007] Preprocess the input hyperspectral image to be detected to obtain the node feature matrix and edge index matrix;
[0008] Performing a random masking operation on the node feature matrix;
[0009] Inputting the node feature matrix after the random mask operation and the edge index matrix into the autoencoder for encoding to obtain a reconstructed feature matrix;
[0010] Calculate the reconstruction error based on the reconstruction feature matrix to obtain the anomaly score;
[0011] The anomaly score is compared with a set threshold, and pixels with anomaly scores exceeding the set threshold are marked as anomalies.
[0012] In combination with the first aspect, optionally, the method for obtaining the node feature matrix includes:
[0013] The input hyperspectral image to be detected is flattened into a two-dimensional matrix of the total number of pixels × the number of bands through the spatial dimension, where the number of rows is the total number of pixels, the number of columns is the number of bands, and each row represents the spectral information of a pixel in all bands;
[0014] For each column of the two-dimensional matrix, calculate its mean and standard deviation;
[0015] For each row of the two-dimensional matrix, subtract the mean value from each pixel and divide it by the standard deviation to obtain a standardized two-dimensional matrix;
[0016] The standardized two-dimensional matrix is used as the node feature matrix.
[0017] In combination with the first aspect, optionally, a method for obtaining an edge index matrix includes:
[0018] Calculate the Euclidean distance between each pixel and all other pixels in the node feature matrix respectively;
[0019] According to the Euclidean distance, the K pixels closest to each pixel are found as neighbors, and edge relationships are constructed to generate a two-dimensional edge index matrix.
[0020] In combination with the first aspect, optionally, performing a random mask operation on the node feature matrix includes: randomly selecting The nodes are masked, where Indicates the ratio of pixels to be masked, and N indicates the total number of nodes;
[0021] For the selected nodes, their feature values are set to 0 or replaced with random values as the masked pixel positions.
[0022] In combination with the first aspect, optionally, the method for constructing the autoencoder includes:
[0023] Construct a GNN encoder, a secondary mask module, and a GNN decoder connected in sequence;
[0024] Construct a training set using hyperspectral images and corresponding known reconstruction feature matrices;
[0025] Taking the node feature matrix and edge index matrix after random masking of the hyperspectral image in the training set as input and the corresponding known reconstructed feature matrix as output, the autoencoder is trained to convergence using a preset loss function;
[0026] The GNN encoder includes a first neural network layer, a first activation layer, a second neural network layer, and a second activation layer connected in sequence;
[0027] The GNN decoder includes a third neural network layer and a third activation layer connected in sequence;
[0028] The first neural network layer is used to perform weighted summation on the input node feature matrix according to the input edge index matrix, thereby updating the feature representation of each node and outputting a first node feature matrix;
[0029] The first activation layer is used to process the first node feature matrix, clipping the negative values to zero while keeping the positive values unchanged, and obtaining a second node matrix;
[0030] The second neural network layer is used to continue processing the node features in the second node matrix and aggregate the information of neighboring nodes to each node;
[0031] The second activation layer is used to perform nonlinear transformation on the output of the second neural network layer to obtain hidden representation;
[0032] The secondary mask module is used to mask the hidden representation;
[0033] The third neural network layer is used to map the masked hidden representation back to the original feature space;
[0034] The third activation layer is used to perform nonlinear transformation on the output of the third neural network layer to obtain a reconstructed feature matrix;
[0035] The structures of the first activation layer, the second activation layer, and the third activation layer are the same, and all use the ReLU function.
[0036] In combination with the first aspect, optionally, the preset loss function for:
[0037] ;
[0038] in, To rebuild the losses, To smooth the loss, is the weight hyperparameter corresponding to the reconstruction loss and smoothing loss, and
[0039] ;
[0040] ;
[0041] in Represents the reconstructed feature matrix of the masked node, which is generated by encoding by the GNN encoder and re-decoding by the GNN decoder; Represents the original feature matrix of the mask node; represents the square of the Euclidean distance; Z represents the reconstructed feature matrix of all nodes, and each row of the matrix corresponds to the feature vector of a node; L represents the Laplace matrix obtained after Laplace regularization of the known hyperspectral image; Representation Matrix The trace of , reflects the smoothness of the eigenvector in the graph structure.
[0042] In combination with the first aspect, optionally, the step of inputting the node feature matrix after the random mask operation and the edge index matrix into an autoencoder for encoding to obtain a reconstructed feature matrix includes:
[0043] The node feature matrix and edge index matrix after random mask operation are used as input and encoded through the GNN encoder to obtain hidden representation;
[0044] Mask the hidden representation output by the GNN encoder;
[0045] The GNN decoder receives the masked hidden representation and decodes it to reconstruct the complete node feature matrix to obtain the reconstructed feature matrix.
[0046] In combination with the first aspect, optionally, the calculation formula of the reconstruction error is as follows:
[0047] ;
[0048] in, For the i The reconstruction error of each node; It is i The initial feature representation of each node is It is the first i The feature representation of a node, Represents the square of the Euclidean distance.
[0049] In combination with the first aspect, optionally, before comparing the anomaly score with a set threshold, the method further includes:
[0050] normalizing the anomaly score;
[0051] The normalized anomaly score The calculation formula is as follows:
[0052] ;
[0053] in, It is i The anomaly score of each node, ; For the i The reconstruction error of each node; nis the number of pixels of the image to be detected; j represents the jth pixel; S j It is j The anomaly score of each node.
[0054] In a second aspect, the present invention provides a graph anomaly detection system based on a mask graph autoencoder, the system comprising:
[0055] A preprocessing module is used to preprocess the input hyperspectral image to be detected and obtain a node feature matrix and an edge index matrix;
[0056] A mask module, used for performing a random mask operation on the node feature matrix;
[0057] An autoencoder is used to encode the node feature matrix after the random mask operation and the edge index matrix to obtain a reconstructed feature matrix;
[0058] The anomaly assessment module is used to calculate the reconstruction error according to the reconstruction feature matrix to obtain the anomaly score, compare the anomaly score with a set threshold, and mark the pixels with anomaly scores higher than the set threshold as abnormal.
[0059] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the image anomaly detection method based on mask image autoencoder described in any one of the first aspects.
[0060] Compared with the prior art, the present invention has the following beneficial effects:
[0061] The image anomaly detection method based on mask graph autoencoder provided by the present invention randomly masks the node feature matrix of the hyperspectral image to be detected and retains the edge index matrix. On the one hand, the complete graph structure information can be referred to when reconstructing the node features. The edge index matrix provides the connection relationship between the nodes, which can better help the model understand the spatial dependency between pixels and improve the accuracy and robustness of anomaly detection. On the other hand, compared with masking the node features and the edge features at the same time, the method provided by the embodiment of the present invention has a smaller computational overhead, while retaining the complete edge index information and avoiding the loss of structural information, it improves the detection efficiency.
[0062] The regularization effect is achieved by performing random masking operations on the node feature matrix, which reduces the sensitivity of the autoencoder to noise. The node feature matrix and the edge index matrix after random masking operations are input into the autoencoder, so that the autoencoder is forced to learn the intrinsic correlation between nodes. The introduction of edge index information increases the constraints of the autoencoder, helps the autoencoder consider the spatial position relationship during reconstruction, makes the reconstruction process more stable, and improves the autoencoder's ability to express high-dimensional features and distinguish between real anomalies and noise. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A flowchart of a method for detecting anomalies in a graph based on a masked graph autoencoder is provided in accordance with an embodiment of the present invention. DETAILED DESCRIPTION
[0064] The technical solution of the present invention is described in detail below through the accompanying drawings and specific embodiments. It should be understood that the embodiments of the present application and the specific features in the embodiments are detailed descriptions of the technical solution of the present application, rather than limitations on the technical solution of the present application.
[0065] In the description of the present invention, if “first” or “second” is described, it is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0066] In the description of the present invention, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0067] Embodiment 1:
[0068] like Figure 1 As shown, this embodiment provides a method for detecting anomalies in a graph based on a mask graph autoencoder, including:
[0069] Step 1: Preprocess the input hyperspectral image to be detected to obtain the node feature matrix and edge index matrix;
[0070] In some embodiments, the method of obtaining a node feature matrix includes:
[0071] The input hyperspectral image to be detected is flattened into a two-dimensional matrix of the total number of pixels × the number of bands through the spatial dimension, where the number of rows is the total number of pixels, the number of columns is the number of bands, and each row represents the spectral information of a pixel in all bands;
[0072] For each column of the two-dimensional matrix, calculate its mean and standard deviation;
[0073] For each row of the two-dimensional matrix, subtract the mean value from each pixel and divide it by the standard deviation to obtain a standardized two-dimensional matrix;
[0074] The standardized two-dimensional matrix is used as the node feature matrix.
[0075] In some embodiments, a method for obtaining an edge index matrix includes:
[0076] The Euclidean distance between each pixel and all other pixels in the node feature matrix is calculated respectively, and the K pixels closest to it are found as neighbors to construct edge relationships, thereby generating a two-dimensional edge index matrix.
[0077] Step 2: Perform a random mask operation on the node feature matrix;
[0078] In some embodiments, including: randomly selecting The nodes are masked, where Indicates the ratio of pixels to be masked, and N indicates the total number of nodes;
[0079] For the selected nodes, their feature values are set to 0 or replaced with random values as the masked pixel positions.
[0080] By performing random masking operations on the node feature matrix, the model is forced to learn the intrinsic associations between nodes. The edge index information is used as an auxiliary to help the model consider the spatial position relationship during reconstruction, improving the model's ability to express high-dimensional features. The random masking operation provides a regularization effect and reduces the model's sensitivity to noise. The introduction of edge index information increases the constraints of the model, making the reconstruction process more stable and improving the model's ability to distinguish between real anomalies and noise.
[0081] Step 3: Input the node feature matrix after random masking operation and the edge index matrix into the autoencoder to obtain a reconstructed feature matrix;
[0082] In some embodiments, the method for constructing an autoencoder includes:
[0083] Construct a GNN encoder, a secondary mask module, and a GNN decoder connected in sequence;
[0084] Construct a training set using hyperspectral images and corresponding known reconstruction feature matrices;
[0085] Taking the node feature matrix and edge index matrix after random masking of the hyperspectral image in the training set as input and the corresponding known reconstructed feature matrix as output, the autoencoder is trained to convergence using a preset loss function;
[0086] The GNN encoder includes a first neural network layer, a first activation layer, a second neural network layer, and a second activation layer connected in sequence;
[0087] The GNN decoder includes a third neural network layer and a third activation layer connected in sequence;
[0088] The first neural network layer is used to perform weighted summation on the input node feature matrix according to the input edge index matrix, thereby updating the feature representation of each node and outputting a first node feature matrix;
[0089] The first activation layer is used to process the first node feature matrix, clipping the negative values to zero while keeping the positive values unchanged, and obtaining a second node matrix;
[0090] The second neural network layer is used to continue processing the node features in the second node matrix and aggregate the information of neighboring nodes to each node;
[0091] The second activation layer is used to perform nonlinear transformation on the output of the second neural network layer to obtain hidden representation;
[0092] The secondary mask module is used to mask the hidden representation;
[0093] The third neural network layer is used to map the masked hidden representation back to the original feature space;
[0094] The third activation layer is used to perform nonlinear transformation on the output of the third neural network layer to obtain a reconstructed feature matrix;
[0095] The structures of the first activation layer, the second activation layer, and the third activation layer are the same, and all use the ReLU function.
[0096] In some embodiments, the loss function for:
[0097] ;
[0098] in, To rebuild the losses, To smooth the loss, is the weight hyperparameter corresponding to the reconstruction loss and smoothing loss, and
[0099] ;
[0100] ;
[0101] in Represents the reconstructed feature matrix of the masked node, which is generated by encoding by the GNN encoder and re-decoding by the GNN decoder; Represents the original feature matrix of the mask node; represents the square of the Euclidean distance; Z represents the reconstructed feature matrix of all nodes, and each row of the matrix corresponds to the feature vector of a node; L represents the Laplace matrix obtained after Laplace regularization of the known hyperspectral image; Representation Matrix The trace of , reflects the smoothness of the eigenvector in the graph structure.
[0102] In this embodiment, the loss function adopts a combination of reconstruction loss and smoothing loss. In this design, the smoothing loss emphasizes the continuity of the graph structure, better maintains the spatial correlation of the hyperspectral data, and reduces the structural distortion in the reconstruction process; it is more sensitive to local discontinuities, helps to detect subtle abnormal changes, and improves the ability to detect small-scale anomalies; it helps to know the noise in the reconstruction process, improves the quality of the reconstruction results, and reduces the false alarm rate; this loss function is relatively simple to calculate, converges quickly, and the training process is more stable.
[0103] In some embodiments, the node feature matrix after the random mask operation and the edge index matrix are input into the autoencoder to obtain the reconstructed features, including:
[0104] The node feature matrix and edge index matrix after random mask operation are used as input and encoded through the GNN encoder to obtain hidden representation;
[0105] Mask the hidden representation output by the GNN encoder;
[0106] The GNN decoder receives the masked hidden representation and decodes it to reconstruct the complete node feature matrix to obtain the reconstructed feature matrix.
[0107] The hidden representation of the GNN encoder output is masked. In this step, the feature representation is enhanced. The second mask forces the model to learn more robust feature representation, increases the model's understanding of high-level features, and improves the discriminative ability of feature representation. To prevent overfitting, the double masking mechanism increases the randomness of training, reduces the model's excessive dependence on specific patterns, and improves the model's generalization ability on unseen samples. Information supplementation is performed. The two maskings promote information reconstruction at different levels, help capture multi-scale abnormal features, and improve the expressiveness of the model. The anomaly detection results are also enhanced. The layer mask provides feature reconstruction from multiple perspectives, enhances the model's ability to recognize different types of anomalies, and improves the reliability of detection.
[0108] Step 4: Calculate the reconstruction error based on the reconstruction feature matrix to obtain the anomaly score;
[0109] In some embodiments, the reconstruction error is calculated as follows:
[0110] ;
[0111] in, For the i The reconstruction error of each node; It is i The initial feature representation of each node is It is the first i The feature representation of a node, Represents the square of the Euclidean distance.
[0112] Step 5: Mark pixels with anomaly scores higher than the set threshold as anomalies;
[0113] In some embodiments, before comparing the anomaly score with a set threshold, the method further includes:
[0114] normalizing the anomaly score;
[0115] Normalized anomaly score The calculation formula is as follows:
[0116] ;
[0117] in, It is i The anomaly score of each node, ; For the i The reconstruction error of each node; n is the number of pixels of the image to be detected; j represents the jth pixel; S j It is j The anomaly score of each node.
[0118] In this embodiment, the anomaly scores are standardized and the scales are unified. The anomaly scores of different dimensions are unified to the same scale, so that the reconstruction errors are comparable and it is convenient to set a unified anomaly threshold. The standardized scores are easier to understand and interpret, and the degree of anomaly can be judged intuitively, which is convenient for determining a reasonable threshold range. The extreme impact of outliers is reduced, making the detection results more stable and reliable, and reducing the sensitivity of threshold selection. It is convenient to compare between different data sets, which helps to evaluate model performance and improve the versatility of detection results.
[0119] The method provided by the embodiment of the present invention is further described below in conjunction with an application example, and the technical effect produced by the method provided by the embodiment of the present invention is further verified:
[0120] In this application example, an airborne visible / infrared imaging spectrometer (AVIRIS) is used to obtain a hyperspectral image of an airport. In order to improve the discrimination of image details, the acquired image is processed using pseudo-color processing technology to obtain the corresponding RGB pseudo-color image, which is referred to as the airport hyperspectral image below. The airport hyperspectral image contains the main background such as the apron and grass. The aircraft in the image is regarded as an abnormal target. The experimental area data size of the image is 100×100.
[0121] The existing GRX, LRX, CRD, LSMAD, LKRX, LAD and the image anomaly detection method based on the mask image autoencoder provided in this embodiment are respectively used to detect abnormal targets on the aforementioned airport hyperspectral image, and the abnormal target detection accuracy is shown in Table 1:
[0122] Table 1 Comparison of hyperspectral abnormal target detection accuracy
[0123] Abnormal target detection method GRX LRX CRD LSMAD LKRX LAD The present invention Abnormal target detection accuracy / % 94.02 91.97 98.05 97.19 92.16 98.54 99.09
[0124] As can be seen from Table 1, the image anomaly detection method based on mask image autoencoder provided in this embodiment is used to detect abnormal targets, and the accuracy rate is as high as 99.09%, which is 0.55% higher than the LAD method with the second highest AUC score. It can be seen that the method provided in this embodiment is significantly better than several other existing methods.
[0125] The above proves that the method of obtaining the node feature matrix and the edge index matrix, randomly masking the node feature matrix, and retaining the edge index matrix in the embodiment of the present invention can fully improve the accuracy and robustness of anomaly detection.
[0126] Embodiment 2:
[0127] A graph anomaly detection system based on a masked graph autoencoder, the system comprising:
[0128] A preprocessing module is used to preprocess the input hyperspectral image to be detected and obtain a node feature matrix and an edge index matrix;
[0129] A mask module, used for performing a random mask operation on the node feature matrix;
[0130] An autoencoder is used to encode the node feature matrix after the random mask operation and the edge index matrix to obtain a reconstructed feature matrix;
[0131] The anomaly assessment module is used to calculate the reconstruction error according to the reconstruction feature matrix to obtain the anomaly score, compare the anomaly score with a set threshold, and mark the pixels with anomaly scores higher than the set threshold as abnormal.
[0132] The image anomaly detection system based on masked image autoencoder provided in an embodiment of the present invention can execute the image anomaly detection method based on masked image autoencoder provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.
[0133] Embodiment three:
[0134] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method in the first embodiment are first implemented.
[0135] The computer-readable storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0136] Those skilled in the art will appreciate that the embodiments of the present application may provide methods, systems or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0137] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0138] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0139] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0140] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for image anomaly detection based on masked image autoencoder, characterized in that: The method comprises: Preprocess the input hyperspectral image to be detected to obtain the node feature matrix and edge index matrix; Performing a random masking operation on the node feature matrix; Inputting the node feature matrix after the random mask operation and the edge index matrix into the autoencoder for encoding to obtain a reconstructed feature matrix; Calculate the reconstruction error based on the reconstruction feature matrix to obtain the anomaly score; The anomaly score is compared with a set threshold, and pixels with anomaly scores higher than the set threshold are marked as abnormal. The method for obtaining the node feature matrix includes: The input hyperspectral image to be detected is flattened into a two-dimensional matrix of the total number of pixels × the number of bands through the spatial dimension, where the number of rows is the total number of pixels, the number of columns is the number of bands, and each row represents the spectral information of a pixel in all bands; For each column of the two-dimensional matrix, calculate its mean and standard deviation; For each row of the two-dimensional matrix, subtract the mean value from each pixel and divide it by the standard deviation to obtain a standardized two-dimensional matrix; The standardized two-dimensional matrix is used as the node feature matrix; Methods for obtaining edge index matrices include: Calculate the Euclidean distance between each pixel and all other pixels in the node feature matrix respectively; According to the Euclidean distance, find the K pixels closest to each pixel as neighbors, build edge relationships, and thus generate a two-dimensional edge index matrix; The method for constructing the autoencoder includes: Construct a GNN encoder, a secondary mask module, and a GNN decoder connected in sequence; Construct a training set using hyperspectral images and corresponding known reconstruction feature matrices; Taking the node feature matrix and edge index matrix after random masking of the hyperspectral image in the training set as input and the corresponding known reconstructed feature matrix as output, the autoencoder is trained to convergence using a preset loss function; The GNN encoder includes a first neural network layer, a first activation layer, a second neural network layer, and a second activation layer connected in sequence; The GNN decoder includes a third neural network layer and a third activation layer connected in sequence; The first neural network layer is used to perform weighted summation on the input node feature matrix according to the input edge index matrix, thereby updating the feature representation of each node and outputting a first node feature matrix; The first activation layer is used to process the first node feature matrix, clipping the negative values to zero while keeping the positive values unchanged, and obtaining a second node matrix; The second neural network layer is used to continue processing the node features in the second node matrix and aggregate the information of neighboring nodes to each node; The second activation layer is used to perform nonlinear transformation on the output of the second neural network layer to obtain hidden representation; The secondary mask module is used to mask the hidden representation; The third neural network layer is used to map the masked hidden representation back to the original feature space; The third activation layer is used to perform nonlinear transformation on the output of the third neural network layer to obtain a reconstructed feature matrix; The structures of the first activation layer, the second activation layer, and the third activation layer are the same, and all use the ReLU function.
2. The method for detecting anomalies in a graph based on a masked graph autoencoder according to claim 1, characterized in that: The random masking operation on the node feature matrix includes: randomly selecting The nodes are masked, where Indicates the ratio of pixels to be masked, and N indicates the total number of nodes; For the selected nodes, their feature values are set to 0 or replaced with random values as the masked pixel positions.
3. The method for detecting anomalies in a graph based on a masked graph autoencoder according to claim 1, characterized in that: The preset loss function for: ; in, To rebuild the losses, To smooth the loss, is the weight hyperparameter corresponding to the reconstruction loss and smoothing loss, and ; ; in Represents the reconstructed feature matrix of the masked node, which is generated by encoding by the GNN encoder and re-decoding by the GNN decoder; Represents the original feature matrix of the mask node; represents the square of the Euclidean distance; Z represents the reconstructed feature matrix of all nodes, and each row of the matrix corresponds to the feature vector of a node; L represents the Laplace matrix obtained after Laplace regularization of the known hyperspectral image; Representation Matrix The trace of , reflects the smoothness of the eigenvector in the graph structure.
4. The method for detecting anomalies in a graph based on a masked graph autoencoder according to claim 1 or 3, characterized in that: The step of inputting the node feature matrix after the random mask operation and the edge index matrix into the autoencoder for encoding to obtain a reconstructed feature matrix includes: The node feature matrix and edge index matrix after random mask operation are used as input and encoded through the GNN encoder to obtain hidden representation; Mask the hidden representation output by the GNN encoder; The GNN decoder receives the masked hidden representation and decodes it to reconstruct the complete node feature matrix to obtain the reconstructed feature matrix.
5. The method for detecting anomalies in a graph based on a masked graph autoencoder according to claim 1, characterized in that: The calculation formula of the reconstruction error is as follows: ; in, For the i The reconstruction error of each node; It is i The initial feature representation of each node is It is the first i The feature representation of a node, Represents the square of the Euclidean distance.
6. The method for detecting anomalies in a graph based on a masked graph autoencoder according to claim 1, characterized in that: Before comparing the anomaly score with the set threshold, the method further includes: normalizing the anomaly score; The normalized anomaly score The calculation formula is as follows: ; in, It is i The anomaly score of each node, ; For the i The reconstruction error of each node; n is the number of pixels of the image to be detected; j represents the jth pixel; S j It is j The anomaly score of each node.
7. A graph anomaly detection system based on mask graph autoencoder, characterized in that: The system comprises: A preprocessing module is used to preprocess the input hyperspectral image to be detected and obtain a node feature matrix and an edge index matrix; A mask module, used for performing a random mask operation on the node feature matrix; An autoencoder, used for encoding the node feature matrix after the random mask operation and the edge index matrix to obtain a reconstructed feature matrix; An anomaly assessment module is used to calculate the reconstruction error according to the reconstruction feature matrix to obtain an anomaly score, compare the anomaly score with a set threshold, and mark pixels with an anomaly score higher than the set threshold as abnormal; Methods for obtaining node feature matrix include: The input hyperspectral image to be detected is flattened into a two-dimensional matrix of the total number of pixels × the number of bands through the spatial dimension, where the number of rows is the total number of pixels, the number of columns is the number of bands, and each row represents the spectral information of a pixel in all bands; For each column of the two-dimensional matrix, calculate its mean and standard deviation; For each row of the two-dimensional matrix, subtract the mean value from each pixel and divide it by the standard deviation to obtain a standardized two-dimensional matrix; The standardized two-dimensional matrix is used as the node feature matrix; Methods for obtaining edge index matrices include: Calculate the Euclidean distance between each pixel and all other pixels in the node feature matrix respectively; According to the Euclidean distance, find the K pixels closest to each pixel as neighbors, build edge relationships, and thus generate a two-dimensional edge index matrix; The method for constructing the autoencoder includes: Construct a GNN encoder, a secondary mask module, and a GNN decoder connected in sequence; Construct a training set using hyperspectral images and corresponding known reconstruction feature matrices; Taking the node feature matrix and edge index matrix after random masking of the hyperspectral image in the training set as input and the corresponding known reconstructed feature matrix as output, the autoencoder is trained to convergence using a preset loss function; The GNN encoder includes a first neural network layer, a first activation layer, a second neural network layer, and a second activation layer connected in sequence; The GNN decoder includes a third neural network layer and a third activation layer connected in sequence; The first neural network layer is used to perform weighted summation on the input node feature matrix according to the input edge index matrix, thereby updating the feature representation of each node and outputting a first node feature matrix; The first activation layer is used to process the first node feature matrix, clipping the negative values to zero while keeping the positive values unchanged, and obtaining a second node matrix; The second neural network layer is used to continue processing the node features in the second node matrix and aggregate the information of neighboring nodes to each node; The second activation layer is used to perform nonlinear transformation on the output of the second neural network layer to obtain hidden representation; The secondary mask module is used to mask the hidden representation; The third neural network layer is used to map the masked hidden representation back to the original feature space; The third activation layer is used to perform nonlinear transformation on the output of the third neural network layer to obtain a reconstructed feature matrix; The structures of the first activation layer, the second activation layer, and the third activation layer are the same, and all use the ReLU function.
Citation Information
Patent Citations
Hyperspectral image abnormality detection method based on homogeneous patches
CN103593852A
Method for identifying pollutant at surface of chicken carcass by utilizing 2D high-spectral image
CN106251328A