ahczhg commited on
Commit
485d034
·
verified ·
1 Parent(s): 45a4741

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +135 -127
README.md CHANGED
@@ -1,167 +1,175 @@
1
- # ECG-Mamba Cardiac Abnormality Classification
2
-
3
- A deep learning project implementing the Mamba architecture for ECG cardiac abnormality classification using the PTB-XL dataset from PhysioNet.
4
-
5
- ## Overview
6
-
7
- This project demonstrates the application of the Mamba state space model for multi-lead ECG signal classification. The model is trained to classify cardiac abnormalities into diagnostic superclasses including NORM, MI, STTC, CD, and HYP.
8
-
9
- ## Features
10
-
11
- - **Mamba Architecture**: Utilizes the efficient Mamba state space model for sequence modeling
12
- - **PTB-XL Dataset**: Automated downloading and preprocessing of ECG data from PhysioNet
13
- - **Multi-lead ECG**: Processes all 12 standard ECG leads
14
- - **GPU Accelerated**: Optimized for GPU training with CUDA support
15
- - **Visualization**: Includes prediction visualization for model interpretation
 
 
 
 
 
 
 
 
16
 
17
  ## Model Architecture
18
 
19
- The ECGMambaClassifier consists of:
20
- - Linear embedding layer (12 channels 64 dimensions)
21
- - 2 Mamba layers with state space modeling
22
- - Layer normalization
23
- - Classification head for multi-class prediction
24
-
25
- Key hyperparameters:
26
- - `d_model`: 64 (model dimension)
27
- - `d_state`: 16 (state space dimension)
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
- **Note**: This project requires a GPU to run the Mamba implementation efficiently. For Google Colab, ensure Runtime type is set to T4 GPU or better.
51
 
52
- ## Usage
 
 
 
53
 
54
- ### Running in Google Colab
55
 
56
- 1. Open the notebook in Google Colab
57
- 2. Set Runtime type to GPU (Runtime → Change runtime type → T4 GPU)
58
- 3. Run all cells sequentially
59
 
60
- The notebook will automatically:
61
- 1. Install all dependencies
62
- 2. Download a subset of PTB-XL dataset (500 records)
63
- 3. Preprocess and normalize ECG signals
64
- 4. Train the Mamba model for 10 epochs
65
- 5. Evaluate on test set and visualize predictions
66
 
67
- ### Dataset
68
 
69
- The notebook uses the PTB-XL dataset, a large publicly available electrocardiography dataset containing:
70
- - 21,837 clinical 12-lead ECGs from 18,885 patients
71
- - 10 second recordings at 100Hz (low resolution) or 500Hz (high resolution)
72
- - Multiple diagnostic statements by cardiologists
73
 
74
- For this implementation, we use:
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
- Dataset citation:
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
- ## Model Performance
 
 
 
 
 
 
94
 
95
- The model achieves competitive performance on cardiac abnormality classification:
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
- ## Visualization
 
 
 
101
 
102
- The notebook includes visualization of:
103
- - Multiple ECG leads with offset for clarity
104
- - True vs. predicted diagnostic classes
105
- - Sample predictions from the test set
106
 
107
- ## Project Structure
 
 
108
 
109
- ```
110
- .
111
- ├── ECG_Mamba_Colab_Test.ipynb # Main Jupyter notebook
112
- ├── README.md # This file
113
- ├── LICENSE # MIT License
114
- └── ptb_xl_data/ # Downloaded dataset (created at runtime)
115
  ```
116
 
117
- ## Diagnostic Classes
118
 
119
- The model classifies ECG signals into the following diagnostic superclasses:
120
- - **NORM**: Normal ECG
121
- - **MI**: Myocardial Infarction
122
- - **STTC**: ST/T Change
123
- - **CD**: Conduction Disturbance
124
- - **HYP**: Hypertrophy
125
 
126
- ## Future Improvements
127
 
128
- - [ ] Increase dataset size for better generalization
129
- - [ ] Implement cross-validation for robust performance metrics
130
- - [ ] Add data augmentation techniques
131
- - [ ] Experiment with deeper Mamba architectures
132
- - [ ] Support for multi-label classification
133
- - [ ] Model deployment pipeline
134
- - [ ] Real-time ECG inference API
135
 
136
- ## References
137
 
138
- 1. **Mamba**: Gu, A., & Dao, T. (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces.
139
- 2. **PTB-XL**: Wagner et al. (2020). PTB-XL, a large publicly available electrocardiography dataset.
140
- 3. **PhysioNet**: Goldberger et al. (2000). PhysioBank, PhysioToolkit, and PhysioNet.
 
 
141
 
142
- ## License
 
 
 
 
 
 
143
 
144
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
 
145
 
146
- ## Acknowledgments
147
 
148
- - PhysioNet for providing the PTB-XL dataset
149
- - The Mamba-SSM team for the efficient state space model implementation
150
- - Google Colab for providing free GPU resources
151
 
152
  ## Citation
153
 
154
- If you use this code in your research, please cite:
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://github.com/yourusername/ecg-mamba}
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
  ```
164
 
165
- ## Contact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- For questions or collaboration opportunities, please open an issue on GitHub.
 
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).