Dynamic Memory-enhanced Transformer for Hyperspectral Image Classification

Muhammad Ahmad, Manuel Mazzara, Salvatore Distefano, Adil Mehmood KhanarXiv 2025 · DOI

Introduction

Hyperspectral Image (HSI) classification is a critical task in remote sensing, enabling precise material identification by capturing hundreds of narrow spectral bands. However, the high dimensionality of HSI data, combined with complex spatial-spectral correlations, presents significant challenges for traditional deep learning models. This paper introduces MemFormer (also referred to as MSST), a lightweight transformer architecture that leverages a dynamic memory-enhanced attention mechanism to achieve state-of-the-art performance with high efficiency.

The Challenge of HSI Classification

The primary difficulty in HSI classification stems from the "Hughes phenomenon," where classification accuracy can decrease as the number of spectral bands increases for a fixed number of training samples. While Convolutional Neural Networks (CNNs) are effective at capturing local spatial features, they often struggle with long-range spectral dependencies. Conversely, standard Transformers, while capable of modeling global context, often suffer from information redundancy and high computational costs, leading to a "forgetting" effect where fine-grained details are diluted across deep layers.

The MemFormer Architecture

The MemFormer architecture addresses these limitations through three core innovations designed to balance local and global feature extraction while maintaining a low parameter footprint.

Figure 1: The MemFormer architecture featuring the Dynamic Memory-based transformer layer and Memory-enhanced Multi-Head Attention (MMHA).

1. Dynamic Memory-enhanced Multi-Head Attention (MMHA)

Unlike standard self-attention mechanisms that process inputs in isolation, MemFormer maintains a global dynamic memory matrix ($M$). This memory module stores and refines critical features across layers using a First-In-First-Out (FIFO) update policy. By interacting with this memory, the attention mechanism can better distinguish between essential signals and redundant noise, effectively acting as a global context refiner.

2. Spatial-Spectral Positional Encoding (SSPE)

To preserve the 3D structural integrity of the HSI cube without the computational expense of 3D convolutions, MemFormer employs a specialized Spatial-Spectral Positional Encoding. SSPE uses separate sinusoidal functions for spatial coordinates ($x, y$) and spectral band indices ($s$), ensuring the model remains aware of the volumetric continuity of the data.

3. Lightweight Design

MemFormer is engineered for efficiency. By utilizing a patch-wise tokenization strategy and a streamlined memory update rule, the model achieves high performance with only four layers and eight attention heads. This results in a compact architecture of approximately 847,632 parameters, significantly fewer than many hybrid CNN-Transformer models.

Experimental Results

The authors evaluated MemFormer on three benchmark datasets: Indian Pines (IP), WHU-Hi-HanChuan (HC), and WHU-Hi-HongHu (HH). The model consistently outperformed existing state-of-the-art (SOTA) methods, including 3D-CNNs and advanced transformers like WaveFormer (WF) and HSST.

Figure 4: Quantitative comparison of MemFormer (MSST) against SOTA models on the Indian Pines dataset, highlighting superior accuracy and efficiency.

As shown in the results table, MemFormer (MSST) achieved an Overall Accuracy (OA) of 99.55% on the Indian Pines dataset. Notably, it maintained a competitive training time of approximately 101 seconds and a significantly lower parameter count compared to high-performing 3D-CNN baselines. Ablation studies further revealed that a memory size of 10 tokens provides the optimal balance between context retention and noise suppression.

Conclusion

MemFormer demonstrates that a dynamic memory module can significantly enhance the performance of transformers in HSI classification by filtering redundancy and refining global context. Its lightweight design and superior accuracy make it a promising candidate for real-world remote sensing applications, including potential deployment on edge devices like UAVs and satellites. Future work will explore domain adaptation and further model compression to enhance robustness across diverse sensors.

Summary updated

BibTeX
@misc{ahmad2025dynamic,
  author = {Muhammad Ahmad and Manuel Mazzara and Salvatore Distefano and Adil Mehmood Khan},
  title = {{Dynamic Memory-enhanced Transformer for Hyperspectral Image Classification}},
  year = {2025},
  eprint = {2504.13242},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.13242},
}
Figure