Demographic-Aware Self-Supervised Anomaly Detection Pretraining for Equitable Rare Cardiac Diagnosis
Organizations: Shanghai Jiao Tong University, Shanghai, China · Shanghai AI Laboratory, Shanghai, China · National University of Defense Technology, Wuhan, China · Ruijin Hospital, Shanghai Jiao Tong University School of Medicine, Shanghai, China · Renji Hospital, Shanghai Jiao Tong University School of Medicine, Shanghai, China
Abstract
Rare cardiac anomalies are difficult to detect from electrocardiograms (ECGs) due to their long-tailed distribution with extremely limited case counts and demographic disparities in diagnostic performance. These limitations contribute to delayed recognition and uneven quality of care, creating an urgent need for a generalizable framework that enhances sensitivity while ensuring equity across diverse populations. In this study, we developed an AI-assisted two-stage ECG framework integrating self-supervised anomaly detection with demographic-aware representation learning. The first stage performs self-supervised anomaly detection pretraining by reconstructing masked global and local ECG signals, modeling signal trends, and predicting patient attributes to learn robust ECG representations without diagnostic labels. The pretrained model is then fine-tuned for multi-label ECG classification using asymmetric loss to better handle long-tail cardiac abnormalities, and additionally produces anomaly score maps for localization, with CPU-based optimization enabling practical deployment. Evaluated on a longitudinal cohort of over one million clinical ECGs, our method achieves an AUROC of 94.7% for rare anomalies and reduces the common-rare performance gap by 73%, while maintaining consistent diagnostic accuracy across age and sex groups. In conclusion, the proposed equity-aware AI framework demonstrates strong clinical utility, interpretable anomaly localization, and scalable performance across multiple cohorts, highlighting its potential to mitigate diagnostic disparities and advance equitable anomaly detection in biomedical signals and digital health. Source code is available at https://github.com/MediaBrain-SJTU/Rare-ECG.
Figures & tables
| Pretraining + Finetuning | |||||||||
| Dataset | Evaluation Data | ECG Sample Count | Metrics | Train from Scratch | Contrastive Learning | MoCo | AD:TSL | AD:Ours Finetuning | AD:Ours Joint-train |
| Internal Validation (ECG-LT) | All Test Data | 189,440 | AUROC | 0.910 ±0.053 | 0.923 ±0.050 | 0.906 ±0.054 | 0.925 ±0.049 | 0.948 ±0.041 | 0.964 ±0.035 |
| Sensitivity | 0.879 | 0.882 | 0.844 | 0.878 | 0.925 | 0.931 ±0.047 | |||
| Specificity | 0.830 | 0.888 | 0.876 | 0.879 | 0.889 | 0.925 ±0.049 | |||
| Common Test Data | 183,810 | AUROC | 0.940 ±0.077 | 0.937 ±0.078 | 0.964 ±0.060 | 0.932 ±0.081 | 0.962 ±0.062 | 0.969 ±0.056 | |
| Sensitivity | 0.887 | 0.886 | 0.920 | 0.890 | 0.919 | 0.935 ±0.079 | |||
| Task | Evaluation | Metrics | State-of-the-art Methods | Ours | |||
| Data | TranAD | AnoTran | BeatGAN | TSL | |||
| Anomaly Detection | All Test Data | AUROC | 0.566 ±0.002 | 0.601 ±0.002 | 0.653 ±0.002 | 0.824 ±0.002 | 0.912 ±0.001 |
| F1 Score | 0.667 | 0.673 | 0.669 | 0.746 | 0.837 ±0.002 | ||
| Sensitivity | 0.511 | 0.579 | 0.522 | 0.793 | 0.842 ±0.002 | ||
| Specificity | 0.514 ±0.002 | 0.564 | 0.698 | 0.668 | 0.830 ±0.002 | ||
| Pre@90 | 0.501 | 0.530 | 0.528 | 0.613 | 0.756 ±0.002 | ||
| Evaluation Data | Metrics | Cardiologist (time constraints) | Cardiologist (no time constraints) | AI | Cardiologist (AI assisted) |
| Common data | Sensitivity | 0.626 ±0.165 | 0.747 ±0.148 | 0.837 ±0.126 | 0.820 ±0.131 |
| Specificity | 0.992 ±0.030 | 0.973 ±0.055 | 0.916 ±0.095 | 0.989 ±0.036 | |
| Long-tail data | Sensitivity | 0.347 ±0.226 | 0.469 ±0.237 | 0.592 ±0.234 | 0.714 ±0.215 |
| Specificity | 0.997 ±0.026 | 0.997 ±0.026 | 0.986 ±0.056 | 0.997 ±0.026 |
| Data | Condition | Cardiac Conditions | # All data | # Test data |
| Type | Types | |||
| Common | 37 | Normal electrocardiogram | 539,607 | 94,304 |
| T wave changes | 182,756 | 33,907 | ||
| Sinus bradycardia | 99,275 | 17,463 | ||
| ST-T segment changes | 80,334 | 11,953 | ||
| Sinus tachycardia | 61,287 | 11,272 |
| Data | Condition | Cardiac Conditions | # All data | # Test data |
| Type | Types | |||
| Uncommon | 36 | Prolonged QT interval | 2,486 | 410 |
| Right axis deviation | 2,476 | 450 | ||
| Old anterior myocardial infarction | 2,403 | 418 | ||
| Old inferior myocardial infarction | 2,344 | 362 | ||
| Left axis deviation | 1,856 | 188 |
| Data | Condition | Cardiac Conditions | # All data | # Test data |
| Type | Types | |||
| Rare | 43 | High lateral myocardial infarction | 394 | 30 |
| Upsloping ST segment depression | 368 | 30 | ||
| Downsloping ST segment depression | 311 | 33 | ||
| Second-degree sinoatrial block | 257 | 50 | ||
| High-degree atrioventricular block | 247 | 20 |
| Dataset | Condition | Cardiac Conditions | # Test data |
| Types | |||
| Renji | 26 | Paced electrocardiogram | 398 |
| Myocardial infarction | 223 | ||
| Complete left bundle branch block | 214 | ||
| Complete right bundle branch block | 209 | ||
| Atrial fibrillation | 144 |
| Data | Condition | Cardiac Conditions | #Data | Rarity |
| Source | Types | |||
| 50 | Normal electrocardiogram | 40 | Common | |
| Sinus tachycardia | 35 | Common | ||
| Atrial fibrillation | 26 | Common | ||
| ST-T segment changes | 26 | Common | ||
| T wave changes | 24 | Common |
| Evaluation | Metrics | None | +MR | +MR+MC | +MR+MC | +MR+MC |
| Data | +TAR | +TAR+APM | ||||
| All Test Data | AUROC | 0.779 | 0.882 | 0.905 | 0.909 | 0.912 |
| F1 Score | 0.720 | 0.802 | 0.828 | 0.833 | 0.837 | |
| Sensitivity | 0.823 | 0.810 | 0.825 | 0.841 | 0.842 | |
| Specificity | 0.537 | 0.790 | 0.833 | 0.823 | 0.830 | |
| Pre@90 | 0.585 | 0.684 | 0.737 | 0.749 | 0.756 |
| Attribute | Reference Range | Normal | Abnormal | |||
| All | Common | Uncommon | Rare | |||
| Gender | 0 (male) or 1 (female) | 86.5% Acc | 75.9% Acc | 76.2% Acc | 69.2% Acc | 70.9% Acc |
| Age | 0 100 years | 12.6 | 14.0 | 13.8 | 16.8 | 18.1 |
| Heart Rate (HR) | 60 100 bpm | 3.64 | 6.94 | 6.86 | 8.20 | 8.62 |
| PR Interval (PR) | 120 200 ms | 18.5 | 26.7 | 26.2 | 35.2 | 37.8 |
| QT Interval (QT) | 320 440 ms | 20.7 | 33.0 | 32.4 | 43.2 | 44.0 |