Official implementation of "Spatial-Semantic Mamba: Preserving 2D Structure and Meaningful Sequencing for Enhanced Computational Pathology"
📄 Spatial-Semantic Mamba: Preserving 2D Structure and Meaningful Sequencing for Enhanced Computational Pathology
This work was developed as a graduate-level research project and is currently an unpublished manuscript / preprint.
SS-Mamba is a novel framework for Whole Slide Image (WSI) classification that addresses two critical limitations in current computational pathology methods:
- Spatial Discrepancy: Standard methods flatten 2D patches into 1D sequences, destroying spatial relationships
- Random Patch Ordering: MIL frameworks process patches in arbitrary order, ignoring semantic relationships
Our approach introduces:
- 2D-SSM Backbone: Bidirectional scanning along horizontal and vertical axes
- Semantic Pre-ordering: Parameter-free ordering based on feature similarity
- BiMamba Aggregator: Bidirectional Mamba for MIL aggregation
SS-Mamba/
├── README.md
├── requirements.txt
├── setup.py
├── configs/
│ └── config.yaml # Configuration file
├── ss_mamba/ # Main package
│ ├── models/
│ │ ├── ss_mamba.py # Full SS-Mamba model
│ │ ├── backbone/
│ │ │ └── mamba_2d.py # 2D-SSM backbone
│ │ ├── ordering/
│ │ │ └── semantic_ordering.py
│ │ └── aggregator/
│ │ └── bimamba_mil.py # BiMamba aggregator
│ ├── data/
│ │ ├── wsi_dataset.py # WSI dataset class
│ │ ├── preprocessing.py # Patch extraction
│ │ └── transforms.py # Augmentations
│ └── utils/
│ ├── metrics.py # Evaluation metrics
│ ├── logger.py # Logging utilities
│ └── visualization.py # Visualization tools
├── tools/
│ ├── train.py # Training script
│ ├── evaluate.py # Evaluation script
│ └── extract_features.py # Feature extraction
└── scripts/
├── run_experiment.sh # Run single experiment
└── run_all_datasets.sh # Run all experiments
Download datasets and organize as follows:
data/
├── camelyon16/
│ ├── train/
│ │ ├── slides/ # .tif files
│ │ └── labels.csv
│ └── test/
├── tcga_brca/
│ ├── slides/
│ └── labels.csv
└── bracs/
├── slides/
└── labels.csv
python tools/extract_features.py \
--data_path /path/to/slides \
--output_path /path/to/patches \
--patch_size 256 \
--magnification 20# Camelyon16 (binary classification)
python tools/train.py \
--dataset camelyon16 \
--data_path /path/to/data \
--num_classes 2 \
--epochs 100
# TCGA-BRCA (4-class classification)
python tools/train.py \
--dataset tcga_brca \
--data_path /path/to/data \
--num_classes 4 \
--epochs 100
# BRACS (7-class classification)
python tools/train.py \
--dataset bracs \
--data_path /path/to/data \
--num_classes 7 \
--epochs 150Or use shell scripts:
bash scripts/run_experiment.sh camelyon16
bash scripts/run_all_datasets.shpython tools/evaluate.py \
--dataset camelyon16 \
--checkpoint /path/to/checkpoint.pth \
--data_path /path/to/dataEdit configs/config.yaml for custom settings:
model:
hidden_dim: 512
num_layers: 2
dropout: 0.25
ordering:
lambda_spatial: 0.5
sigma: 100
training:
lr: 0.0002
weight_decay: 0.05
epochs: 100
batch_size: 1| Dataset | WSIs | Classes | Task | Link |
|---|---|---|---|---|
| Camelyon16 | 399 | 2 | Metastasis Detection | Link |
| TCGA-BRCA | 1,098 | 4 | Molecular Subtyping | Link |
| BRACS | 547 | 7 | Tumor Typing | Link |
- Mamba for the State Space Model implementation
- VMamba for 2D scanning patterns
- CLAM for WSI preprocessing pipeline
- Sina Mansouri - Smansou3@gmu.edu
- Neelesh Prakash Wadhwani - nwadhwan@gmu.edu
- Philip Stavrev - pstavrev@gmu.edu