Download README.md from JaumeLab/TissueQC: direct link, hf CLI and curl.
- Browser
- Download file 3.86 kB
-
https://huggingface.co/JaumeLab/TissueQC/resolve/main/README.md
- Command line
-
hf download hf://JaumeLab/TissueQC/README.md
-
curl -L -o README.md https://huggingface.co/JaumeLab/TissueQC/resolve/main/README.md
license: apache-2.0
library_name: segmentation-models-pytorch
pipeline_tag: image-segmentation
tags:
- histopathology
- whole-slide-image
- tissue-segmentation
- quality-control
- artifact-detection
TissueQC
TissueQC segments a histology tile into background, tissue and artifact in a single forward pass at 5x (2 µm/px). The same output gives a tissue mask with artifacts kept or a tissue mask with artifacts cut out, so a whole-slide pipeline can drop folds, ink, blur and debris without running a second model.
| Class | Index | Meaning |
|---|---|---|
| background | 0 | glass, area outside the slide, artifacts lying on bare glass |
| tissue | 1 | tissue, including natural holes enclosed by tissue once filled |
| artifact | 2 | artifact on tissue: tissue fold, ink, out-of-focus area, knife line, air bubble, debris |
The network is a U-Net with an EfficientNet-B0 encoder (4.5M parameters). The encoder was initialised from the Apache-2.0 ImageNet weights timm/efficientnet_b0.ra_in1k.
Usage
import json, torch, segmentation_models_pytorch as smp
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
repo = "JaumeLab/TissueQC"
cfg = json.load(open(hf_hub_download(repo, "config.json")))
model = smp.Unet(encoder_name=cfg["encoder_name"], encoder_weights=None, classes=cfg["num_classes"],
decoder_channels=tuple(cfg["decoder_channels"]))
model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
model.eval()
# tile: uint8 RGB array read at 2 µm/px, H and W multiples of 32 (512 x 512 recommended)
x = torch.from_numpy(tile).permute(2, 0, 1)[None].float() / 255
x = (x - torch.tensor(cfg["mean"]).view(1, 3, 1, 1)) / torch.tensor(cfg["std"]).view(1, 3, 1, 1)
with torch.inference_mode():
classes = model(x).argmax(1)[0] # 0 background, 1 tissue, 2 artifact
Read tiles at 2 µm/px (5x). The model was trained on 512 x 512 tiles and is fully convolutional.
From class map to slide mask
The two masks are built from the stitched class map of the whole slide:
- Default: tissue plus artifact regions with at least 25 % of their border on tissue, with enclosed holes filled. Artifacts lying mostly on bare glass count as background.
- Artifacts removed: the default mask with artifact regions cut out. Regions narrower than 24 µm or smaller than 0.005 mm² are kept as tissue, so thin cracks and specks do not fragment the mask.
A pixel is artifact when that class is the most likely one. A lower cut-off on the artifact probability finds more artifacts at the cost of more false positives.
Performance
On held-out test tiles, tissue Dice is 0.98 and artifact-on-tissue Dice is 0.95. On tiles of empty glass, 0.2 % of the area is predicted as tissue (0.5 % for v1.0.0). Through a whole-slide pipeline on 16 TCGA slides, TissueQC took 52 s against 190 s for the HEST tissue segmenter on one GPU, with artifact removal included at no extra cost.
Training
TissueQC was trained on whole-slide images including TCGA and GTEx, with H&E and immunohistochemistry stains.
Versions
- v1.1.0 (current). Empty Visium capture areas and stain film on the glass are predicted as background. Brain and dense lymphoid tissue are no longer predicted as artifact.
- v1.0.0. First release, kept under the tag
v1.0.0(passrevision="v1.0.0"tohf_hub_download).
Limitations
- Sections that are only partly out of focus are only partly predicted as artifact.
- A thin artifact rim is sometimes drawn along the tissue edge.
- Large air spaces in lung are predicted as background.
- In thyroid, the dark folded edges of colloid are often predicted as artifact.
- Artifact boundaries tend to be drawn wider than the visible artifact.
- The model has not been validated for diagnostic use.
License
Apache-2.0.