1. Introduction
Hyperspectral images (HSIs) are complex three-dimensional remote sensing data that integrate abundant spectral and spatial information [
1]. The spectral dimension of HSIs typically spans tens to hundreds of contiguous bands, providing fine-grained reflectance characteristics of each pixel across multiple wavelengths. Such high spectral resolution enables the discrimination of materials with subtle spectral differences, making HSIs a valuable data source for land-cover classification, mineral mapping [
2], and environmental monitoring [
3,
4]. However, the high-dimensional complexity of HSIs and the constraints of data acquisition pose significant challenges for effective classification [
5]. On the one hand, labeling HSIs is costly and time-consuming, resulting in a limited number of annotated samples. Deep learning models generally require a large amount of labeled data to achieve satisfactory performance; when trained with only a few samples, they often suffer from poor generalization and overfitting [
6]. On the other hand, due to variations in land-cover distribution, the number of samples per class in HSIs is typically imbalanced: certain classes contain only a few pixels, while majority classes have abundant samples [
7]. This class imbalance causes the model to be biased toward majority classes during training, leading to low recognition accuracy for minority classes. The dual challenges of limited samples and class imbalance jointly hinder the effective training and generalization of hyperspectral classification models. Therefore, how to fully exploit the spectral–spatial discriminative information in HSIs and enhance the representational capacity of models under the conditions of scarce annotations and imbalanced class distributions remains a critical and unresolved issue.
Early studies applied conventional machine learning (SVM [
8], KNN [
9]) to hyperspectral image (HSI) classification. These methods exploit rich spectral information and can be robust when labeled samples are scarce, achieving encouraging results. However, they usually rely on hand-crafted features and struggle to capture the complex joint spectral–spatial cues in HSIs. Their limited capacity to model high-dimensional spectral–spatial structures leaves them vulnerable to the “Hughes phenomenon”, often leading to overfitting and degraded classification performance [
10]. The advent of deep learning has provided new solutions for HSI classification. By stacking nonlinear transformations, deep models learn hierarchical representations directly from data, removing the dependence on manual feature engineering and showing strong capability in feature extraction and pattern discovery [
11].
However, the strong performance of deep models typically hinges on large quantities of labeled data [
12]. For classes with subtle spectral differences and scarce samples, their discriminative capacity is markedly constrained. To alleviate the impact of sample scarcity and class imbalance on hyperspectral image (HSI) classification, data augmentation has been widely adopted as a key means of improving model generalization [
13,
14]. Conventional augmentation techniques (rotation, flipping, and noise injection) can moderately increase dataset diversity, but they often fail to capture the complex spectral–spatial variations present in real HSI scenes and therefore offer limited relief from overfitting [
13]. GAN-based augmentation offers a stronger alternative by learning hyperspectral distributions and synthesizing realistic samples with diverse spectral signatures, thereby enriching minority-class coverage and improving generalization in low-label regimes [
15]. Representative works such as HSGAN [
16] and SSARL [
17] demonstrate that adversarial generation can effectively boost few-shot HSI classification by providing additional training diversity.
Nonetheless, existing GAN-driven augmentation still faces notable limitations from a security and reliability perspective. First, many models lack targeted quality optimization for minority-class synthesis, yielding unreliable samples for long-tail categories. Second, discriminator overfitting may cause generators to collapse into producing homogeneous outputs, i.e., mode collapse, which results in insufficient intra-class coverage and leaves minority-class vulnerabilities unresolved [
18]. Although WGAN-GP stabilizes adversarial training [
19], its global distance optimization does not explicitly enforce the spectral smoothness and spatial coherence inherent to HSIs, often producing oscillatory artifacts and locally inconsistent samples that may introduce new risks in downstream classification [
20]. Moreover, most hyperspectral GANs rely on pure noise vectors or noisy labels without physical priors, leading to unstable multi-class synthesis and a persistent trade-off between sample quality and diversity. These issues motivate the need for prior-guided generative augmentation that can simultaneously improve realism and diversity, especially for security-critical minority classes.
In summary, in order to address the above challenges, our work rethinks the HSI data feature extraction process from two different perspectives and designs a novel Swin-based HSI classification method (based on Swin: Spatial–Spectral Cooperative Conditional Adversarial Network). Specifically, this study first uses the WGAN-GP framework to construct a generative adversarial module and introduces a spectral smoothness constraint (SSC) in the loss function of the GAN. This constraint incorporates the band continuity of hyperspectral data as a regularization term into the optimization process of the generative network, guiding the model to enable the generator to synthesize more realistic and physically compliant samples that conform to the spectral smoothness characteristics, thereby effectively expanding the training data. Secondly, based on the spatial window attention mechanism of the classic Swin Transformer, we design a hybrid Swin transformer architecture and propose a spectral window attention mechanism to divide the spectral dimension into windows. The hyperspectral data structure is fully utilized by alternating spatial and spectral self-attention operations in the network layer. In our design, the Transformer encoder consists of layers that alternate attention types in sequence: one layer performs multi-head self-attention on spatial tags within a local window (like the standard Swin Transformer layers), and the next layer performs multi-head self-attention on the spectral window partitioned by the spectral dimension at each spatial location (treating the spectral bands as a sequence of attention). In this way, spatial structures (such as shape, texture, and neighborhood context) are captured in a set of layers, while spectral dependencies (such as continuous reflectance spectrum curves, absorption features, and cross-band interactions) are learned in alternating layers. This design effectively decouples the learning of spatial and spectral features, allowing each attention mechanism to focus on one of them. The spatial attention layers are confined to a local window with a shift, which maintains computational efficiency and allows the model to gradually build a scene representation from the local to the more global spatial context. On the other hand, the spectral attention layers ensure that the model explicitly learns how information propagates and correlates across wavelengths—a purely spatial transformer may only learn implicitly. By stacking these layers alternately, the network can be viewed as a two-branch transformer merged into one: with a deep-rooted understanding of both spatial layout and spectral features. Our main contributions are as follows:
A novel constraint: We propose a spectral smoothness constraint (SSC) mechanism, which fully utilizes the physical prior property that the difference in spectral reflectance values between adjacent bands of hyperspectral data is usually small. This method explicitly introduces the band continuity of hyperspectral data as a regularization term into the optimization process of the generative network. To our knowledge, this is the first attempt to explore the potential of constraint conditions in generative networks.
We novelly propose a spectral attention window module, which adds a spectral attention window to the original Swin space window to complete the spatial–spectral fusion in one block. At the same time, in different blocks, the spatial–spectral and spectral–spatial interleaving executions are flexibly completed, further improving the fine-grainedness of spectral feature extraction.
We conducted extensive experiments on four benchmark datasets (Indian Pines, Pavia University, Botswana, and Salinas Scene). The results show that our proposed method outperforms other state-of-the-art methods.
3. Methodology
As illustrated in
Figure 1, the overall architecture of S2A-Swin comprises three main components: a pre-processing module, an SSC-cGAN, and a HybridSwinBlock. Given a hyperspectral image (HSI)
, where
H,
W, and
C denote the height, width, and number of spectral bands, respectively, we first reshape
to
and apply normalization and zero-padding. An image patch
, centred on the target pixel, is then cropped from
and fed into the SSC-cGAN, which generates a set of synthetic samples. The resulting embeddings are forwarded to the HybridSwinBlock, followed by a multilayer perceptron (MLP) that outputs the final prediction
, where
N is the number of classes. The network is trained end-to-end using the standard cross-entropy loss.
3.1. Data Preprocessing and Spatial-Spectral Patch Construction
In order to eliminate the negative impact of data scale differences in different spectral bands on model training, this study first performed normalization processing band by band. Hyperspectral images are usually represented as a three-dimensional data cube, and each pixel contains rich spectral information. The input hyperspectral image is represented as:
where
H and
W are the image height and width, and
C is the spectral dimension (number of bands). Let
(
) denote the
b-th spectral band; the normalised band
is defined by
where
and
are, respectively, the minimum and maximum pixel values in band
b, and
is a small constant that prevents division by zero.
To exploit spatial context, a square neighbourhood window of size
(
in this study) is centred at every labelled pixel. For any pixel located at
with a non-zero class label, the corresponding spatial–spectral patch
is constructed as
where
is the window radius (
when
). To ensure that border pixels can provide a full spatial context, the normalised image
is mirror-padded along both spatial dimensions:
After padding, the spatial dimensions of are extended from the original to , which enables smooth extraction of patches near the image boundaries.
Each spatial–spectral patch
is paired with the class label
of its centre pixel to form a supervised training sample:
At the final stage of training and test split, we employ a stratified random sampling strategy to ensure that each class is well represented in both the training and test sets.
Let
be the total number of available samples for class
c, then the number of samples selected for the test set,
, is defined as:
where
is the proportion of test samples. In this study, we set
to ensure that each class has at least one sample in the test set, while the remaining samples are used for training.
3.2. Spectral–Spatial GAN (SSC-cGAN)
The goal of SSC-cGAN is to generate sample patches that closely resemble hyperspectral characteristics under conditions of data imbalance and sample scarcity, thereby augmenting the training dataset. During training, we first perform one or more gradient descent steps on the generator G, followed by gradient updates on the discriminator D. To enhance model stability and generation quality, a gradient penalty term is introduced, which is computed by sampling random points between real and generated patches through interpolation. Throughout the iterative training process, the discriminator D learns to distinguish between real patches and generated ones conditioned on class labels, while the generator G progressively improves to produce increasingly realistic patches. These generated patches become indistinguishable from real ones and adhere to spectral and spatial smoothness constraints. Once training converges, we use G to generate a large number of synthetic patches for each class, augmenting the original training set. In the subsequent classification model training, we combine real and synthetic samples. In cases where certain classes have very few samples, the synthetic data significantly increases the size and diversity of the training dataset. To ensure balanced representation across classes, we apply a class-balanced sampling strategy during augmentation. The detailed implementation of each module is described below:
3.2.1. Generative Adversarial Backbone
We adopt Conditional WGAN-GP (Wasserstein GAN with Gradient Penalty) to generate synthetic hyperspectral images (HSI) for spectral augmentation. The WGAN-GP consists of two convolutional neural networks: a generator
G and a discriminator
D. The generator
takes as input a random noise vector
z (sampled from a uniform or Gaussian distribution) and a conditional label
y, and outputs a synthetic hyperspectral image
. The generator is implemented as a deep convolutional network. It upsamples the noise into an image with
pixels and
B spectral bands, using transposed convolutions (deconvolution) or pixel-shuffling techniques. The conditional label
y is embedded and injected into intermediate layers via conditional normalization. The discriminator
is also a convolutional network. It takes as input either a real or synthetic HSI
X, together with the label
y, and outputs a scalar score. Unlike conventional GANs, which use binary cross-entropy loss, WGAN-GP employs the Earth-Mover (Wasserstein) distance to measure the discrepancy between the real and generated distributions. The discriminator (also referred to as the critic) does not output probabilities, but rather estimates the Wasserstein distance by maximizing the difference between real and generated samples. In practice, the training objective minimizes the negative critic score with the addition of a gradient penalty term for regularization. Formally, let
denote the critic’s output score for an input HSI
X with label
y. The discriminator loss is defined as:
where the first term
encourages the discriminator
D to assign higher scores to real patches, and the second term
encourages
D to assign lower scores to generated patches. The third term is the gradient penalty proposed in WGAN-GP (weighted by
), where
denotes samples interpolated between real and generated patches (i.e., for a random
,
). This term penalizes the gradient norm
to be close to 1, thereby enforcing the Lipschitz constraint required for Wasserstein distance estimation. The gradient penalty helps stabilize training and prevents the discriminator from becoming too sharp or discontinuous, which is especially important for high-dimensional HSI input spaces.
The generator aims to fool the discriminator while adhering to spectral smoothness regularization. Specifically, the generator
G tries to maximize
(i.e., the discriminator’s score for fake data), as a higher score implies that the discriminator considers the fake data more realistic. Therefore, we minimize the negative of this score. Without regularization, the basic generator loss would be:
3.2.2. Spectral–Spatial Smoothness Constraint (SSC)
The continuity of hyperspectral data arises inherently from the continuous spectral reflectance properties of real-world materials and is further modulated by the overlapping Spectral Response Functions (SRFs) of adjacent detector elements in the spectrometer. While natural hyperspectral signals may exhibit low-frequency variations due to atmospheric scattering, the synthetic samples generated by unconstrained GANs often suffer from unphysical high-frequency spectral jitter. This jitter is akin to amplified sensor shot noise or adversarial checkerboard artifacts, which do not conform to physical imaging mechanisms. However, the existing data augmentation methods based on generative adversarial networks (GANs) do not explicitly consider this physical continuity constraint along the spectral dimension, which often leads to drastic unphysical changes between bands or unrealistic spectral anomalies. To this end, we propose an explicit spectral smoothness constraint mechanism (Spectral Smoothness Constraint, SSC). The core idea is to explicitly introduce the band continuity of hyperspectral data as a regularization term into the optimization process of the generative network. Therefore, we express this spectral continuity feature as:
where
denotes the pixel value at spatial location
in band
c of a real sample. Guided by this observation, we enforce an analogous continuity on the generated samples,
where
is the output of the generator
G given latent code
z (and, if applicable, conditioning
y). Equivalently,
Specifically, the proposed SSC penalizes discrepancies between adjacent spectral bands of a generated sample, thereby enforcing realistic and smooth behavior along the spectral dimension. To rigorously encode this continuity, we design a loss that directly measures inter-band differences and adopt the squared Euclidean distance so that abrupt changes are strongly penalized. The spectral smoothness loss is defined as
where
denotes the spectral smoothness regularization term,
is the generator’s hyperspectral output, and
C is the number of spectral bands. Here
is the image at band
c, and
denotes the squared
norm over spatial pixels, i.e.,
Abrupt discrepancies between adjacent spectral bands are typically physically implausible and often indicate anomalies or noise. Therefore, by explicitly penalizing such discrepancies, we can effectively reduce the probability that the generator produces anomalous samples. This explicit constraint drives the generator to directly learn, during training, to produce spectra that are smoother and more consistent with real-world material characteristics, thereby markedly improving the quality of synthetic samples. In addition, to further enhance the quality of the generated data, we introduce an auxiliary spatial smoothness regularization to suppress abrupt spatial changes in the generated samples:
The spatial smoothness loss enforces local spatial continuity of generated data, preventing spatial artifacts or anomalous patterns. Serving as an auxiliary term, it cooperates with the spectral smoothness regularization to jointly improve data quality along both the spatial and spectral dimensions. The final optimization objective of the generator combines the adversarial loss with the above constraints:
Unlike conventional methods that encourage band-to-band continuity only implicitly, our approach encodes an explicit difference loss between adjacent spectral bands directly in the optimization objective, thereby enabling precise control over the generated data. A potential concern regarding the SSC is whether enforcing local smoothness might inadvertently blur the discriminative features of the synthesized samples, such as specific absorption valleys or red-edge characteristics crucial for classification. It is important to emphasize that SSC does not operate in isolation. In the overall objective (Equation (
8)), the spectral smoothness is balanced by the conditional adversarial loss
. The conditional discriminator rigorously enforces the preservation of class-specific spectral signatures to prevent mode mixing. Consequently, controlled by an appropriate weight
, the SSC functions as a localized physical low-pass filter: it effectively mitigates unphysical inter-band high-frequency noise without over-smoothing the macro-level spectral discriminative features (e.g., absorption depths) that are essential for accurate representation and classification.
3.3. HybridSwinBlock
Traditional Swin Transformer usually only performs window division and attention calculation in the spatial dimension, ignoring the importance of the spectral dimension and its interaction with the spatial dimension [
35]. To this end, this study proposes the HybridSwinBlock module: it integrates the spatial window mechanism and the spectral window mechanism. By completing the window division and attention calculation of the spatial and spectral dimensions in sequence within a single block, and at the same time, alternating between the spatial and spectral dimensions, it can achieve a deep fusion of spatial and spectral features, and more fully capture the interaction between spatial and spectral features in hyperspectral images. The specific process and data changes are as follows:
A hyperspectral image is typically represented as a three-dimensional data cube, where each pixel contains rich spectral information. The input hyperspectral image is denoted by
where
h and
w are the image height and width, and
c is the spectral dimension (number of channels). We first partition the spatial plane into non-overlapping windows of size
. Within each window, the data has shape
, and the collection of windowed tensors is
where
is the total number of spatial windows after partitioning. For efficient attention computation, the data inside each window is flattened into a two-dimensional matrix of size
, and a multi-head self-attention (MSA) operation is applied to extract spatial features. After the spatial attention, the features of each window are reshaped back to
and reassembled to the full feature map of size
:
After obtaining
, its dimensionality remains
. No further reshaping is performed; the spatially attended features are directly used as the input to the spectral-attention computation:
Along the spectral dimension,
is partitioned into contiguous spectral windows of size
. Each window then has shape
. Next, the data in each spectral window is flattened into a two-dimensional matrix of size
, and a multi-head self-attention operation is performed independently within every window along the spectral dimension to capture inter-band dependencies and spectral continuity. After spectral attention, the features are reshaped back to
:
The final output feature representation is
To further enhance the network’s ability to capture fine-grained spatial and spectral features, we propose an interleaved ordering mechanism inside each HybridSwinBlock, in which consecutive blocks adopt different window-attention orders:
Apply spatial attention first, followed by spectral attention:
Apply spectral attention first, followed by spatial attention:
Multiple HybridSwinBlocks together form a SwinStage. Each SwinStage consists of a series of HybridSwinBlocks; adjacent blocks alternate between the spatial-first and spectral-first windowing orders. That is, if the n-th block is spatial-first, then the -th block is spectral-first. This interleaved attention computation enables the model to capture richer spectral interactions present in HSI data. The hybrid Swin Transformer effectively balances model complexity with hyperspectral-specific feature learning. By restricting spatial self-attention to local windows, we keep the computational cost within a controllable range (per layer , rather than the of global attention). Moreover, spectral attention is inherently parallel across spatial locations because the spectral interactions of each pixel are computed independently, which allows an efficient GPU implementation with minimal inter-thread communication.
The alternation of spatial and spectral self-attention yields a hybrid multi-scale attention mechanism, enabling tokens to progressively integrate spatial neighborhood context together with inter-spectral dependencies as depth increases. Compared with traditional hybrid spatial–spectral filtering methods, our approach learns a dynamically weighted mixture (attention) instead of fixed convolutional kernels, thereby capturing more flexible, data-driven relationships more efficiently.
5. Discussion
Under the extremely low supervision quota of only 10% labeled samples per class, the generalization of the classifier is mainly dominated by two types of risks: first, the prior bias of the long-tail class is amplified, and the discrimination boundary of the minority class is eroded by the majority class in the process of empirical risk minimization; second, the statistical sufficiency of the spectral–spatial three-dimensional structure is insufficient, making it difficult for the model to simultaneously learn the stable coupling of long-range dependencies and local geometry. Around these two points, the contribution of the data-side and model-side innovations of this method in the 10% scenario will be significantly “amplified”: after removing SS-cGAN, the decrease in macro-average indicators (AA, macro-F1, G-mean) and
will be significantly greater than that of OA, accompanied by a significant increase in the intra-class recall variance, an expansion of the off-diagonal terms of the confusion matrix in the long tail and similar classes (such as Gravel/Bricks, Grapes Untrained/Vineyard Untrained), and an earlier overfitting and lower peak in the learning curve, indicating that the benefit of SS-cGAN does not come from “data accumulation”, but from the correct shaping of the minority class distribution and spectral-space continuity. If only spectral smoothing is removed, the unphysical spectral noise corrupts the discriminative absorption features, causing the intermixing rate of near-spectral similar classes to increase most significantly. This further confirms that SSC preserves the subtle discriminative features against generative noise, causing the intermixing rate of near-spectral similar classes to increase most significantly. To intuitively illustrate this preservation and confirm that the SSC does not inadvertently cause negative “over-smoothing”, we visualize the spectral signatures in
Figure 12. Using four extreme minority classes from the Indian Pines dataset as examples, it can be observed that the generated spectra (dashed red lines) tightly follow the real data’s macroscopic envelopes (solid blue lines). Most importantly, highly discriminative local features—such as the sharp absorption valleys and distinct peaks—are perfectly retained rather than being artificially flattened. This visual evidence confirms that our calibrated SSC functions as a targeted physical constraint, eliminating unnatural high-frequency GAN jitter while strictly respecting the intrinsic spectral signatures of individual classes. Meanwhile removing only spatial smoothing will manifest as a deterioration of block consistency in the classification graph and an increase in noise points, which is consistent with the key role of spatial prior in combating noise in the 10% scenario. Replacing SS-cGAN with vanilla cGAN is equivalent, even with matching generation scale, it is difficult to replicate the same improvement in AA/
, indicating that “conditional generation with spectral-space consistency”, rather than “unconstrained amplification”, is the source of performance.
On the model side, removing the spectral window and retaining only the spatial window directly weakens cross-band alignment and near-spectral discrimination, with AA and
being the primary impactin
Table 14. Disrupting or removing the execution order of cross-order attention disrupts the prior “spectral → space/space → spectral” pairings, leading to boundary erosion and breakage of slender structures in the ROI, while also releasing errors for adjacent categories in the confusion matrix. Replacing the domain perception module with a standard Swin or 2D-CNN block further amplifies these distortions under equal parameter and computational conditions, suggesting that the inductive bias of “two-dimensional windowing + order alternation” is necessary, not redundant, for the three-dimensional properties of HSI.
More importantly, under the 10% annotation quota, the two aforementioned improvement paths exhibit a synergistic effect: SS-cGAN improves the coverage and balance of the “learnable distribution” at the data level, mitigating long tails and noise, while the domain-aware hybrid Swin provides a spectral–spatial decoupling and recoupling mechanism that matches this distribution at the model level, ensuring that generated and real samples are aligned in the representation space and can be consistently utilized. The combined effect of these two approaches is evident in simultaneous improvements in AA, macro-F1, and , significant reductions in per-class recall variance and ECE, and a gentler rise in the learning curve with later early stopping points. This chain of evidence is particularly critical under the 10% annotation quota, as it transforms “superficial OA gains” into substantial improvements in “class balance, calibration, and robustness,” thereby avoiding misinterpretation of these improvements as incidental gains from parameter tuning or data augmentation.
6. Conclusions
In this paper, we propose a novel Transformer-based model for HSI classification, named S2A-Swin, which combines the properties of HSI with the Swin Transformer network architecture. Specifically, S2A-Swin models local and hierarchical spatial-spectral relationships while building discriminative representations for better classification. S2A-Swin primarily consists of SSC-cGAN and the HybridSwinBlock. Instead of directly applying GAN to generate dependencies, SSC-cGAN leverages spectral physical properties as constraints to reorganize image patches into overlapping cubes. At the data level, a conditional generative adversarial network (SSC-cGAN) with spectral and spatial smoothing regularization is introduced to synthesize patches of scarce categories while maintaining spectral continuity and local geometric consistency, mitigating long-tail bias and insufficient training data at the source. At the model level, a domain-aware hybrid Transformer module is constructed. Through local windowing and cross-order attention in both spatial and spectral dimensions, cross-dimensional information interaction is explicitly guided, enabling the aggregation of long-range dependencies while preserving detail fidelity with manageable complexity. HybridSwinBlock extracts hierarchical spatial–spectral relationships from these tag embeddings with the help of spatial-MSA and spectral-MSA, integrating features from the Swin Transformer module to improve discriminative ability and facilitate training. The two models form a synergistic mechanism: SSC-cGAN provides a more balanced and physically consistent “learnable distribution,” while hybrid Swin uses a matching two-dimensional window and sequential prior to achieve efficient spectral–spatial joint modeling. Experiments on four HSI datasets from different scenarios demonstrate that the proposed S2A-Swin achieves comparable results to existing state-of-the-art HSI classifiers in terms of classification accuracy and computational cost.