Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,167 +1,175 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
|
| 14 |
-
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
## Model Architecture
|
| 18 |
|
| 19 |
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
-
- `d_conv`: 4 (convolution kernel size)
|
| 29 |
-
- `expand`: 2 (expansion factor)
|
| 30 |
-
|
| 31 |
-
## Requirements
|
| 32 |
-
|
| 33 |
-
- Python 3.7+
|
| 34 |
-
- PyTorch
|
| 35 |
-
- mamba-ssm
|
| 36 |
-
- causal-conv1d >= 1.2.0
|
| 37 |
-
- wfdb
|
| 38 |
-
- pandas
|
| 39 |
-
- numpy
|
| 40 |
-
- scikit-learn
|
| 41 |
-
- matplotlib
|
| 42 |
-
- requests
|
| 43 |
-
|
| 44 |
-
## Installation
|
| 45 |
-
|
| 46 |
-
```bash
|
| 47 |
-
pip install torch mamba-ssm causal-conv1d wfdb pandas numpy scikit-learn matplotlib requests
|
| 48 |
-
```
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
2. Set Runtime type to GPU (Runtime → Change runtime type → T4 GPU)
|
| 58 |
-
3. Run all cells sequentially
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
##
|
| 68 |
|
| 69 |
-
|
| 70 |
-
-
|
| 71 |
-
-
|
| 72 |
-
- Multiple diagnostic statements by cardiologists
|
| 73 |
|
| 74 |
-
For
|
| 75 |
-
- 500 records (configurable via `NUM_RECORDS`)
|
| 76 |
-
- Low resolution (100Hz) for faster processing
|
| 77 |
-
- Single diagnostic superclass per record for simplified classification
|
| 78 |
|
| 79 |
-
|
| 80 |
-
```
|
| 81 |
-
Wagner, P., Strodthoff, N., Bousseljot, R., Samek, W., & Schaeffter, T. (2020).
|
| 82 |
-
PTB-XL, a large publicly available electrocardiography dataset (version 1.0.3).
|
| 83 |
-
PhysioNet. https://doi.org/10.13026/x4td-x982
|
| 84 |
-
```
|
| 85 |
-
|
| 86 |
-
## Training Results
|
| 87 |
-
|
| 88 |
-
Typical training performance (10 epochs, 500 records):
|
| 89 |
-
- Training Accuracy: ~75%
|
| 90 |
-
- Test Accuracy: ~70%
|
| 91 |
-
- Training time: ~2-3 minutes on T4 GPU
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
- Fast inference time thanks to Mamba's efficient architecture
|
| 97 |
-
- Good generalization on multi-class ECG classification
|
| 98 |
-
- Potential for improvement with larger datasets and longer training
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
-
#
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
.
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
├── LICENSE # MIT License
|
| 114 |
-
└── ptb_xl_data/ # Downloaded dataset (created at runtime)
|
| 115 |
```
|
| 116 |
|
| 117 |
-
##
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
- **HYP**: Hypertrophy
|
| 125 |
|
| 126 |
-
##
|
| 127 |
|
| 128 |
-
-
|
| 129 |
-
-
|
| 130 |
-
-
|
| 131 |
-
-
|
| 132 |
-
- [ ] Support for multi-label classification
|
| 133 |
-
- [ ] Model deployment pipeline
|
| 134 |
-
- [ ] Real-time ECG inference API
|
| 135 |
|
| 136 |
-
##
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
-
|
|
|
|
| 145 |
|
| 146 |
-
##
|
| 147 |
|
| 148 |
-
-
|
| 149 |
-
-
|
| 150 |
-
-
|
| 151 |
|
| 152 |
## Citation
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
```bibtex
|
| 157 |
@software{ecg_mamba_2024,
|
| 158 |
title={ECG-Mamba: Cardiac Abnormality Classification using Mamba Architecture},
|
| 159 |
-
author={Your Name},
|
| 160 |
year={2024},
|
| 161 |
-
url={https://
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
```
|
| 164 |
|
| 165 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
For questions or
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- ecg
|
| 5 |
+
- mamba
|
| 6 |
+
- cardiac
|
| 7 |
+
- classification
|
| 8 |
+
- medical
|
| 9 |
+
- ptb-xl
|
| 10 |
+
- state-space-model
|
| 11 |
+
datasets:
|
| 12 |
+
- PTB-XL
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
library_name: pytorch
|
| 16 |
+
pipeline_tag: image-classification
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# ECG-Mamba: Cardiac Abnormality Classification
|
| 20 |
+
|
| 21 |
+
## Model Description
|
| 22 |
+
|
| 23 |
+
ECG-Mamba is a deep learning model that leverages the Mamba state space architecture for classifying cardiac abnormalities from 12-lead ECG signals. The model is trained on the PTB-XL dataset from PhysioNet.
|
| 24 |
|
| 25 |
## Model Architecture
|
| 26 |
|
| 27 |
+
- **Base Architecture**: Mamba (Selective State Space Model)
|
| 28 |
+
- **Input**: 12-lead ECG signals (1000 timesteps × 12 channels at 100Hz)
|
| 29 |
+
- **Output**: 5-class classification (NORM, MI, STTC, CD, HYP)
|
| 30 |
+
- **Parameters**:
|
| 31 |
+
- Model dimension (d_model): 64
|
| 32 |
+
- State space dimension (d_state): 16
|
| 33 |
+
- Number of Mamba layers: 2
|
| 34 |
+
- Convolution kernel size (d_conv): 4
|
| 35 |
+
- Expansion factor: 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
## Intended Use
|
| 38 |
|
| 39 |
+
This model is designed for:
|
| 40 |
+
- Research purposes in cardiac abnormality detection
|
| 41 |
+
- Educational demonstrations of Mamba architecture on medical signals
|
| 42 |
+
- Baseline comparison for ECG classification tasks
|
| 43 |
|
| 44 |
+
**Note**: This model is NOT intended for clinical diagnosis or medical decision-making.
|
| 45 |
|
| 46 |
+
## Training Data
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
- **Dataset**: PTB-XL (PhysioNet)
|
| 49 |
+
- **Training samples**: ~400 records (80% of 500 record subset)
|
| 50 |
+
- **Validation samples**: ~100 records (20% of 500 record subset)
|
| 51 |
+
- **Sampling rate**: 100 Hz (low resolution)
|
| 52 |
+
- **Signal length**: 10 seconds (1000 samples)
|
| 53 |
+
- **Preprocessing**: Standardization (zero mean, unit variance per channel)
|
| 54 |
|
| 55 |
+
## Performance
|
| 56 |
|
| 57 |
+
On the test subset (500 records):
|
| 58 |
+
- **Training Accuracy**: ~75%
|
| 59 |
+
- **Test Accuracy**: ~70%
|
|
|
|
| 60 |
|
| 61 |
+
**Important**: These metrics are from a small-scale demonstration. For production use, train on the full PTB-XL dataset (21,837 records).
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
## Diagnostic Classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
| Class | Description |
|
| 66 |
+
|-------|-------------|
|
| 67 |
+
| NORM | Normal ECG |
|
| 68 |
+
| MI | Myocardial Infarction |
|
| 69 |
+
| STTC | ST/T Change |
|
| 70 |
+
| CD | Conduction Disturbance |
|
| 71 |
+
| HYP | Hypertrophy |
|
| 72 |
|
| 73 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
```python
|
| 76 |
+
import torch
|
| 77 |
+
import numpy as np
|
| 78 |
+
from mamba_ssm import Mamba
|
| 79 |
|
| 80 |
+
# Load model (you'll need to save/load weights separately)
|
| 81 |
+
model = ECGMambaClassifier(n_classes=5)
|
| 82 |
+
model.load_state_dict(torch.load('model_weights.pth'))
|
| 83 |
+
model.eval()
|
| 84 |
|
| 85 |
+
# Prepare your ECG data
|
| 86 |
+
# ecg_signal: numpy array of shape (1000, 12)
|
| 87 |
+
ecg_tensor = torch.tensor(ecg_signal, dtype=torch.float32).unsqueeze(0)
|
| 88 |
|
| 89 |
+
# Inference
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
logits = model(ecg_tensor)
|
| 92 |
+
predicted_class = torch.argmax(logits, dim=1)
|
|
|
|
|
|
|
| 93 |
```
|
| 94 |
|
| 95 |
+
## Limitations
|
| 96 |
|
| 97 |
+
1. **Small training set**: Model trained on only 500 records for demonstration
|
| 98 |
+
2. **Simplified classification**: Single-label classification (many ECGs have multiple conditions)
|
| 99 |
+
3. **Class imbalance**: Not addressed in this implementation
|
| 100 |
+
4. **No clinical validation**: Not validated on independent clinical datasets
|
| 101 |
+
5. **Research use only**: Not approved for medical diagnosis
|
|
|
|
| 102 |
|
| 103 |
+
## Ethical Considerations
|
| 104 |
|
| 105 |
+
- This model should NOT be used for clinical diagnosis
|
| 106 |
+
- Medical decisions should only be made by qualified healthcare professionals
|
| 107 |
+
- The model may exhibit biases present in the PTB-XL dataset
|
| 108 |
+
- Performance may vary across different patient populations
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
## Training Procedure
|
| 111 |
|
| 112 |
+
### Preprocessing
|
| 113 |
+
1. Download PTB-XL records from PhysioNet
|
| 114 |
+
2. Extract low-resolution (100Hz) 12-lead ECG signals
|
| 115 |
+
3. Filter for single-label diagnostic superclass
|
| 116 |
+
4. Standardize signals (zero mean, unit variance)
|
| 117 |
|
| 118 |
+
### Training Hyperparameters
|
| 119 |
+
- **Optimizer**: AdamW
|
| 120 |
+
- **Learning rate**: 1e-3
|
| 121 |
+
- **Batch size**: 32
|
| 122 |
+
- **Epochs**: 10
|
| 123 |
+
- **Loss function**: CrossEntropyLoss
|
| 124 |
+
- **Hardware**: NVIDIA T4 GPU
|
| 125 |
|
| 126 |
+
### Data Augmentation
|
| 127 |
+
None applied in this implementation.
|
| 128 |
|
| 129 |
+
## Environmental Impact
|
| 130 |
|
| 131 |
+
- **Hardware**: NVIDIA T4 GPU (Google Colab)
|
| 132 |
+
- **Training time**: ~2-3 minutes
|
| 133 |
+
- **Carbon footprint**: Minimal due to short training time
|
| 134 |
|
| 135 |
## Citation
|
| 136 |
|
| 137 |
+
### This Model
|
|
|
|
| 138 |
```bibtex
|
| 139 |
@software{ecg_mamba_2024,
|
| 140 |
title={ECG-Mamba: Cardiac Abnormality Classification using Mamba Architecture},
|
|
|
|
| 141 |
year={2024},
|
| 142 |
+
url={https://huggingface.co/your-username/ecg-mamba}
|
| 143 |
+
}
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### PTB-XL Dataset
|
| 147 |
+
```bibtex
|
| 148 |
+
@article{wagner2020ptbxl,
|
| 149 |
+
title={PTB-XL, a large publicly available electrocardiography dataset},
|
| 150 |
+
author={Wagner, Patrick and Strodthoff, Nils and Bousseljot, Ralf-Dieter and Kreiseler, Dieter and Lunze, Fatima I and Samek, Wojciech and Schaeffter, Tobias},
|
| 151 |
+
journal={Scientific Data},
|
| 152 |
+
volume={7},
|
| 153 |
+
number={1},
|
| 154 |
+
pages={154},
|
| 155 |
+
year={2020}
|
| 156 |
}
|
| 157 |
```
|
| 158 |
|
| 159 |
+
### Mamba
|
| 160 |
+
```bibtex
|
| 161 |
+
@article{gu2023mamba,
|
| 162 |
+
title={Mamba: Linear-Time Sequence Modeling with Selective State Spaces},
|
| 163 |
+
author={Gu, Albert and Dao, Tri},
|
| 164 |
+
journal={arXiv preprint arXiv:2312.00752},
|
| 165 |
+
year={2023}
|
| 166 |
+
}
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
## Model Card Authors
|
| 170 |
+
|
| 171 |
+
This model card was created as part of the ECG-Mamba project.
|
| 172 |
+
|
| 173 |
+
## Model Card Contact
|
| 174 |
|
| 175 |
+
For questions or issues, please open an issue on the [GitHub repository](https://github.com/skkuhg/ecg-mamba).
|