PDAC-TSR-AutoSeg: Virchow2 tissue-segmentation decoders
Five fold decoders that segment H&E tiles of pancreatic ductal adenocarcinoma (PDAC) into 11 tissue classes from the frozen token grid of the Virchow2 pathology foundation model. They produced the 8 µm/pixel label maps used for all whole-slide measurements in the study Carcinoma burden, not stroma, underlies the prognostic value of tumour-stroma ratio in pancreatic cancer.
Code, analysis protocols and the research toolkit: https://github.com/bhyang123/PDAC-TSR-AutoSeg
The Virchow2 encoder is not included. Request access at https://huggingface.co/paige-ai/Virchow2 and use it under its licence. These decoders are useful only together with that encoder.
Files
| File | Contents |
|---|---|
fold_0.safetensors … fold_4.safetensors |
Decoder weights of the five cross-validation folds (1.51 M parameters each) |
decoder_config.json |
Architecture, class list, preprocessing, and the early-stopping epoch of each fold |
decoder.py |
ConvDecoder definition (identical to seg_fm/src/segfm/decoder.py in the GitHub repository) |
inference_example.py |
Minimal example: one tile → class probabilities |
nested_cv_metrics.json |
Nested cross-validation metrics of the same training recipe |
SHA256SUMS |
Checksums of all files |
Model
- Input: a 128 × 128 µm H&E tile read at 0.5 µm/pixel (256 × 256 px), resized to 224 × 224 px (bicubic, antialiased) and normalised with ImageNet mean and standard deviation.
- Encoder (frozen, float16): Virchow2 ViT-H/14 with four register tokens. The last-layer patch tokens (class and register tokens removed) form a 16 × 16 grid with 1,280 channels, one token per 8 × 8 µm.
- Decoder: 1 × 1 projection to 256 channels, two blocks of 3 × 3 convolution, batch normalisation, GELU and dropout (0.1), and a 1 × 1 classifier applied on the token grid.
- Ensemble: the softmax probabilities of the five fold decoders are averaged; the most probable class of each token is the label. In the study, token labels were written without upsampling to an 8 µm/pixel slide label map.
Classes
| Index | Class |
|---|---|
| 0 | Tumor |
| 1 | Stroma |
| 2 | Acinar |
| 3 | Adipose |
| 4 | Lymphoid aggregate |
| 5 | Islet |
| 6 | Nerve |
| 7 | Blood vessel |
| 8 | Ductal cell |
| 9 | Necrosis |
| 11 | Other tissue |
Index 10 is a reserved output that is not a tissue class; it is excluded from all tissue areas, ratios and Dice means.
Training
- Annotations: exhaustive polygon annotations on 26 H&E slides from 16 cases (22 resection slides from 12 patients and four tissue microarray slides) from Peking University First Hospital. Annotations were drawn in QuPath by a trained pathology researcher and reviewed region by region by a senior pancreatobiliary pathologist. The resulting 50,418 non-overlapping tiles are not released.
- Splits: five folds by case (all slides of a case in the same fold), balanced on tumour and stroma pixels.
- Optimisation: features cached once; 0.5 × class-weighted cross-entropy (median-frequency weights) + 0.5 × soft
Dice loss; AdamW (learning rate 1 × 10⁻³, weight decay 1 × 10⁻⁴), 2 warm-up epochs then cosine decay, batch size
64, up to 40 epochs, early stopping on the mean Dice of tumour, stroma and other tissue (patience 8); flips and
90° rotations applied jointly to token grids and masks. All settings are in
seg_fm/configs/protocol_v1.yaml. - Each released fold model was early-stopped on its own held-out fold (
decoder_config.jsonlists the selected epochs). Its out-of-fold performance is therefore optimistic and is not reported here.
Performance (nested cross-validation)
For an unbiased estimate, the same recipe was rerun with nested cross-validation: train on three folds, early-stop on a fourth, test once on the fifth. Pixel-level Dice, pooled over the five test folds (16 cases), with 95% case-bootstrap confidence intervals (1,000 resamples):
| Measure | Dice |
|---|---|
| Mean of tumour, stroma and other tissue (primary) | 0.921 (95% CI 0.892–0.946) |
| Tumour | 0.884 (95% CI 0.833–0.918) |
| Stroma | 0.941 (95% CI 0.899–0.973) |
| Mean of the 11 tissue classes | 0.704 |
Per class: acinar 0.967, adipose 0.945, lymphoid aggregate 0.973, islet 0.873, nerve 0.854, blood vessel 0.699,
ductal cell 0.116, necrosis 0.141, other tissue 0.352 (nested_cv_metrics.json). Virchow2 ranked first of 24 frozen encoders on the primary measure in both the original and the nested evaluation; the full
leaderboards are in the GitHub repository (results/segmentation_benchmark/).
Intended use and limitations
- Research use only. Not a medical device, and not for diagnosis or treatment decisions.
- Trained on one institution's formalin-fixed resection slides scanned at 0.25 or 0.5 µm/pixel. Performance on other scanners, staining protocols, frozen sections or biopsy material has not been established beyond the cohorts analysed in the study.
- Ductal cells, necrosis and other tissue are segmented poorly (Dice 0.12–0.35); measures that depend on them should be interpreted with caution.
- Small nerve fragments are unreliable; in the study, nerve profiles below 1,000 µm² were discarded.
- Segmentation errors propagate to patient-level measures. The study quantifies this with the pixel confusion matrix (Monte Carlo propagation and deconvolution; script 32 in the GitHub repository).
Use
pip install torch timm safetensors huggingface_hub pillow numpy
huggingface-cli login # access to paige-ai/Virchow2 is required
python inference_example.py tile_256px_0.5um.png
To run whole-slide inference with the study pipeline, place the files of this repository in
seg_fm/outputs/v1/results/virchow2/ of the GitHub repository; seg_fm/scripts/04_infer_wsi.py reads
fold_<k>.safetensors and decoder_config.json from there.
Licence
CC BY-NC 4.0. Virchow2 is subject to its own licence and terms of use, which also apply to any use of these decoders.
Citation
Please cite the article; see CITATION.cff in the GitHub repository.
Model tree for bhyang814/PDAC-TSR-AutoSeg
Base model
paige-ai/Virchow2