How katherlab/stamp works
Project type and purpose
• This is a Python-based command-line tool (“stamp”) implementing an end-to-end deep-learning pipeline for computational pathology.
• It’s not a classic web or mobile app but a CLI application with subcommands (“init”, “preprocess”, “train”, “crossval”, “deploy”, “statistics”, “heatmaps”) that orchestrate a multi-stage data-science workflow on whole-slide images.
File structure
• Top-level: CI config, docs, README, pyproject.toml, tests.
• src/stamp: the core package.
– __main__.py loads the CLI, dispatches subcommands.
– cache.py implements disk caching of features.
– config.py + config.yaml handle loading and validating run parameters.
– preprocessing/: image-to-feature pipeline (tiling + a family of “extractor” plugins).
– modeling/: data loaders, transforms, model classes (Vision Transformer), training, cross-validation, deployment wrappers, Alibi interpretability.
– heatmaps/: post hoc visualization.
– statistics/: metric calculators (ROC, PRC, categorical stats).
• tests/ verify each logical component.
README for additional insights
• The README confirms the CLI commands and dependencies (OpenSlide, OpenCV, PyTorch Lightning).
Diagramming the architecture
• CLI entrypoint (“stamp”).
• Configuration manager (parses YAML).
• Preprocessing subsystem
– Tiling → Extractors (conch, gigapath, dinobloom, etc.) → feature cache.
• Modeling subsystem
– Data loader + transforms → Vision Transformer via PyTorch Lightning → trained model artifacts.
– Cross-validation variant (k-fold orchestration).
– Alibi module for interpretability.
• Deployment subsystem (loads model, serves predictions).
• Heatmap generator (uses model + tiling to produce visual overlays).
• Statistics subsystem (loads predictions + labels → computes AUROC, AUPRC, etc.).
• Shared disk storage/file system for input WSIs, intermediate feature caches, model weights, and output artifacts.
1. User runs “stamp <command>” → CLI → loads config.
2. “preprocess” reads WSIs → tiler → extractor plugins → writes feature vectors to cache.
3. “train” reads feature cache + labels → transforms → model training → writes model .ckpt.
4. “crossval” orchestrates multiple “train” runs with splits.
5. “deploy” loads .ckpt → runs inference on new WSIs/features → writes predictions.
6. “heatmaps” loads predictions + spatial metadata → produces slide overlays.
7. “statistics” reads predictions + ground-truth → computes metrics → writes reports.
c. Architectural patterns & design principles
• Modular “component” pattern: each stage (preprocess, modeling, stats) lives in its own package.
• Plugin pattern for extractors (each extractor class registers itself).
• Command pattern for CLI subcommands.
• Pipeline pattern chaining discrete data-transformation steps.
• Separation of concerns: caching, I/O, model code, metrics are orthogonal.
d. Key technologies & libraries
• Python CLI via argparse (in __main__.py).
• YAML config (PyYAML or ruamel.yaml).
• OpenSlide & OpenCV for image I/O.
• PyTorch Lightning for training orchestration.
• Vision Transformer architecture, Alibi for explainability.
• pytest for tests.
Detail is critical
• Explicitly show the cache layer sitting between preprocessing and modeling.