Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Tumo505/SSL-for-ECG-classification/llms.txt

Use this file to discover all available pages before exploring further.

SSRL-ECG is a self-supervised representation learning framework purpose-built for ECG-based cardiovascular disease classification under low-data conditions. By leveraging unlabeled ECG signals during pretraining, the framework learns rich cardiac representations that generalize effectively even when only 10% of labeled data is available for fine-tuning — addressing one of the most persistent bottlenecks in clinical AI: the scarcity of expert-annotated recordings.

The Problem: Limited Labeled ECG Data

Annotating ECG recordings for multi-class cardiovascular disease requires trained cardiologists, making large labeled datasets expensive and slow to produce. Standard supervised models trained on small labeled subsets struggle to generalize, producing unreliable predictions across the five major diagnostic classes. SSRL-ECG tackles this by pretraining on the full unlabeled corpus first, then fine-tuning on a fraction of labeled samples.

The Solution: Self-Supervised Pretraining with Domain-Adaptive Augmentations

SSRL-ECG pairs two well-established SSL frameworks — SimCLR (contrastive learning) and BYOL (momentum-based self-distillation) — with a suite of seven augmentations that are grounded in ECG physiology rather than borrowed from computer vision. These augmentations expose the encoder to realistic signal variations it will encounter in clinical practice, including heart rate fluctuations, electrode motion artifacts, and bandlimited noise.

Key Results

The table below compares SSL-pretrained models against a fully supervised CNN baseline, all evaluated on the PTB-XL held-out test fold (fold 10) with 10% labeled training data.
MethodAUROCF1SensitivitySpecificity
Supervised (Focal + Oversample)0.86060.57500.67720.9357
SimCLR + Augmentations0.87170.64480.68310.9411
BYOL + Augmentations0.85650.63010.66480.9278
SimCLR achieves a +12.15% F1 improvement over the supervised baseline and outperforms BYOL by 0.0152 AUROC. Multi-seed validation across 10 random seeds confirms robustness: AUROC 0.8717 ± 0.0032 (95% CI: 0.8671–0.8763).

Domain-Adaptive Augmentations

The seven augmentations in ssrl_ecg/augmentations.py are designed specifically for 12-lead ECG signals and applied probabilistically during SSL pretraining to generate two correlated views of each recording.
AugmentationMechanismApplication Rate
Frequency warping±5% heart rate variation50%
Medical mixupECG-aware blending (λ ~ Beta distribution)40%
Bandpass filteringf_low ∈ [0.5, 1.5] Hz, f_high ∈ [40, 60] Hz30%
Segment CutMix10–30% temporal masking25%
Motion artifactsBaseline wander at 0.5–2 Hz, 0.01–0.05 mV20%
Per-channel noise0.5–2% per-channel standard deviation60%
Temporal dropout5–20% masking with interpolation30%

Primary Dataset: PTB-XL

SSRL-ECG is evaluated on PTB-XL, the largest openly available clinical ECG dataset. The standard 10-fold split is used: folds 1–8 for training (17,489 samples), fold 9 for validation (2,154 samples), and fold 10 for testing (2,194 samples).

Dataset Size

21,799 ECGs from 18,869 patients — 12-lead recordings at 500 Hz, 10 seconds each.

5 Cardiovascular Classes

NORM (9,514) · MI (5,469) · STTC (5,235) · CD (4,898) · HYP (2,649)

Class Imbalance

3.32× imbalance ratio (NORM vs. HYP). Addressed via oversampling and Focal Loss during fine-tuning.

Secondary Dataset

MIT-BIH arrhythmia database (48 records) used as an external robustness check for transfer validation.

Project Module Structure

The package lives under src/ssrl_ecg/ and is organized into focused modules. Each module is independently importable once the package is installed.

augmentations.py

Core module implementing all 7 domain-adaptive ECG augmentations with physiological grounding.

train_ssl_simclr.py

SimCLR pretraining — NT-Xent contrastive loss, ECGEncoder1DCNN backbone, dual augmented views per sample.

train_ssl_byol.py

BYOL pretraining — momentum encoder with exponential moving average updates, no negative pairs required.

train_finetune.py

Linear probing fine-tuner — loads a pretrained encoder checkpoint and trains a classification head on labeled data.

train_supervised.py

Supervised CNN baseline — trains from scratch with Focal Loss and oversampling for fair comparison.

evaluate.py

Comprehensive evaluation reporting AUROC, macro-F1, sensitivity, specificity, and per-class metrics.

data/ptbxl.py

PTB-XL dataset loader — handles 10-fold splits, label encoding, and stratified label-fraction sampling.

models/cnn.py

ECGEncoder1DCNN — three stacked Conv1D layers producing a 256-dimensional latent representation.
SSRL-ECG ships as an installable Python package. All training scripts run as python -m ssrl_ecg.<module_name> — no manual sys.path manipulation required. See the Installation guide to get set up.

Build docs developers (and LLMs) love