2.1. Proposed DSSN Architecture
This section presents the structure of the DSSN and the role of each branch. The DSSN is organized around three core components, a 3D-CNN spectral stream for local spectral–spatial feature extraction, a nested Transformer spatial stream for multi-scale contextual modelling, and an AFM for dynamic feature integration. Given an input hyperspectral patch, the two streams learn complementary representations from different receptive-field ranges. The AFM then recalibrates and fuses these representations before the final classification layer. The spectral stream is designed to preserve short-range spectral correlations and local spectral–spatial structures. Hyperspectral data are naturally represented as volumetric cubes, and 3D convolutions are suitable for jointly processing neighboring spatial pixels and adjacent spectral bands. Therefore, this stream is built from cascaded 3D convolutional layers, as shown in
Figure 1a.
Let the input feature map of the
layer be
, with the dimensions of the feature maps being
; this layer contains
3D convolutional kernels,
, with
indexing the current feature map and
indexing the connected feature map from the previous layer. The activation of the
feature map at spatial–spectral position
in layer
, denoted as
, is computed as follows [
22]:
In this equation, represents the nonlinear activation function. is the number of feature maps in the previous layer. denote the height, width and spectral depth of the 3D convolution kernel, respectively. The kernel parameter is denoted by , and b is the bias term. The indices specify positions inside the convolutional kernel, while indexes the connected feature map from the previous layer. Then, the spectral stream feature is obtained with the shape .
In DSSN, the spectral stream contains three 3D convolutional layers. To avoid excessive compression along the spectral dimension, the network uses valid padding spectrally and same padding spatially; this design progressively aggregates spectral information and produces a feature cube enriched with spectral features. Although the spectral stream captures local spectral–spatial patterns, its convolutional receptive field is limited. DSSN therefore introduces a nested Transformer spatial stream to model broader contextual dependencies. The module contains an inner pixel-level loop for fine local interactions and an outer patch-level loop for broader spatial relationships, allowing local details and global context to be represented within the same nested attention structure.
Assume the input to the DSSN is the preprocessed hyperspectral data cube
, where
B,
D,
H, and
W represent the batch size, the number of spectral bands, the input height, and the input width, respectively. When necessary, the input is padded along the bottom and right boundaries so that the padded height,
, and width,
W′, are divisible by
P. The outer-patch grid is defined as
and
, and the number of outer patch tokens is
. Each outer patch contains
pixel-level tokens. The input
is mapped into two separate embedding spaces using the following formulas:
The pixel-level branch applies a non-overlapping unfold operation within each outer patch. The resulting token sequence, , has tokens per outer patch, and each token contains the spectral values from a spatial subregion. Therefore, the unprojected token dimension is . A learnable linear projection maps each token to the pixel-level embedding dimension, , producing . In parallel, the patch-level branch flattens each outer patch into a single patch token. Each outer patch contains values before projection, and the resulting patch-level sequence contains tokens. The projected patch-level representation is denoted by . This step establishes two parallel yet interconnected sequences: for capturing local details and for carrying global information.
In the
nested attention block, Multi-Head Self-Attention (MSA) [
22,
23] is applied to model the local correlations between the pixels. The formula is as follows:
where
denotes the pixel-level feature entering the
layer, and
denotes the attention-updated intermediate representation. Subsequently, the DRNet is used in the feedforward block instead of a conventional Multi-Layer Perceptron (MLP) [
24] to improve nonlinear feature extraction, as shown in
Figure 1b, yielding the refined pixel features,
, output by the inner loop. The formula is as follows:
As illustrated in
Figure 1b, DRNet reshapes the input feature and then feeds it into two consecutive dual-branch blocks. Each block consists of two parallel branches, both comprising a convolutional layer, a batch normalization layer, and an ReLU activation function. The upper branch employs a
convolution to capture local spatial information, whereas the lower branch uses a
convolution to perform channel-wise feature transformation. The outputs of the two branches are fused through element-wise addition. After the two dual-branch blocks, the resulting feature is further refined by a
convolution followed by a PReLU activation. A long residual connection adds the original reshaped feature to the refined feature, facilitating information preservation and stable feature learning. Finally, the fused feature is reshaped to produce the output. The primary purpose of DRNet is to refine the input features by combining local spatial feature extraction, channel-wise feature transformation, and residual learning. This design enhances feature representation while preserving the original information and improving the stability of network optimization.
To pass inner-loop details into the outer layer, the network aggregates pixel-level information along the spatial dimension to obtain an aggregated vector,
. This operation is defined as follows:
Here, represents the pixel feature and is a learnable linear projection matrix used to align the feature dimensions from to .
The aggregated local representation,
, is then added to the patch-level feature to obtain an enhanced patch feature,
, which integrates local details and serves as the input for the outer loop. The formula is as follows:
After obtaining the feature
, a standard Transformer structure is utilized in the outer loop to model global contextual relationships, yielding the final patch feature,
, output by the
nested block. This operation is defined as follows:
where the intermediate
denotes the features after the attention mechanism. The number of nested attention layers and attention heads in the MSA modules used in Equations (6) and (10) are specified in
Table 1.
After processing through
layers of nested blocks, the final patch sequence output is obtained. To align the final patch sequence with the spatial feature map generated by the 3D-CNN stream, a spatial reconstruction operation is performed. The resulting feature map,
is used as the output feature of the spatial stream, using the following formula:
Here, denotes the final patch token sequence produced by the nested Transformer blocks. The operator rearranges the sequence into the two-dimensional outer-patch grid of size , yielding . After channel projection using convolutions, the spatial stream feature, , is bilinearly interpolated to match the spectral stream feature, . When the input dimensions are not divisible by the outer-patch size, boundary padding is used only to construct a complete token grid; a valid-region mask is generated simultaneously to distinguish the original input pixels from padded positions; the mask is propagated to the pixel-level aggregation and patch-level attention operations; therefore, the padded positions do not contribute to the aggregated representation or attention computation. After spatial interpolation, the valid-region mask is also applied before feature fusion, ensuring that the final prediction is determined only by the original input region.
After the spectral stream feature,
, and the spatial stream feature,
, are obtained, with shapes
and
, respectively, the DSSN uses a channel-attention-based AFM to integrate them. The AFM is inspired by the squeeze-and-excitation mechanism, but is used here to recalibrate the relative contribution of the spectral and spatial streams during dual-stream fusion [
25].
Figure 2 shows the AFM workflow; the spectral and spatial feature maps are joined along the channel axis to obtain a mixed feature map,
, with the shape
. This operation is defined as follows:
where
denotes the channel-wise joining of the two branch outputs.
To determine the importance of each channel, the representation is simplified. Instead of computing the value of every pixel, this part only requires the overall response intensity of the entire channel. Therefore, this network averages across the
spatial dimensions to obtain the global channel feature
, with a shape of
; this vector represents the global distribution of the current sample across all feature channels, and the formula is as follows:
Next, a small MLP is used to learn the dependencies between channels; the MLP reduces the number of channels to form a bottleneck representation and then restores the channel dimension. After restoring the channel count to
, the output values are mapped between 0 and 1 to obtain the attention weight vector,
, with a shape of
, using the following formula:
where
represents the Sigmoid activation function,
represents the ReLU activation function,
is the weight matrix of the first dimensionality reduction layer, and
is the weight matrix of the second dimensionality reduction layer.
The generated weights are multiplied channel-by-channel with the original concatenated features to yield a new mixed feature map,
; important feature channels are enhanced, while unimportant or noisy channels are suppressed, using the following formula:
Finally, these filtered features are blended using a
convolution via linear combination, allowing the two streams to interact across channels; this operation compresses the fused channels, resulting in a more compact spatial output feature,
, using the following formula:
the final feature,
, is mapped to the category space through fully connected layers, followed by a softmax function that outputs the class–probability distribution. The detailed implementation of the forward propagation of DSSN is presented in Algorithm 1.
| Algorithm 1 Forward propagation of DSSN. | |
Input: Hyperspectral patch X ∈ RB×D×H×W Output: Predicted class yhat | |
| 1: S ← X | //B × D × H × W |
| 2: S ← Conv3D(S) | //3D convolution |
| 3: S ← BN(S); S ← ReLU(S) | //Spectral stream |
| 4: S ← Conv3D(S) | //3D convolution |
| 5: S ← BN(S); S ← ReLU(S) | |
| 6: S ← Conv3D(S) | //3D convolution |
| 7: S ← BN(S); S ← ReLU(S) | //Spectral feature |
| 8: Xp ← DivideIntoPatches(X, P) | //Patch size P × P |
| 9: Q ← PixelEmbedding(Xp, p) | //Pixel window p × p |
| 10: K ← PatchEmbedding(Xp) | //Patch representation |
| 11: for l = 1, …, L do | //L nested blocks |
| 12: Q ← PixelTransformer(Q) | //Inner Transformer |
| 13: Q ← DRNet(Q) | //Local feature refinement |
| 14: K ← K + Aggregate(Q) | //Local-to-patch aggregation |
| 15: K ← PatchTransformer(K) | //Outer Transformer |
| 16: end for | |
| 17: R ← SpatialReconstruction(K) | //Spatial feature map |
| 18: R ← Resize (R, size(S)) | //Match S and R |
| 19: F ← Concatenate (S, R) | //Dual-stream feature |
| 20: F ← AFM(F) | //Adaptive feature fusion |
| 21: F ← AveragePooling(F) | //Global average pooling |
| 22: F ← Dropout (F, r) | //Dropout rate r |
| 23: F ← FC1(F) | //Fully connected layer |
| 24: F ← FC2(F) | //Fully connected layer |
| 25: y ← Softmax(F) | //K class probabilities |
| 26: yhat ← Argmax(y) | //Predicted class |
| 27: return yhat | |
2.3. Experimental Setup
All experiments were implemented in PyTorch 2024.3.4 and conducted on a workstation equipped with an Intel Core i5-12400F CPU (Intel Corporation, Santa Clara, CA, USA), 16 GB RAM, and an NVIDIA GeForce GTX 1660 Ti GPU (NVIDIA Corporation, Santa Clara, CA, USA); the implementation used CUDA acceleration when available. To reduce the influence of random initialization and data partitioning, the random seeds of Python 3.9, NumPy 1.23.5, and PyTorch 2024.3.4 were fixed during training, and the cuDNN 8.9 backend was set to deterministic mode. For each hyperspectral dataset, the raw hyperspectral cube and its corresponding ground-truth map were loaded from mat files, only labeled pixels were used for training and testing, while background pixels with label value 0 were excluded from metric calculation. In the current implementation, each hyperspectral scene is first divided into a training region and a test region, after which normalization and patch extraction are performed. Specifically, the original hyperspectral scene is represented as ; after the data split, the training region is reshaped into , and the minimum and maximum values are computed independently for each spectral band. The complete hyperspectral scene is then min–max-normalized using the statistics obtained exclusively from the training region, and the normalized data are reshaped back into the format. Then, fixed-size spatial–spectral patches are extracted from the normalized scene around the labeled center pixels in the original ground-truth map; these patches are assigned to the training or test set according to the partition to which their center pixels belong. The spatial patch size was set to 12 × 12, and the number of spectral channels depended on the dataset: 200 bands for Indian Pines, 103 bands for Pavia University, and 204 bands for Salinas. To ensure that pixels located at the image boundaries receive a fixed-size spatial neighborhood, we applied reflection padding to the two spatial dimensions of the normalized hyperspectral image before patch extraction. No padding was applied along the spectral dimension, and reflection padding mirrors the true pixels adjacent to the image boundaries to complete the missing neighborhood and does not introduce zero-valued or constant spectral vectors. For a labeled center pixel located at an image edge or corner, both its spatial coordinate and ground-truth label were retained from the original image; only the portion of its spatial neighborhood extending beyond the original image boundaries was supplemented with reflected values. Consequently, boundary pixels could be inferred using the same input size and model as interior pixels. Importantly, reflected pixels were not treated as additional training or testing samples, center coordinates were selected from the original ground-truth map using the condition gt > 0, and the train–test split was performed exclusively among these original labeled center pixels. The input of DSSN was constructed as a spatial–spectral patch centered on each labeled pixel. Within each local input patch, the Transformer stream partitions the patch into non-overlapping outer patches. Each outer patch is further divided into non-overlapping pixel-level subregions. Therefore, a input patch produces a outer-patch grid containing four patch-level tokens, while each outer patch contains four pixel-level tokens; for input dimensions that are not divisible by the outer patch size, reflection padding is applied before tokenization.
Therefore, each input sample retained both the local neighborhood structure and the complete spectral signature of the center pixel. To avoid overlap between training and testing neighborhoods, the image was partitioned into spatial blocks before sample extraction. Different blocks were assigned exclusively to the training or testing partition, and a buffer zone of at least 6 pixels was introduced along the partition boundary, corresponding to the radius of the 12 × 12 neighborhood. Labeled center pixels falling within this buffer zone were excluded from both partitions. Thus, no raw image pixel was shared by any training patch and testing patch. The labeled samples of each dataset were split in a class-wise manner; for every land-cover class, 10 percent of the samples in the designated training region were randomly selected for training, with at least 10 training samples retained per class. The remaining labeled samples were used for testing; this class-wise sampling strategy prevents large classes from dominating the split and ensures that small classes with very few samples still contribute to the training process.
During training, simple spatial data augmentation was applied to the training patches, this included random horizontal flipping, random vertical flipping, and random rotations by multiples of 90 degrees; these operations preserve the spectral identity of the land-cover categories while increasing the spatial diversity of local neighborhoods. Such augmentation is particularly suitable for hyperspectral image classification because many land-cover classes are not sensitive to absolute orientation, but the model still needs to recognize them under different local spatial arrangements. The proposed DSSN was trained for 200 epochs with a batch size of 64; AdamW was used as the optimizer, with an initial learning rate of 1 × 10−3 and a weight decay of 1 × 10−4. To make the early training stage more stable, a warm-up strategy was adopted for the first 10% of the total epochs, after which a cosine annealing learning rate schedule was used, with the minimum learning rate set to 1 × 10−6. Cross-entropy loss with label smoothing was used for classification, and the label-smoothing factor was set to 0.1; the dropout rate in the final classifier was set to 0.5 to reduce overfitting; automatic mixed precision training was enabled to improve the computational efficiency of the GPU; gradient clipping with a maximum norm of 1.0 was applied to avoid the unstable updates caused by occasional large gradients; the model checkpoint was saved according to the monitored training loss and early stopping was used to prevent unnecessary training after convergence. The early stopping patience was set to 20 epochs in the main DSSN implementation. For repeated comparative experiments in the project records, each model dataset setting was run five times using different random seeds, and the mean and standard deviation were calculated from cycle runs; training data, including loss and training accuracy, were saved after training for convergence analysis; prediction maps were generated by applying the trained model to all labeled pixels in the scene, using the same patch extraction and reflection padding strategy as in training.