A small sample anomaly detection method based on multi-scale hypergraph and feature registration
Through the multi-scale hypergraph and cross-attention mechanism, the problem of scarcity of annotation data and difficulty in capturing multi-scale feature differences in image anomaly detection is solved, achieving higher detection accuracy and generalization, and is suitable for a variety of image types.
Patent Information
- Application Number
- CN202410918180.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-10
AI Technical Summary
Existing technologies in image anomaly detection have problems such as scarcity of annotated data, uneven data distribution, and difficulty in capturing differences in multi-scale image features, resulting in poor detection accuracy and generalization capabilities.
Using a multi-scale hypergraph and cross-attention mechanism, we build a multi-scale hypergraph model to capture the complex feature differences of images of different scales, and perform feature registration through the twin network to form a unified feature representation to improve detection accuracy and generalization. sex.
It effectively captures complex features, improves the accuracy and generalization of image anomaly detection, overcomes the problem of insufficient data volume in small samples and subtle differences in features, is suitable for a variety of image types, and improves the robustness and performance of the model.
Smart Images

Figure CN118470442B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image anomaly detection and relates to a small sample anomaly detection method based on multi-scale hypergraph and feature registration. Background Art
[0002] With the in-depth application of computer vision technology in the field of image anomaly detection, the ability to acquire and process image data has been significantly improved, but it also brings problems such as data redundancy, noise interference, and abnormal image detection. In the fields of medical diagnosis, industrial inspection, video surveillance, etc., accurately and efficiently identifying abnormal images is of great significance to ensuring system security and improving diagnostic efficiency. Traditional image anomaly detection methods mostly rely on a large amount of labeled data for model training. However, in practical applications, we often face problems such as scarce labeled data and uneven data distribution, which greatly restricts the performance of existing methods. In addition, the feature differences between abnormal images and normal images may be very subtle, especially at multiple scales, and such differences are even more difficult to be effectively captured by existing methods.
[0003] In this regard, researchers have proposed a small sample anomaly detection learning method. By providing only a limited number of normal images in each category, more training samples can be generated based on limited labeled data through data augmentation technology to simulate more abnormal images and improve the generalization ability of the model, thereby solving problems such as scarce labeled data and uneven data distribution. In addition, image feature registration technology provides a new idea for image anomaly detection. By comparing the feature differences between normal images and images to be detected, abnormal areas can be effectively identified. However, under small sample conditions, feature extraction and registration of image features face two major challenges. On the one hand, due to the limitation of data volume, small sample data often cannot fully support complex feature extraction and registration models for effective learning. On the other hand, the feature differences between abnormal images and normal images may be extremely subtle, which makes it difficult for existing methods to effectively capture these subtle differences, thereby increasing the difficulty of feature registration.
[0004] In recent years, graph-based image anomaly detection models have shown superior performance. Graph neural networks can be used to represent vertex relationships and transmit connection information between vertices. However, traditional graph-based image anomaly detection models often construct graph data as simple bipartite graphs for processing, which limits their ability to capture complex high-order information between vertices. In image anomaly detection, high-order information is crucial for identifying abnormal information. Compared with traditional graph structures, hypergraphs, as a special graph structure, can effectively represent high-order correlations between data and simultaneously consider the relationships between multiple vertices, thereby more comprehensively describing the intrinsic structure of image data.
[0005] Existing methods have limitations when dealing with image anomaly detection. They often can only capture partial information and ignore the structure and relationship between multi-scale images, resulting in incomplete information and inability to effectively integrate multi-scale information. In addition, existing small sample feature registration methods fail to truly utilize the commonalities between categories, resulting in poor generalization ability and not applicable to all image types.
[0006] On the one hand, in traditional image anomaly detection, due to the diverse categories of abnormal samples and the relatively limited number of anomalies, abnormal images often have complex structures and relationships with normal images. These structures and relationships may span multiple scales and are not easy to capture using traditional feature representation methods. In addition, when using traditional graph structures, data can often only be represented at a fixed scale, which limits the integration of multi-scale information and may lead to low accuracy of anomaly detection, and prone to false positives or missed abnormalities.
[0007] On the other hand, in small sample image anomaly detection, most models learn shared features between different categories through feature registration, which helps improve the performance of the model when processing small sample data and makes anomalies easier to detect and analyze in images. However, this method fails to fully utilize the commonalities between categories, resulting in poor generalization ability of the model and failure to perform well on different types of image sets, thus affecting the performance of anomaly detection. Summary of the invention
[0008] In order to overcome the above defects, the present invention provides a small sample anomaly detection method based on multi-scale hypergraph and feature registration. By constructing a small sample image feature registration model based on multi-scale hypergraph, the high-order representation ability of the hypergraph can be fully utilized to capture the complex and subtle feature differences in images of different scales, and the multi-scale hypergraph features are fused by introducing a cross-attention mechanism to form a unified representation of the features, so that the model can more accurately capture and emphasize the key features in the image, better understand the feature relationship of the image, and then the model can combine the feature registration technology under the condition of less samples to achieve effective feature extraction and registration, thereby overcoming the problems caused by insufficient data and subtle feature differences. The present invention can not only capture complex features and ensure accurate registration of image features at different scales, but also enable the model to focus more on the pixel area that plays a decisive role in classification, thereby improving the accuracy and generalization of anomaly detection.
[0009] The present invention is implemented by the following technical solution, a small sample anomaly detection method based on multi-scale hypergraph and feature registration, the steps are as follows:
[0010] S1: Preprocess small sample image data using multi-scale feature learning methods, use multi-scale prototypes to represent normal patterns, and capture spatial information at different scales;
[0011] S2: Hypergraph is used to integrate information between different scales. The multi-scale spatial information features captured by multi-scale prototypes are used as the vertices of the hypergraph. Agglo-MS clustering is then performed on the vertices of each scale to generate hyperedges.
[0012] S3: The features of different scales are fused through the cross attention mechanism to form the fused features and calculate the cross attention weights;
[0013] S4: The fused features are spatially transformed by the spatial transformation neural network to obtain spatial transformation features, and then the twin network is used for training to achieve feature registration and obtain registration features. During the training process, the samples to be tested and the support samples are respectively input into the two branches of the twin network;
[0014] S5: Use the distribution estimation model to fit the registration feature distribution of the support image to obtain the feature distribution model; use the anomaly assessment function to calculate the Mahalanobis distance matrix between the registration features of the image to be tested and the feature distribution model. The Mahalanobis distance matrix constitutes an anomaly score matrix, which indicates the abnormal area in the image to be tested, thereby realizing anomaly detection.
[0015] Specifically, in step S1, the multi-scale prototype is used to represent the normal mode and capture the spatial information of different scales. The process is as follows:
[0016] S11: Definition is the set of all normal samples during training ;in Representing images is normal or abnormal;
[0017] S12: Use the feature extraction network pre-trained on ImageNet to obtain the features of the input image at different scales; use the features Represents the i-th input image of the feature extraction network The output of scale j; features Is a depth ,high ,width Tensor of ; represents the features at scale j; Represents dimension;
[0018] S13: Prototype at scale j is from K features randomly extracted from , and prototypes updated through K-means clustering;
[0019] S14: After K-means clustering, the number of prototypes is set to a certain proportion of the number of normal samples; define the feature at scale j The residual to the L2 norm of the nearest prototype is:
[0020] ,
[0021] (1);
[0022] in, Represented by The distance obtained by the constraint condition The most recent prototype, represents the element-wise L2 distance between two tensors, , Represents the kth prototype at scale j.
[0023] Specifically, in step S2, the hypergraph Contains a finite set of vertices Collection and super edge The weighted hypergraph is a set E of hyperedges in the hypergraph. Add the corresponding weights , represents a weighted hypergraph, when When, super edge With Vertex Associated, opposite vertices , the degree of the vertex is It is represented by formula (2) and defined as follows: , its degree of use It is expressed as follows, and is defined by formula (3):
[0024] (2);
[0025] (3);
[0026] Given any set , express The cardinality of the hyperedge , its degree is defined as ;
[0027] when , hour, represents the i-th vertex, represents the i+1th vertex, represents the i-th hyperedge, Represents the k-1th hyperedge, generating optional sequences on different vertices and hyperedges , Hypergraph and The correlation matrix Associated.
[0028] Specifically, in step S2, a hypergraph is used to integrate information between different scales. Representing three scales The vertex set below, is the vertex set at scale j; represents the hyperedge sets at three scales, is the set of vertices at scale j; for each scale, the spatial information features captured by the multi-scale prototype are taken as vertices:
[0029] (4);
[0030] in is the i-th vertex at scale j, representing a feature vector or feature point;
[0031] For each scale vertex, perform Agglo-MS clustering: Use the Agglo-MS clustering algorithm to cluster the vertex set Perform clustering to obtain a set of clusters ,in is the number of clusters at scale j, In represents the index of different clusters at scale j, Indicates that the index under scale j is Clustering of
[0032] For each scale, generate a set of hyperedges :
[0033] (5);
[0034] The index at scale j is The super edge Connections belong to clusters The vertices in .
[0035] Specifically, in step S2, the hyperedges based on spatial relations in the hypergraph It is composed of the central pixel and its spatial neighborhood pixels. The neighborhood size is selected as F. There are a total of F+1 vertices in a hypergraph. Each hyperedge , and provides a weight , Hyperedges representing spatial relationships, Represents the distance from the center pixel; the association matrix of the spatial relationship of the hypergraph G Expressed as:
[0036] (6);
[0037] In generating the spatial relationship matrix of the hypergraph G Finally, the central pixel and pixel in the hypergraph are weighted:
[0038] (7);
[0039] In the formula In the hypergraph Pixel coordinates are weighted pixels, where m is the horizontal coordinate of the pixel and n is the vertical coordinate of the pixel; is the number of hyperedges at scale j.
[0040] Specifically, in step S3, for the vertices at scale j , the initial feature at scale j is expressed as ,in , is the dimension of the feature at scale j. Through the cross-attention mechanism, the fused features It is expressed as follows:
[0041] (8);
[0042] is the vertex and vertices The attention weights between is the weight matrix under the jth scale integrated under the tth scale, is the vertex at scale t, is the initial feature at scale t;
[0043] Attention Weight The calculation is done in the following way:
[0044] (9);
[0045] in, is the learned attention parameter vector, express The transpose of Represents a splicing operation, is the activation function, is the weight matrix at scale j, is the weight matrix at scale t.
[0046] Specifically, in step S4, a spatial transformation neural network is used to transform the fused features Perform spatial transformation to obtain spatial transformation features. Formula (10) is as follows:
[0047] (10);
[0048] Among them (s j , t j ) is the fused feature The target coordinates, (u j , v j ) is the fused feature The original coordinates of is the affine transformation matrix, θ 11 ,θ 12 ,θ 13 ,θ 21 ,θ 22 ,θ 23 are the six parameters of the affine transformation matrix.
[0049] Specifically, in step S4, the encoder in the twin network is used to process the spatial transformation features, and the image feature registration loss function D is used to achieve feature registration. The calculation formula is shown in (11):
[0050] (11);
[0051] in, is the encoded feature of the image to be detected at scale j obtained by the predictor, is the feature of the support image after being encoded by the encoder at scale j, where for Regularization operation.
[0052] Specifically, in step S5, the distribution estimation model is used to fit the registration feature distribution of the support image to obtain a feature distribution model. The specific process is:
[0053] Divide the support image into Grid, where It is used to estimate the resolution of the normally distributed features and calculate the registration features of the support image at each position, and calculate the sample covariance matrix :
[0054] (12);
[0055] in , , is the grid position of the rth support image The registration features at is the transformed features of C support images A collection of; for The sample mean of ; is the regularization term.
[0056] Specifically, in step S5, the Mahalanobis distance matrix The calculation formula is shown in (13):
[0057] (13);
[0058] in, is the sample covariance The inverse matrix of .
[0059] Beneficial effects of the present invention:
[0060] By constructing hypergraphs at different scales and using multi-scale hypergraph structures as an advanced form of data representation, hypergraphs are introduced into small sample anomaly detection tasks. It is difficult to effectively capture these subtle differences when matching small sample features. The hyperedges of the hypergraph are used to represent the relationship between features of different scales, capturing richer context and structural information, and improving the accuracy of image anomaly detection.
[0061] The cross-attention mechanism is used to fuse multi-scale hypergraph features. The cross-attention mechanism calculates the correlation information between multiple input features and performs weighted fusion of hypergraph features of different scales through attention weights, so that the model pays more attention to the pixel areas in the image that play a decisive role in classification, while ignoring those task-irrelevant or redundant information. In this way, the commonalities between categories can be learned during training, the generalization ability of the model can be improved, the robustness of anomaly detection can be improved, and the shortcomings of small sample registration can be solved.
[0062] The small sample anomaly detection model enhances the recognition ability of key features by learning effective representations of feature registration and utilizing multi-scale hypergraph features in the feature registration network, providing the model with more expressive and discriminative features, enabling the model to learn commonalities between categories, thereby improving the performance and generalization ability of the model.
[0063] In summary, the present invention can solve the small sample problem in image feature registration. It uses hypergraphs to capture the complex relationship between images of different scales and combines feature registration technology to effectively improve the accuracy and generalization of anomaly detection in small sample conditions. It has important application value for small sample anomaly detection problems in the fields of image analysis, security monitoring, and medical diagnosis. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 The figure is a flow chart of the method of the present invention.
[0065] Figure 2 It is a 4-neighborhood hypergraph spatial relationship.
[0066] Figure 3 It is an 8-neighborhood hypergraph spatial relationship.
[0067] Figure 4 It is a 12-neighborhood hypergraph spatial relationship.
[0068] Figure 5 It is a 24-neighborhood hypergraph spatial relationship. DETAILED DESCRIPTION
[0069] The present invention will be further described in detail below with reference to the accompanying drawings.
[0070] like Figure 1 As shown in FIG. 1 , a small sample anomaly detection method based on multi-scale hypergraph and feature registration is shown in FIG. 1 . The steps are as follows:
[0071] S1: Preprocess small sample image data using multi-scale feature learning methods, use multi-scale prototypes to represent normal patterns, and capture spatial information at different scales;
[0072] S2: Hypergraph is used to integrate information between different scales. The multi-scale spatial information features captured by multi-scale prototypes are used as the vertices of the hypergraph. Agglo-MS clustering is then performed on the vertices of each scale to generate hyperedges.
[0073] S3: The features of different scales are fused through the cross attention mechanism to form the fused features and calculate the cross attention weights;
[0074] S4: The fused features are spatially transformed by the spatial transformation neural network to obtain spatial transformation features, and then the twin network is used for training to achieve feature registration and obtain registration features. During the training process, the samples to be tested and the support samples are respectively input into the two branches of the twin network;
[0075] S5: Use the distribution estimation model to fit the registration feature distribution of the support image to obtain the feature distribution model, and use the anomaly assessment function to calculate the Mahalanobis distance matrix between the registration features of the image to be tested and the feature distribution model. The Mahalanobis distance matrix constitutes the anomaly score matrix, and the anomaly score matrix is used to indicate the abnormal area in the image to be tested, thereby realizing anomaly detection.
[0076] Specifically, in step S1 of this embodiment, the multi-scale prototype is used to represent the normal mode and capture spatial information of different scales. The process is as follows:
[0077] S11: Definition is the set of all normal samples during training ;in Representing images is normal (0) or abnormal (1);
[0078] S12: Use a feature extraction network pre-trained on ImageNet (such as ResNet) to obtain features of the input image at different scales; use features Represents the i-th input image of the feature extraction network The output of scale j; features Is a depth ,high ,width Tensor of ; represents the features at scale j; Represents dimension;
[0079] S13: Prototype at scale j is from K features randomly extracted from , and prototypes updated through K-means clustering;
[0080] S14: After K-means clustering, the prototypes at each scale remain unchanged in the subsequent small sample anomaly detection training; Due to the large difference in the number of normal samples in different data sets, in order to obtain a suitable number of prototypes, the number of prototypes is set to a certain proportion of the number of normal samples; The prototypes of three scales are used , used to extract features The feature extraction network parameters of remain unchanged during the K-means clustering process; in addition, the feature The residual to the L2 norm of the nearest prototype is:
[0081] ,
[0082] (1);
[0083] in, Represented by The distance obtained by the constraint condition The most recent prototype, represents the element-wise L2 distance between two tensors, , represents the kth prototype at scale j. The input small sample image data can match different prototypes at different scales because the prototypes at each scale are learned independently.
[0084] As a new deep learning architecture, the advantage of the hypergraph network model is that it can express more complex and diverse relationships than traditional graph structures. In a graph structure, the relationship between vertices is usually limited to pairwise connections, while in a hypergraph, a hyperedge can connect multiple vertices at the same time, thereby capturing and expressing more detailed and rich information structures. Therefore, using hypergraphs to build models for images is of great help for subsequent research and operations.
[0085] A hypergraph is defined as a finite set of vertices Collection and super edge The set E, that is , . is called a vertex set and the hyperedge set A hypergraph is a graph composed of two vertices. A hyperedge consisting of only two vertices is an edge of a simple graph. A weighted hypergraph is a hypergraph in which each hyperedge Add the corresponding weights , can represent a weighted hypergraph. When, super edge With Vertex Associated. Vertex , the degree of the vertex is It is represented by formula (2) and defined as follows: , its degree of use It is expressed as follows, and is defined by formula (3):
[0086] (2);
[0087] (3);
[0088] Given any set , express The cardinality of the hyperedge , its degree is defined as .
[0089] when , hour, represents the i-th vertex, represents the i+1th vertex, represents the i-th hyperedge, Represents the k-1th hyperedge, generating optional sequences on different vertices and hyperedges , the optional sequence is called at the first vertex and the kth vertex A hypergraph is connected if every pair of vertices has a hyperpath. In subsequent feature fusion, the hypergraphs mentioned are always assumed to be connected. Mathematically, a hypergraph and The correlation matrix Associated.
[0090] Hypergraph After definition, a hypergraph is used to integrate information between different scales. Representing three scales The vertex set below, is the set of vertices at scale j. represents the hyperedge sets at three scales, is the set of vertices at scale j. For each scale, the spatial information features captured by the multi-scale prototype are taken as vertices:
[0091] (4);
[0092] in It is the i-th vertex at scale j, representing a feature vector or feature point.
[0093] For each scale vertex, perform Agglo-MS clustering: Use the Agglo-MS clustering algorithm to cluster the vertex set Perform clustering to obtain a set of clusters ,in is the number of clusters at scale j, In represents the index of different clusters at scale j, Indicates that the index under scale j is Clustering.
[0094] For each scale, generate a set of hyperedges :
[0095] (5);
[0096] The index at scale j is The super edge Connections belong to clusters The weight of the hyperedge can be determined according to the degree of association between the vertices, and the distance or similarity between the cluster centers can usually be used as the weight.
[0097] In small sample feature registration, using hypergraphs to construct spatial relationships helps to better express the feature relationships between pixels, thus facilitating subsequent feature registration operations. The Euclidean distance is used to measure the similarity between pixels in the image space. Hyperedges based on spatial relationships in hypergraphs It is composed of the central pixel and its spatial neighbors. Figure 2-Figure 5 The relationship between the four central pixels and their neighboring pixels is shown. Figure 2-Figure 5 With the pixel represented by the digital sign "1" as the center, the pixels represented by other digital signs constitute the neighborhood pixels connected to the central pixel. Figure 2-Figure 5 Four different neighborhood types are shown, including 4 neighborhoods, 8 neighborhoods, 12 neighborhoods, and 24 neighborhoods, respectively. The distances from the center pixel are expressed as 2, 3, 4, and 5. Assume that the neighborhood size is F, and there are a total of F+1 vertices in a hypergraph. Each hyperedge , and provides a weight , Hyperedges representing spatial relationships, Represents the distance from the center pixel; the association matrix of the spatial relationship of the hypergraph G It can be expressed as:
[0098] (6);
[0099] In generating the spatial relationship matrix of the hypergraph G After that, the central pixel and the pixel in the hypergraph are weighted to capture their relationship with the surrounding pixels, thereby forming a sample with image feature information. The calculation formula is expressed as:
[0100] (7);
[0101] In the formula In the hypergraph Pixel coordinates are weighted pixels, where m is the horizontal coordinate of the pixel and n is the vertical coordinate of the pixel; is the number of hyperedges at scale j.
[0102] The cross-attention mechanism can effectively fuse the hypergraph features of different scales to form a fused feature. The cross-attention mechanism allows each vertex in the hypergraph to dynamically adjust its features according to its relationship with other vertices. Specifically, for a vertex at scale j , the initial feature at scale j is expressed as ,in , is the dimension of the feature at scale j. Through the cross-attention mechanism, the fused features It can be expressed as follows:
[0103] (8);
[0104] is the vertex and vertices The attention weights between is the weight matrix under the jth scale integrated under the tth scale, is the vertex at scale t, is the initial feature at scale t.
[0105] Attention Weight The calculation is done in the following way:
[0106] (9);
[0107] in, is the learned attention parameter vector, express The transpose of Represents a splicing operation, is the activation function, is the weight matrix at scale j, is the weight matrix at scale t. and Represents the features of two different scales respectively The result of linear transformation is obtained by concatenating them into a longer feature vector for calculating attention weights. Through the cross-attention mechanism, hypergraph features of different scales can be dynamically fused according to the complex relationship between them to form fused features, which effectively captures the richness and complexity of multi-scale information.
[0108] The feature registration network is composed of a spatial transformer neural network (STN) and a twin network. The spatial transformer neural network is used to fusion the features. Perform spatial transformation to obtain spatial transformation features. Formula (10) is as follows:
[0109] (10);
[0110] Among them (s j , t j ) is the fused feature The target coordinates, (u j , v j ) is the fused feature The original coordinates of is the affine transformation matrix, θ 11 ,θ 12 ,θ 13 ,θ 21 ,θ 22 ,θ 23 are the six parameters of the affine transformation matrix.
[0111] The encoder in the twin network is used to process the spatial transformation features, and the image feature registration loss function D is used to achieve feature registration. The calculation formula is shown in (11):
[0112] (11);
[0113] in, is the encoded feature of the image to be detected at scale j obtained by the predictor, is the feature of the support image after being encoded by the encoder at scale j, where for Regularization operation.
[0114] After feature registration, the distribution estimation model is used to fit the registration feature distribution of the support image to obtain the feature distribution model. The support image is divided into Grid, where It is used to estimate the resolution of the normally distributed features and calculate the registration features of the support image at each position, and calculate the sample covariance matrix :
[0115] (12);
[0116] in , , is the grid position of the rth support image The registration features at is the transformed features of C support images A collection of; for The sample mean of ; is a regularization term that makes the sample covariance matrix full rank and invertible.
[0117] Finally, the anomaly assessment function is used to calculate the Mahalanobis distance matrix between the registration features of the image to be tested and the feature distribution model , the Mahalanobis distance matrix The anomaly score matrix is formed. The anomaly score matrix indicates the abnormal area in the image to be tested. The calculation formula is shown in (13):
[0118] (13);
[0119] in, is the sample covariance The inverse matrix of .
[0120] The present invention can capture small sample features at various scales from local to global through multi-scale hypergraph feature learning, avoiding the problem of focusing on only part of the image information, thereby ensuring the integrity of the information. Compared with the traditional graph structure, the hypergraph can naturally represent the complex relationship between features of different scales, which is usually reflected by the hyperedge of the hypergraph, that is, the hyperedge can connect multiple vertices, indicating the non-paired interaction between vertices. Therefore, through operations such as hypergraph convolution, the hypergraph can more effectively integrate these image information, overcome the problem of information fragmentation, and thus improve the accuracy of the model. In addition, the hypergraph can not only integrate local features, but also capture global context information through the connection relationship between vertices. At the same time, when extracting features, a cross-attention mechanism is introduced to fuse multi-scale hypergraph features. By treating features of different scales as different sequences or feature sets and calculating the correlation between them, the attention weight of each scale feature can be obtained, which can help the model better utilize limited small sample data in subsequent small sample feature registration and improve the generalization ability of the model.
[0121] In the feature registration task, an efficient fusion feature strategy is designed to more accurately capture the subtle differences and geometric transformations between images. The cross-attention mechanism is used to fuse multi-scale features to enhance the model's ability to perceive and recognize global and abnormal patterns. Combined with the Spatial Transformer feature registration technology, the model can pay more attention to the pixel areas in the image that are decisive for classification, thereby learning the commonalities between categories during small sample training and reducing the problem of poor data generalization. In response to the shortcomings of small sample registration, this module can better capture key features under limited data conditions and improve the model's adaptability to small samples.
[0122] The preferred embodiments of the present invention disclosed above are only used to help explain the present invention. The preferred embodiments do not describe all the details in detail, nor do they limit the present invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.
Claims
1. A small sample anomaly detection method based on multi-scale hypergraph and feature registration, characterized in that: Here are the steps: S1: Preprocess small sample image data using multi-scale feature learning methods, use multi-scale prototypes to represent normal patterns, and capture spatial information at different scales; S2: Hypergraph is used to integrate information between different scales. The multi-scale spatial information features captured by multi-scale prototypes are used as the vertices of the hypergraph. Agglo-MS clustering is then performed on the vertices of each scale to generate hyperedges. S3: The features of different scales are fused through the cross attention mechanism to form the fused features and calculate the cross attention weights; S4: The fused features are spatially transformed by the spatial transformation neural network to obtain spatial transformation features, and then the twin network is used for training to achieve feature registration and obtain registration features. During the training process, the samples to be tested and the support samples are respectively input into the two branches of the twin network; S5: Use the distribution estimation model to fit the registration feature distribution of the support image to obtain the feature distribution model; use the anomaly assessment function to calculate the Mahalanobis distance matrix between the registration features of the image to be tested and the feature distribution model. The Mahalanobis distance matrix constitutes an anomaly score matrix. The anomaly score matrix indicates the abnormal area in the image to be tested, thereby realizing anomaly detection; In step S2, the hypergraph Contains a finite set of vertices Collection and super edge The weighted hypergraph is a set E of hyperedges in the hypergraph. Add the corresponding weights , represents a weighted hypergraph, when When, super edge With Vertex Associated, opposite vertices , the degree of the vertex is It is represented by formula (2) and defined as follows: , its degree of use It is expressed as follows, and is defined by formula (3): (2); (3); Given any set , express The cardinality of the hyperedge , its degree is defined as ; when , hour, represents the i-th vertex, represents the i+1th vertex, represents the i-th hyperedge, Represents the k-1th hyperedge, generating optional sequences on different vertices and hyperedges , Hypergraph and The correlation matrix associated; In step S2, a hypergraph is used to integrate information between different scales. Representing three scales The vertex set below, is the vertex set at scale j; represents the hyperedge sets at three scales, is the set of vertices at scale j; for each scale, the spatial information features captured by the multi-scale prototype are taken as vertices: (4); in is the i-th vertex at scale j, representing a feature vector or feature point, is the number under scale j; For each scale vertex, perform Agglo-MS clustering: Use the Agglo-MS clustering algorithm to cluster the vertex set Perform clustering to obtain a set of clusters ,in is the number of clusters at scale j, In represents the index of different clusters at scale j, Indicates that the index under scale j is Clustering of For each scale, generate a set of hyperedges : (5); The index at scale j is The super edge Connections belong to clusters The vertices in In step S2, the hyperedges based on spatial relations in the hypergraph It is composed of the central pixel and its spatial neighborhood pixels. The neighborhood size is selected as F. There are a total of F+1 vertices in a hypergraph. Each hyperedge , and provides a weight , Hyperedges representing spatial relationships, Represents the distance from the center pixel; the association matrix of the spatial relationship of the hypergraph G Expressed as: (6); In generating the spatial relationship matrix of the hypergraph G Finally, the central pixel and pixel in the hypergraph are weighted: (7); In the formula In the hypergraph Pixel coordinates are weighted pixels, where m is the horizontal coordinate of the pixel and n is the vertical coordinate of the pixel; is the number of hyperedges at scale j; In step S3, for the vertices at scale j , the initial feature at scale j is expressed as ,in , is the dimension of the feature at scale j; through the cross attention mechanism, the fused features It is expressed as follows: (8); is the vertex and vertices The attention weights between is the weight matrix under the jth scale integrated under the tth scale, is the vertex at scale t, is the initial feature at scale t; Attention Weight The calculation is done in the following way: (9); in, is the learned attention parameter vector, express The transpose of Represents a splicing operation, is the activation function, is the weight matrix at scale j, is the weight matrix at scale t.
2. The small sample anomaly detection method based on multi-scale hypergraph and feature registration according to claim 1 is characterized in that: In step S1, the multi-scale prototype is used to represent the normal mode and capture the spatial information of different scales. The process is as follows: S11: Definition is the set of all normal samples during training, ;in Representing images is normal or abnormal; S12: Use the feature extraction network pre-trained on ImageNet to obtain the features of the input image at different scales; Using Features Represents the i-th input image of the feature extraction network The output of scale j; features Is a depth ,high ,width Tensor of ; represents the features at scale j; Represents dimension; S13: Prototype at scale j is from K features randomly extracted from , and prototypes updated through K-means clustering; S14: After K-means clustering, the number of prototypes is set to a certain proportion of the number of normal samples; define the feature at scale j The residual to the L2 norm of the nearest prototype is: , (1); in, Represented by The distance obtained by the constraint condition The most recent prototype, represents the element-wise L2 distance between two tensors, , Represents the kth prototype at scale j.
3. The small sample anomaly detection method based on multi-scale hypergraph and feature registration according to claim 1, characterized in that: In step S4, a spatial transformation neural network is used to transform the fused features Perform spatial transformation to obtain spatial transformation features. Formula (10) is as follows: (10); Among them (s j , t j ) is the fused feature The target coordinates, (u j , v j ) is the fused feature The original coordinates of is the affine transformation matrix, θ 11 ,θ 12 ,θ 13 ,θ 21 ,θ 22 ,θ 23 are the six parameters of the affine transformation matrix.
4. The small sample anomaly detection method based on multi-scale hypergraph and feature registration according to claim 3 is characterized in that: In step S4, the encoder in the twin network is used to process the spatial transformation features, and the image feature registration loss function D is used to achieve feature registration. The calculation formula is shown in (11): (11); in, is the encoded feature of the image to be detected at scale j obtained by the predictor, is the feature of the support image after being encoded by the encoder at scale j, where for Regularization operation.
5. The small sample anomaly detection method based on multi-scale hypergraph and feature registration according to claim 4 is characterized in that: In step S5, the distribution estimation model is used to fit the registration feature distribution of the support image to obtain a feature distribution model. The specific process is as follows: Divide the support image into Grid, where It is used to estimate the resolution of the normally distributed features and calculate the registration features of the support image at each position, and calculate the sample covariance matrix : (12); in , , is the grid position of the rth support image The registration features at is the transformed features of C support images A collection of; for The sample mean of ; is the regularization term.
6. The small sample anomaly detection method based on multi-scale hypergraph and feature registration according to claim 5, characterized in that: In step S5, the Mahalanobis distance matrix The calculation formula is shown in (13): (13); in, is the sample covariance The inverse matrix of .
Citation Information
Patent Citations
Few-sample image anomaly detection method and system based on image registration
CN114972871A
Method for inverting above-ground biomass based on Hypergraph-Transformer structure
CN117034778A
Local map point cloud global alignment method and device, electronic equipment and storage medium
CN117351047A
Double convolutional network road extraction method based on hypergraph and multistage feature fusion
CN117854027A
Point cloud segmentation method based on cross attention and multi-scale feature fusion
CN117975013A
