Repository navigation
Add TissueQC: tissue and artifact segmentation in one model - #251
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).
--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.hest.hest,grandqcandotsubehave as before, and--remove_penmarksstill uses GrandQC.Changes
trident/segmentation_models/load.py:TissueQCSegmenter, atissueqcbranch insegmentation_model_factory, and atissueqcentry inlocal_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 insegment_tissue. A segmenter that definesto_contours(class_map, level0_mpp, holes_are_tissue)turns its own stitched class map into contours, in place of the binarised mask andmask_to_gdf. A segmenter can also setnum_workers.run_batch_of_slides.pyandrun_single_slide.py:tissueqcin--segmenter. A segmenter withdetects_artifactshandles--remove_artifactsitself. The model'sbatch_sizeis used when--seg_batch_sizeis not set.api,faq,quickstart,installation) and the.claudeskill list TissueQC.Why TissueQC traces its own contours
mask_to_gdfresizes 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)
--segmenter hest)--remove_artifactsHEST 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_artifactswithout GrandQC; HEST keeps the GrandQC remover.tests/test_segmentation_models.py: TissueQC forward pass (integration-gated, like HEST and GrandQC). Passes on GPU.🤖 Generated with Claude Code