This project presents an end-to-end ECG Arrhythmia Classification system, combining deep learning with an interactive Streamlit web dashboard.
A 1D Convolutional Neural Network (CNN) is trained on ECG signals to detect abnormal rhythms, and users can interactively upload signals, visualize them, and view predictions in real time.
-
Data Preprocessing
- ECG signals (from MIT-BIH dataset or CSV files) are normalized.
- Noise reduction and segmentation are applied to ensure high-quality signals.
-
Model Training (1D CNN)
- A 1D Convolutional Neural Network is implemented in TensorFlow/Keras.
- Layers: Conv1D → BatchNorm → MaxPooling → Dropout → Dense → Softmax.
- Loss:
categorical_crossentropy, Optimizer:Adam. - Model trained on arrhythmia classes.
-
Model Saving
- Trained model is stored as
cnn_ecg.h5for deployment.
- Trained model is stored as
-
Streamlit Deployment
- Users upload ECG CSV files.
- ECG waveform is plotted.
- The model predicts arrhythmia type and shows class probabilities.
- Provides an easy-to-use interface for clinical and educational purposes.
The model can classify the following rhythms:
- Normal Sinus Rhythm (NSR)
- Atrial Fibrillation (AFib)
- Ventricular Tachycardia (VTach)
- Premature Ventricular Contraction (PVC)
├── model\_training/
│ ├── train\_model.py # Script to train the CNN model
│ ├── ecg\_dataset.csv # Training data (or link to MIT-BIH)
│ └── cnn\_ecg.h5 # Saved trained model
│
├── app/
│ ├── app.py # Streamlit application
│ └── sample\_ecg.csv # Example ECG input
│
├── requirements.txt # Python dependencies
└── README.md # Documentation
model = Sequential([
Conv1D(filters=32, kernel_size=5, activation='relu', input_shape=(input_length, 1)),
BatchNormalization(),
MaxPooling1D(pool_size=2),
Dropout(0.2),
Conv1D(filters=64, kernel_size=5, activation='relu'),
BatchNormalization(),
MaxPooling1D(pool_size=2),
Dropout(0.3),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.4),
Dense(num_classes, activation='softmax')
])- Optimizer: Adam
- Loss: Categorical Crossentropy
- Metrics: Accuracy
-
Clone the repository:
git clone https://github.com/your-username/ecg-arrhythmia-dashboard.git cd ecg-arrhythmia-dashboard -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Train the model (if you want to retrain):
python model_training/train_model.py
-
Run the Streamlit app:
streamlit run app/app.py
-
Upload your ECG CSV file in the sidebar (single column of ECG values).
-
The app will:
- Plot the ECG waveform.
- Predict the arrhythmia type.
- Display class probabilities with a bar chart.
-
Input ECG Plot: A waveform visualization of the uploaded ECG signal.
-
Prediction:
Predicted Class: Atrial Fibrillation (AFib) Confidence: 92.5% -
Class Probabilities (Bar Chart):
- NSR: 5%
- AFib: 92.5%
- VTach: 1.5%
- PVC: 1%
- Python
- TensorFlow / Keras
- NumPy and Pandas
- Matplotlib
- Streamlit
- Integrate Grad-CAM for interpretability (highlighting important ECG regions).
- Support multi-lead ECG inputs.
- Deploy app on Streamlit Cloud / Hugging Face Spaces.
- Extend arrhythmia coverage using MIT-BIH Arrhythmia Database.