How surya-teja-kancharla/ecg-decision-support-system works
Purpose and Entry Points
ECG-DSS is a PyTorch/Streamlit clinical decision-support prototype for multi-label classification of variable-length 12-lead ECGs into nine arrhythmia-related classes. Its operational entry points are the Streamlit inference dashboard at app.py and the training runner at run_phase3.py. A trained model checkpoint is supplied as ecg_model_v1.pth.
Input Data Boundary
The system consumes preprocessed pickle ECG records rather than raw device streams. Demo inputs live in samples/; representative full-data layout is under data/comparision_data/preprocessed/. Raw PhysioNet-style ECG artifacts (.hea metadata and .mat waveforms) are represented under data/comparision_data/raw/, forming the acquisition-to-preprocessing boundary.
Preprocessing and Dataset Layer
Signal normalization, resampling/duration standardization, and serialized-record preparation are centralized in src/preprocessing.py. src/dataset.py provides lazy-loading dataset access, avoiding loading the full ECG corpus into memory and supporting scalable training/inference. The expected model input is normalized 12-lead, 250 Hz, 60-second signal data with multi-hot targets during training.
Model and Inference
src/model.py defines the ECG classifier: a 1D residual CNN for cross-lead temporal features, followed by attention pooling and independent sigmoid outputs for multi-label probabilities. ecg_model_v1.pth is loaded for deployment inference. The dashboard in app.py accepts .pk uploads, simulates streaming with sliding windows, performs device-aware inference, applies class-specific decision thresholds, and presents decision-support explanations.
Training and Imbalance Strategy
run_phase3.py orchestrates the model-training phase using the components in src/train.py, src/dataset.py, and src/model.py. Training targets independent labels rather than a mutually exclusive class, with focal-loss-oriented imbalance handling and PyTorch device selection across CUDA, Apple MPS, or CPU. src/augmentation.py provides ECG-oriented augmentation support at the training boundary.
Evaluation and Decision Calibration
src/evaluate.py owns multi-label evaluation concerns: Hamming loss, macro/micro F1, per-class ROC-AUC, and threshold-sensitive prediction quality. Per-label threshold optimization is an explicit post-model decision layer, separating probability representation from clinical alerting behavior. split_train_into_train_val.py supports creation of train/validation partitions; validation analysis is also captured in notebooks/03_phase3_evaluation.ipynb and notebooks/04_phase4_validation.ipynb.
Ensemble and Runtime Dependencies
src/ensemble.py is the extension point for combining model predictions, although the supplied deployment artifact is ecg_model_v1.pth. Primary runtime infrastructure is Python, PyTorch, Streamlit, NumPy/scikit-learn, and WFDB; dependencies are declared in requirements.txt. External data originates from PhysioNet/CPSC-style ECG sources and community-preprocessed distributions, while the deployed UI is intended for Streamlit hosting rather than a separate backend service.
Components 16
ECG Data
- PhysioNet/CPSC sources
- Raw ECG artifacts
- Preprocessing · Normalizes and standardizes ECG records.
src/preprocessing.py - Preprocessed ECG records · Normalized 12-lead, 250 Hz, 60-second records.
Training & Validation
- Lazy ECG dataset · Loads records without materializing the full corpus.
src/dataset.py - ECG augmentation
src/augmentation.py - Train/validation split
split_train_into_train_val.py - Phase 3 runner
run_phase3.py - Training loop · Uses focal-loss-oriented multi-label training and device selection.
src/train.py
Model & Decisions
- ECG classifier · Cross-lead temporal features, attention pooling, and sigmoid labels.
src/model.py - Multi-label evaluation · Computes F1, Hamming loss, ROC-AUC, and per-label thresholds.
src/evaluate.py - Prediction ensemble
src/ensemble.py
Deployment Runtime
- Demo ECG inputs
- Deployment checkpoint
ecg_model_v1.pth - Streamlit dashboard · Uploads .pk ECGs, simulates sliding windows, and explains alerts.
app.py - Clinical decision support · Class-specific thresholds turn probabilities into displayed guidance.
Connections 19
- PhysioNet/CPSC sources → Raw ECG artifacts: acquired as
- Raw ECG artifacts → Preprocessing: prepared by
- Preprocessing → Preprocessed ECG records: serializes
- Preprocessed ECG records → Train/validation split: partitioned for
- Preprocessed ECG records → Lazy ECG dataset: lazy-loaded by
- Train/validation split → Phase 3 runner: provides splits
- Phase 3 runner → Training loop: orchestrates
- Lazy ECG dataset → ECG augmentation: training records
- ECG augmentation → Training loop: augmented batches
- Training loop → ECG classifier: optimizes
- ECG classifier → Multi-label evaluation: validation probabilities
- Multi-label evaluation → Deployment checkpoint: calibrates deployment model
- ECG classifier → Deployment checkpoint: trained weights
- Demo ECG inputs → Streamlit dashboard: demo input
- Deployment checkpoint → Streamlit dashboard: loaded for inference
- Streamlit dashboard → ECG classifier: sliding-window inference
- ECG classifier → Prediction ensemble: prediction extension
- Multi-label evaluation → Streamlit dashboard: per-label thresholds
- Streamlit dashboard → Clinical decision support: presents