# li-yapeng/mambahsi architecture

> Architecture diagram of the GitHub repository li-yapeng/mambahsi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/li-yapeng/mambahsi
- Repository: https://github.com/li-yapeng/mambahsi

## Overview

MambaHSI is a hyperspectral-image classification research application. Its main workflow loads a selected dataset, samples labeled pixels into training, validation, and test splits, trains the spatial-spectral Mamba model, and reports classification metrics. The model implementation and evaluation utilities are sampled; some training-script sections are omitted, so uncertain connections to visualization and artifact-writing helpers are not asserted.

Main entry points: [`train_MambaHSI.py`](https://github.com/li-yapeng/mambahsi/blob/main/train_MambaHSI.py) (Training runner), [`model/MambaHSI.py`](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py) (MambaHSI network), [`utils/data_load_operate.py`](https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py) (Label sampling), [`utils/evaluation.py`](https://github.com/li-yapeng/mambahsi/blob/main/utils/evaluation.py) (Metric evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_loader["Dataset loading"]
  node_preparation["Image preparation<br/>[HSICommonUtils.py]"]
  node_sampling["Label sampling"]
  node_image_splits["Image split maps"]
end

subgraph group_model["Classification model"]
  node_network["MambaHSI network<br/>[MambaHSI.py]"]
  node_spatial_mamba["Spatial Mamba<br/>[MambaHSI.py]"]
  node_spectral_mamba["Spectral Mamba<br/>[MambaHSI.py]"]
  node_fusion["Spatial-spectral fusion<br/>[MambaHSI.py]"]
  node_classifier["Classification head<br/>[MambaHSI.py]"]
end

subgraph group_training["Training and evaluation"]
  node_trainer["Training runner<br/>[train_MambaHSI.py]"]
  node_loss["Segmentation loss<br/>[Loss.py]"]
  node_evaluator["Metric evaluation<br/>[evaluation.py]"]
end

subgraph group_outputs["Results and visualization"]
  node_metrics["Classification metrics"]
  node_visualizer["Prediction visualization<br/>[visual_predict.py]"]
  node_visual_outputs["Prediction and GT maps"]
end

node_researcher(("Researcher"))
node_hsi_data["HSI datasets"]
node_ssm_dependency["Mamba SSM"]

node_researcher -->|"starts run"| node_trainer
node_hsi_data -->|"loads files"| node_loader
node_trainer -->|"loads dataset"| node_loader
node_trainer -->|"stretches image"| node_preparation
node_trainer -->|"requests splits"| node_sampling
node_sampling -->|"creates label maps"| node_image_splits
node_trainer -->|"uses splits"| node_image_splits
node_trainer -->|"constructs and trains"| node_network
node_network -->|"applies spatial modeling"| node_spatial_mamba
node_network -->|"applies spectral modeling"| node_spectral_mamba
node_network -->|"combines branches"| node_fusion
node_fusion -->|"evaluates branch"| node_spatial_mamba
node_fusion -->|"evaluates branch"| node_spectral_mamba
node_network -->|"produces logits"| node_classifier
node_spatial_mamba -->|"invokes"| node_ssm_dependency
node_spectral_mamba -->|"invokes"| node_ssm_dependency
node_trainer -->|"computes loss"| node_loss
node_trainer -->|"updates metrics"| node_evaluator
node_evaluator -->|"reports"| node_metrics
node_visualizer -->|"saves maps"| node_visual_outputs

click node_trainer "https://github.com/li-yapeng/mambahsi/blob/main/train_MambaHSI.py"
click node_loader "https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py"
click node_preparation "https://github.com/li-yapeng/mambahsi/blob/main/utils/HSICommonUtils.py"
click node_sampling "https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py"
click node_image_splits "https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py"
click node_network "https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py"
click node_spatial_mamba "https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py"
click node_spectral_mamba "https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py"
click node_fusion "https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py"
click node_classifier "https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py"
click node_loss "https://github.com/li-yapeng/mambahsi/blob/main/utils/Loss.py"
click node_evaluator "https://github.com/li-yapeng/mambahsi/blob/main/utils/evaluation.py"
click node_visualizer "https://github.com/li-yapeng/mambahsi/blob/main/utils/visual_predict.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_preparation,node_sampling,node_image_splits toneBlue
class node_network,node_spatial_mamba,node_spectral_mamba,node_fusion,node_classifier toneAmber
class node_trainer,node_loss,node_evaluator toneMint
class node_metrics,node_visualizer,node_visual_outputs toneRose
class node_researcher,node_hsi_data,node_ssm_dependency toneIndigo
```

## Components

### Data preparation

- [Dataset loading](https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py): `utils/data_load_operate.py`
- [Image preparation](https://github.com/li-yapeng/mambahsi/blob/main/utils/HSICommonUtils.py): `utils/HSICommonUtils.py`
- [Label sampling](https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py): `utils/data_load_operate.py`
- [Image split maps](https://github.com/li-yapeng/mambahsi/blob/main/utils/data_load_operate.py): `utils/data_load_operate.py`

### Classification model

- [MambaHSI network](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py): `model/MambaHSI.py`
- [Spatial Mamba](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py): `model/MambaHSI.py`
- [Spectral Mamba](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py): `model/MambaHSI.py`
- [Spatial-spectral fusion](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py): `model/MambaHSI.py`
- [Classification head](https://github.com/li-yapeng/mambahsi/blob/main/model/MambaHSI.py): `model/MambaHSI.py`

### Training and evaluation

- [Training runner](https://github.com/li-yapeng/mambahsi/blob/main/train_MambaHSI.py): `train_MambaHSI.py`
- [Segmentation loss](https://github.com/li-yapeng/mambahsi/blob/main/utils/Loss.py): `utils/Loss.py`
- [Metric evaluation](https://github.com/li-yapeng/mambahsi/blob/main/utils/evaluation.py): `utils/evaluation.py`

### Results and visualization

- **Classification metrics**
- [Prediction visualization](https://github.com/li-yapeng/mambahsi/blob/main/utils/visual_predict.py): `utils/visual_predict.py`
- **Prediction and GT maps**

### Other components

- **Researcher**
- **HSI datasets**
- **Mamba SSM**

## Connections

- Researcher → Training runner: starts run
- HSI datasets → Dataset loading: loads files
- Training runner → Dataset loading: loads dataset
- Training runner → Image preparation: stretches image
- Training runner → Label sampling: requests splits
- Label sampling → Image split maps: creates label maps
- Training runner → Image split maps: uses splits
- Training runner → MambaHSI network: constructs and trains
- MambaHSI network → Spatial Mamba: applies spatial modeling
- MambaHSI network → Spectral Mamba: applies spectral modeling
- MambaHSI network → Spatial-spectral fusion: combines branches
- Spatial-spectral fusion → Spatial Mamba: evaluates branch
- Spatial-spectral fusion → Spectral Mamba: evaluates branch
- MambaHSI network → Classification head: produces logits
- Spatial Mamba → Mamba SSM: invokes
- Spectral Mamba → Mamba SSM: invokes
- Training runner → Segmentation loss: computes loss
- Training runner → Metric evaluation: updates metrics
- Metric evaluation → Classification metrics: reports
- Prediction visualization → Prediction and GT maps: saves maps
