A small sample hyperspectral image classification method and system based on lightweight transform
Patent Information
- Application Number
- CN202611275793.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-21
- Publication Date
- 2026-10-30
AI Technical Summary
[0005]本发明实施例提供一种基于轻量化Transformer的小样本高光谱图像分类方法及系统,能够解决现有技术中小样本高光谱图像分类依赖局部特征提取、模型复杂度过高、训练稳定性差,在每类样本数量较少的极端条件下无法实现高精度、高鲁棒性分类的问题
[0011]本发明提供的方法通过构建包含输入投影模块、位置编码模块、Transformer编码器模块、特征聚合模块及分类头模块的轻量化Transformer模型,并按照特征投影、位置编码、全局与局部特征提取、多特征融合及余弦相似度计算的流程完成模型构建,能够在降低模型复杂度的同时,充分捕捉高光谱数据的全局关联与局部结构信息,提升小样本场景下的特征表达能力与分类可靠性。
Smart Images

Figure CN123016083A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hyperspectral image processing and pattern recognition technology, and in particular to a small-sample hyperspectral image classification method and system based on a lightweight Transformer. Background Technology
[0002] Hyperspectral images simultaneously carry detailed spectral and spatial structural information, making them valuable for applications in remote sensing monitoring, agricultural yield estimation, and environmental surveys. However, in practical engineering scenarios, limitations such as the cost of ground feature annotation and the difficulty of sample acquisition mean that large amounts of hyperspectral data can only provide a very small number of labeled samples. Therefore, high-precision classification under small sample conditions has become a key technical requirement in the field of hyperspectral image processing.
[0003] Existing technologies often employ deep learning models to classify hyperspectral images. Among them, the method based on convolutional neural networks extracts spectral-spatial features through local receptive fields and enhances small-sample adaptability by combining simple data augmentation, which is the current mainstream implementation method for small-sample hyperspectral classification.
[0004] Existing methods based on convolutional neural networks rely on local feature extraction. When the sample size is extremely scarce, the feature representation ability drops significantly. The model is prone to overfitting and training oscillations. It cannot stably output high-precision classification results under extremely small sample conditions (e.g., only a dozen or so samples per class), making it difficult to meet the dual requirements of classification accuracy and model reliability in practical engineering. Summary of the Invention
[0005] This invention provides a method and system for classifying small-sample hyperspectral images based on a lightweight Transformer. It can solve the problems of existing technologies where small-sample hyperspectral image classification relies on local feature extraction, has excessively high model complexity, poor training stability, and cannot achieve high-precision and robust classification under extreme conditions where the number of samples in each class is small.
[0006] To achieve the above objectives, the embodiments of the present invention adopt the following technical solutions: Firstly, a method for classifying few-sample hyperspectral images based on a lightweight Transformer is provided, comprising: acquiring a hyperspectral data cube; preprocessing the hyperspectral data cube to obtain a sequence of spectral spatial feature blocks; dividing the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples; training the lightweight Transformer model according to the training set, a data augmentation strategy, and an optimized training strategy to obtain a trained classification model; acquiring the target hyperspectral image to be classified; and using the trained classification model to perform inference to obtain the final classification result of the hyperspectral image.
[0007] The method provided by this invention obtains a sequence of spectral spatial feature blocks by preprocessing a hyperspectral data cube, divides the dataset according to a preset number of samples, trains the model based on the training set and corresponding strategies, and finally infers the classification result from the hyperspectral image of the target to be classified. It constructs a complete process from small sample hyperspectral data input to final classification output, which can be adapted to small sample learning scenarios and achieve efficient and stable classification of hyperspectral images, providing a complete and feasible technical path for hyperspectral image processing under extremely small sample conditions.
[0008] In one possible implementation of the first aspect, the preprocessing of the hyperspectral data cube to obtain a spectral spatial feature block sequence includes: normalizing the mean and standard deviation of the spectral dimension of the hyperspectral data cube to obtain a normalized hyperspectral data cube; expanding the boundary of the normalized hyperspectral data cube using a reflection filling method to obtain an expanded data cube; extracting spectral spatial feature blocks centered on the target pixel from the expanded data cube according to a preset spatial size, and flattening the three-dimensional feature blocks into a one-dimensional sequence to obtain a spectral spatial feature block sequence.
[0009] The method provided by this invention performs spectral dimension mean and standard deviation normalization, reflection filling boundary expansion, preset size feature block extraction and flattening on a hyperspectral data cube in sequence. This can standardize the distribution of hyperspectral data, avoid incomplete edge pixel feature extraction, effectively fuse spectral features and spatial context information, suppress spectral noise interference, provide high-quality and standardized feature sequences for subsequent model input, and improve the accuracy and stability of model feature extraction.
[0010] In one possible implementation of the first aspect, the lightweight Transformer model includes an input projection module, a position encoding module, a Transformer encoder module, a feature aggregation module, and a classification head module. The construction process of the lightweight Transformer model includes: inputting the spectral space feature block sequence into the input projection module, obtaining low-dimensional projection features through feature mapping and nonlinear transformation; inputting the low-dimensional projection features into the position encoding module, adding category tokens and position embedding information to obtain a feature sequence with position information; inputting the feature sequence with position information into the Transformer encoder module, extracting global and local features through multi-layer self-attention and feedforward networks; inputting the global and local features into the feature aggregation module, fusing global semantic features and local statistical features to obtain a comprehensive feature vector; and inputting the comprehensive feature vector into the classification head module, obtaining the model's classification output through cosine similarity calculation.
[0011] The method provided by this invention constructs a lightweight Transformer model that includes an input projection module, a position encoding module, a Transformer encoder module, a feature aggregation module, and a classification head module. The model is constructed by following the process of feature projection, position encoding, global and local feature extraction, multi-feature fusion, and cosine similarity calculation. This method can reduce model complexity while fully capturing the global correlation and local structural information of hyperspectral data, thereby improving the feature expression ability and classification reliability in small sample scenarios.
[0012] In one possible implementation of the first aspect, the Transformer encoder module consists of multiple lightweight Transformer blocks. The Transformer blocks adopt a pre-normalized architecture, include a multi-head self-attention mechanism and a feedforward network, and both the feedforward network and the self-attention mechanism are configured with random deactivation regularization operations.
[0013] The method provided by this invention employs an encoder module composed of multiple lightweight Transformer blocks, with the Transformer blocks using a pre-normalized architecture, combined with a multi-head self-attention mechanism, a feedforward network, and random deactivation regularization operations. This ensures the stability of model training, suppresses overfitting problems that are prone to occur in few-shot learning, and maintains efficient feature extraction capabilities while reducing the number of model parameters, thus balancing model lightweighting and classification performance.
[0014] In one possible implementation of the first aspect, dividing the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples includes: performing balanced sampling of the spectral spatial feature block sequence according to the land cover category to obtain a sample set corresponding to each category; selecting a specified number of samples from each category sample set as the training set and the validation set according to the preset number of samples; and determining the remaining samples as the test set to complete the division of the dataset under the condition of small sample size.
[0015] The method provided by this invention performs balanced sampling of spectral spatial feature block sequences according to land cover categories, selects training and validation sets based on a preset number of samples, and uses the remaining samples as a test set. This ensures that the distribution of each category in the dataset is balanced, strictly adapts to the sample number constraint of small sample learning, avoids model classification bias caused by sample imbalance, and improves the rationality of dataset partitioning and the effectiveness of model training under small sample conditions.
[0016] In one possible implementation of the first aspect, training the lightweight Transformer model based on the training set, data augmentation strategy, and optimization training strategy includes: performing data augmentation on the samples in the training set using a mixup and cutmix approach to obtain augmented training samples; calculating the model loss value using the label smooth cross-entropy loss function based on the augmented training samples; and updating the model parameters using the AdamW optimizer combined with gradient clipping, learning rate warm-up, and early stopping mechanisms based on the model loss value to obtain the trained classification model.
[0017] The method provided by this invention expands the diversity of training samples by adopting a mixed data augmentation strategy of Mixup and CutMix, calculates the model loss using the label smooth cross-entropy loss function, and completes parameter updates by combining the AdamW optimizer, gradient clipping, learning rate warm-up and early stopping mechanism. It can effectively alleviate the problems of model overfitting and training instability under small sample size, accelerate the model convergence speed, and improve the generalization ability and robustness of the trained classification model.
[0018] In one possible implementation of the first aspect, the step of using the trained classification model to perform inference to obtain the final classification result of the hyperspectral image includes: preprocessing the target hyperspectral image to be classified to obtain a corresponding spectral spatial feature block sequence; inputting the spectral spatial feature block sequence into the trained classification model to obtain an initial classification result; and performing probability fusion and decision on the initial classification result to obtain the final classification result of the hyperspectral image.
[0019] The method provided by this invention obtains the corresponding feature block sequence by performing the same preprocessing as the training phase on the hyperspectral image of the target to be classified. After obtaining the initial classification result through model inference, probability fusion and decision are then performed. This ensures that the feature processing logic of the inference process is consistent with that of the training process, improves the credibility and accuracy of the classification result, and achieves stable and accurate classification of hyperspectral images with small samples.
[0020] Secondly, this invention provides a small-sample hyperspectral image classification system based on a lightweight Transformer, comprising: an acquisition unit for acquiring a hyperspectral data cube and preprocessing the hyperspectral data cube to obtain a spectral spatial feature block sequence; a partitioning unit for partitioning the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples; a training unit for training the lightweight Transformer model according to the training set, a data augmentation strategy, and an optimization training strategy to obtain a trained classification model; and a classification unit for acquiring the target hyperspectral image to be classified, performing inference using the trained classification model, and obtaining the final classification result of the hyperspectral image.
[0021] Thirdly, an electronic device is provided, the electronic device including a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, which, when executed by the processor, cause the electronic device to perform the method as described in any implementation of the first aspect.
[0022] Fourthly, a computer-readable storage medium is provided, including computer instructions that, when executed on an electronic device, cause the electronic device to perform a method as described in any implementation of the first aspect.
[0023] Fifthly, a computer program product is provided that, when run on a computer, causes the computer to perform the method in any implementation of the first aspect.
[0024] Understandably, the beneficial effects achieved by the system of the second aspect, the electronic device of the third aspect, the computer-readable storage medium of the fourth aspect, and the computer program product of the fifth aspect provided above can be referred to with reference to the beneficial effects of the first aspect and any of its possible design embodiments, which will not be repeated here. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention; Figure 2 A flowchart of a small-sample hyperspectral image classification method based on a lightweight Transformer is provided for embodiments of the present invention; Figure 3 A schematic diagram of the structure of a lightweight Transformer model provided in an embodiment of the present invention; Figure 4 A schematic diagram of a data augmentation strategy provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the system architecture of a classification system provided in an embodiment of the present invention. Detailed Implementation
[0026] The technical solutions of the embodiments of the present invention will be described below with reference to the accompanying drawings. In the description of the present invention, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can represent A or B. The "or" in the present invention is merely a description of the relationship between the related objects, indicating that three relationships can exist. For example, A or B can represent: A alone, A and B simultaneously, and B alone. A and B can be singular or plural. Furthermore, in the description of the present invention, unless otherwise stated, "multiple" refers to two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items.
[0027] Furthermore, to facilitate a clear description of the technical solutions of the embodiments of the present invention, the terms "first" and "second" are used in the embodiments of the present invention to distinguish identical or similar items with essentially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.
[0028] In this embodiment of the invention, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in this embodiment of the invention should not be construed as superior or more advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner for ease of understanding.
[0029] Hyperspectral images simultaneously carry detailed spectral and spatial structural information, making them valuable for applications in remote sensing monitoring, agricultural yield estimation, and environmental surveys. However, in practical engineering scenarios, limitations such as the cost of ground feature annotation and the difficulty of sample acquisition mean that large amounts of hyperspectral data can only provide a very small number of labeled samples. Therefore, high-precision classification under small sample conditions has become a key technical requirement in the field of hyperspectral image processing.
[0030] Existing technologies often employ deep learning models to classify hyperspectral images. Among them, the method based on convolutional neural networks extracts spectral-spatial features through local receptive fields and enhances small-sample adaptability by combining simple data augmentation, which is the current mainstream implementation method for small-sample hyperspectral classification.
[0031] Existing methods based on convolutional neural networks rely on local feature extraction. When the sample size is extremely scarce, the feature representation ability drops significantly. The model is prone to overfitting and training oscillations. It cannot stably output high-precision classification results under extremely small sample conditions (e.g., only a dozen or so samples per class), making it difficult to meet the dual requirements of classification accuracy and model reliability in practical engineering.
[0032] In view of this, embodiments of the present invention provide a small-sample hyperspectral image classification method and system based on a lightweight Transformer, comprising: acquiring a hyperspectral data cube; preprocessing the hyperspectral data cube to obtain a spectral spatial feature block sequence; dividing the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples; training the lightweight Transformer model according to the training set, a data augmentation strategy, and an optimized training strategy to obtain a trained classification model; acquiring the target hyperspectral image to be classified; and using the trained classification model to perform inference to obtain the final classification result of the hyperspectral image.
[0033] The method provided by this invention obtains a sequence of spectral spatial feature blocks by preprocessing a hyperspectral data cube, divides the dataset according to a preset number of samples, trains the model based on the training set and corresponding strategies, and finally infers the classification result from the hyperspectral image of the target to be classified. It constructs a complete process from small sample hyperspectral data input to final classification output, which can be adapted to small sample learning scenarios and achieve efficient and stable classification of hyperspectral images, providing a complete and feasible technical path for hyperspectral image processing under extremely small sample conditions.
[0034] In some embodiments, a lightweight Transformer-based few-sample hyperspectral image classification method provided in this invention can be executed by a lightweight Transformer-based few-sample hyperspectral image classification system 100 (hereinafter referred to as classification system 100).
[0035] As an example, the classification system 100 can be any electronic device 200 with data processing capabilities, such as a general-purpose computer, personal computer, laptop computer, switch, or tablet computer. The specific implementation of the classification system 100 is not limited here.
[0036] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention is shown. The electronic device 200 includes a processor 210, a memory 220, and a communication interface 230.
[0037] Processor 210 may include one or more processing cores. Processor 210 connects to various parts within electronic device 200 using various interfaces and lines, and performs various functions and processes data of electronic device 200 by running or executing instructions, programs, code sets, or instruction sets stored in memory 220, and by calling data stored in memory 220. Optionally, processor 210 may be implemented using at least one of the following hardware forms: Central Processing Unit (CPU), Graphics Processing Unit (GPU), Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
[0038] The memory 220 may include random access memory (RAM) or read-only memory (ROM). Optionally, the memory 220 may include a non-transitory computer-readable storage medium. The memory 220 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 220 may include a program storage area. This program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the various method embodiments described above, etc.
[0039] Communication interface 230 is used to communicate with other devices, equipment or communication networks, such as data storage devices, image processing devices or Ethernet, wireless access network (RAN), wireless local area network (WLAN), etc.
[0040] In terms of physical implementation, the aforementioned devices (such as processor 210, memory 220, and communication interface 230) can each be devices within the same device (such as a laptop computer). Alternatively, at least two of these devices can be located within the same device, i.e., as different devices within the same device, similar to the deployment of devices or components in a distributed system.
[0041] It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 200. In other embodiments of the present invention, the electronic device 200 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0042] The following description, in conjunction with the accompanying drawings, illustrates a small-sample hyperspectral image classification method based on a lightweight Transformer, provided by an embodiment of the present invention.
[0043] Figure 2 This is a flowchart illustrating a few-sample hyperspectral image classification method based on a lightweight Transformer, provided as an embodiment of the present invention. Optionally, this method can be... Figure 1 The illustrated electronic device 200 performs this method, which includes the following steps: S1. Obtain a hyperspectral data cube, and preprocess the hyperspectral data cube to obtain a spectral spatial feature block sequence.
[0044] Specifically, a hyperspectral data cube is a three-dimensional data structure denoted as H×W×C, where H is the height of the image, i.e., the number of spatial rows of pixels, and W is the width of the image, i.e., the number of spatial columns of pixels. Together, they constitute the two-dimensional spatial dimension, used to characterize the spatial distribution of ground features. C is the number of spectral bands, usually tens to hundreds of consecutive bands, constituting the third spectral dimension, used to characterize the reflectance characteristics of each pixel corresponding to the ground feature at different wavelengths. Each pixel of the hyperspectral data cube corresponds to a spectral vector of length C, which can completely record the continuous spectral curve of the ground feature at that location and can be used to distinguish different ground feature categories with similar spectral characteristics.
[0045] Furthermore, the spectral spatial feature block is extracted from the hyperspectral data cube, and is a local three-dimensional neighborhood block centered on the target pixel, denoted as P×P×C, where P is the spatial size of the patch (preferably 9 in this invention). This patch block simultaneously contains the spectral features of the target pixel and the spatial context features of its surrounding P×P neighboring pixels, solving the problem that single-pixel spectral features are easily affected by noise and lack spatial information.
[0046] In one possible implementation, the preprocessing of the hyperspectral data cube to obtain a spectral spatial feature block sequence includes: normalizing the mean and standard deviation of the spectral dimensions of the hyperspectral data cube to obtain a normalized hyperspectral data cube; expanding the boundaries of the normalized hyperspectral data cube using a reflection filling method to obtain an expanded data cube; extracting spectral spatial feature blocks centered on the target pixel from the expanded data cube according to a preset spatial size, and flattening the three-dimensional feature blocks into a one-dimensional sequence to obtain a spectral spatial feature block sequence.
[0047] Specifically, the mean and standard deviation normalization process is implemented by calculating the mean and standard deviation of the spectral dimension of all pixels in the hyperspectral data cube, and standardizing the spectral features of each pixel using the following formula: ; Where, x norm denoted as spectral feature value after normalization; x represents the original spectral feature value before normalization; μ represents the feature mean of all pixels in the hyperspectral data cube along the spectral dimension; σ represents the feature standard deviation of all pixels in the hyperspectral data cube along the spectral dimension. It should be noted that the reflection padding method can expand the boundaries of the original hyperspectral data cube, avoiding the problem that the image edge pixels cannot extract complete feature blocks. The padding size is half the size of the feature block. This can also be understood as follows: to avoid the inability to extract complete patch blocks from image edge pixels, this invention uses reflection padding to expand the boundaries of the original hyperspectral data cube, with a padding size of P / / 2 (i.e., when P=9, 4 pixels are filled). After extraction, the 3D patch block is flattened into a 1D sequence (P2)×C, which is used as input to the Transformer model, avoiding the high computational complexity of 2D convolution while preserving complete spectral-spatial correlation information.
[0048] The preferred spatial size of the spectral spatial feature block is 9×9. The extracted feature block is a local three-dimensional block centered on the target pixel. This block includes both the spectral features of the target pixel and the spatial context features of its surrounding neighboring pixels. Flattening the three-dimensional feature block into a one-dimensional sequence avoids the high computational complexity of two-dimensional convolution while preserving complete spectral and spatial correlation information.
[0049] The method provided by this invention performs spectral dimension mean and standard deviation normalization, reflection filling boundary expansion, preset size feature block extraction and flattening on a hyperspectral data cube in sequence. This can standardize the distribution of hyperspectral data, avoid incomplete edge pixel feature extraction, effectively fuse spectral features and spatial context information, suppress spectral noise interference, provide high-quality and standardized feature sequences for subsequent model input, and improve the accuracy and stability of model feature extraction.
[0050] S2. Based on the spectral spatial feature block sequence and the preset number of samples, the hyperspectral image dataset is divided into a training set, a validation set, and a test set.
[0051] In one example, the hyperspectral image dataset is divided into a training set, a validation set, and a test set according to a preset number of samples per category, with 12-20 training samples and 6 validation samples per category.
[0052] S3. Train the lightweight Transformer model according to the training set, data augmentation strategy and optimization training strategy to obtain the trained classification model.
[0053] In some embodiments, see Figure 3 The lightweight Transformer model includes an input projection module, a position encoding module, a Transformer encoder module, a feature aggregation module, and a classification head module. The construction process of the lightweight Transformer model includes: inputting the spectral space feature block sequence into the input projection module, obtaining low-dimensional projected features through feature mapping and nonlinear transformation; inputting the low-dimensional projected features into the position encoding module, adding category tokens and position embedding information to obtain a feature sequence with position information; inputting the feature sequence with position information into the Transformer encoder module, extracting global and local features through multi-layer self-attention and feedforward networks; inputting the global and local features into the feature aggregation module, fusing global semantic features and local statistical features to obtain a comprehensive feature vector; and inputting the comprehensive feature vector into the classification head module, obtaining the model's classification output through cosine similarity calculation.
[0054] Specifically, the input projection module maps the original high-dimensional spectral spatial feature block sequence to a low-dimensional feature space. It achieves feature dimensionality reduction and nonlinear transformation through two linear layers combined with layer normalization and Gaussian error linear unit activation functions, while suppressing spectral noise. The position encoding module introduces learnable category tokens and position embedding information, adding spatial location information from the original feature block to each unit in the feature sequence, compensating for the lack of spatial awareness in the Transformer self-attention mechanism. The Transformer encoder module extracts features through multi-layered stacked lightweight Transformer blocks, using a multi-head self-attention mechanism to capture the spectral spatial relationships between any units in the feature sequence. It also leverages a feedforward network to mine texture and spectral variation features between adjacent units, thus obtaining global and local features. The feature aggregation module employs a dual-branch fusion structure. Branch one extracts global semantic features corresponding to the category tokens, while branch two performs adaptive global average pooling on all feature units to obtain local statistical features. The two types of features are then concatenated to obtain a fixed-dimensional comprehensive feature vector. The classification head module uses a cosine classifier to normalize the comprehensive feature vector and the classification weight matrix, then calculates the cosine similarity between them, adjusts the output value range by setting a scaling factor, and finally obtains the model's classification output.
[0055] In one possible implementation, the feedforward network structure of the Transformer encoder module is: a first linear layer, a GELU activation function layer, a first Dropout layer, a second linear layer, and a second Dropout layer connected in sequence. The first linear layer has a mapping relationship of d_model→4×d_model, which is used to linearly expand the dimension of the input features to achieve dimensionality-upgrading mapping of the feature space, thereby capturing the complex nonlinear spectral-spatial correlation in hyperspectral data. The GELU activation function layer is used to perform nonlinear transformation on the dimensionality-upgraded features, introducing nonlinear expressive power to fit the complex nonlinear laws of the spectral curves of ground objects and spatial texture distribution in hyperspectral images. The first Dropout layer randomly deactivates the activated feature values with a probability of 0.2, which is used to suppress feature redundancy during model training, prevent overfitting in small sample scenarios, and improve the generalization ability of the model. The second linear layer has a mapping relationship of 4×d_model→d_model, which is used to linearly reduce the dimensionality of the high-dimensional expanded features to restore the model feature dimension, thereby achieving feature information condensation and reconstruction. The second Dropout layer further performs regularization processing on the dimensionality-downgraded features with a probability of 0.2, which works in conjunction with the feedforward network to ensure that the feature extraction ability and training stability of the model are maintained under the premise of significantly reduced parameter quantity (total parameter quantity ≤ 694,913).
[0056] To facilitate understanding of this solution, this embodiment of the invention provides a specific example to further explain the process of inputting spectral spatial feature blocks into a lightweight Transformer model.
[0057] In one example, after inputting the spectral spatial feature block obtained in the previous step (which has been flattened into a (P2)×C sequence) into the lightweight Transformer model, the model obtains a comprehensive feature vector that simultaneously represents global contextual information and local structural information through the following hierarchical feature fusion process. This vector is used to fully characterize the spectral distribution and spatial texture distribution of the hyperspectral local region: 1) Input projection layer: Maps the original high-dimensional spectral features (C-dimensional) to a low-dimensional feature space (128-dimensional in this invention). The feature dimensionality reduction and nonlinear transformation are completed through two linear layers + LayerNorm + GELU activation function, while suppressing spectral noise. 2) Position Encoding Module: Introduces learnable category tokens (cls_token) and position embeddings (pos_embed) to add spatial position information of each token in the sequence to the original patch, thus solving the defect that the Transformer self-attention mechanism itself does not have spatial awareness. 3) Transformer encoder module: Utilizing a multi-head self-attention mechanism, it simultaneously captures data through three stacked Transformer blocks. i. Global context information: the spectral-spatial association between any two tokens; ii. Local neighborhood information: texture and spectral variation features between adjacent tokens; each Transformer block adopts a pre-normalization architecture to ensure training stability, while suppressing overfitting under small sample sizes through dropout regularization; 4) Dual-branch feature aggregation module: i. Branch 1: Extract the cls_token feature to represent the global semantic information of the entire patch; ii. Branch 2: Perform adaptive global average pooling on all patch tokens to characterize the local statistical features of the entire patch; iii. The features of the two branches are concatenated to obtain a comprehensive feature vector with a dimension of 256, thereby achieving complementary fusion of global semantics and local statistical information.
[0058] 5) Classification Head Module: A cosine classifier is used to normalize the fused features and calculate the cosine similarity with the classification weight matrix. The classification output is adjusted by a scaling factor (scale=16).
[0059] Furthermore, the training process of the lightweight Transformer model provided in this embodiment of the invention is as follows: 1) Data augmentation: Combining Mixup and CutMix augmentation strategies, random augmentation operations such as flipping, rotating, adding spectral noise, scaling, and feature block mixing are performed on the training samples; 2) Loss function: Label Smoothing Cross-Entropy Loss (LabelSmoothingCE) is used, with a smoothing coefficient of 0.1; 3) Optimization strategy: Use the AdamW optimizer with a learning rate of 5e-4, weight decay of 1e-3, and gradient clipping threshold of 1.0; introduce learning rate warmup (warmup_epochs=10) and early stopping mechanism (patience=50).
[0060] It should be noted that the model ensemble and inference process specifically includes: training three models initialized with different random seeds; employing a test-time augmentation (TTA) strategy; averaging the prediction probabilities of multiple models to obtain the final classification result. Data augmentation only applies to the input sample; TTA generates multiple augmented versions of the same input and merges their prediction results; model ensemble merges the prediction results of multiple different models; the cosine classifier is the last layer of each model, directly outputting the classification probability.
[0061] The Test-Time Enhancement (TTA) strategy involves adding 0.02 times Gaussian noise to the input sample to generate 5 enhanced samples, and averaging the prediction probabilities of the 5 samples.
[0062] The method provided by this invention constructs a lightweight Transformer model that includes an input projection module, a position encoding module, a Transformer encoder module, a feature aggregation module, and a classification head module. The model is constructed by following the process of feature projection, position encoding, global and local feature extraction, multi-feature fusion, and cosine similarity calculation. This method can reduce model complexity while fully capturing the global correlation and local structural information of hyperspectral data, thereby improving the feature expression ability and classification reliability in small sample scenarios.
[0063] Furthermore, in another possible implementation, the Transformer encoder module consists of multiple lightweight Transformer blocks. The Transformer blocks adopt a pre-normalized architecture, including a multi-head self-attention mechanism and a feedforward network, and both the feedforward network and the self-attention mechanism are equipped with random deactivation regularization operations.
[0064] The pre-normalization architecture involves performing normalization before the computation of the multi-head self-attention mechanism and the feedforward network. This effectively stabilizes the numerical distribution during model training, preventing gradient vanishing or exploding. The multi-head self-attention mechanism can capture the correlation between features at different positions and dimensions in the feature sequence in parallel, comprehensively extracting global contextual information from hyperspectral data. The feedforward network performs nonlinear transformations and mappings on the extracted features, enhancing their expressive power. Random deactivation regularization randomly discards the outputs of some neurons during the computation of the feedforward network and the multi-head self-attention mechanism, reducing the model's over-reliance on certain features and suppressing overfitting in small-sample scenarios. The multi-layer lightweight Transformer block stacking structure deepens feature extraction layer by layer while controlling the total number of model parameters, allowing the model to maintain a lightweight design while achieving excellent classification performance.
[0065] The method provided by this invention employs an encoder module composed of multiple lightweight Transformer blocks, with the Transformer blocks using a pre-normalized architecture, combined with a multi-head self-attention mechanism, a feedforward network, and random deactivation regularization operations. This ensures the stability of model training, suppresses overfitting problems that are prone to occur in few-shot learning, and maintains efficient feature extraction capabilities while reducing the number of model parameters, thus balancing model lightweighting and classification performance.
[0066] In some embodiments, S3 specifically includes: performing data augmentation on the samples in the training set using a mixup and cutmix method to obtain augmented training samples; calculating the model loss value using the label smooth cross-entropy loss function based on the augmented training samples; and updating the model parameters using the AdamW optimizer combined with gradient clipping, learning rate warm-up, and early stopping mechanisms according to the model loss value to obtain a trained classification model.
[0067] Mixup data augmentation works by using a beta distribution to generate mixing coefficients and linearly mixing the features and labels of two samples, resulting in new samples with a smoother distribution. CutMix data augmentation works by randomly selecting a subset of feature unit sequences and replacing and splicing them between different samples, generating new samples with local feature differences. Combining these two augmentation methods simultaneously increases the quantity and diversity of training samples, enhancing the model's adaptability to various feature variations.
[0068] For example, see Figure 4The Mixup enhancement mentioned above is implemented by using a β distribution (α=0.4) to generate the mixing coefficients and linearly mixing the features and labels of the two samples. The CutMix enhancement is implemented by randomly selecting a portion of the token sequence for sample replacement, and the mixing coefficients are generated by a β distribution (α=1.0).
[0069] The label-smoothing cross-entropy loss function reduces the model's overconfidence in the training sample labels, minimizing the interference of noisy labels on model training. The AdamW optimizer enables adaptive learning rate adjustment during parameter updates, while also providing stable weight decay. Gradient clipping limits the maximum gradient value, preventing gradient explosion during training. Learning rate warm-up gradually increases the learning rate to a set value in the early stages of training, resulting in smoother initial training. Early stopping terminates training when validation set performance no longer improves, preventing overfitting due to overtraining and shortening overall training time.
[0070] The method provided by this invention expands the diversity of training samples by adopting a mixed data augmentation strategy of Mixup and CutMix, calculates the model loss using the label smooth cross-entropy loss function, and completes parameter updates by combining the AdamW optimizer, gradient clipping, learning rate warm-up and early stopping mechanism. It can effectively alleviate the problems of model overfitting and training instability under small sample size, accelerate the model convergence speed, and improve the generalization ability and robustness of the trained classification model.
[0071] S4. Obtain the hyperspectral image of the target to be classified, and use the trained classification model to perform inference to obtain the final classification result of the hyperspectral image.
[0072] In one possible implementation, S4 specifically includes: preprocessing the target hyperspectral image to be classified to obtain a corresponding spectral spatial feature block sequence; inputting the spectral spatial feature block sequence into a trained classification model to obtain an initial classification result; and performing probability fusion and decision on the initial classification result to obtain the final classification result of the hyperspectral image.
[0073] The preprocessing operations performed on the target hyperspectral image to be classified are exactly the same as the preprocessing process performed on the hyperspectral data cube during the training phase. The preprocessing includes mean and standard deviation normalization of the spectral dimension, boundary expansion of the reflection filling method, extraction of spectral spatial feature blocks of preset spatial size, and flattening of the three-dimensional feature blocks into a one-dimensional sequence, which can obtain a spectral spatial feature block sequence consistent with the training sample format.
[0074] Furthermore, after inputting the spectral spatial feature block sequence into the trained classification model, the model will complete forward inference according to the predetermined process of feature mapping, position encoding, global and local feature extraction, feature fusion, and cosine similarity calculation, outputting the initial classification result. Probability fusion and decision-making on the initial classification result integrates the probability information of each category output by the model, eliminates interference from outlier probability values, and further improves the reliability and accuracy of the classification result. This inference process maintains consistency with the processing logic of the training phase, avoids feature distribution shifts caused by differences in processing methods, and can stably output accurate hyperspectral image classification results under small sample conditions.
[0075] As can be seen from S1-S4 above, the method provided by the embodiments of the present invention obtains a spectral spatial feature block sequence by preprocessing the hyperspectral data cube, completes the dataset division according to a preset number of samples, completes model training based on the training set and corresponding strategy, and finally obtains the classification result by inferring from the hyperspectral image of the target to be classified. It constructs a complete process from small sample hyperspectral data input to final classification output, which can adapt to small sample learning scenarios, realize efficient and stable classification of hyperspectral images, and provide a complete and feasible technical path for hyperspectral image processing under extremely small sample conditions.
[0076] This invention can also be understood as follows: It adopts a lightweight Transformer architecture design, simplifies the Transformer encoder structure, combines category tokens and global pooling feature aggregation methods, reduces model complexity while ensuring feature extraction capabilities, uses a cosine classifier to replace the traditional fully connected classification head, improves classification stability under small sample conditions through feature normalization and cosine similarity calculation, integrates Mixup and CutMix enhancements and combines geometric transformation and spectral enhancement to expand the diversity of training samples, further improves classification robustness through model integration and test-time enhancement strategies, and introduces learning rate warm-up, gradient clipping, early stopping mechanism and label smoothing to solve the problems of overfitting and training instability under small sample conditions. This invention achieves overall accuracy, average accuracy, and Kappa coefficient all above 0.85 under extremely small sample conditions of 12 to 20 training samples per class, significantly outperforming existing methods in classification performance. It has fewer model parameters, faster inference speed, and is suitable for embedded devices or real-time processing scenarios. Through hybrid data augmentation and model ensemble, it has strong resistance to noise and illumination changes. It can also be adapted to different hyperspectral datasets such as IndianPines and PaviaUniversity without requiring significant modifications to the model structure, making it highly versatile.
[0077] It should be noted that in one example, the hardware environment is NVIDIA GPU (≥8GB VRAM), CPU (≥8 cores), and RAM ≥16GB; the software environment is Python 3.8+, PyTorch 1.10+, NumPy, Scikit-learn, etc.
[0078] The specific code implementation of the method provided in this embodiment of the invention is as follows: 1. Dataset Preparation Taking the Indian Pines hyperspectral dataset as an example, the dataset contains 145×145 pixels, 220 spectral bands, and 16 land cover classes. The hyperspectral data cube and label matrix in .mat format are loaded, and the data is normalized. def load_hsi_array(path: str) ->np.ndarray: ext = os.path.splitext(path)[1].lower() if ext ==".npy": return np.load(path) if ext ==".mat": mat = loadmat(path) valid_keys = [k for k in mat.keys() if not k.startswith("__")] return np.array(mat[valid_keys[0]]) raise ValueError(f"Unsupported: {path}") #Normalization reshaped = self.data_cube.reshape(-1, c) self.mean = reshaped.mean(axis=0, keepdims=True) self.std = reshaped.std(axis=0, keepdims=True) + 1e-8 reshaped = (reshaped - self.mean) / self.std self.data_cube = reshaped.reshape(h, w, c) 2. Model Building The core code for building a lightweight Transformer model is as follows: class SimpleTransformer(nn.Module): def __init__(self, num_tokens, num_bands, num_classes, d_model=128, n_heads=4, num_layers=3, dropout=0.2): super().__init__() #Input projection self.input_proj = nn.Sequential( nn.Linear(num_bands, d_model * 2), nn.LayerNorm(d_model * 2), nn.GELU(), nn.Dropout(dropout), nn.Linear(d_model * 2, d_model), nn.LayerNorm(d_model), ) #Location Encoding self.cls_token = nn.Parameter(torch.zeros(1, 1, d_model)) self.pos_embed = nn.Parameter(torch.zeros(1, num_tokens + 1,d_model)) self.pos_drop = nn.Dropout(dropout) # Transformer block self.blocks = nn.ModuleList([ TransformerBlock(d_model, n_heads, dropout) for _ in range(num_layers) ]) self.norm = nn.LayerNorm(d_model) #Feature Aggregation self.pool = nn.AdaptiveAvgPool1d(1) #Cosine Classifier self.head = CosineClassifier(d_model * 2, num_classes, scale=16.0) def forward_features(self, x): B, N, C = x.shape x = self.input_proj(x) cls = self.cls_token.expand(B, -1, -1) x = torch.cat([cls, x], dim=1) x = x + self.pos_embed[:, :x.size(1), :] x = self.pos_drop(x) for block in self.blocks: x = block(x) x = self.norm(x) cls_feat = x[:, 0] pool_feat = self.pool(x[:, 1:].transpose(1, 2)).squeeze(-1) return torch.cat([cls_feat, pool_feat], dim=-1) def forward(self, x): feat = self.forward_features(x) return self.head(feat) 3. Model Training The training process employs hybrid data augmentation, label smoothing loss, and the AdamW optimizer. The core code is as follows: def train_epoch(model, loader, optimizer, criterion, device, use_mixup=True): model.train() total_loss, total_acc, n = 0, 0, 0 for x, y in loader: x, y = x.to(device), y.to(device) # Randomly select the augmentation method if use_mixup: r = random.random() if r<0.3: x, y_a, y_b, lam = mixup_data(x, y, 0.4) optimizer.zero_grad() logits = model(x) loss = lam * criterion(logits, y_a) + (1 - lam) *criterion(logits, y_b) elif r<0.5: x, y_a, y_b, lam = cutmix_data(x, y, 1.0) optimizer.zero_grad() logits = model(x) loss = lam * criterion(logits, y_a) + (1 - lam) *criterion(logits, y_b) else: optimizer.zero_grad() logits = model(x) loss = criterion(logits, y) y_a, y_b, lam = y, y, 1.0 loss.backward() torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0) optimizer.step() # Calculate the loss and accuracy with torch.no_grad(): total_loss += loss.item() acc = lam * (logits.argmax(-1) == y_a).float().mean().item() acc += (1 - lam) * (logits.argmax(-1) == y_b).float().mean().item() total_acc += acc n += 1 return total_loss / n, total_acc / n 4. Model Integration and Inference Train models with three different random seeds and use the TTA strategy for inference: def ensemble_predict(models, loader, device, num_classes): all_probs = [] all_targets = [] for x, y in loader: x = x.to(device) #Collect predictions from all models batch_probs = None for model in models: model.eval() probs = predict_with_tta(model, x, device, n_aug=3) if batch_probs is None: batch_probs = probs else: batch_probs = batch_probs + probs batch_probs = batch_probs / len(models) all_probs.append(batch_probs.cpu()) all_targets.append(y) #Calculate classification indicators probs = torch.cat(all_probs) targets = torch.cat(all_targets).numpy() preds = probs.argmax(-1).numpy() oa = (preds == targets).mean() cm = confusion_matrix(targets, preds, labels=list(range(num_classes))) class_acc = np.array([cm[c, c] / cm[c].sum() if cm[c].sum()>0else 0 for c in range(num_classes)]) aa = class_acc[class_acc>0].mean() kappa = cohen_kappa_score(targets, preds) return oa, aa, kappa, class_acc In the above example, the experimental results for 15 training samples per class on the ndian Pines dataset are as follows: The training parameter value was 694913, the overall accuracy (OA) was 0.80±0.02, the average accuracy (AA) was 0.89±0.01, and the Kappa coefficient was 0.80±0.02.
[0079] The foregoing mainly describes the solutions of the embodiments of the present invention from a methodological perspective. It is understood that, in order to achieve the above-mentioned functions, the classification system 100 includes at least one of the hardware structures and software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, in conjunction with the units and algorithm steps of the various examples described in the embodiments disclosed herein, the embodiments of the present invention can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of the present invention.
[0080] In this embodiment of the invention, the classification system 100 can be divided into functional units according to the above method example. For example, the classification system 100 can be divided into functional units corresponding to various functions, or two or more functions can be integrated into one processing unit. The integrated unit can be implemented in hardware or as a software functional unit. It should be noted that the unit division in this embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0081] For example, Figure 5 A schematic diagram of the hardware structure of a classification system provided in an embodiment of the present invention is shown. The classification system 100 includes: an acquisition unit 110, used to acquire a hyperspectral data cube and preprocess the hyperspectral data cube to obtain a spectral spatial feature block sequence; a partitioning unit 120, used to partition the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples; a training unit 130, used to train the lightweight Transformer model according to the training set, data augmentation strategies, and optimization training strategies to obtain a trained classification model; and a classification unit 140, used to acquire the target hyperspectral image to be classified, and use the trained classification model to perform inference to obtain the final classification result of the hyperspectral image.
[0082] Furthermore, the training unit 130 also includes a loss calculation submodule, an optimizer submodule, and a data augmentation submodule; the loss calculation submodule is used to calculate the label smoothing cross-entropy loss (LabelSmoothingCE), with a smoothing coefficient set to 0.1, to alleviate the model's sensitivity to mislabeled samples and improve the robustness of the classifier; the optimizer submodule is used to integrate the AdamW optimizer, configured with a learning rate of 5×10⁻⁶. -4 The weight decays to 1×10 -3 The model parameters are updated efficiently and stably by combining gradient clipping (threshold of 1.0) and a learning rate warmup strategy (warmup_epochs = 10). The data augmentation submodule is used to dynamically switch between geometric transformation augmentation (flipping, rotation), spectral augmentation (Gaussian noise addition, scaling), Mixup augmentation (α=0.4) and CutMix augmentation (α=1.0) to expand the diversity of training samples and improve the model's adaptability to noise and deformation.
[0083] It should be understood that specific descriptions of the above-mentioned optional methods can be found in the foregoing method embodiments, and will not be repeated here. Furthermore, explanations of any of the classification systems 100 provided above, as well as descriptions of their beneficial effects, can be found in the corresponding method embodiments described above, and will not be repeated here.
[0084] This invention also provides a computer-readable storage medium storing at least one computer instruction, which is loaded and executed by a processor to implement the methods of the various embodiments described above. Explanations of the relevant content and descriptions of the beneficial effects of any of the computer-readable storage media provided above can be found in the corresponding embodiments described above, and will not be repeated here.
[0085] This invention also provides a chip. This chip integrates a control circuit for implementing the functions of the classification system 100 described above, and one or more ports. Optionally, the functions supported by this chip are as described above, and will not be repeated here.
[0086] Those skilled in the art will understand that the program for implementing all or part of the steps of the above embodiments, which can be executed by a program instructing related hardware, can be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a random access memory, etc. The processing unit or processor mentioned above can be a central processing unit, a general-purpose processor, an application-specific integrated circuit (ASIC), a microprocessor (DSP), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof.
[0087] This invention also provides a computer program product containing instructions that, when executed on a computer, cause the computer to perform any of the methods described in the above embodiments. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this invention is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., SSD), etc.
[0088] It should be noted that the devices for storing computer instructions or computer programs provided in the embodiments of the present invention, such as, but not limited to, the aforementioned memory, computer-readable storage medium, and communication chip, are all non-transitory. Those skilled in the art should recognize that the functions described in the embodiments of the present invention in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable storage medium or transmitted as one or more instructions or code on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of computer programs from one place to another. Storage media can be any available medium accessible to general-purpose or special-purpose computers.
[0089] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A small-sample hyperspectral image classification method based on lightweight Transformer, characterized in that, include: A hyperspectral data cube is acquired, and the hyperspectral data cube is preprocessed to obtain a sequence of spectral spatial feature blocks; Based on the spectral spatial feature block sequence and the preset number of samples, the hyperspectral image dataset is divided into a training set, a validation set, and a test set; The lightweight Transformer model is trained using the training set, data augmentation strategy, and optimized training strategy to obtain a trained classification model. The target hyperspectral image to be classified is acquired, and the trained classification model is used for inference to obtain the final classification result of the hyperspectral image.
2. The method according to claim 1, characterized in that, The preprocessing of the hyperspectral data cube to obtain a sequence of spectral spatial feature blocks includes: The mean and standard deviation of the spectral dimension of the hyperspectral data cube are normalized to obtain the normalized hyperspectral data cube. The normalized hyperspectral data cube was expanded by using a reflection filling method to obtain an expanded data cube. According to the preset spatial size, spectral spatial feature blocks centered on the target pixel are extracted from the expanded data cube, and the three-dimensional feature blocks are flattened into a one-dimensional sequence to obtain the spectral spatial feature block sequence.
3. The method according to claim 1, characterized in that, The lightweight Transformer model includes an input projection module, a position encoding module, a Transformer encoder module, a feature aggregation module, and a classification head module; The construction process of the lightweight Transformer model includes: The spectral spatial feature block sequence is input to the input projection module, and low-dimensional projection features are obtained through feature mapping and nonlinear transformation. The low-dimensional projection features are input into the location encoding module, and category tokens and location embedding information are added to obtain a feature sequence with location information. The feature sequence with location information is input into the Transformer encoder module, and global and local features are extracted through a multi-layer self-attention and feedforward network. The global and local features are input into the feature aggregation module, and the global semantic features and local statistical features are fused to obtain a comprehensive feature vector. The comprehensive feature vector is input into the classification head module, and the model's classification output is obtained through cosine similarity calculation.
4. The method according to claim 3, characterized in that, The Transformer encoder module consists of multiple lightweight Transformer blocks. The Transformer blocks adopt a pre-normalized architecture, including a multi-head self-attention mechanism and a feedforward network. Random deactivation regularization operations are set in both the feedforward network and the self-attention mechanism.
5. The method according to claim 1, characterized in that, The process of dividing the hyperspectral image dataset into a training set, a validation set, and a test set based on the spectral spatial feature block sequence and a preset number of samples includes: The spectral spatial feature block sequence is sampled evenly according to the land cover category to obtain the sample set corresponding to each category; A specified number of samples are selected from each category's sample set as the training set and validation set, based on a preset sample size. The remaining samples were designated as the test set, thus completing the dataset partitioning under the condition of a small sample size.
6. The method according to claim 1, characterized in that, The training of the lightweight Transformer model based on the training set, data augmentation strategies, and optimization training strategies includes: Data augmentation was performed on the samples in the training set using a combination of Mixup and CutMix methods to obtain augmented training samples; Based on the enhanced training samples, the model loss value is calculated using the label smooth cross-entropy loss function; Based on the model loss value, the AdamW optimizer is used in conjunction with gradient clipping, learning rate warm-up, and early stopping mechanisms to update the model parameters, resulting in a fully trained classification model.
7. The method according to claim 1, characterized in that, The process of using the trained classification model to perform inference and obtain the final classification result of the hyperspectral image includes: The hyperspectral image of the target to be classified is preprocessed to obtain the corresponding spectral spatial feature block sequence; The spectral spatial feature block sequence is input into the trained classification model to obtain the initial classification result; The initial classification results are subjected to probability fusion and decision to obtain the final classification result of the hyperspectral image.
8. A small-sample hyperspectral image classification system based on a lightweight Transformer, characterized in that, include: The acquisition unit is used to acquire a hyperspectral data cube, preprocess the hyperspectral data cube, and obtain a sequence of spectral spatial feature blocks. A partitioning unit is used to divide the hyperspectral image dataset into a training set, a validation set, and a test set according to the spectral spatial feature block sequence and a preset number of samples. The training unit is used to train the lightweight Transformer model according to the training set, data augmentation strategy and optimization training strategy to obtain the trained classification model. The classification unit is used to acquire the hyperspectral image of the target to be classified, and to perform inference using the trained classification model to obtain the final classification result of the hyperspectral image.
9. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to enable the computer to perform the method as described in any one of claims 1-7.
