Downloads · 30 days
0
ahczhg/ECG-Mamba2-Bidirectional-MultiLead
ECG-Mamba2-Bidirectional-MultiLead is a machine learning model from ahczhg. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains an enhanced version of the ECG-Mamba model for 12-lead ECG arrhythmia classification. The Enhanced ECG-Mamba2 builds upon the original modelsmambaecg.py implementation with significant archite…
Downloads · 30 days
0
Access
Public
Updated Nov 28, 2025
Repo size
—
Likes
1
Public
Click a slice to open those files.
.ipynb315 KB · 89%
From the Hugging Face model README
This repository contains an enhanced version of the ECG-Mamba model for 12-lead ECG arrhythmia classification. The Enhanced ECG-Mamba2 builds upon the original models_mamba_ecg.py implementation with significant architectural improvements.
Enhanced ECG-Mamba2 is a deep learning model for ECG classification that combines:
models_mamba_ecg.py| Feature | Original (models_mamba_ecg.py) | Enhanced (Enhanced_ECG_Mamba_Test.ipynb) |
|---|---|---|
| State Space Model | VisionMamba (Mamba-1 based) | Mamba-2 (State Space Duality) |
| Scanning Direction | Unidirectional | Bidirectional (Forward + Backward) |
| Lead Processing | Single pathway | Multi-branch (4 lead groups) |
| Attention | None | Transformer attention layer |
| Training | Standard | Adversarial + Frequency Masking |
| Explainability | None | MambaLRP |
The CNN layers from the original implementation are preserved:
Input: (batch, 12, 8192) -> Conv1d layers -> Output: (batch, 729, 384)
Four specialized branches process different ECG lead groups:
Multi-head self-attention layer captures short-term dependencies that complement Mamba-2's long-range modeling.
Global average pooling followed by a linear classifier.
FGSM-style perturbations are applied during training to improve model robustness.
Random frequency bands are masked in the FFT domain to make the model robust to noise and artifacts.
MambaLRP (Layer-wise Relevance Propagation) provides interpretability by highlighting which parts of the ECG signal contribute most to the model's predictions.
The model is designed for the PhysioNet Challenge 2021 dataset with 5 arrhythmia classes:
torch>=2.0
mamba-ssm>=2.0
causal-conv1d
einops
wfdb
numpy
scikit-learn
matplotlib
models_mamba_ecg.py - Original VisionMamba implementation for ECGEnhanced_ECG_Mamba_Test.ipynb - Enhanced ECG-Mamba2 implementation with all improvementsREADME.md - This fileLICENSE - MIT Licensefrom enhanced_ecg_mamba2 import EnhancedECGMamba2
# Create model
model = EnhancedECGMamba2(
n_classes=5,
embed_dim=384,
n_layers=4,
use_multi_branch=True,
use_attention=True
)
# Forward pass
# Input: (batch, seq_len=8192, channels=12)
output = model(x)
If you use this code, please cite:
@software{enhanced_ecg_mamba2,
title={Enhanced ECG-Mamba2: Bidirectional State Space Model for ECG Classification},
year={2024},
note={Improvements over models_mamba_ecg.py with Mamba-2, bidirectional scanning, multi-branch architecture, and attention}
}
This project is licensed under the MIT License - see the LICENSE file for details.