Object Detection in Medical Images
Module: Healthcare AI | Difficulty: Advanced
IoU (Intersection over Union)
FROC (Free-Response ROC)
YOLO Loss
Non-Maximum Suppression (NMS)
For each detection with confidence :
- Sort by descending
- Suppress if
Medical Detection Architectures
| Method | Type | mAP | Sensitivity | False Positives/Scan | |--------|------|-----|-------------|---------------------| | Faster R-CNN | Two-stage | 0.72 | 0.85 | 3.2 | | RetinaNet | One-stage | 0.69 | 0.82 | 4.1 | | FCOS | Anchor-free | 0.71 | 0.84 | 3.5 | | DETR | Transformer | 0.73 | 0.86 | 2.8 | | YOLO v8 | One-stage | 0.68 | 0.80 | 4.5 |
import torch
import torch.nn as nn
import torchvision
class FPNBackbone(nn.Module):
def __init__(self):
super().__init__()
resnet = torchvision.models.resnet50(pretrained=True)
self.layer1 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.relu, resnet.maxpool)
self.layer2 = resnet.layer1
self.layer3 = resnet.layer2
self.layer4 = resnet.layer3
self.layer5 = resnet.layer4
self.fpn1 = nn.Conv2d(2048, 256, 1)
self.fpn2 = nn.Conv2d(1024, 256, 1)
self.fpn3 = nn.Conv2d(512, 256, 1)
def forward(self, x):
c1 = self.layer1(x)
c2 = self.layer2(c1)
c3 = self.layer3(c2)
c4 = self.layer4(c3)
c5 = self.layer5(c4)
p5 = self.fpn1(c5)
p4 = self.fpn2(c4) + nn.functional.interpolate(p5, size=c4.shape[2:])
p3 = self.fpn3(c3) + nn.functional.interpolate(p4, size=c3.shape[2:])
return [p3, p4, p5]
def compute_iou(box1, box2):
x1 = max(box1[0], box2[0])
y1 = max(box1[1], box2[1])
x2 = min(box1[2], box2[2])
y2 = min(box1[3], box2[3])
inter = max(0, x2 - x1) * max(0, y2 - y1)
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
return inter / (area1 + area2 - inter + 1e-6)
backbone = FPNBackbone()
x = torch.randn(1, 3, 512, 512)
features = backbone(x)
print(f'FPN features: {[f.shape for f in features]}')
Research Insight: Anchor-free detection methods (FCOS, CenterNet) are particularly well-suited for medical imaging because lesion shapes are highly variable and do not fit predefined anchor boxes well. Center-based detection with heatmap regression achieves comparable performance to anchor-based methods while eliminating the need for anchor hyperparameter tuning.