Skip to content

AQ-MedAI/ShapeEFM

Repository files navigation

ShapeEFM: A Shape-based Pretrained Foundation Model on ECG Morphology Comprehension

ShapeEFM (Shape-based ECG Foundation Model) is a two-stage self-supervised learning framework for ECG analysis. It learns rich ECG representations through shape tokenization and masked language modeling, enabling effective transfer learning for downstream ECG classification tasks.

Highlights

  • Shape-aware tokenization: A VQ-VAE tokenizer learns a discrete codebook of 8192 ECG shape primitives via Perceptually Important Points (PIP) extraction
  • Masked language pretraining: A 12-layer Transformer predicts masked shape tokens, learning contextual ECG representations
  • Data-efficient transfer: Linear probing on downstream tasks with as little as 1% labeled data
  • Multi-dataset support: MIMIC-IV ECG, EchoNext, and CSN arrhythmia

Usage

Installation

cd ShapeEFM
pip install -r requirements.txt

Step 1: Tokenization (Train Shape Reconstruction)

Train the VQ-VAE tokenizer to learn discrete ECG shape primitives:

bash tokenizer.sh

Step 2: Pretrain ShapeEFM

Train the masked language model on tokenized ECG

bash train.sh

Step 3: Fine-tuning / Linear Probing

Linear probing freezes all layers of the pre-trained model except the final classification head, and only trains this linear layer on the downstream task.

Key Hyperparameters

Parameter Value Description
seq_len 248 Number of ECG shape segments per sample
embed_dim 256 Transformer embedding dimension
codebook_size 8192 Number of discrete shape tokens
codebook_dim 128 Codebook embedding dimension
mask_ratio 0.5 Fraction of tokens masked during pretraining
sampling_rate 500 Hz ECG sampling rate

Dependencies

See requirements.txt for the full list. Key dependencies:

  • PyTorch >= 2.4.0
  • timm >= 1.0.24
  • numpy, pandas, scikit-learn
  • wfdb (for ECG waveform processing)
  • pyhealth (for healthcare data utilities)

About

[MICCAI 2026] ShapeEFM: A Shape-based Pretrained Foundation Model on ECG Morphology Comprehension

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors