Heart Reader
From Deep Learning to Edge AI for Automated 12-Lead ECG Diagnosis
Chaima Massaoudi — March 2026
A production-ready, multimodal deep learning pipeline for multi-label ECG classification of five diagnostic superclasses from 12-lead electrocardiogram recordings — featuring an InceptionTime1D + Squeeze-and-Excitation backbone fused with 1,313 PTB-XL+ structured features , an interactive web dashboard, and a complete edge deployment pipeline.
Quick Start •
Demo •
Architecture •
Results •
Dashboard •
Edge AI •
Full Report
Macro-AUC 0.9268
Macro F1 0.7239
F-max 0.7574
AUPRC 0.8097
Parameters 977K
Model Size 2.37 MB
Per-Class AUC Breakdown (Test Set — Fold 10)
Class
AUC
90% CI
Description
NORM
0.957
[0.949, 0.964]
Normal ECG
MI
0.927
[0.915, 0.940]
Myocardial Infarction
STTC
0.930
[0.918, 0.941]
ST/T Change
CD
0.913
[0.902, 0.928]
Conduction Disturbance
HYP
0.908
[0.893, 0.924]
Hypertrophy
All classes exceed AUC 0.90 , demonstrating robust classification across the full diagnostic spectrum.
Interactive dashboard — 12-lead ECG visualization, real-time diagnosis, and confidence scores (5× speed)
Watch full demo video →
Challenge
Our Solution
Manual ECG interpretation requires years of specialist training
Automated AI-powered diagnosis in milliseconds
Single-modality models miss complementary clinical features
Multimodal fusion of raw signals + 1,313 structured PTB-XL+ features
Large models can't run on portable medical devices
Edge-optimized pipeline: pruning + INT8 quantization + ONNX (2.37 MB)
Research models lack practical interfaces
Interactive web dashboard with real-time analysis & export
ECG diagnosis is multi-label (patients have multiple conditions)
Multi-label classification handling co-occurring pathologies
Multimodal Late Fusion Pipeline
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ 12-Lead ECG Signal │ │ PTB-XL+ Features │
│ (1000 × 12 matrix) │ │ (1313-dim vector) │
└──────────────┬──────────────┘ └──────────────┬──────────────┘
│ │
┌────────────▼────────────┐ ┌────────────▼────────────┐
│ InceptionTime1D │ │ Feature MLP │
│ + SE Channel Attention│ │ [1313 → 256 → 128 → 64]│
│ (6 blocks, multi- │ │ BN + ReLU + Dropout │
│ scale: k=39,19,9) │ └────────────┬────────────┘
└────────────┬────────────┘ │
│ 64-dim embed
AdaptiveConcatPool1d │
+ Linear → 256-dim │
│ │
└────────────┬─────────────────────────┘
│
Concat [256 ‖ 64] = 320-dim
│
┌────────▼────────┐
│ Fusion MLP Head │
│ [320 → 128 → 5] │
│ ReLU + BN + Drop │
└────────┬────────┘
│
5-class sigmoid
(multi-label output)
Signal Backbone: InceptionTime1D + SE Attention
Component
Configuration
Inception Blocks
6 deep, residual every 3
Multi-scale Kernels
k=39, k=19, k=9 (captures patterns at multiple temporal resolutions)
SE Attention
Reduction ratio 16 (adaptive channel recalibration)
Pooling
AdaptiveConcatPool1d (avg + max)
Output
256-dim signal embedding
Technique
Configuration
Purpose
Focal Loss
gamma=2, alpha=0.25
Handle class imbalance (HYP is 4x rarer)
Label Smoothing
epsilon=0.05
Better calibrated confidence scores
Mixup
alpha=0.3
Data augmentation + regularization
SWA
From epoch 40
Converge to flatter minima
OneCycleLR
max_lr=0.003
Super-convergence scheduling
AdamW
wd=0.01
Decoupled weight regularization
AMP (FP16)
Automatic
2× memory reduction & speed
Gradient Clipping
max_norm=1.0
Training stability
ECG-Specific Data Augmentation
Gaussian noise (sigma=0.05) — simulates sensor noise
Random amplitude scaling (0.8–1.2×) — accounts for gain variation
Lead dropout (up to 2 leads, p=0.1) — robustness to disconnection
Baseline wander (sinusoidal drift, p=0.3) — common ambulatory artifact
Temporal warping (interpolation, p=0.2) — heart rate variability robustness
Test Set Performance (Fold 10, N=2,198)
All confidence intervals via 100 bootstrap resamples (5th–95th percentile).
Metric
Score
90% CI
Macro-AUC
0.9268
[0.9204, 0.9332]
F-max
0.7574
[0.7441, 0.7696]
Macro F1
0.7239
[0.7048, 0.7468]
Macro AUPRC
0.8097
[0.7946, 0.8256]
F-beta (beta=2)
0.7902
[0.7809, 0.8066]
Per-Class Classification Report
Class
Precision
Recall
F1
Support
NORM
0.82
0.95
0.88
954
MI
0.59
0.87
0.70
415
STTC
0.63
0.90
0.74
506
CD
0.67
0.82
0.74
496
HYP
0.38
0.74
0.50
222
Macro Avg
0.62
0.86
0.71
2,593
High recall across all classes (≥0.74) means the model reliably detects pathological patterns — clinically preferred over high precision alone.
Comparison with Published PTB-XL Benchmarks
Model
Macro-AUC
Input
Source
inception1d (benchmark)
0.925
Signal only
Strodthoff et al., 2021
xresnet1d101 (benchmark)
0.925
Signal only
Strodthoff et al., 2021
resnet1d_wang (benchmark)
0.930
Signal only
Strodthoff et al., 2021
Heart Reader (Ours)
0.927
Signal + PTB-XL+
This work
git clone https://github.com/chaima-massaoudi/Heart-Reader-From-Deep-Learning-to-Edge-AI-for-Automated-ECG-Diagnosis.git
cd Heart-Reader-From-Deep-Learning-to-Edge-AI-for-Automated-ECG-Diagnosis
python -m venv .venv
.venv\S cripts\A ctivate.ps1 # Windows
# source .venv/bin/activate # Linux / macOS
pip install -r heart_reader/requirements.txt
Download from PhysioNet (free, requires credentialed access):
Dataset
Version
Path (relative to repo root)
PTB-XL
1.0.3
data/ptbxl/
PTB-XL+
1.0.1
ptb-xl-a-comprehensive-electrocardiographic-feature-dataset-1.0.1/
Expected directory layout
repo-root/
├── data/
│ └── ptbxl/
│ ├── ptbxl_database.csv
│ ├── scp_statements.csv
│ └── records100/...
├── ptb-xl-a-comprehensive-electrocardiographic-feature-dataset-1.0.1/
│ └── features/
│ ├── 12sl_features.csv
│ └── ecgdeli_features.csv
└── heart_reader/
└── (this project)
cd heart_reader
# Improved config (focal loss, mixup, SWA) — recommended
python train.py --config configs/improved.yaml --backbone inception1d
# Default baseline training
python train.py
python run_server.py
# Open http://localhost:8000
6. Export for Edge Devices
python export.py --backbone inception1d
A full-featured, interactive FastAPI-powered medical dashboard for real-time ECG analysis.
Feature
Description
Random Sample
Load a random test-set ECG with full-model predictions
File Upload
Upload your own 12-lead CSV for instant analysis
12-Lead ECG Viewer
Full waveform visualization across all leads (Chart.js)
Probability Chart
Interactive bar chart with per-class confidence scores
Diagnosis Panel
Clear Normal/Abnormal banner with detailed class breakdown
Graph Export
One-click PNG download of any visualization
Dark Medical Theme
Professional dark interface with ECG-green (#00df80) accents
Format
Description
Signal-only
12 columns × 1000 rows (one column per ECG lead)
Signal + Features
>12 columns × 1000 rows (first 12 = leads, rest = PTB-XL+ features)
One sample CSV per diagnostic class is included in heart_reader/test_files/:
File
Expected Diagnosis
Confidence
sample_norm.csv
NORM
1.000
sample_mi.csv
MI
0.872
sample_sttc.csv
STTC
0.674
sample_cd.csv
CD
0.962
sample_hyp.csv
HYP
0.710
A complete compression pipeline for deploying on resource-constrained devices (Raspberry Pi, mobile, embedded medical hardware).
Full Model (3.79 MB)
│
├── L1 Structured Pruning ──→ 50% filter removal
│
├── INT8 Dynamic Quantization ──→ FP32 → INT8 weights
│
└── ONNX Export ──→ Cross-platform inference
Variant
Size
Compression
Format
Full Fusion (FP32)
3.79 MB
1.0×
PyTorch
Quantized (INT8)
2.37 MB
1.6×
PyTorch
Signal-Only ONNX
2.16 MB
1.75×
ONNX
Configuration
Mean
Std Dev
Full Fusion (FP32)
717 ms
±398 ms
Quantized (INT8)
827 ms
—
Following the official PTB-XL benchmark (Strodthoff et al., 2021) — strict fold-based stratification with no patient overlap.
Split
Folds
Samples
Purpose
Train
1–8
16,289
Model training
Validation
9
2,034
Hyperparameter tuning, threshold optimization
Test
10
2,050
Final evaluation only (never used during development)
Class
Abbreviation
Test Samples
Multi-label?
Normal ECG
NORM
954
—
Myocardial Infarction
MI
415
Often + STTC
ST/T Change
STTC
506
Often + MI, HYP
Conduction Disturbance
CD
496
Can co-occur
Hypertrophy
HYP
222
Often + STTC
64% of records have exactly one label, 28% have two, 8% have three or more.
heart_reader/
├── configs/
│ ├── default.yaml # Base configuration
│ └── improved.yaml # Enhanced: focal loss + mixup + SWA
│
├── data/
│ ├── preprocessing.py # PTB-XL loading, label mapping, PTB-XL+ features
│ ├── dataset.py # PyTorch Dataset & DataLoader
│ └── augmentation.py # ECG-specific augmentations
│
├── models/
│ ├── inception1d.py # InceptionTime1D + SE attention
│ ├── xresnet1d.py # XResNet1d family (18–152 layers)
│ ├── se_resnet1d.py # SE-ResNet1d (Wang-style)
│ ├── fusion_model.py # Multimodal signal + feature fusion
│ ├── feature_branch.py # MLP for structured features
│ ├── ensemble.py # Weighted ensemble (Nelder-Mead)
│ └── heads.py # Pooling, SE blocks, weight init
│
├── training/
│ ├── trainer.py # Training loop (AMP, SWA, early stopping)
│ ├── losses.py # Focal loss, label smoothing BCE, mixup
│ ├── metrics.py # AUC, Fmax, G_beta, AUPRC
│ └── callbacks.py # LR scheduling callbacks
│
├── evaluation/
│ ├── evaluate.py # Bootstrap evaluation, CI, CSV export
│ └── visualization.py # ROC curves, confusion matrix, plots
│
├── edge/
│ ├── prune.py # L1 structured pruning
│ ├── quantize.py # INT8 dynamic quantization
│ ├── export_tflite.py # ONNX export
│ └── benchmark.py # Inference benchmarking
│
├── frontend/
│ ├── app.py # FastAPI backend (REST API)
│ └── static/ # Dashboard (HTML, CSS, JS)
│
├── results/
│ ├── evaluation_report.json # Full metrics with bootstrap CIs
│ └── edge/edge_stats.json # Compression & latency stats
│
├── test_files/ # Pre-selected test CSVs per class
├── train.py # Main entry point
├── evaluate.py # Standalone evaluation
├── export.py # Edge deployment pipeline
├── run_server.py # Web dashboard launcher
├── demo.mp4 / demo.gif # Video demonstration
├── REPORT.md # Detailed technical report (658 lines)
└── requirements.txt # Python dependencies
Component
Specification
GPU
NVIDIA GeForce RTX 3050 6GB
CUDA
12.6
PyTorch
2.10.0+cu126
Python
3.13
Training Time
~27 minutes (41 epochs, early stop at 26)
Seed
42 (full deterministic reproducibility)
Wagner, P., et al. "PTB-XL, a large publicly available electrocardiography dataset." Scientific Data 7 (2020). DOI
Strodthoff, N., et al. "Deep Learning for ECG Analysis: Benchmarks and Insights from PTB-XL." IEEE JBHI 25.5 (2021). DOI
Strodthoff, N., et al. "PTB-XL+, a comprehensive electrocardiographic feature dataset." Scientific Data 10 (2023). DOI
Fawaz, H.I., et al. "InceptionTime: Finding AlexNet for time series classification." DMKD 34.6 (2020). DOI
Hu, J., et al. "Squeeze-and-Excitation Networks." CVPR (2018).
Lin, T.-Y., et al. "Focal Loss for Dense Object Detection." IEEE TPAMI 42.2 (2020).
Zhang, H., et al. "mixup: Beyond Empirical Risk Minimization." ICLR (2018).
Izmailov, P., et al. "Averaging Weights Leads to Wider Optima and Better Generalization." UAI (2018).
This project is for research and educational purposes . Please refer to the individual dataset licenses for data usage terms:
Heart Reader — Automated ECG Diagnosis from Signal to Edge
Built with PyTorch, FastAPI, and clinical rigor