AI for Cardiology: ECG and Cardiac Imaging
Module: Healthcare AI | Difficulty: Advanced
Heart Rate Variability
Ejection Fraction
Cardiac AI Performance
| Task | Model | Accuracy | AUC | Clinical Use |
|---|---|---|---|---|
| Arrhythmia Detection | ResNet-34 | 0.94 | 0.97 | Screening |
| AF Detection | CNN-LSTM | 0.96 | 0.98 | Monitoring |
| EF Prediction | EchoNet | - | 0.92 | Diagnosis |
| Cardiomyopathy | DenseNet | 0.89 | 0.93 | Screening |
| MI Detection | 1D-CNN | 0.92 | 0.95 | Emergency |
import torch
import torch.nn as nn
class ECGClassifier(nn.Module):
def __init__(self, num_classes=5, in_channels=12):
super().__init__()
self.conv1 = nn.Conv1d(in_channels, 64, kernel_size=50, stride=5)
self.conv2 = nn.Conv1d(64, 128, kernel_size=20, stride=2)
self.conv3 = nn.Conv1d(128, 256, kernel_size=10, stride=2)
self.bn1 = nn.BatchNorm1d(64)
self.bn2 = nn.BatchNorm1d(128)
self.bn3 = nn.BatchNorm1d(256)
self.attention = nn.MultiheadAttention(256, num_heads=8, batch_first=True)
self.classifier = nn.Linear(256, num_classes)
def forward(self, x):
x = torch.relu(self.bn1(self.conv1(x)))
x = torch.relu(self.bn2(self.conv2(x)))
x = torch.relu(self.bn3(self.conv3(x)))
x = x.permute(0, 2, 1)
attn_out, _ = self.attention(x, x, x)
x = attn_out[:, -1, :]
return self.classifier(x)
model = ECGClassifier(num_classes=5)
ecg = torch.randn(1, 12, 5000)
output = model(ecg)
print(f'ECG classification output: {output.shape}')
rr_intervals = np.random.uniform(0.6, 1.2, 100)
rmssd = np.sqrt(np.mean(np.diff(rr_intervals) ** 2))
print(f'RMSSD: {rmssd:.4f}')
Research Insight: ECG AI models can detect conditions beyond their training labels: models trained for arrhythmia detection can identify atr fibrillation, predict future AF episodes, and even estimate left ventricular ejection fraction from standard 12-lead ECGs. This suggests ECG signals contain far more cardiac information than traditionally extracted.