A tested PyTorch framework for computational pathology research with working benchmarks on PatchCamelyon and CAMELYON16
View on GitHub matthewvaishnav/computational-pathology-research
Complete guide to running experiments on PatchCamelyon and CAMELYON16 datasets.
The PatchCamelyon (PCam) dataset consists of 96×96 pixel patches extracted from histopathologic scans of lymph node sections.
python scripts/generate_synthetic_pcam.py
python experiments/train_pcam.py --config experiments/configs/pcam.yaml
python experiments/evaluate_pcam.py \
--checkpoint checkpoints/pcam/best_model.pth \
--data-root data/pcam \
--output-dir results/pcam
Synthetic subset (8 epochs):
See PCAM_BENCHMARK_RESULTS.html for detailed analysis.
Slide-level classification using pre-extracted patch features with attention-based aggregation.
python scripts/generate_synthetic_camelyon.py
# Quick test (1 epoch)
python experiments/train_camelyon.py \
--config experiments/configs/camelyon_quick_test.yaml
# Full training (50 epochs)
python experiments/train_camelyon.py \
--config experiments/configs/camelyon.yaml
python experiments/evaluate_camelyon.py \
--checkpoint checkpoints/camelyon/best_model.pth \
--data-root data/camelyon \
--output-dir results/camelyon \
--save-predictions-csv
See CAMELYON_TRAINING_STATUS.html for detailed guide.
Load and fine-tune pretrained encoders:
from src.models.pretrained import load_pretrained_encoder
# Load ResNet50 with ImageNet weights
encoder = load_pretrained_encoder(
model_name='resnet50',
source='torchvision',
pretrained=True,
num_classes=2
)
# Access feature dimension
feature_dim = encoder.feature_dim # 2048 for ResNet50
Supported Sources:
Analyze model performance and export for deployment:
# Profile inference latency
python scripts/model_profiler.py \
--checkpoint models/best_model.pth \
--profile-type time
# Export to ONNX format
python scripts/export_onnx.py \
--checkpoint models/best_model.pth \
--output models/model.onnx
Compare multiple model architectures:
# Quick test (3 epochs)
python experiments/compare_pcam_baselines.py \
--configs experiments/configs/pcam_comparison/*.yaml \
--quick-test
# Full training
python experiments/compare_pcam_baselines.py \
--configs experiments/configs/pcam_comparison/*.yaml
See PCAM_COMPARISON_GUIDE.html for detailed comparison guide.
Example training configuration:
# experiments/configs/pcam.yaml
data:
root_dir: "data/pcam"
batch_size: 32
num_workers: 4
model:
architecture: "resnet18"
num_classes: 2
dropout: 0.5
training:
epochs: 10
learning_rate: 0.001
weight_decay: 0.0001
optimizer: "adam"