ECG atrial-fibrillation early warning (single-lead, streaming)

Small models that read a single-lead ECG as a stream of 10-second windows (250 Hz, 2500 samples, millivolts) and give, for every window, the probability that atrial fibrillation (AF) is under way ("detect") and that it will start within 1, 2, 5, 10 or 30 minutes.

Research models, not a medical device. Do not use them to make decisions about anyone's care.

Try them in the browser, running on your device: ECG early warning Space.

Files

Path What
neural-single-lead/bundle-fold0.npz End-to-end model, one lead: a pretrained Transformer window encoder (0.8M parameters; 0.2-s patches, lead embedding, per-window median/spread normalisation) and a GRU (0.12M) over successive windows. Fold 0 of 5.
neural-two-lead/bundle-fold0.npz The same architecture trained with the recording's second lead as optional context (hidden at random during training). Fold 0 of 5.
trees/gbm-af.npz Baseline: LightGBM (300 trees per head, heads detect and h10) on 49 hand-made features per window and their causal context (196 inputs), exported as flat arrays.
trees-vtvf/gbm-vtvf.npz VT/VF early warning: the same tree design (49 features + causal context) trained on seven open ventricular-event databases; heads detect (VT/VF under way) and h2 (VT/VF starts within 2 minutes).
encoder-causal/encoder-readouts.npz A 4.8M-parameter causal Transformer encoder (attends only to the past, pretrained by masked reconstruction without Icentia11k), float16 weights, with linear read-outs on its one-lead window embedding: PR, P duration, QRS, QT, T-peak and RR intervals (ms; fitted on LUDB) and a signal-quality class (good / fair / poor; fitted on BUT QDB).
thresholds.json Alarm thresholds for each model at 1 and 0.2 false alarms per hour, and the label-free score's settings.

Bundle format

np.savez archives readable with np.load(path, allow_pickle=False): every weight as float32 under its PyTorch state_dict name (enc.* encoder, head.* GRU head; GRU gate order r, z, n), and meta, a JSON string with the configuration (enc_cfg, hidden, heads, horizons_min, ctx_leads, ...). One window: round the samples to float16, normalise, embed the own lead (plus the other lead for the two-lead model), and take one GRU step with an extra input log1p(gap) (windows missing since the previous one, 0 for a continuous stream). The output is 6 logits: detect, h1, h2, h5, h10, h30.

Lead identity is an input. Use 1 for lead II (or MLII, or the usual monitoring lead) and 13 for an unnamed bipolar Holter lead.

Alarm rule

A model alarms when the causal mean of its last 3 window scores (30 s) exceeds the threshold. While the score stays up, the alarm repeats every 30 windows (5 minutes). The thresholds were fixed on held-out training-source recordings to give 1 or 0.2 false alarms per hour in time far from any AF.

  • Neural models: the thresholds apply to the logit.
  • Trees: the thresholds apply to the probability.
  • Two-lead model: its thresholds were set with both leads present.

Each fold model has its own thresholds; do not mix them.

Training data

All the training data are public ambulatory (Holter and patch) ECG databases:

  • MIT-BIH Atrial Fibrillation (ODC-By)
  • Long-Term AF (ODC-By)
  • SHDB-AF (ODC-By)
  • PAF Prediction Challenge (PhysioNet)
  • Icentia11k (CC BY-NC-SA 4.0)
  • IRIDIA-AF (CC BY 4.0)
  • CPSC 2021 (CC BY 4.0)

The two-lead model also trained on VitalDB (surgery, CC BY 4.0); the single-lead model and the trees never saw it. Because Icentia11k is non-commercial and share-alike, these weights are released under CC BY-NC-SA 4.0.

What to expect

  • Detection. Detecting AF that is already under way works well.
  • Early warning. In testing on ambulatory recordings, at one false alarm per hour, the neural model warned of about 7% of AF onsets at least ten minutes ahead. The boosted trees warned of about 3%, and chance was about 2%. Most onsets get no warning from any method.
  • Two leads. The two-lead model warns slightly more often when the second lead is present.
  • Other settings. The models were trained on ambulatory recordings. Surgery, intensive care, exercise and consumer wearables can differ.

VT/VF and measurements

  • VT/VF: with thresholds fixed on other patients, a new alert started 1 to 5 minutes before 14 to 18 % of sustained VT/VF onsets at 0.2 alarms per hour (chance under 1 %), and 18 to 27 % at one per hour (chance 6 %), over three seeds. Most of that warning comes from long Holter recordings before sudden death. Neural models did not do better.
  • Measurements (one lead, patients not used for fitting): QT is off by about 16 ms on average (a calibrated classical delineator: 22 ms); QRS, PR and P duration are within about 10 ms. Signal quality: AUROC 0.95. These were fitted on resting 10-second ECGs and wearable recordings; monitoring and surgical ECGs are harder.

Runtimes

  • A Rust runtime that reads these bundles, and also compiles to WebAssembly, reproduces the PyTorch reference to within 1e-5 on the logits.
  • It also contains a line-by-line port of the 49 features and the tree evaluator.
  • Speed on one laptop CPU thread: about 1 ms per window natively and about 3 ms in a browser with WebAssembly SIMD.
  • The Space above runs that runtime.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using mkieffer/ecg-af-early-warning 1