Electrocardiogram (ECG) data in clinical practice frequently suffers from noise, baseline wander, electrode motion artifacts, and missing or corrupted leads. TolerantECG is a foundation model designed specifically to handle imperfect ECG signals by learning robust representations across signal perturbations.
1import torch
2from huggingface_hub import hf_hub_download
3from src.models.ecg_encoder.convnext import ConvNeXtV2
4
5# 1. Instantiate the ConvNeXt V2 ECG Encoder (12-lead input, 768-dim output)
6model = ConvNeXtV2(
7 in_chans=12,
8 depths=[3, 3, 9, 3],
9 dims=[96, 192, 384, 768],
10 drop_path_rate=0.0
11)
12
13# 2. Download pre-trained weights from HuggingFace Hub
14weights_path = hf_hub_download(
15 repo_id="ndhuynh02/TolerantECG",
16 filename="TolerantECG_encoder.pth"
17)
18
19# 3. Load state_dict into the model
20state_dict = torch.load(weights_path, map_location="cpu")
21model.load_state_dict(state_dict)
22model.eval()
23
24# 4. Extract embeddings from sample 12-lead ECG tensor (Batch size=2, 12 leads, 5000 time steps)
25dummy_ecg = torch.randn(2, 12, 5000)
26
27with torch.no_grad():
28 # Returns 768-dimensional embedding vector per sample
29 embeddings = model(dummy_ecg)
30
31print("ECG Embeddings Shape:", embeddings.shape)
32# Output: torch.Size([2, 768])
This model checkpoint and repository are distributed under the
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0). Refer to the
LICENCE file for details.
1@inproceedings{10.1145/3746027.3755287,
2 author = {Nguyen, Huynh Dang and Pham, Trong-Thang and Le, Ngan and Nguyen, Van},
3 title = {TolerantECG: A Foundation Model for Imperfect Electrocardiogram},
4 year = {2025},
5 isbn = {9798400720352},
6 publisher = {Association for Computing Machinery},
7 address = {New York, NY, USA},
8 url = {https://doi.org/10.1145/3746027.3755287},
9 doi = {10.1145/3746027.3755287},
10 booktitle = {Proceedings of the 33rd ACM International Conference on Multimedia},
11 pages = {8097–8105},
12 numpages = {9},
13 keywords = {contrastive learning, electrocardiogram (ecg), foundation model, imperfect signal, knowledge retrieval, self-supervised learning},
14 location = {Dublin, Ireland},
15 series = {MM '25}
16}