← Work
04Medical AI

Swin Transformer for Histopathologic Cancer Detection

A Swin-Tiny Vision Transformer fine-tuned for binary tumor classification on PatchCamelyon histopathology patches, reaching ROC-AUC 0.955 and PR-AUC 0.99 at 85.7% accuracy. Evaluated on sensitivity and specificity rather than accuracy alone, because the false-negative cost in a diagnostic setting is not symmetric.

PyTorchSwin TransformerVision TransformerstimmPatchCamelyonMedical ImagingImage Classification
Swin Transformer for Histopathologic Cancer Detection cover

CASE STUDY

Select a section to explore the project one part at a time.

Problem

A model can be accurate and still fail the patient.


Histopathology patch classification is usually reported as accuracy, and accuracy is close to meaningless here. The two errors a tumour classifier can make are not symmetric: a false positive sends a slide for review, and a false negative sends a patient home.

This project fine-tunes a Swin Transformer for binary tumour classification on PatchCamelyon, then evaluates it the way a diagnostic setting would — sensitivity and specificity separately, with the confusion matrix reported rather than summarised.

What this project asks

  1. Do Vision Transformers work at this patch scale? Swin-Tiny is built for 224×224 inputs. These patches are centre-cropped to 32×32.
  2. Which metric should be trusted under imbalance? ROC-AUC and PR-AUC disagree when the positive class dominates, and one of them is misleading.
  3. Where do the errors actually land? An aggregate accuracy figure hides whether a model fails safe or fails dangerous.

PatchCamelyon, binary tumour classification, 60/20/20 split. Swin-Tiny (swin_tiny_patch4_window7_224, timm), 25 epochs, batch 32, Adam at 1e-4, cross-entropy loss. Rotation 0–360° and random affine augmentation for orientation invariance.