Cross-scene hyperspectral image classification method based on domain generalization
By combining the convolutional network and the Transformer network, we design the generator and integrate text image alignment and supervised contrastive learning, which solves the problems of low hyperspectral image classification accuracy and poor generalization effect in the existing technology, and achieves more efficient cross-scene image classification. .
Patent Information
- Application Number
- CN202410651112.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-24
- Publication Date
- 2024-09-06
AI Technical Summary
Existing cross-scene hyperspectral image classification methods have low classification accuracy and poor generalization effect in the target scene. They cannot fully utilize the spectral information of hyperspectral images, and methods based on text-image alignment have a low degree of alignment.
Combine the convolutional network and Transformer network to design the generator, introduce the feature randomization process, build the extended domain generator, and integrate the text image alignment method and supervised contrastive learning into a unified framework to align image features from different fields and improve the generalization of the model. chemical performance.
Effectively utilizing the spatial and spectral information of hyperspectral images, the classification accuracy and generalization performance are improved, and the classification effect in the target scene is significantly improved.
Smart Images

Figure CN118608944A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of hyperspectral remote sensing image processing, and further relates to hyperspectral image classification, specifically a cross-scene hyperspectral image classification method based on domain generalization, which can be used to realize cross-scene image classification in multiple scenes such as mineral exploration, precision agriculture, and environmental testing. Background Art
[0002] Cross-scene hyperspectral image classification aims to generalize the source scene with labeled samples to other target scenes with unlabeled samples for classification. Among them, the cross-scene classification method based on domain generalization does not require any labeled samples of the target scene. When computing resources are limited, it can directly classify the target scene without retraining. It is widely used in mineral exploration, military reconnaissance, precision agriculture, environmental testing and other scenarios.
[0003] In recent years, in the field of cross-scene hyperspectral image classification, domain generalization methods based on data enhancement, supervised learning, domain alignment, etc. have developed rapidly and have attracted widespread attention from researchers. For example, Zhang YuXiang et al. proposed a cross-scene hyperspectral image classification method that aligns text image features in semantic space in the paper "Language-Aware Domain Generalization Network for Cross-Scene Hyperspectral Image Classification". Zhao Hanqing et al. proposed a generator based on a convolutional network for data enhancement in the paper "Language-Aware Domain Generalization Networkfor Cross-Scene Hyperspectral Image Classification", and then learned domain-invariant representations through supervised contrast methods, and finally completed cross-scene hyperspectral image classification. In the above methods, the generator model based on the convolutional network effectively extracts the spatial information of the hyperspectral image, but cannot make full use of the spectral information; in the method based on text image alignment, a large number of training samples are often required for feature alignment, resulting in a low degree of alignment between different domains. Therefore, how to further improve the accuracy of cross-scene hyperspectral image classification is a problem worth exploring. Summary of the invention
[0004] The purpose of the present invention is to propose a cross-scene hyperspectral image classification method based on domain generalization in view of the deficiencies of the above-mentioned prior art, which solves the problems of low classification accuracy and poor generalization effect of the existing classification methods in the target scene. The present invention effectively combines the convolutional network and the Transformer network to design a generator network that can fully utilize the hyperspectral image information. At the same time, the text image alignment method and supervised contrast learning are integrated into a unified framework, aligning image features from different fields to improve the generalization performance of the model.
[0005] The specific steps of the present invention to achieve the above-mentioned purpose include the following:
[0006] (1) Combining the convolutional network with the Transformer network and introducing the feature randomization process, an extended domain generator consisting of a convolutional layer, a linear transformation layer, a Transformer encoding layer, an inverse linear transformation layer, and a deconvolution layer is constructed to generate extended domain data;
[0007] (2) Based on the extended domain data and the source domain data, randomized parameters are introduced simultaneously to obtain the intermediate domain data as a transition between the two;
[0008] (3) Use the discriminator to process the extended domain data and calculate the extended domain cross entropy loss L based on its output ED ; At the same time, the source domain data is used as positive samples, the extended domain and intermediate domain data are used as negative samples, and the generator intra-class supervision contrast loss L is calculated adv , combined with L ED With L adv Construct the overall loss function L of the generator g , used to optimize the extended domain generator;
[0009] (4) Use the source domain, extended domain, and intermediate domain data to calculate their corresponding cross entropy losses L respectively SD , L ED , L ID ; Take the same category as positive samples and different categories as negative samples, and calculate the inter-class supervision contrast loss L of the discriminator sup ; Align the image features with the text features generated by their corresponding categories, and calculate the text image contrast loss L of the source domain, extended domain, and intermediate domain respectively SDIT , L EDIT , L IDIT , combining cross entropy loss, discriminator inter-class supervision contrast loss and text image contrast loss to construct the overall loss function L of the discriminator D , used to optimize the discriminator;
[0010] (5) Use the extended domain generator and discriminator to build a classification model. Use the loss functions constructed in steps (3) and (4) to optimize the extended domain generator and discriminator in the model respectively to achieve model optimization training. Use the trained model to classify the target scene to obtain the final classification result.
[0011] Compared with the prior art, the present invention has the following advantages:
[0012] First, the present invention effectively combines the advantages of convolutional networks and Transformer network design generators for data enhancement, which can not only effectively utilize the spatial information of hyperspectral images, but also fully learn the spectral information of hyperspectral images.
[0013] Second, the present invention integrates the domain alignment method of text-image alignment with supervised contrastive learning into a unified framework, performs image feature alignment from different perspectives, and effectively improves the generalization performance of the discriminator model for target scene classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 Flow chart for realizing the method of the present invention;
[0015] Figure 2 It is the overall model framework diagram of the method of the present invention;
[0016] Figure 3 It is a structural diagram of a generator of the method of the present invention;
[0017] Figure 4 Pseudo-color image and true value image of the Pavia dataset used in this invention;
[0018] Figure 5 Pseudo-color image and true value image of the HyRANK data set used in the present invention;
[0019] Figure 6 The pseudo-color image and true value image of the Houston dataset used in the present invention;
[0020] Figure 4-Figure 6 In the figure, (a) is the pseudo-color image of the source scene, (b) is the true value image of the source scene, (c) is the pseudo-color image of the target scene, and (d) is the true value image of the target scene;
[0021] Figure 7 This is a comparison chart of the classification results of the method of the present invention and the mainstream method on the Pavia dataset;
[0022] Figure 8 This is a comparison chart of the classification results of the method of the present invention and the mainstream method on the HyRANK data set;
[0023] Fig. 9This is a comparison chart of the classification results of the method of the present invention and the mainstream method on the Houston dataset. DETAILED DESCRIPTION
[0024] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0025] Example 1: Reference Figure 1 The present invention proposes a cross-scene hyperspectral image classification method based on domain generalization, which is implemented in the following steps:
[0026] Step A. Combine the convolutional network with the Transformer network and introduce a feature randomization process to construct an extended domain generator consisting of a convolutional layer, a linear transformation layer, a Transformer encoding layer, an inverse linear transformation layer, and a deconvolution layer to generate extended domain data. This embodiment generates extended domain data according to the following steps:
[0027] (a1) The cut hyperspectral image X∈R s×s×d Input a 2D convolution with a kernel size of 1×1 to obtain a 3D feature matrix Where s represents the size of the image spatial dimension, d represents the size of the image spectral dimension, dim1 represents the output channel of the convolution, the step size is 1, and there is no padding;
[0028] (a2) Perform a linear transformation on X1 to obtain the feature token T∈R wz :
[0029] T=softmax(X1W a ) T (X1W v )
[0030] in, and Respectively, they represent the weight matrices of dim1×w and dim1×z dimensions initialized with Gaussian distribution, w represents the number of tokens, and z represents the embedding dimension of each token;
[0031] (a3) For feature token T = [T1, T2, ..., T w ] and a learnable classification tag Connected together, the tag is used to perform the classification task and the position information PE pos Appended to the token representation, we get the input T of the Transformer encoding module in , the process is obtained by the following formula:
[0032]
[0033] (a4) T inInput the Transformer encoding block. In the multi-head self-attention mechanism, the input is mapped into the query matrix Q, the key matrix K, and the value matrix V through multiple sets of learnable weight matrices. The attention scores are calculated separately, and then multiple attention scores are concatenated to obtain the multi-head attention score. This process is obtained by the following formula:
[0034] head i =Attention(QW i Q ,KW i K ,VW i V )
[0035] MultiHead(Q,K,V)=Concat(head1,...,head h )W O
[0036] Among them, head i represents the attention value of the i-th head, W i Q , W i K and W i V They are the learnable query parameter matrix, the learnable key parameter matrix, and the learnable value parameter matrix, W O is the weight matrix;
[0037] (a5) The output z of the Transformer encoding block is obtained through regularization and MLP layer;
[0038] (a6) Introducing randomness into the features modeled by spatial-spectral features, the formula is obtained:
[0039]
[0040]
[0041]
[0042]
[0043]
[0044] Among them, S represents the number of spatial pixels, C represents the number of spectral channels, μ and σ represent the mean and standard deviation, Represents the randomly generated features, Represents the feature z after randomization R ;
[0045] (a7) The feature z is transformed by the inverse linear transformation R Mapped into a three-dimensional feature matrix
[0046]
[0047] (a8) After a deconvolution of X2, the generated extended domain data X is obtained. ED .
[0048] Step B: Based on the extended domain data and the source domain data, randomization parameters are introduced at the same time to obtain the intermediate domain data X as the transition between the two. ID :
[0049] X ID =ωX+(1-ω)X ED
[0050] Among them, X SD represents the source domain data, X ED represents the extended domain data, and ω is a random initialization parameter.
[0051] Step C. Use the discriminator to process the extended domain data and calculate the extended domain cross entropy loss L for its output ED ; At the same time, the source domain data is used as positive samples, the extended domain and intermediate domain data are used as negative samples, and the generator intra-class supervision contrast loss L is calculated adv , combined with L ED With L adv Construct the overall loss function L of the generator g , used to optimize the extended domain generator;
[0052] The discriminator is a two-layer Conv2d-ReLU-MaxPool2d structure, followed by two fully connected layers, and finally two forked fully connected layers represent the image feature extraction layer and the classification projection layer respectively.
[0053] Step D: Use the source domain, extended domain, and intermediate domain data to calculate their corresponding cross entropy losses L respectively SD , L ED , L ID ; Take the same category as positive samples and different categories as negative samples, and calculate the inter-class supervision contrast loss L of the discriminator sup ; Align the image features with the text features generated by their corresponding categories, and calculate the text image contrast loss L of the source domain, extended domain, and intermediate domain respectively SDIT , L EDIT , L IDIT , combining cross entropy loss, discriminator inter-class supervision contrast loss and text image contrast loss to construct the overall loss function L of the discriminator D , used to optimize the discriminator;
[0054] Step E. Use the extended domain generator and discriminator to build a classification model. Use the loss functions constructed in steps (3) and (4) to optimize the extended domain generator and discriminator in the model respectively to achieve model optimization training. Use the trained model to classify the target scene to obtain the final classification result.
[0055] The method of using an extended domain generator and a discriminator to construct a classification model is specifically as follows: first, the extended domain generator is used to expand the source domain data to obtain intermediate domain data and extended domain data, and then the source domain, intermediate domain and extended domain data are input into the discriminator, and the loss is calculated using the classification result and image features obtained by the discriminator and the text features corresponding to the source domain, intermediate domain and extended domain data, and finally the obtained loss is used to train and optimize the extended domain generator and the discriminator.
[0056] The loss functions constructed by steps (3) and (4) respectively optimize the extended domain generator and the discriminator in the model by setting the number of iterations, batch size, hyperparameters and learning rate, and using the Adam optimizer; the final classification result is obtained by using the trained model to classify the target scene through the image feature extraction layer and the classification projection layer in the discriminator, and outputting the probability that each pixel belongs to each category, that is, the classification result.
[0057] The above optimization of the extended domain generator in the model is implemented as follows:
[0058] lm g =L ED +βL adv
[0059]
[0060]
[0061] Among them, N represents the total number of samples, X represents the output result of the classification projection layer, Y represents the true label, and x EDn represents the nth sample in the extended domain, y n Represents x EDn The true label, L ce represents the cross entropy loss of a single sample, and C represents the predicted x EDn The category to which it belongs; F represents the cosine similarity, z k represents the kth sample in the cth class sample, Indicates the source domain with z k Other samples of the same category; Indicates the middle domain or extended domain with z k Samples of the same category, n crepresents the number of samples of the cth category in the source domain, P c (k) and A c (k) represents the positive and negative sample sets of the c-th class of samples, respectively, and τ represents the control parameter in the logarithmic range.
[0062] The above optimization of the discriminator in the model is implemented as follows:
[0063]
[0064]
[0065]
[0066]
[0067]
[0068] Among them, J represents the number of all samples in the source domain, the intermediate domain, and the extended domain, and x n represents the nth sample in the source domain, x IDn represents the nth sample in the intermediate domain, and C represents the predicted x EDn Category of loss I and loss T Represent the cross entropy loss of image features and text features respectively, represents the jth sample among all samples in the source domain, intermediate domain, and extended domain, Indicates the source domain, intermediate domain, and extended domain The rest of the samples in the same category, Indicates the source domain, intermediate domain, and extended domain For the remaining samples of different categories, P(j) and A(j) represent Positive and negative sample sets; y n Represents x EDn The real label.
[0069] The present invention effectively combines the advantages of convolutional networks and Transformer network design generators for data enhancement, which can not only effectively utilize the spatial information of hyperspectral images, but also fully learn the spectral information of hyperspectral images. In addition, the discriminator is optimized by effectively combining domain alignment and supervised contrastive learning. By integrating the domain alignment method of text image alignment with supervised contrastive learning into a unified framework, image feature alignment is performed from different angles, thereby improving the generalization performance of the model for target scene classification.
[0070] Embodiment 2: The cross-scene hyperspectral image classification method proposed in this embodiment has the same overall implementation steps as embodiment 1. Figure 2 and 3The implementation process of the present invention is further described in detail:
[0071] Step 1. Build a generator based on convolutional network and Transformer network:
[0072] First, in order to extract the spatial features of the hyperspectral image, the segmented hyperspectral image X∈R s×s×d Input a 2D convolution with a kernel size of 1×1, and we get The three-dimensional feature matrix of dim1 represents the output channel of the convolution, with a stride of 1 and no padding.
[0073] The three-dimensional features extracted by convolution operation are not enough to fully describe the characteristics of hyperspectral images. In order to input the features into the Transformer network for spectral feature extraction, a linear transformation is performed on X1 to obtain the feature token T∈R wz , the transformation process is obtained by the following formula:
[0074] T=softmax(X1W a ) T (X1W v )
[0075] in, and represents the weight matrix initialized with Gaussian distribution, w represents the number of tokens, z represents the embedding dimension of each token, and then X1 and W a Perform a 1×1 dot product to map X1 to the semantic group, then transpose it, use the softmax function to focus on the important semantics, and finally combine it with (X1W v ) are multiplied to obtain the feature token T.
[0076] For feature tokens T = [T1, T2, ..., T w ], and a learnable classification label T0 cls Connected together, the tag is used to perform the classification task and the position information PE pos Appended to the token representation, we get the input T of the Transformer encoding module in ; Next, T inInput the Transformer encoding block. In the multi-head self-attention mechanism, the input is mapped into Q, K, and V matrices through multiple sets of learnable weight matrices, and the attention scores are calculated respectively. Then, multiple attention scores are concatenated to obtain multi-head attention scores. In order to make the generated extended data more diverse, randomness is introduced for the features modeled by spatial-spectral features, so as to avoid the generated data being too dependent on the style features of the original data, and better capture and represent the diversity of data, which helps the model better generalize and adapt to input data of different styles. Then, the feature z is transformed into R Mapped into a three-dimensional feature matrix This process can be obtained by the following formula:
[0077]
[0078] Finally, after a deconvolution, the generated extended domain data X is obtained. ED , the input and output channels of this deconvolution are opposite to those of the generator's initial two-dimensional convolution, and the rest are the same.
[0079] Step 2. Generate intermediate domain data:
[0080] Introducing the randomization parameter ω, using the extended domain data X ED and the source domain data X to obtain the intermediate domain data X ID , the process is obtained by the following formula:
[0081] X ID =ωX+(1-ω)X ED
[0082] Step 3. Optimize the generator:
[0083] First, in order to ensure that the generated extended domain data is in the correct label space, that is, the validity of the generated data, and to prevent the generator from generating wrong data and causing the discriminator to produce wrong feature divisions, the cross entropy classification loss of the extended domain data is used as the auxiliary loss for generator optimization. The calculation formula is as follows:
[0084]
[0085] Where L ce is the cross entropy loss function, and its calculation formula is as follows:
[0086]
[0087] Secondly, in order to allow the generator to learn the specific information about the domain contained in a specific category, intra-class comparison learning is introduced. Specifically, for the cth category, the expression of the contrast loss is:
[0088]
[0089] Among them, n c Represents the number of samples of the cth category. The samples of the cth category in the source domain data are used as the positive sample set and P c (i) indicates that in each iteration, we randomly select the cth sample in the extended domain data or the intermediate domain data as the negative sample set A. c (i) represents, and the positive sample set and the negative sample set are marked with pseudo labels 0 and -1 respectively. In the process of optimizing the generator, the generated extended domain samples and the source domain samples of the same category can be separated from each other in the feature space, so that the discriminator cannot easily distinguish the samples by extracting domain invariant information, and can effectively distinguish the features of different categories from multiple domains, so that the generalization ability of the model is better.
[0090] Finally, the overall optimization loss function calculation expression of the generator is as follows:
[0091] lm g =L ED +βL adv
[0092] where β is a hyperparameter that balances the intra-class supervised contrastive loss and the cross entropy loss.
[0093] Step 4. Optimize the discriminator:
[0094] First, in order for the classification head of the discriminator to effectively distinguish different categories and make more accurate predictions on the target domain data in the test phase, the sum of the three cross entropy classification losses of the source domain, the extended domain, and the intermediate domain is used as the overall classification loss. The extended domain and intermediate domain data corresponding to the source domain data have the same label as the source domain data. The label is used to calculate the entire cross entropy loss. The calculation expression is as follows:
[0095]
[0096]
[0097] Secondly, the language features extracted by the text encoder are projected into the semantic space to construct a cross-domain shared space to learn domain-invariant representations. In the same batch, the data samples of the source domain, the extended domain, and the intermediate domain are respectively combined with the text of the corresponding category to form image-text pairs. By aligning the visual features with the text features in the shared space, the visual features of the same category can be aggregated in a closer semantic space. The image-text alignment loss function is expressed as follows:
[0098]
[0099]
[0100]
[0101] Among them, loss i and loss t are the cross entropy losses of image features and text features respectively, softmax(s[:,j]) converts the model output into a probability distribution, and labels are the true labels.
[0102] Similarly, the text-image contrast loss L of the extended domain and the intermediate domain can be calculated EDIT (X ED ) and L IDIT (X ID ).
[0103] Then, in order to further make the features of the same category extracted by the discriminator closer, supervised contrastive learning is introduced to encourage the discriminator to distinguish samples by category. Finally, the overall optimization loss function calculation expression of the discriminator is as follows:
[0104]
[0105]
[0106] Among them, α1 and α2 are hyperparameters that balance the supervised contrast loss and the image-text alignment loss, L sup is the intra-class supervised contrast loss.
[0107] Step 5. Hyperspectral image classification:
[0108] After the optimization process is completed, the hyperspectral image X of the target scene is sent to the trained discriminator, and the classification result is output through the feature extraction module and the classification projection head. Finally, the softmax function is used to obtain the final classification result of each pixel.
[0109] Embodiment 3: The overall implementation steps of the cross-scene hyperspectral image classification method proposed in this embodiment are the same as those of Embodiments 1 and 2. Now, given specific parameter settings, how to use the method of the present invention to achieve classification is further described by example:
[0110] Step 1): In order to build an effective generator, the parameters are set as follows: the input and output channels of the first convolution layer are the number of bands of the input hyperspectral image and 128, and the convolution kernel size is 1×1; the dimension of the feature token generated during the linear transformation is 4×64; the number of attention heads in the Transformer encoding block is 8, and the dimension of the attention vector is 64; the input and output channels in the final deconvolution are 128 and the number of bands of the input hyperspectral image.
[0111] Step 2): Introduce the randomization parameter ω and use the extended domain data XED and the source domain data X to obtain the intermediate domain data X ID .
[0112] Step 3): Use the Adam optimizer to optimize the generator, set the learning rate to 0.001, set the hyperparameter β for balancing the intra-class supervised contrast loss and the cross entropy loss to 0.1, use CrossEntropyLoss as the cross entropy loss function, and use SupConLoss as the supervised contrast loss function.
[0113] Step 4): The discriminator is optimized using the Adam optimizer, the learning rate is set to 0.001, and the hyperparameters α1 and α2 that balance the supervised contrast loss and the image-text alignment loss are set to 1.0 and 1.0.
[0114] Step 5): Before classifying the target scene, the model needs to be trained and optimized. The present invention uses the following three data sets (a)-(c) for training and optimization:
[0115] (a) Pavia dataset: pseudo-color images and true value images Figure 4 The ground feature coverage information is shown in Table 1.
[0116] Table 1 Pavia land cover information
[0117]
[0118] (b) HyRANK dataset: pseudo-color image and true value image Figure 5 The ground feature coverage information is shown in Table 2.
[0119] Table 2 HyRANK ground feature coverage information
[0120]
[0121] (c) Houston dataset: pseudo-color images and true value images Figure 6 The ground feature coverage information is shown in Table 3.
[0122] Table 3 Houston land cover information
[0123]
[0124]
[0125] During the training process, the batch size is set to 128, the number of iterations is set to 400, and the text encoder uses the ViT-B-32.pt model pre-trained by CLIP. For the Pavia and Houston datasets, 80% of the labeled data in the source domain are randomly selected as the training set, while in the HyRANK dataset, only 5% of the labeled data in the source domain are selected as the training set. All the labeled data in the target domain of the three datasets are used as the test set. The source domain scenes are PaviaU, Dioni, and Houston13, and the target scenes are PaviaC, Loukia, and Houston18. The classification results of the target scenes are shown in Figure 2. Figure 8 , Fig. 9 As shown in MDFAnet.
[0126] The effect of the present invention will be further described below in conjunction with experiments.
[0127] 1. Experimental conditions:
[0128] The hardware platform of the simulation experiment of the present invention includes: the core processor is Intel(R) Core(TM)-i5-12600K, and the graphics card is NVIDIA TITAN Xp.
[0129] The software platform of the simulation experiment of the present invention: CUDA version is 12.2, Python version is 3.7.16, PyTorch version is 1.13.1, and the operating system is Ubuntu 18.04LTS.
[0130] 2. Experimental content:
[0131] This experiment evaluates the classification performance of the method of the present invention on the Houston, Pavia and HyRANK datasets. On each dataset, the classification effects of the method of the present invention and eight mainstream methods are compared from three perspectives: average classification accuracy, overall classification accuracy and Kappa coefficient.
[0132] Among them, the mainstream methods mainly include DAAN [Paper: Transfer Learning with Dynamic Adversarial Adaptation Network], MRAN [Paper: Multi-Representation Adaptation Network for Cross-Domain Image Classification], DSAN [Paper: Deep Subdomain Adaptation Network for Image Classification], HTCNN [Paper: Heterogeneous Transfer Learning for Hyperspectral Image Classification Based on Convolutional Neural Network], PDEN [Paper: Progressive Domain Expansion Networkfor Single Domain Generalization], SDEnet [Paper: Single-Source Domain Expansion Network for Cross-Scene Hyperspectral Image Classification], LDGnet [Paper: Language-Aware Domain Generalization Network for Cross-Scene Hyperspectral Image Classification] and LLURnet [Paper: Locally Linear Unbiased Randomization Network for Cross-Scene Hyperspectral Image Classification].
[0133] 3. Simulation results and analysis:
[0134] Figure 7 to Figure 9 The comparison diagram of the classification results of the method of the present invention and the mainstream method on three public data sets, where MDFAnet represents the classification result diagram of the method of the present invention, and gt-map represents the true label. Tables 4 to 6 list the average classification accuracy AA, overall classification accuracy OA, and Kappa coefficient KC of the method of the present invention and the mainstream method on the three data sets.
[0135] Table 4 Classification results of the proposed method and mainstream methods on the Houston dataset
[0136]
[0137] Table 5 Classification results of the proposed method and mainstream methods on the Pavia dataset
[0138]
[0139] Table 6 Classification results of the method of the present invention and the mainstream method on the HyRANK dataset
[0140]
[0141]
[0142] It can be seen from the above results that in the three target scenes, the MDFAnet algorithm proposed in the present invention obtains the best classification results. The present invention proposes a generator model combining convolution and Transformer, which makes full use of the spatial and spectral information of hyperspectral images, and generates more diverse extended domain data through the reconstruction of spectral and spatial features. In addition, the cross-domain invariant representation is learned through text image alignment to ensure the recognition performance of the discriminator for cross-domain objects of the same category. In the Houston18 scene, the overall accuracy of the MDFAnet algorithm is slightly improved. The possible reason is that the Houston dataset only contains 48 spectral bands and less spectral information is available. This result reflects from the side that the MDFAnet algorithm effectively utilizes spectral information when the spectral information is sufficient.
[0143] The above experimental results prove the correctness and effectiveness of the method proposed in the present invention.
[0144] Parts of the present invention that are not described in detail belong to common knowledge among those skilled in the art.
[0145] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Obviously, for professionals in this field, after understanding the content and principles of the present invention, they may make various modifications and changes in form and details without departing from the principles and structures of the present invention. However, these modifications and changes based on the ideas of the present invention are still within the scope of protection of the claims of the present invention.
Claims
1. A cross-scene hyperspectral image classification method based on domain generalization, characterized in that: The steps are as follows: (1) Combining the convolutional network with the Transformer network and introducing the feature randomization process, an extended domain generator consisting of a convolutional layer, a linear transformation layer, a Transformer encoding layer, an inverse linear transformation layer, and a deconvolution layer is constructed to generate extended domain data; (2) Based on the extended domain data and the source domain data, randomized parameters are introduced simultaneously to obtain the intermediate domain data as a transition between the two; (3) Use the discriminator to process the extended domain data and calculate the extended domain cross entropy loss L based on its output ED ; At the same time, the source domain data is used as positive samples, the extended domain and intermediate domain data are used as negative samples, and the generator intra-class supervision contrast loss L is calculated adv , combined with L ED With L adv Construct the overall loss function L of the generator g , used to optimize the extended domain generator; (4) Use the source domain, extended domain, and intermediate domain data to calculate their corresponding cross entropy losses L respectively SD , L ED , L ID ; Take the same category as positive samples and different categories as negative samples, and calculate the inter-class supervision contrast loss L of the discriminator sup ; Align the image features with the text features generated by their corresponding categories, and calculate the text image contrast loss L of the source domain, extended domain, and intermediate domain respectively SDIT , L EDIT , L IDIT , combining cross entropy loss, discriminator inter-class supervision contrast loss and text image contrast loss to construct the overall loss function L of the discriminator D , used to optimize the discriminator; (5) Use the extended domain generator and discriminator to build a classification model. Use the loss functions constructed in steps (3) and (4) to optimize the extended domain generator and discriminator in the model respectively to achieve model optimization training. Use the trained model to classify the target scene to obtain the final classification result.
2. The method according to claim 1, characterized in that: The extended domain generator in step (1) generates extended domain data specifically according to the following steps: (1.1) The cut hyperspectral image X∈R s×s×d Input a two-dimensional convolution with a kernel size of 1×1 to obtain a three-dimensional feature matrix X1∈R s×s×dim1 , where s represents the size of the image space dimension, d represents the size of the image spectral dimension, dim1 represents the output channel of the convolution, the step size is 1, and there is no padding; (1.2) Perform a linear transformation on X1 to obtain the feature token T∈R wz : T=softmax(X1W a ) T (X1W v ) in, and Respectively, they represent the weight matrices of dim1×w and dim1×z dimensions initialized with Gaussian distribution, w represents the number of tokens, and z represents the embedding dimension of each token; (1.3) For feature token T = [T1, T2, ..., T w ] and a learnable classification tag Connected together, the tag is used to perform the classification task and the position information PE pos Appended to the token representation, we get the input T of the Transformer encoding module in , the process is obtained by the following formula: (1.4) T in Input the Transformer encoding block. In the multi-head self-attention mechanism, the input is mapped into the query matrix Q, the key matrix K, and the value matrix V through multiple sets of learnable weight matrices. The attention scores are calculated separately, and then multiple attention scores are concatenated to obtain the multi-head attention score. This process is obtained by the following formula: MultiHead(Q,K,V)=Concat(head1,...,head h )W O Among them, head i represents the attention value of the i-th head, and They are the learnable query parameter matrix, the learnable key parameter matrix, and the learnable value parameter matrix, W O is the weight matrix; (1.5) Obtain the output z of the Transformer encoding block through regularization and MLP layer; (1.6) Introducing randomness into the features modeled by spatial-spectral features, the formula is obtained: Among them, S represents the number of spatial pixels, C represents the number of spectral channels, μ and σ represent the mean and standard deviation, Represents the randomly generated features, Represents the feature z after randomization R ; (1.7) The feature z is transformed by the inverse linear transformation R Mapped into a three-dimensional feature matrix (1.8) After a deconvolution of X2, the generated extended domain data X is obtained. ED .
3. The method according to claim 1, characterized in that: The intermediate domain data in step (2) is generated according to the following formula: X ID =ωX+(1-ω)X ED Among them, X ID Indicates the intermediate domain data, X SD represents the source domain data, X ED represents the extended domain data, and ω is a random initialization parameter.
4. The method according to claim 1, characterized in that: The discriminator described in step (3) is a two-layer Conv2d-ReLU-MaxPool2d structure, which is then connected to two fully connected layers, and finally consists of two forked fully connected layers representing the image feature extraction layer and the classification projection layer respectively.
5. The method according to claim 4, characterized in that: The overall loss function L of the generator in step (3) g , as follows: L g =L ED +βL adv Here, β represents a hyperparameter that balances the cross entropy loss and the supervised contrast loss.
6. The method according to claim 1, characterized in that: The overall loss function L of the discriminator in step (4) is D , as follows: Among them, α1 and α2 represent the hyperparameters for balancing the cross entropy loss and the text and image contrast losses, respectively.
7. The method according to claim 1, characterized in that: In step (5), the extended domain generator and the discriminator are used to construct a classification model. Specifically, the extended domain generator is first used to expand the source domain data to obtain the intermediate domain data and the extended domain data. The source domain, intermediate domain and extended domain data are then input into the discriminator. The loss is calculated using the classification results and image features obtained by the discriminator and the text features corresponding to the source domain, intermediate domain and extended domain data. Finally, the obtained loss is used to train and optimize the extended domain generator and the discriminator.
8. The method according to claim 7, characterized in that: The loss functions constructed by steps (3) and (4) respectively optimize the extended domain generator and the discriminator in the model by setting the number of iterations, batch size, hyperparameters and learning rate, and using the Adam optimizer; the final classification result is achieved by using the trained model to classify the target scene through the image feature extraction layer and classification projection layer in the discriminator, and outputting the probability that each pixel belongs to each category.
9. The method according to claim 8, characterized in that: The extended domain generator in the model is optimized as follows: minL g =L ED +βL adv Among them, N represents the total number of samples, X represents the output result of the classification projection layer, Y represents the true label, and x EDn represents the nth sample in the extended domain, y n Represents x EDn The true label, L ce represents the cross entropy loss of a single sample, and C represents the predicted x EDn The category to which it belongs; F represents the cosine similarity, z k represents the kth sample in the cth class sample, Indicates the source domain with z k Other samples of the same category; Indicates the middle domain or extended domain with z k Samples of the same category, n c represents the number of samples of the cth category in the source domain, P c (k) and A c (k) represents the positive and negative sample sets of the c-th class samples, respectively, and τ represents the control parameter in the logarithmic range.
10. The method according to claim 8, characterized in that: The discriminator in the model is optimized as follows: Among them, J represents the number of all samples in the source domain, the intermediate domain, and the extended domain, and x n represents the nth sample in the source domain, x IDn represents the nth sample in the intermediate domain, and C represents the predicted x EDn Category of loss I and loss T Represent the cross entropy loss of image features and text features respectively, represents the jth sample among all samples in the source domain, intermediate domain, and extended domain, Indicates the source domain, intermediate domain, and extended domain The rest of the samples in the same category, Indicates the source domain, intermediate domain, and extended domain For the remaining samples of different categories, P(j) and A(j) represent Positive and negative sample sets; y n Represents x EDn The real label.
Citation Information
Cited By
Tamarix chinensis identification method based on attention mechanism and feature alignment
CN119723339A
