macrotome-segformer / README.md
NorbertRop's picture
TorchScript files and model card of macrotome-segformer-0.2
1628f90 verified
|
Raw History Blame Contribute Delete
4.04 kB
---
license: cc-by-nc-sa-4.0
base_model: nvidia/mit-b2
base_model_relation: finetune
tags:
- pathology
- whole-slide-image
- tissue-segmentation
- image-segmentation
- quality-control
pipeline_tag: image-segmentation
---
# macrotome SegFormer
SegFormer with a MiT-B2 encoder (25 M parameters) and three sigmoid heads, trained from NVIDIA's ImageNet MiT-B2 weights. The default macrotome model: about 2 s per 50 × 25 mm slide on an RTX 3090, in 2048 px tiles at 8 µm/px.
Segmentation of brightfield whole-slide images into three layers at 8 µm/px, for any stain, organ and scanner:
- **tissue**: every piece of tissue on the glass, including fat, pale IHC and small fragments;
- **pen**: marker ink and printed marks, on glass or over tissue;
- **quality**: image defects such as bubbles, folds, blur, debris, coverslip edges and dark scan corners.
Part of [macrotome](https://github.com/cancercenterai/macrotome). Other macrotome models: [SegFormer fast](https://huggingface.co/CancerCenterAI/macrotome-segformer-fast), [SAM 2.1](https://huggingface.co/CancerCenterAI/macrotome-sam2.1), [SAM 3](https://huggingface.co/CancerCenterAI/macrotome-sam3).
## Use
```bash
pip install "macrotome[segformer] @ git+https://github.com/cancercenterai/macrotome"
macrotome segment slide.svs --model segformer --out out/
```
```python
import macrotome
model = macrotome.load("segformer") # downloads the weights from this repository
res = model.segment("slide.svs")
tissue, pen, quality = res.mask("tissue"), res.mask("pen"), res.mask("quality")
res.write("out/") # label TIFF, QuPath GeoJSON, JSON summary, overlay
```
## QuPath
`segformer.torchscript.pt` (float32, for the CPU and Apple's GPU) and `segformer.torchscript-bf16.pt` (bfloat16, for an NVIDIA GPU, as the
published scores) are this model as TorchScript, for the macrotome QuPath extension, which downloads them itself. They
take float RGB in 0..255 and return the three probabilities; the tile size, overlap, the 32 px white margin at image
edges and the resolution are in `macrotome.json` inside each file.
## Results
98 held-out slides (Tissues with Issues, Conflux, pathologist-labelled breast slides). SegFormer was trained on none
of them. The two SAM models were trained on an earlier label snapshot that still held the 20 breast slides; on those
20 slides they score the same as SegFormer models that never saw them (Dice 0.967–0.971).
| | Tissue Dice median / p10 | False tissue mm²/slide | Pen F1 | Quality P / R |
|---|---|---|---|---|
| **SegFormer** | 0.988 / 0.962 | 3.1 | 0.941 | 0.68 / 0.77 |
| SAM 2.1 tuned | 0.984 / 0.951 | 5.5 | 0.903 | 0.76 / 0.63 |
| SAM 3 tuned | 0.984 / 0.958 | 4.1 | 0.932 | 0.86 / 0.62 |
| SlideSegmenter | 0.951 / 0.751 | 14.2 | 0.691 | – |
Scored on 26 November 2026, every row on the labels of that day.
Training data, evaluation on the public test sets, examples and limitations are in the
[repository README](https://github.com/cancercenterai/macrotome).
## Versions
- `macrotome-segformer-0.2` (26 November 2026), the files in this repository: trained with 1024 px crops on the labels
of 23 November 2026.
- `macrotome-segformer-0.1`, the first release: trained with 768 px crops on the labels of 12 November 2026. By the
measures of the table above it scores 0.985 / 0.954, 3.4, 0.935 and 0.67 / 0.76. Its files are at revision
`eb6a7f3` of this repository:
```python
import macrotome
from macrotome import hub
weights = hub.weights_path("segformer", revision="eb6a7f3750eb1cddfd98f4151d914f2afdfd17d3")
model = macrotome.load("segformer", weights=weights)
```
## Licence
CC BY-NC-SA 4.0: research and other non-commercial use, with attribution, and adaptations under the same terms. The training data include sets under non-commercial and share-alike terms. The encoder starts from NVIDIA's MiT-B2 ImageNet weights (NVIDIA Source Code License, non-commercial).
Not for clinical use: the models are research tools and are not validated for diagnosis or any clinical decision.