Skip to content

Add TissueQC: tissue and artifact segmentation in one model - #251

Merged
guillaumejaume merged 1 commit into
mainfrom
feat/tissueqc
Nov 24, 2026
Merged

guillaumejaume merged 1 commit into
mainfrom
feat/tissueqc

Conversation

@guillaumejaume

Copy link
Copy Markdown
Contributor

Summary

Adds TissueQC as a tissue segmenter: --segmenter tissueqc. Weights: JaumeLab/TissueQC (Apache-2.0).

TissueQC is a U-Net with an EfficientNet-B0 encoder (4.5M parameters) that predicts three classes per pixel at 5x (2 µm/px): background, tissue, and artifact on tissue (fold, ink, out-of-focus area, knife line, bubble, debris).

  • Default mask: tissue plus artifacts on tissue, enclosed holes filled. Artifacts lying on bare glass are background.
  • --remove_artifacts: artifact regions are cut out of the same prediction. No GrandQC pass runs.
  • --seg_conf_thresh: for TissueQC, the artifact probability threshold (default 0.5). Lower it to find more artifacts.
  • The default segmenter stays hest. hest, grandqc and otsu behave as before, and --remove_penmarks still uses GrandQC.

Changes

  • trident/segmentation_models/load.py: TissueQCSegmenter, a tissueqc branch in segmentation_model_factory, and a tissueqc entry in local_ckpts.json. Weights load like HEST: registry first, else download into the trident cache.
  • trident/segmentation_models/model_zoo/tissueqc.py: the slide-level mask rules.
  • trident/wsi_objects/WSI.py: one hook in segment_tissue. A segmenter that defines to_contours(class_map, level0_mpp, holes_are_tissue) turns its own stitched class map into contours, in place of the binarised mask and mask_to_gdf. A segmenter can also set num_workers.
  • run_batch_of_slides.py and run_single_slide.py: tissueqc in --segmenter. A segmenter with detects_artifacts handles --remove_artifacts itself. The model's batch_size is used when --seg_batch_size is not set.
  • README, docs (api, faq, quickstart, installation) and the .claude skill list TissueQC.

Why TissueQC traces its own contours

mask_to_gdf resizes the mask to a 2000 px edge and keeps holes of 4000 resized pixels or more (about 0.1 mm²). Removed artifacts are holes inside tissue, and nearly all of them fell under that limit. TissueQC builds its masks at 8 µm/px and keeps artifact cuts down to 24 µm wide and 0.005 mm², so thin cracks and specks stay tissue.

Why 32 workers and batch 4

At 5x, slide decoding limits speed, not the model. The default (2 workers per batch item) left decoding underused.

Results (16 TCGA slides, one GPU, shared machine)

Time GeoJSON
HEST (--segmenter hest) 206 s 37 MB
TissueQC 56 s 5.2 MB
TissueQC --remove_artifacts 70 s 7.1 MB

HEST output is byte-identical to main. Known limitations, listed on the model card: dense tissue (cellular tumour, smooth muscle, thick fat septa) and thyroid colloid edges are sometimes predicted as artifact.

Tests

  • tests/test_tissueqc.py (no weights needed): mask rules on synthetic class maps (fold, thin crack, ink on glass, holes), contour scaling to level 0, and the factory branch.
  • tests/test_run_batch_of_slides.py: TissueQC handles --remove_artifacts without GrandQC; HEST keeps the GrandQC remover.
  • tests/test_segmentation_models.py: TissueQC forward pass (integration-gated, like HEST and GrandQC). Passes on GPU.
  • Full suite: 113 passed, 78 skipped (integration-gated).

🤖 Generated with Claude Code

TissueQC (JaumeLab/TissueQC on the Hub, Apache-2.0) is a 5x U-Net with an
EfficientNet-B0 encoder that predicts background, tissue and artifact in one
pass. --segmenter tissueqc gives a tissue mask that keeps artifacts on
tissue; with --remove_artifacts the artifact regions are cut out of the same
prediction and no GrandQC pass runs. --seg_conf_thresh is the artifact
probability threshold for this model. The default segmenter stays hest.

WSI.segment_tissue gains one hook: a segmenter that defines to_contours()
turns its own stitched class map into contours, in place of the binarised
mask and mask_to_gdf. TissueQC traces them at 8 um/px, because mask_to_gdf
drops holes under about 0.1 mm2 and with them nearly every artifact cut.
Artifact regions narrower than 24 um or smaller than 0.005 mm2 stay tissue.
A segmenter can also set num_workers and batch_size; TissueQC uses 32 and 4
because decoding, not inference, limits speed at 5x.

On 16 TCGA slides: 56 s against 206 s for HEST on one GPU, GeoJSON 5.2 MB
against 37 MB. HEST, GrandQC and Otsu outputs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@guillaumejaume
guillaumejaume merged commit 13052c1 into main Nov 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant