A disentangled diffusion model (DiffStyleTS) for generating synthetic ECG signals via style transfer between Atrial Fibrillation (AFib) and Normal Sinus Rhythm classes. Designed for training data augmentation in AFib detection systems.
1from huggingface_hub import hf_hub_download
2import torch
3
4# Download model files from Hugging Face
5diffusion_path = hf_hub_download(
6 repo_id="TharakaDil2001/diffusion-ecg-augmentation",
7 filename="diffusion_model.pth"
8)
9classifier_path = hf_hub_download(
10 repo_id="TharakaDil2001/diffusion-ecg-augmentation",
11 filename="classifier_model.pth"
12)
13
14# Load the diffusion model checkpoint
15checkpoint = torch.load(diffusion_path, map_location="cpu")
16
17# The checkpoint contains:
18# - checkpoint['content_encoder'] → Content Encoder state dict
19# - checkpoint['style_encoder'] → Style Encoder state dict
20# - checkpoint['unet'] → UNet state dict
21# - checkpoint['config'] → Training config with all hyperparameters
22
23# Load the classifier checkpoint
24cls_checkpoint = torch.load(classifier_path, map_location="cpu")
25# - cls_checkpoint['model_state_dict'] → AFibResLSTM state dict
26
27# To use the full pipeline, clone the repository:
28# git clone https://github.com/vlbthambawita/PERA_AF_Detection.git
29# See: diffusion_pipeline/final_pipeline/ for model architectures
1# Clone the full codebase with all model architectures
2git clone https://github.com/vlbthambawita/PERA_AF_Detection.git
3cd PERA_AF_Detection/diffusion_pipeline/final_pipeline/
4
5# Download weights
6pip install huggingface_hub
7python -c "
8from huggingface_hub import hf_hub_download
9hf_hub_download('TharakaDil2001/diffusion-ecg-augmentation', 'diffusion_model.pth', local_dir='.')
10hf_hub_download('TharakaDil2001/diffusion-ecg-augmentation', 'classifier_model.pth', local_dir='.')
11"
1@misc{pera_af_detection_2025,
2 title={Diffusion-Based Data Augmentation for Atrial Fibrillation Detection},
3 author={Dilshan, D.M.T. and Karunarathne, K.N.P.},
4 year={2025},
5 institution={University of Peradeniya, Sri Lanka},
6 collaboration={SimulaMet, Oslo, Norway}
7}