Toolkit for large-scale whole-slide image processing.
626
stars
244
commits
Python
primary language
Aug 28, 2026
updated
arXiv | Blog | Cite | Documentation | License
Trident is a toolkit for large-scale whole-slide image processing. This project was developed by the Mahmood Lab at Harvard Medical School and Brigham and Women's Hospital. This work was funded by NIH NIGMS R35GM138216.
[!NOTE] Contributions are welcome! Please report any issues. You may also contribute by opening a pull request.
--task all) or stage-by-stage.--remove_artifacts / --remove_penmarks clean-up pass..png, .jpeg), SDPC, OME-Zarr (.zarr), Zeiss CZI (.czi). Or convert to pyramidal TIFF with trident convert.--gpus 0 1 2 3 distributes pending slides across GPUs.--job_dir skips already-completed work. .lock files protect in-flight tasks; stale ones are cleaned safely with --clear_dead_locks.--wsi_cache /local/ssd --cache_batch_size 32 stages slides locally via a producer/consumer pipeline.summary.md (human-readable), runs/<id>.json (manifest), and wsi_states/<slide>.json (per-slide tasks, attempts, errors, resume info).conda create -n "trident" python=3.10, and activate it conda activate trident.git clone https://github.com/mahmoodlab/trident.git && cd trident.pip install -e ..
timm>=0.9.16,<2, transformers>=4.51,<5, safetensors, etc.).Optional install profiles:
pip install -e ".[patch-encoders]" for patch embedding-related extras (e.g. CONCH, MUSK, CTransPath / CHIEF).pip install -e ".[slide-encoders]" for slide embedding-related extras (e.g. PRISM, GigaPath, Madeleine).pip install -e ".[omezarr]" for OME Zarr WSI reader support (OME-NGFF / OME-Zarr).pip install -e ".[czi]" for Zeiss CZI WSI reader support (pylibCZIrw).pip install -e ".[convert]" for slide conversion to tiff.pip install -e ".[full]" to install all pip-installable optional dependencies.Run checks before launching jobs:
trident-doctor --profile basetrident-doctor --profile patch-encoders --check-gatedtrident-doctor --profile slide-encoderstrident-doctor --profile converttrident-doctor --profile full --check-gated[!NOTE] Some models still require manual setup (e.g., local CHIEF repository path in
trident/slide_encoder_models/local_ckpts.json) or HuggingFace gated access approvals.
[!TIP] Using an AI coding agent (e.g. Claude Code)? Trident ships an Agent Skill at
.claude/skills/trident/. Open this repo in Claude Code and your agent can drive Trident end-to-end β segmentation, patching, and patch/slide feature extraction β with the correct encoderβresolution pairings, output layout, and common-pitfall handling baked in. Copy the folder to~/.claude/skills/to use it from any project.
Already familiar with WSI processing? Perform segmentation, patching, and UNI feature extraction from a directory of WSIs with:
python run_batch_of_slides.py --task all --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Feeling cautious?
Run this command to perform all processing steps for a single slide:
python run_single_slide.py --slide_path ./wsis/xxxx.svs --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Convert images/WSIs to pyramidal TIFF:
trident convert --input_dir ./wsis --mpp_csv ./wsis/to_process.csv --job_dir ./pyramidal_tiff --downscale_by 1 --num_workers 1
--mpp_csv is required and must contain wsi,mpp columns. Only files listed in the CSV are converted.
If embedded MPP metadata is detected in a slide, Trident compares it to the CSV value and logs mismatches.
Or follow step-by-step instructions:
Step 1: Tissue Segmentation: Segments tissue vs. background from a dir of WSIs
python run_batch_of_slides.py --task seg --wsi_dir ./wsis --job_dir ./trident_processed --gpus 0 --segmenter hest
--task seg: Specifies that you want to do tissue segmentation.--wsi_dir ./wsis: Path to dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--gpus 0: Use GPU index 0. Pass multiple IDs (e.g. --gpus 0 1) to shard across GPUs, or -1 to force CPU.--segmenter: Segmentation model. Defaults to hest. Use grandqc (Citation necessary, Non-commercial use, Original repository) for fast H&E segmentation or otsu for a classical image-processing-only fallback. Add the option --remove_artifacts for additional artifact clean up../trident_processed/thumbnails../trident_processed/contours../trident_processed/contours_geojson. These can be opened in QuPath for editing/quality control, if necessary.| Segmenter | Args | Link | License |
|---|---|---|---|
| HEST (default) | --segmenter hest | MahmoodLab/hest-tissue-seg | π CC-BY-NC-SA-4.0 |
| GrandQC | --segmenter grandqc | cpath-ukk/grandqc | π CC-BY-NC-SA-4.0 |
| Otsu | --segmenter otsu | β | β (classical, no model) |
Step 2: Tissue Patching: Extracts patches from segmented tissue regions at a specific magnification.
python run_batch_of_slides.py --task coords --wsi_dir ./wsis --job_dir ./trident_processed --mag 20 --patch_size 256 --overlap 0
--task coords: Specifies that you want to do patching.--wsi_dir wsis: Path to the dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--mag 20: Extracts patches at 20x magnification.--patch_size 256: Each patch is 256x256 pixels.--overlap 0: Patches overlap by 0 pixels, always an absolute number in pixels, e.g., --overlap 128 for 50% overlap for 256x256 patches../trident_processed/20x_256px_0px_overlap/patches../trident_processed/20x_256px_0px_overlap/visualization.Step 3a: Patch Feature Extraction: Extracts features from tissue patches using a specified encoder
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
--task feat: Specifies that you want to do feature extraction.--wsi_dir wsis: Path to the dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--patch_encoder uni_v1: Uses the UNI patch encoder. See below for list of supported models.--mag 20: Features are extracted from patches at 20x magnification.--patch_size 256: Patches are 256x256 pixels in size../trident_processed/20x_256px_0px_overlap/features_uni_v1. (Shape: (n_patches, feature_dim))Trident supports 33 patch encoders, loaded via a patch encoder_factory. Models requiring specific installations will return error messages with additional instructions. Gated models on HuggingFace require access requests.
| Patch Encoder | Embedding Dim | Args | Link | License |
|---|---|---|---|---|
| UNI | 1024 | --patch_encoder uni_v1 --patch_size 256 --mag 20 | MahmoodLab/UNI | π CC-BY-NC-ND-4.0 |
| UNI2-h | 1536 | --patch_encoder uni_v2 --patch_size 256 --mag 20 | MahmoodLab/UNI2-h | π CC-BY-NC-ND-4.0 |
| CONCH | 512 | --patch_encoder conch_v1 --patch_size 512 --mag 20 | MahmoodLab/CONCH | π CC-BY-NC-ND-4.0 |
| CONCHv1.5 | 768 | --patch_encoder conch_v15 --patch_size 512 --mag 20 | MahmoodLab/conchv1_5 | π CC-BY-NC-ND-4.0 |
| Virchow | 2560 | --patch_encoder virchow --patch_size 224 --mag 20 | paige-ai/Virchow | π Apache-2.0 |
| Virchow2 | 2560 | --patch_encoder virchow2 --patch_size 224 --mag 20 | paige-ai/Virchow2 | π CC-BY-NC-ND-4.0 |
| Virchow2 (CLS) | 1280 | --patch_encoder virchow2-cls --patch_size 224 --mag 20 | paige-ai/Virchow2 | π CC-BY-NC-ND-4.0 |
| Phikon | 768 | --patch_encoder phikon --patch_size 224 --mag 20 | owkin/phikon | π Owkin non-commercial |
| Phikon-v2 | 1024 | --patch_encoder phikon_v2 --patch_size 224 --mag 20 | owkin/phikon-v2 | π Owkin non-commercial |
| KEEP | 768 | --patch_encoder keep --patch_size 256 --mag 20 | Astaxanthin/KEEP | π MIT |
| Prov-Gigapath | 1536 | --patch_encoder gigapath --patch_size 256 --mag 20 | prov-gigapath | π Apache-2.0 |
| Prov-Gigapath-Flash | 384 | --patch_encoder gigapath-flash --patch_size 256 --mag 20 | prov-gigapath-flash | π Apache-2.0 |
| H-Optimus-0 | 1536 | --patch_encoder hoptimus0 --patch_size 224 --mag 20 | bioptimus/H-optimus-0 | π Apache-2.0 |
| H-Optimus-1 | 1536 | --patch_encoder hoptimus1 --patch_size 224 --mag 20 | bioptimus/H-optimus-1 | π CC-BY-NC-ND-4.0 |
| H0-mini | 768/1536 | --patch_encoder h0-mini --patch_size 224 --mag 20 | bioptimus/H0-mini | π CC-BY-NC-ND-4.0 |
| MUSK | 1024 | --patch_encoder musk --patch_size 384 --mag 20 | xiangjx/musk | π CC-BY-NC-ND-4.0 |
| Midnight-12k | 3072 | --patch_encoder midnight12k --patch_size 224 --mag 20 | kaiko-ai/midnight | π MIT |
| Phaet | 1024 | --patch_encoder phaet --patch_size 224 --mag 20 | wearewaiv/phaet | π Waiv non-commercial |
| Mascaret | 1536/3072 | --patch_encoder mascaret --patch_size 224 --mag 20 | wearewaiv/mascaret | π Waiv non-commercial |
| OpenMidnight | 1536 | --patch_encoder openmidnight --patch_size 224 --mag 20 | SophontAI/OpenMidnight | π Apache-2.0 |
| GPFM | 1024 | --patch_encoder gpfm --patch_size 224 --mag 20 | majiabo/GPFM | π MIT |
| GenBio-PathFM | 4608 | --patch_encoder genbio-pathfm --patch_size 224 --mag 20 | genbio-ai/genbio-pathfm | π GenBio AI Community |
| Gemma 4 ΒΉ | 768/1152 | --patch_encoder {gemma4-e4b, gemma4-26b} --patch_size 224 --mag 20 | google/gemma-4-E4B / google/gemma-4-26B-A4B | π Gemma Terms |
| Kaiko | 384/768/1024 | --patch_encoder {kaiko-vits8, kaiko-vits16, kaiko-vitb8, kaiko-vitb16, kaiko-vitl14} --patch_size 256 --mag 20 | 1aurent/kaikoai-models-66636c99d8e1e34bc6dcf795 | π Kaiko non-commercial |
| Lunit | 384 | --patch_encoder lunit-vits8 --patch_size 224 --mag 20 | 1aurent/vit_small_patch8_224.lunit_dino | π Lunit non-commercial |
| Hibou | 1024 | --patch_encoder hibou_l --patch_size 224 --mag 20 | histai/hibou-L | π Apache-2.0 |
| CTransPath-CHIEF | 768 | --patch_encoder ctranspath --patch_size 256 --mag 10 | β | π GPL-3.0 |
| ResNet50 | 1024 | --patch_encoder resnet50 --patch_size 256 --mag 20 | β | π BSD-3-Clause |
ΒΉ Gemma 4 requires transformers>=5, which is incompatible with hibou_l. Use a separate environment.
Step 3b: Slide Feature Extraction: Extracts slide embeddings using a slide encoder. Will also automatically extract the right patch embeddings.
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --slide_encoder titan --mag 20 --patch_size 512
--task feat: Specifies that you want to do feature extraction.--wsi_dir wsis: Path to the dir containing WSIs.--job_dir ./trident_processed: Output dir for processed results.--slide_encoder titan: Uses the Titan slide encoder. See below for supported models.--mag 20: Features are extracted from patches at 20x magnification.--patch_size 512: Patches are 512x512 pixels in size../trident_processed/20x_512px_0px_overlap/slide_features_titan. (Shape: (feature_dim))Trident supports 12 slide encoders, loaded via a slide-level encoder_factory. Models requiring specific installations will return error messages with additional instructions. Gated models on HuggingFace require access requests.
| Slide Encoder | Patch Encoder | Args | Link | License |
|---|---|---|---|---|
| Threads | conch_v15 | --slide_encoder threads --patch_size 512 --mag 20 | (Coming Soon!) | β |
| Titan | conch_v15 | --slide_encoder titan --patch_size 512 --mag 20 | MahmoodLab/TITAN | π CC-BY-NC-ND-4.0 |
| PRISM | virchow | --slide_encoder prism --patch_size 224 --mag 20 | paige-ai/Prism | π CC-BY-NC-ND-4.0 |
| PRISM2 | virchow2-cls | --slide_encoder prism2 --patch_size 224 --mag 20 | paige-ai/Prism2 | π CC-BY-NC-ND-4.0 |
| CHIEF | ctranspath | --slide_encoder chief --patch_size 256 --mag 10 | CHIEF | π AGPL-3.0 |
| GigaPath | gigapath | --slide_encoder gigapath --patch_size 256 --mag 20 | prov-gigapath | π Apache-2.0 |
| GigaPath-Flash | gigapath-flash | --slide_encoder gigapath-flash --patch_size 256 --mag 20 | prov-gigapath-flash | π Apache-2.0 |
| Madeleine | conch_v1 | --slide_encoder madeleine --patch_size 256 --mag 10 | MahmoodLab/madeleine | π MIT |
| Feather | conch_v15 | --slide_encoder feather --patch_size 512 --mag 20 | MahmoodLab/FEATHER | π CC-BY-NC-ND-4.0 |
| Feather-UNI2 | uni_v2 | --slide_encoder feather_uni_v2 --patch_size 256 --mag 20 | MahmoodLab/FEATHER | π CC-BY-NC-ND-4.0 |
| CARE | conch_v15 | --slide_encoder care --patch_size 512 --mag 20 | Zipper-1/CARE | π CC-BY-NC-4.0 |
| ABMIL | any | Python API only β untrained aggregator, see note below | β | β |
[!NOTE] ABMIL is an untrained attention-pooling aggregator, not a pretrained encoder. It is only usable from the Python API with explicit hyperparameters (
encoder_factory('abmil', pretrained=False, input_feature_dim=768, n_heads=1, head_dim=64, dropout=0.1, gated=True));--slide_encoder abmilraises aTypeError.
[!NOTE] If your task includes multiple slides per patient, you can generate patient-level embeddings by: (1) processing each slide independently and taking their average slide embedding (late fusion) or (2) pooling all patches together and processing that as a single "pseudo-slide" (early fusion). For an implementation of both fusion strategies, please check out our sister repository Patho-Bench.
Please see our tutorials for more support as well as a detailed readme for additional features.
Q: How do I extract patch embeddings from legacy patch coordinates extracted with CLAM?
python run_batch_of_slides.py --task feat --wsi_dir ..wsis --job_dir legacy_dir --patch_encoder uni_v1 --mag 20 --patch_size 256 --coords_dir extracted_mag20x_patch256_fp/
Q: How do I keep patches corresponding to holes in the tissue?
run_batch_of_slides, this behavior is default. Set --remove_holes to exclude patches on top of holes.Q: I see weird messages when building models using timm. What is happening?
timm>=0.9.16,<2.Q: gigapath, gigapath-flash or prism2 fails with a FlashAttention error. What do I do?
flash-attn>=2.7.3. Grab a prebuilt wheel from its
releases β PyPI ships only an sdist.Q: Whatβs the recommended way to run Trident from another project?
trident single -- --slide_path ./wsis/example.svs --job_dir ./job --patch_encoder uni_v1 --mag 20 --patch_size 256
trident batch -- --task all --wsi_dir ./wsis --job_dir ./job --patch_encoder uni_v1 --mag 20 --patch_size 256
If you need to call Trident from Python, just use the public API (Processor, load_wsi).
Q: I am not satisfied with the tissue vs background segmentation. What can I do?
--segmenter grandqc (Citation necessary, Non-commercial use, Original repository) or --segmenter otsu.Q: I want to process a custom list of WSIs. Can I do it? Also, most of my WSIs don't have the micron per pixel (mpp) stored. Can I pass it?
--custom_list_of_wsis argument. Provide a list of WSI names in a CSV (with slide extension, wsi). Optionally, provide the mpp (field mpp)Q: Do I need to install any additional packages to use Trident?
pip install -e . installs core dependencies. Some optional components still require extra installs. Use profiles (.[patch-encoders], .[slide-encoders], .[convert], .[omezarr] or .[full]) and run trident-doctor for preflight checks.β Mahmood Lab. This repository is released under the CC-BY-NC-ND 4.0 license and may only be used for non-commercial, academic research purposes with proper attribution. Any commercial use, sale, or other monetization of this repository is prohibited and requires prior approval. By downloading any pretrained encoder, you agree to follow the model's respective license.
The project was built on top of amazing repositories such as Timm, HuggingFace, and open-source contributions from the community. We thank the authors and developers for their contribution.
This work was funded by NIH NIGMS R35GM138216.
If you find our work useful in your research or if you use parts of this code, please consider citing our papers:
@article{zhang2025standardizing,
title={Accelerating Data Processing and Benchmarking of AI Models for Pathology},
author={Zhang, Andrew and Jaume, Guillaume and Vaidya, Anurag and Ding, Tong and Mahmood, Faisal},
journal={arXiv preprint arXiv:2502.06750},
year={2025}
}
@article{vaidya2025molecular,
title={Molecular-driven Foundation Model for Oncologic Pathology},
author={Vaidya, Anurag and Zhang, Andrew and Jaume, Guillaume and Song, Andrew H and Ding, Tong and Wagner, Sophia J and Lu, Ming Y and Doucet, Paul and Robertson, Harry and Almagro-Perez, Cristina and others},
journal={arXiv preprint arXiv:2501.16652},
year={2025}
}
Python
97.0%
Jupyter Notebook
3.0%
Toolkit for large-scale whole-slide image processing.
626
stars
244
commits
Python
primary language
Aug 28, 2026
updated
arXiv | Blog | Cite | Documentation | License
Trident is a toolkit for large-scale whole-slide image processing. This project was developed by the Mahmood Lab at Harvard Medical School and Brigham and Women's Hospital. This work was funded by NIH NIGMS R35GM138216.
[!NOTE] Contributions are welcome! Please report any issues. You may also contribute by opening a pull request.
--task all) or stage-by-stage.--remove_artifacts / --remove_penmarks clean-up pass..png, .jpeg), SDPC, OME-Zarr (.zarr), Zeiss CZI (.czi). Or convert to pyramidal TIFF with trident convert.--gpus 0 1 2 3 distributes pending slides across GPUs.--job_dir skips already-completed work. .lock files protect in-flight tasks; stale ones are cleaned safely with --clear_dead_locks.--wsi_cache /local/ssd --cache_batch_size 32 stages slides locally via a producer/consumer pipeline.summary.md (human-readable), runs/<id>.json (manifest), and wsi_states/<slide>.json (per-slide tasks, attempts, errors, resume info).conda create -n "trident" python=3.10, and activate it conda activate trident.git clone https://github.com/mahmoodlab/trident.git && cd trident.pip install -e ..
timm>=0.9.16,<2, transformers>=4.51,<5, safetensors, etc.).Optional install profiles:
pip install -e ".[patch-encoders]" for patch embedding-related extras (e.g. CONCH, MUSK, CTransPath / CHIEF).pip install -e ".[slide-encoders]" for slide embedding-related extras (e.g. PRISM, GigaPath, Madeleine).pip install -e ".[omezarr]" for OME Zarr WSI reader support (OME-NGFF / OME-Zarr).pip install -e ".[czi]" for Zeiss CZI WSI reader support (pylibCZIrw).pip install -e ".[convert]" for slide conversion to tiff.pip install -e ".[full]" to install all pip-installable optional dependencies.Run checks before launching jobs:
trident-doctor --profile basetrident-doctor --profile patch-encoders --check-gatedtrident-doctor --profile slide-encoderstrident-doctor --profile converttrident-doctor --profile full --check-gated[!NOTE] Some models still require manual setup (e.g., local CHIEF repository path in
trident/slide_encoder_models/local_ckpts.json) or HuggingFace gated access approvals.
[!TIP] Using an AI coding agent (e.g. Claude Code)? Trident ships an Agent Skill at
.claude/skills/trident/. Open this repo in Claude Code and your agent can drive Trident end-to-end β segmentation, patching, and patch/slide feature extraction β with the correct encoderβresolution pairings, output layout, and common-pitfall handling baked in. Copy the folder to~/.claude/skills/to use it from any project.
Already familiar with WSI processing? Perform segmentation, patching, and UNI feature extraction from a directory of WSIs with:
python run_batch_of_slides.py --task all --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Feeling cautious?
Run this command to perform all processing steps for a single slide:
python run_single_slide.py --slide_path ./wsis/xxxx.svs --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Convert images/WSIs to pyramidal TIFF:
trident convert --input_dir ./wsis --mpp_csv ./wsis/to_process.csv --job_dir ./pyramidal_tiff --downscale_by 1 --num_workers 1
--mpp_csv is required and must contain wsi,mpp columns. Only files listed in the CSV are converted.
If embedded MPP metadata is detected in a slide, Trident compares it to the CSV value and logs mismatches.
Or follow step-by-step instructions:
Step 1: Tissue Segmentation: Segments tissue vs. background from a dir of WSIs
python run_batch_of_slides.py --task seg --wsi_dir ./wsis --job_dir ./trident_processed --gpus 0 --segmenter hest
--task seg: Specifies that you want to do tissue segmentation.--wsi_dir ./wsis: Path to dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--gpus 0: Use GPU index 0. Pass multiple IDs (e.g. --gpus 0 1) to shard across GPUs, or -1 to force CPU.--segmenter: Segmentation model. Defaults to hest. Use grandqc (Citation necessary, Non-commercial use, Original repository) for fast H&E segmentation or otsu for a classical image-processing-only fallback. Add the option --remove_artifacts for additional artifact clean up../trident_processed/thumbnails../trident_processed/contours../trident_processed/contours_geojson. These can be opened in QuPath for editing/quality control, if necessary.| Segmenter | Args | Link | License |
|---|---|---|---|
| HEST (default) | --segmenter hest | MahmoodLab/hest-tissue-seg | π CC-BY-NC-SA-4.0 |
| GrandQC | --segmenter grandqc | cpath-ukk/grandqc | π CC-BY-NC-SA-4.0 |
| Otsu | --segmenter otsu | β | β (classical, no model) |
Step 2: Tissue Patching: Extracts patches from segmented tissue regions at a specific magnification.
python run_batch_of_slides.py --task coords --wsi_dir ./wsis --job_dir ./trident_processed --mag 20 --patch_size 256 --overlap 0
--task coords: Specifies that you want to do patching.--wsi_dir wsis: Path to the dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--mag 20: Extracts patches at 20x magnification.--patch_size 256: Each patch is 256x256 pixels.--overlap 0: Patches overlap by 0 pixels, always an absolute number in pixels, e.g., --overlap 128 for 50% overlap for 256x256 patches../trident_processed/20x_256px_0px_overlap/patches../trident_processed/20x_256px_0px_overlap/visualization.Step 3a: Patch Feature Extraction: Extracts features from tissue patches using a specified encoder
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
--task feat: Specifies that you want to do feature extraction.--wsi_dir wsis: Path to the dir with your WSIs.--job_dir ./trident_processed: Output dir for processed results.--patch_encoder uni_v1: Uses the UNI patch encoder. See below for list of supported models.--mag 20: Features are extracted from patches at 20x magnification.--patch_size 256: Patches are 256x256 pixels in size../trident_processed/20x_256px_0px_overlap/features_uni_v1. (Shape: (n_patches, feature_dim))Trident supports 33 patch encoders, loaded via a patch encoder_factory. Models requiring specific installations will return error messages with additional instructions. Gated models on HuggingFace require access requests.
| Patch Encoder | Embedding Dim | Args | Link | License |
|---|---|---|---|---|
| UNI | 1024 | --patch_encoder uni_v1 --patch_size 256 --mag 20 | MahmoodLab/UNI | π CC-BY-NC-ND-4.0 |
| UNI2-h | 1536 | --patch_encoder uni_v2 --patch_size 256 --mag 20 | MahmoodLab/UNI2-h | π CC-BY-NC-ND-4.0 |
| CONCH | 512 | --patch_encoder conch_v1 --patch_size 512 --mag 20 | MahmoodLab/CONCH | π CC-BY-NC-ND-4.0 |
| CONCHv1.5 | 768 | --patch_encoder conch_v15 --patch_size 512 --mag 20 | MahmoodLab/conchv1_5 | π CC-BY-NC-ND-4.0 |
| Virchow | 2560 | --patch_encoder virchow --patch_size 224 --mag 20 | paige-ai/Virchow | π Apache-2.0 |
| Virchow2 | 2560 | --patch_encoder virchow2 --patch_size 224 --mag 20 | paige-ai/Virchow2 | π CC-BY-NC-ND-4.0 |
| Virchow2 (CLS) | 1280 | --patch_encoder virchow2-cls --patch_size 224 --mag 20 | paige-ai/Virchow2 | π CC-BY-NC-ND-4.0 |
| Phikon | 768 | --patch_encoder phikon --patch_size 224 --mag 20 | owkin/phikon | π Owkin non-commercial |
| Phikon-v2 | 1024 | --patch_encoder phikon_v2 --patch_size 224 --mag 20 | owkin/phikon-v2 | π Owkin non-commercial |
| KEEP | 768 | --patch_encoder keep --patch_size 256 --mag 20 | Astaxanthin/KEEP | π MIT |
| Prov-Gigapath | 1536 | --patch_encoder gigapath --patch_size 256 --mag 20 | prov-gigapath | π Apache-2.0 |
| Prov-Gigapath-Flash | 384 | --patch_encoder gigapath-flash --patch_size 256 --mag 20 | prov-gigapath-flash | π Apache-2.0 |
| H-Optimus-0 | 1536 | --patch_encoder hoptimus0 --patch_size 224 --mag 20 | bioptimus/H-optimus-0 | π Apache-2.0 |
| H-Optimus-1 | 1536 | --patch_encoder hoptimus1 --patch_size 224 --mag 20 | bioptimus/H-optimus-1 | π CC-BY-NC-ND-4.0 |
| H0-mini | 768/1536 | --patch_encoder h0-mini --patch_size 224 --mag 20 | bioptimus/H0-mini | π CC-BY-NC-ND-4.0 |
| MUSK | 1024 | --patch_encoder musk --patch_size 384 --mag 20 | xiangjx/musk | π CC-BY-NC-ND-4.0 |
| Midnight-12k | 3072 | --patch_encoder midnight12k --patch_size 224 --mag 20 | kaiko-ai/midnight | π MIT |
| Phaet | 1024 | --patch_encoder phaet --patch_size 224 --mag 20 | wearewaiv/phaet | π Waiv non-commercial |
| Mascaret | 1536/3072 | --patch_encoder mascaret --patch_size 224 --mag 20 | wearewaiv/mascaret | π Waiv non-commercial |
| OpenMidnight | 1536 | --patch_encoder openmidnight --patch_size 224 --mag 20 | SophontAI/OpenMidnight | π Apache-2.0 |
| GPFM | 1024 | --patch_encoder gpfm --patch_size 224 --mag 20 | majiabo/GPFM | π MIT |
| GenBio-PathFM | 4608 | --patch_encoder genbio-pathfm --patch_size 224 --mag 20 | genbio-ai/genbio-pathfm | π GenBio AI Community |
| Gemma 4 ΒΉ | 768/1152 | --patch_encoder {gemma4-e4b, gemma4-26b} --patch_size 224 --mag 20 | google/gemma-4-E4B / google/gemma-4-26B-A4B | π Gemma Terms |
| Kaiko | 384/768/1024 | --patch_encoder {kaiko-vits8, kaiko-vits16, kaiko-vitb8, kaiko-vitb16, kaiko-vitl14} --patch_size 256 --mag 20 | 1aurent/kaikoai-models-66636c99d8e1e34bc6dcf795 | π Kaiko non-commercial |
| Lunit | 384 | --patch_encoder lunit-vits8 --patch_size 224 --mag 20 | 1aurent/vit_small_patch8_224.lunit_dino | π Lunit non-commercial |
| Hibou | 1024 | --patch_encoder hibou_l --patch_size 224 --mag 20 | histai/hibou-L | π Apache-2.0 |
| CTransPath-CHIEF | 768 | --patch_encoder ctranspath --patch_size 256 --mag 10 | β | π GPL-3.0 |
| ResNet50 | 1024 | --patch_encoder resnet50 --patch_size 256 --mag 20 | β | π BSD-3-Clause |
ΒΉ Gemma 4 requires transformers>=5, which is incompatible with hibou_l. Use a separate environment.
Step 3b: Slide Feature Extraction: Extracts slide embeddings using a slide encoder. Will also automatically extract the right patch embeddings.
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --slide_encoder titan --mag 20 --patch_size 512
--task feat: Specifies that you want to do feature extraction.--wsi_dir wsis: Path to the dir containing WSIs.--job_dir ./trident_processed: Output dir for processed results.--slide_encoder titan: Uses the Titan slide encoder. See below for supported models.--mag 20: Features are extracted from patches at 20x magnification.--patch_size 512: Patches are 512x512 pixels in size../trident_processed/20x_512px_0px_overlap/slide_features_titan. (Shape: (feature_dim))Trident supports 12 slide encoders, loaded via a slide-level encoder_factory. Models requiring specific installations will return error messages with additional instructions. Gated models on HuggingFace require access requests.
| Slide Encoder | Patch Encoder | Args | Link | License |
|---|---|---|---|---|
| Threads | conch_v15 | --slide_encoder threads --patch_size 512 --mag 20 | (Coming Soon!) | β |
| Titan | conch_v15 | --slide_encoder titan --patch_size 512 --mag 20 | MahmoodLab/TITAN | π CC-BY-NC-ND-4.0 |
| PRISM | virchow | --slide_encoder prism --patch_size 224 --mag 20 | paige-ai/Prism | π CC-BY-NC-ND-4.0 |
| PRISM2 | virchow2-cls | --slide_encoder prism2 --patch_size 224 --mag 20 | paige-ai/Prism2 | π CC-BY-NC-ND-4.0 |
| CHIEF | ctranspath | --slide_encoder chief --patch_size 256 --mag 10 | CHIEF | π AGPL-3.0 |
| GigaPath | gigapath | --slide_encoder gigapath --patch_size 256 --mag 20 | prov-gigapath | π Apache-2.0 |
| GigaPath-Flash | gigapath-flash | --slide_encoder gigapath-flash --patch_size 256 --mag 20 | prov-gigapath-flash | π Apache-2.0 |
| Madeleine | conch_v1 | --slide_encoder madeleine --patch_size 256 --mag 10 | MahmoodLab/madeleine | π MIT |
| Feather | conch_v15 | --slide_encoder feather --patch_size 512 --mag 20 | MahmoodLab/FEATHER | π CC-BY-NC-ND-4.0 |
| Feather-UNI2 | uni_v2 | --slide_encoder feather_uni_v2 --patch_size 256 --mag 20 | MahmoodLab/FEATHER | π CC-BY-NC-ND-4.0 |
| CARE | conch_v15 | --slide_encoder care --patch_size 512 --mag 20 | Zipper-1/CARE | π CC-BY-NC-4.0 |
| ABMIL | any | Python API only β untrained aggregator, see note below | β | β |
[!NOTE] ABMIL is an untrained attention-pooling aggregator, not a pretrained encoder. It is only usable from the Python API with explicit hyperparameters (
encoder_factory('abmil', pretrained=False, input_feature_dim=768, n_heads=1, head_dim=64, dropout=0.1, gated=True));--slide_encoder abmilraises aTypeError.
[!NOTE] If your task includes multiple slides per patient, you can generate patient-level embeddings by: (1) processing each slide independently and taking their average slide embedding (late fusion) or (2) pooling all patches together and processing that as a single "pseudo-slide" (early fusion). For an implementation of both fusion strategies, please check out our sister repository Patho-Bench.
Please see our tutorials for more support as well as a detailed readme for additional features.
Q: How do I extract patch embeddings from legacy patch coordinates extracted with CLAM?
python run_batch_of_slides.py --task feat --wsi_dir ..wsis --job_dir legacy_dir --patch_encoder uni_v1 --mag 20 --patch_size 256 --coords_dir extracted_mag20x_patch256_fp/
Q: How do I keep patches corresponding to holes in the tissue?
run_batch_of_slides, this behavior is default. Set --remove_holes to exclude patches on top of holes.Q: I see weird messages when building models using timm. What is happening?
timm>=0.9.16,<2.Q: gigapath, gigapath-flash or prism2 fails with a FlashAttention error. What do I do?
flash-attn>=2.7.3. Grab a prebuilt wheel from its
releases β PyPI ships only an sdist.Q: Whatβs the recommended way to run Trident from another project?
trident single -- --slide_path ./wsis/example.svs --job_dir ./job --patch_encoder uni_v1 --mag 20 --patch_size 256
trident batch -- --task all --wsi_dir ./wsis --job_dir ./job --patch_encoder uni_v1 --mag 20 --patch_size 256
If you need to call Trident from Python, just use the public API (Processor, load_wsi).
Q: I am not satisfied with the tissue vs background segmentation. What can I do?
--segmenter grandqc (Citation necessary, Non-commercial use, Original repository) or --segmenter otsu.Q: I want to process a custom list of WSIs. Can I do it? Also, most of my WSIs don't have the micron per pixel (mpp) stored. Can I pass it?
--custom_list_of_wsis argument. Provide a list of WSI names in a CSV (with slide extension, wsi). Optionally, provide the mpp (field mpp)Q: Do I need to install any additional packages to use Trident?
pip install -e . installs core dependencies. Some optional components still require extra installs. Use profiles (.[patch-encoders], .[slide-encoders], .[convert], .[omezarr] or .[full]) and run trident-doctor for preflight checks.β Mahmood Lab. This repository is released under the CC-BY-NC-ND 4.0 license and may only be used for non-commercial, academic research purposes with proper attribution. Any commercial use, sale, or other monetization of this repository is prohibited and requires prior approval. By downloading any pretrained encoder, you agree to follow the model's respective license.
The project was built on top of amazing repositories such as Timm, HuggingFace, and open-source contributions from the community. We thank the authors and developers for their contribution.
This work was funded by NIH NIGMS R35GM138216.
If you find our work useful in your research or if you use parts of this code, please consider citing our papers:
@article{zhang2025standardizing,
title={Accelerating Data Processing and Benchmarking of AI Models for Pathology},
author={Zhang, Andrew and Jaume, Guillaume and Vaidya, Anurag and Ding, Tong and Mahmood, Faisal},
journal={arXiv preprint arXiv:2502.06750},
year={2025}
}
@article{vaidya2025molecular,
title={Molecular-driven Foundation Model for Oncologic Pathology},
author={Vaidya, Anurag and Zhang, Andrew and Jaume, Guillaume and Song, Andrew H and Ding, Tong and Wagner, Sophia J and Lu, Ming Y and Doucet, Paul and Robertson, Harry and Almagro-Perez, Cristina and others},
journal={arXiv preprint arXiv:2501.16652},
year={2025}
}
Python
97.0%
Jupyter Notebook
3.0%