Twelve to One: ECG diagnosis from 12 leads down to a smartwatch's single lead

Three 1D ResNet models (resnet1d_wang) that read a 10-second ECG and score 5 diagnostic classes: normal, myocardial infarction (MI), ST/T change, conduction disturbance and hypertrophy. They use 12 leads, 2 leads (I + II) or Lead I only, which is what a smartwatch records.

โš ๏ธ Research model, not a medical device. Trained and tested on public retrospective data only. Do not use it for diagnosis or treatment decisions.

โ–ถ Try it in your browser (no install): https://huggingface.co/spaces/rigel08/twelve-to-one-ecg ยท Code, training and full results: https://github.com/rigel08/ecg-wearable-diagnosis

Results (PTB-XL test fold 10, 2,158 ECGs, macro AUROC)

Leads This model (single seed) Project headline
12 leads 0.929 0.930 for a 3-seed ensemble (95% CI 0.923โ€“0.936), matching the published benchmark
2 leads (I, II) 0.897 0.898
Lead I only (smartwatch) 0.839 0.839

The 12-lead ensemble scores 0.852 on an unseen hospital (Georgia, USA). On Lead I alone, inferior MI drops from 0.940 to 0.756, because inferior leads are no longer recorded.

Files

File What it is
ecg_12.onnx, ecg_2.onnx, ecg_1-leadI.onnx Full-precision ONNX models. Input x (batch, leads, 250); outputs logits (batch, 5) and features
model_12.pt, model_2.pt, model_1-leadI.pt PyTorch checkpoints (load with the build() function in the GitHub repo)
config.json Classes, per-lead normalisation, window positions, temperature and decision thresholds per model
example_ecg.json One real PTB-XL test ECG (a conduction disturbance) to try
example.py Runs the steps below

Use it (5 lines of setup, then plain numpy)

pip install onnxruntime huggingface_hub numpy
python example.py        # downloads the model and scores the example ECG
import json, numpy as np, onnxruntime as ort
from huggingface_hub import hf_hub_download

repo = "rigel08/twelve-to-one-ecg"
cfg = json.load(open(hf_hub_download(repo, "config.json")))
m = cfg["models"]["12"]                      # or "2", "1-leadI"
sess = ort.InferenceSession(hf_hub_download(repo, m["onnx"]))

ecg = np.array(json.load(open(hf_hub_download(repo, "example_ecg.json")))["x_mV_time_by_lead"], np.float32)  # (1000, 12) in mV at 100 Hz
idx = m["lead_idx"]
x = (ecg[:, idx] - np.array(cfg["per_lead_mean_mV"])[idx]) / np.array(cfg["per_lead_std_mV"])[idx]   # per-lead normalisation
windows = np.stack([x[s:s + 250].T for s in cfg["window_starts"]])     # 7 overlapping 2.5 s windows
logits = sess.run(["logits"], {"x": windows})[0].mean(0)               # average the windows
prob = 1 / (1 + np.exp(-logits / m["temperature"]))                     # calibrated probabilities
for c, p, t in zip(cfg["classes"], prob, m["thresholds"]):
    print(f"{c:5s} {p:.3f}  {'FLAG' if p >= t else ''}")

Input format: 10 s at 100 Hz in millivolts, leads in the order I, II, III, aVR, aVL, aVF, V1โ€“V6. Resample other rates to 100 Hz first.

Training data and method

  • PTB-XL v1.0.3 (Wagner et al., 2020; CC BY 4.0), official patient-level folds: 1โ€“8 train, 9 validation, 10 test.
  • 2.5 s random crops during training. At test time, 7 window logits are averaged. Temperature scaling and per-class thresholds were fitted on the validation fold (9).

Limitations

  • One source of training data (Germany, 1989โ€“1996 devices). External test on one US dataset.
  • "Smartwatch" here means Lead I taken from a 12-lead recording, not a real watch's noisier signal.
  • Single model per lead set (the 0.930 headline is a 3-seed ensemble).

Portfolio: https://rigel08.github.io/portfolio-site/ ยท GitHub: https://github.com/rigel08 ยท All my models and demos: https://huggingface.co/rigel08

Downloads last month
37
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using rigel08/twelve-to-one-ecg 1

Evaluation results

  • macro AUROC (single model) on PTB-XL (test fold 10)
    self-reported
    0.929