Medical Imaging with Deep Learning
Why Medical Imaging AI?
Radiologists process thousands of images daily, and the volume grows approximately 10% per year. Deep learning models achieve radiologist-level performance across imaging modalities.
- Reduce interpretation time by 30-50%
- Catch subtle findings missed during high-volume reads
- Provide consistent performance regardless of fatigue
- Enable screening in under-resourced settings
Convolutional Neural Networks (CNNs)
A CNN learns hierarchical features through convolutional, pooling, and fully connected layers.
Convolution Operation
Batch Normalization
ResNet Skip Connections
import torch
import torch.nn as nn
import torchvision.models as models
class MedicalResNet(nn.Module):
def __init__(self, num_classes=2, pretrained=True):
super().__init__()
self.backbone = models.resnet50(pretrained=pretrained)
in_features = self.backbone.fc.in_features
self.backbone.fc = nn.Sequential(
nn.Dropout(0.5),
nn.Linear(in_features, 256),
nn.ReLU(),
nn.Dropout(0.3),
nn.Linear(256, num_classes)
)
def forward(self, x):
return self.backbone(x)
Data Augmentation for Limited Medical Datasets
Geometric Augmentations
| Augmentation | Description | Medical Use Case |
|---|---|---|
| Rotation | Rotate by theta in [-15^circ, 15^circ] | View normalization |
| Flip | Horizontal/vertical mirroring | Symmetry-aware training |
| Elastic Deformation | Random displacement fields | Tissue variability |
Intensity Augmentations
- Contrast adjustment:
- Gaussian noise:
from torchvision import transforms
medical_transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.RandomHorizontalFlip(p=0.5),
transforms.RandomRotation(15),
transforms.ColorJitter(brightness=0.2, contrast=0.2),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
Mixup
where .
Transfer Learning Strategies
- Feature extraction: Freeze pretrained layers
- Gradual unfreezing: Progressively unfreeze layers
- Full fine-tuning: Update all weights with small learning rate
def create_medical_model(num_classes):
model = models.resnet50(pretrained=False)
checkpoint = torch.load('medical_resnet50.pth')
model.load_state_dict(checkpoint['model_state_dict'])
model.fc = nn.Linear(model.fc.in_features, num_classes)
return model
Evaluation Metrics
Practical Considerations
- Class imbalance: Use focal loss or class-weighted cross-entropy
- Data privacy: Consider federated learning for multi-site studies
- Explainability: Use Grad-CAM to visualize model attention