⚡ Improve Engine Performance and Implementation#578
Conversation
- Use `pyproject.toml` for `bdist_wheel` configuration
- Improve `Engines` performance and implementation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #578 +/- ##
===========================================
+ Coverage 99.41% 99.53% +0.12%
===========================================
Files 72 83 +11
Lines 9540 11354 +1814
Branches 1267 1493 +226
===========================================
+ Hits 9484 11301 +1817
+ Misses 29 28 -1
+ Partials 27 25 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Refactor engines_abc.py
Engines Performance and ImplementationEngine Performance and Implementation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
## Summary This PR integrates KongNet, a state‑of‑the‑art multi‑headed deep learning architecture for nucleus detection and classification. It adds complete documentation, examples, and notebook support covering both patch‑based and whole‑slide image (WSI) processing. Multiple pretrained models are now available for major pathology datasets, each demonstrated through updated example notebooks. The PR also introduces a new visualization image and practical usage patterns for the NucleusDetector class, enabling streamlined workflows for researchers using TIAToolbox. ## What’s New ### 🧠 KongNet Model Integration Added pretrained KongNet models: - KongNet_CoNIC_1, KongNet_PanNuke_1, KongNet_MONKEY_1, - KongNet_PUMA_T1_3, KongNet_PUMA_T2_3, KongNet_Det_MIDOG_1. - These models capture multi-headed detection signals and achieve strong performance on CoNIC, PanNuke, MONKEY, PUMA, and MIDOG 2025 datasets. ### 📘 New Example Notebook: Nucleus Detection A comprehensive example notebook demonstrates: - Patch‑level and WSI‑level detection - Mitosis and immune‑cell detection - Use of NucleusDetector with KongNet pretrained models - Interactive visualization via TIAViz - [x] Add KongNet Model - [x] Add tests - [x] Add example notebook (Nucleus Detector) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> Co-authored-by: Jiaqi Lv <jiaqilv@Jiaqis-MacBook-Pro.local>
## Summary
This PR introduces a full **EfficientNet‑UNet Tissue Mask Model** implementation. It adds the EfficientNet‑B0 encoder, UNet‑style decoder, segmentation head, and utilities for preprocessing, postprocessing, and batch inference. The model enables high‑quality binary tissue segmentation with ImageNet normalization and morphology‑based cleanup.
## What's New
- New architecture components:
- EfficientNet‑B0 encoder (MBConv blocks, SAME‑padding convs)
- UNet decoder with skip connections
- Segmentation head
- `EfficientUNetTissueMaskModel` with `preproc`, `postproc`, and `infer_batch`
- Integration with `SemanticSegmentor` for direct WSI‑scale tissue masking.
## Examples
### 1. Using with `SemanticSegmentor`
```python
from pathlib import Path
from tiatoolbox.models.engine.semantic_segmentor import SemanticSegmentor
segmentor = SemanticSegmentor(model="efficientunet-tissue_mask")
outputs = segmentor.run(
images=["/path/to/wsi.svs"],
patch_mode=False,
output_type="annotationstore",
save_dir=Path("./tissue_mask_outputs"),
)
```
### 2. Direct model usage
```python
import numpy as np, torch
from tiatoolbox.models.architecture.efficientunet_tissue_mask_model import EfficientUNetTissueMaskModel
model = EfficientUNetTissueMaskModel(num_classes=1)
img = np.ones((256, 256, 3), dtype=np.uint8) * 128
processed = model.preproc(img)
batch = torch.from_numpy(processed[None]).float()
probs = model.infer_batch(model, batch, device="cpu")
mask = model.postproc(probs[0])
```
---------
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>
…1000) ## Summary This PR modernises the annotation workflow by moving fully to SQLite (`.db`) annotation stores and updates the HoverNet box‑segmentation path to use the current API. Test coverage is expanded accordingly. ## Key Changes - Add tests for annotation saving and HoverNet execution on a selected box region. - Standardise annotation handling by converting and loading `.db` stores instead of legacy `.dat` files. - Update HoverNet integration to use the newer `run()` interface and revised model parameters. - Simplify TileServer ingestion logic by removing the old `add_from_dat` path and loading annotations directly from SQLite stores. - Reverts `Bokeh` Tests for Compatibility with the New Engine Design --------- Co-authored-by: measty <20169086+measty@users.noreply.github.com>
…1002) ## Summary This PR updates the multi‑task segmentation example notebook to align with the latest TIAToolbox API and data sources. It cleans up metadata, modernizes API usage, and switches all sample downloads to stable HuggingFace hosting. ## Key Changes - Removed deprecated metadata (`remove-cell` tags, old IDs). - Updated documentation links and installation notes. - Updated dependencies: removed `joblib`, added `zarr`, adjusted apt packages. - Switched sample image/WSI downloads to HuggingFace. - Migrated to new TIAToolbox API: - `predict()` → `run()` - `pretrained_model` → `model` - `num_loader_workers` → `num_workers` - `mode` → `patch_mode` - Added new args (`wsireader_kwargs`, `return_predictions`, `overwrite`) - Output now saved as Zarr with keys: `layer_segmentation`, `nuclei_segmentation`.
- Update Jupyter Notebook `07-advanced-modeling.ipynb`
- Update slide-graph notebooks
- Refactor `models.engine` to `models.engines` for Consistency
## Summary This PR updates the WSI segmentation workflow so that whole‑slide images are processed **only within the tissue‑mask bounds**, and the resulting predictions are **padded back to full-slide dimensions** once inference completes. It also adds support for supplying a global **offset** to all model post‑processing steps, ensuring instance and semantic outputs (centroids, contours, boxes) remain aligned with the original slide coordinates. The dataset/engine API is made more consistent (`mask_path` → `input_mask`), and tests are expanded to cover masked, non-square, and tile-based scenarios. ## Key Changes ### Mask-bounded processing and output padding - Engines compute `mask_bounds`, filter output locations to those inside the mask, and track required padding. - Final probabilities and predictions are padded using Dask to restore the original full-slide output shape. - Supports both semantic and multi-task segmentation paths. ### Offset-aware post-processing - `HoVerNet`, `HoVerNetPlus`, and `MicroNet` now accept an `offset` argument and apply it to all geometric outputs. - Engines automatically provide the appropriate offset based on mask origin or tile layout. ### API and docstring updates - `mask_path` is renamed to `input_mask` and now accepts either a file path or an `np.ndarray` mask. - Docstrings clarify default behaviors for `auto_get_mask`, probabilities, memory thresholds, and worker counts. - Type hints and parameter descriptions improved for consistency across dataset and engine classes. ### Tile merging and instance ID handling - Horizontal merge functions support a fixed `canvas_width` to avoid allocating overly large row canvases. - Tile-based instance merging now preserves unique instance IDs across tiles and handles overlaps more safely. ### Test updates - Tests updated to use `input_mask`, verify masked execution paths, validate shapes and probability behavior, and cover tile mode and offset-aware post-processing.
There was a problem hiding this comment.
Pull request overview
This PR refactors TIAToolbox’s model/engine stack into a unified engines API with a consistent run() interface, adds new nucleus detection/segmentation capabilities, and updates CLIs/tests/docs to match the new architecture and improve large-WSI performance.
Changes:
- Introduces unified engine/IO-config interfaces + new CLI commands for segmentation, detection, and feature extraction.
- Adds optimized post-processing utilities (Dask overlap peak detection + NMS) and updates model architectures to standardized outputs.
- Updates test suite, sample data sources, and example/docs references for the new API.
Reviewed changes
Copilot reviewed 66 out of 102 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| tiatoolbox/models/dataset/init.py | Re-exports dataset APIs with explicit __all__. |
| tiatoolbox/models/architecture/vanilla.py | Refactors backbone registries + shared postproc utility usage. |
| tiatoolbox/models/architecture/utils.py | Adds postproc utilities (peak detection, NMS) and UNet++ helper modules. |
| tiatoolbox/models/architecture/unet.py | Aligns inference output to ndarray and adds argmax postproc. |
| tiatoolbox/models/architecture/sccnn.py | Switches to overlap-aware peak detection and standardizes infer/postproc signatures. |
| tiatoolbox/models/architecture/micronet.py | Adds Dask-aware postproc + standardizes outputs to task dicts. |
| tiatoolbox/models/architecture/mapde.py | Switches to overlap-aware peak detection and standardizes infer/postproc signatures. |
| tiatoolbox/models/architecture/hovernetplus.py | Adds Dask-aware postproc output dictionaries + offset handling. |
| tiatoolbox/models/architecture/hovernet.py | Adds Dask-support helpers + offset-aware instance info, standardized return format. |
| tiatoolbox/models/architecture/init.py | Updates pretrained model loading and adds backbone shortcut support. |
| tiatoolbox/models/init.py | Switches public exports from engine to engines and adds new engines/models. |
| tiatoolbox/data/remote_samples.yaml | Adds new HF-hosted thumbnail sample. |
| tiatoolbox/cli/tissue_mask.py | Tightens --mode choices. |
| tiatoolbox/cli/semantic_segmentor.py | New semantic segmentation CLI using new engine API. |
| tiatoolbox/cli/semantic_segment.py | Removes legacy semantic segmentation CLI. |
| tiatoolbox/cli/patch_predictor.py | Migrates CLI to new run() engine API + unified options. |
| tiatoolbox/cli/nucleus_instance_segment.py | Migrates CLI to new run() API + unified options. |
| tiatoolbox/cli/nucleus_detector.py | Adds nucleus detector CLI. |
| tiatoolbox/cli/multitask_segmentor.py | Adds multitask segmentor CLI. |
| tiatoolbox/cli/deep_feature_extractor.py | Adds deep feature extractor CLI. |
| tiatoolbox/cli/init.py | Registers new CLI commands and renames semantic seg command. |
| tests/test_wsireader.py | Updates remote sample URL to Hugging Face. |
| tests/test_tileserver.py | Updates tile server tests to use SQLiteStore via store_from_dat. |
| tests/test_cli.py | Adds tests for new CLI parsing utilities. |
| tests/test_app_bokeh.py | Adjusts save/load annotation layer test ordering and cleanup. |
| tests/models/test_multi_task_segmentor.py | Removes legacy multitask segmentor tests (replaced elsewhere). |
| tests/models/test_models_abc.py | Adds get_pretrained_model error-path tests. |
| tests/models/test_hovernetplus.py | Updates for new postproc return structure + offset parameter. |
| tests/models/test_hovernet.py | Updates for new postproc return structure + offset parameter. |
| tests/models/test_feature_extractor.py | Removes legacy feature extractor tests (replaced in engines tests). |
| tests/models/test_dataset.py | Expands dataset tests for new dataset/WSI patch dataset behaviors. |
| tests/models/test_arch_vanilla.py | Updates postproc test data types. |
| tests/models/test_arch_utils.py | Adds tests for new peak detection, NMS, and attention module utilities. |
| tests/models/test_arch_timm_efficientnet.py | Adds unit tests for timm EfficientNet encoder helpers. |
| tests/models/test_arch_sccnn.py | Updates tests for new SCCNN peak-map postproc output. |
| tests/models/test_arch_micronet.py | Migrates test to new NucleusInstanceSegmentor + zarr output assertions. |
| tests/models/test_arch_mapde.py | Updates tests for new peak-map postproc output + override params. |
| tests/models/test_arch_kongnet.py | Adds extensive unit tests for new KongNet model and detector integration. |
| tests/models/test_arch_grandqc.py | Adds GrandQC model tests + SemanticSegmentor integration checks. |
| tests/models/test_arch_efficientnetunet_tissue_mask_model.py | Adds EfficientUNet tissue mask model tests + integration checks. |
| tests/engines/test_nucleus_instance_segmentor.py | Adds engine + CLI tests for nucleus instance segmentation. |
| tests/engines/test_nucleus_detection_engine.py | Adds engine + CLI tests for nucleus detection and output types. |
| tests/engines/test_ioconfig.py | Adds validation and conversion tests for IOConfig models. |
| tests/engines/test_feature_extractor.py | Adds engine + CLI tests for deep feature extraction in patch/WSI modes. |
| tests/engines/init.py | Adds tests.engines package marker. |
| tests/conftest.py | Adds new WSI sample + rm_dir fixture. |
| requirements/requirements.txt | Adds new dependencies for Dask + ipywidgets. |
| examples/full-pipelines/slide-graph.ipynb | Updates install/docs links + adds incompatibility notice for v2+. |
| examples/README.md | Adds new nucleus detection example entry. |
| examples/11-import-foundation-models.ipynb | Migrates notebook to new engines API + HF sample download + zarr outputs. |
| examples/04-patch-extraction.ipynb | Updates sample URLs to HF dataset and adjusts cells/metadata. |
| docs/pretrained.rst | Updates pretrained model IOConfig examples and extends KongNet documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Can you generate a summary of this PR? |
## TIAToolbox v2.0.0 (2026-03-11) ### ✨ Major Updates and Feature Improvements #### ⚙️ Engine Redesign (PR #578) TIAToolbox 2.0.0 introduces a completely re-engineered inference engine designed for significant performance, scalability, and memory-efficiency improvements. #### Key Enhancements - A modern processing stack built on **Dask** (parallel/distributed execution) and **Zarr** (chunked, out-of-core storage) - **Standardised output formats** across all engines: - Python `dict` - **Zarr** - **AnnotationStore** (SQLite-backed) - **QuPath JSON** - Cleaner runtime behavior with reduced warning noise and a unified progress bar - More predictable memory usage through chunked streaming - Broader test coverage across engine components ### 🗺️ Improved QuPath Support Enhancements include: - Better handling of **GeoJSON** - Support for **multipoint geometries** (#841) - Improved semantic output helpers: - `dict_to_store_semantic_segmentor` (#926) - OME-TIFF probability overlays (#929) ### 🔬 New Nucleus Detection Engine A dedicated nucleus detection pipeline has been added, built on the redesigned engine for improved accuracy and efficient large-scale processing. #### 🧠 KongNet Model Family TIAToolbox 2.0.0 introduces **KongNet**, a high-performance architecture that achieved top results across multiple international challenges: - 🥇 **1st place: MONKEY Challenge (overall detection)** - 🥇 **1st place: MIDOG (mitosis detection)** - ⭐ Top-tier performance on **PUMA** Multiple pretrained variants are available (CoNIC, PanNuke, MONKEY, PUMA, MIDOG), each with standardised IO configurations. ### 🧬 Expanded Foundation Model Support Additional foundation models are now supported (#906), broadening the range of high-capacity architectures available for feature extraction and downstream tasks. ### 🖼️ SAM Segmentation in TIAViz TIAViz now integrates Meta’s Segment Anything Model (SAM), enabling: - Interactive segmentation - Rapid region extraction - Exploratory annotation workflows Simplified SAM usage (#968) streamlines its integration into analysis pipelines. ### 🧩 Enhanced WSIReader & Metadata Handling Major improvements include: - More robust cross-vendor **metadata extraction** (#1001) - **Multichannel image support** (PR #825) for immunofluorescence and non-RGB modalities - Simplified Windows installation using `openslide-bin` (no manual DLL steps) - macOS Tileserver fix (#976) - Improved DICOM reading (#934) ### ☁️ New Cloud-Native Reader: FsspecJSONWSIReader (PR #897) A new reader supporting **fsspec-compatible filesystems**, enabling seamless access to WSIs stored on: - S3 - GCS - Azure - HPC clusters - Any fsspec-supported backend This enables cloud-native and distributed data workflows. Contributed by @aacic ### 🤗 Pretrained Models Migrated to Hugging Face All pretrained models and sample assets have been migrated (#945, #983), improving: - Download reliability - Versioning and reproducibility - Caching and CI integration - Licensing clarity per model family ### 🛡️ Security, Compatibility & Tooling #### 🔐 Security & Dependency Updates - Dependency upgrades - Internal security improvements - Explicit workflow permissions added (#1021, #1023) #### 🐍 Python Version Support - **Dropped:** Python **3.9** - **Added:** Python **3.13** - **Supported:** Python 3.10–3.13 - Updated CUDA wheel source to **cu126** #### 🛠️ Developer Tooling & CI/CD - Expanded **mypy** type-checking coverage (#912, #931, #935, #951) - Updated pre-commit hooks and general formatting - CI uses **CPU-only PyTorch** for faster, more reliable builds (#974, #979) - Updated pip install workflow (#1013) - Added new **Python 3.13 Docker images** (#1014, #1019) ### 🧹 Bug Fixes & Stability Improvements - Fixed multi-GPU behaviour with `torch.compile` (#923) - Fixed DICOM reading issue (#934) - Fixed annotation contour handling with holes (#956) - Fixed consecutive annotation load bug (#927) - Fixed SCCNN model issues (#970) - Fixed MapDe `dist_filter` shape issue (#914) - Improved notebook reliability on Colab (#1026–#1030) - macOS TileServer issues resolved (#976) ### 🧭 Migration Guide for Users #### 🔄 Updating from 1.x to 2.0.0 #### Update calls: replace `.predict()` with `.run()` ```python # Old results = segmentor.predict(imgs=[...], ioconfig=config) # New results = segmentor.run(images=[...], ioconfig=config) ``` #### Use `patch_mode`: replace `mode="patch"` with `patch_mode=True` and `mode="tile"` or "wsi" with `patch_mode=False` ```python # Old results = segmentor.predict(imgs=[...], mode="patch", ioconfig=config) # New results = segmentor.run(images=[...], patch_mode=True, ioconfig=config) ``` ```python # Old results = segmentor.predict(imgs=[...], mode="wsi", ioconfig=config) # New results = segmentor.run(images=[...], patch_mode=False, ioconfig=config) ``` #### Use the new I/O configs ```python from tiatoolbox.models.engine.io_config import IOSegmentorConfig config = IOSegmentorConfig( patch_input_shape=(256, 256), stride_shape=(240, 240), input_resolutions=[{"resolution": 0.25, "units": "mpp"}], save_resolution={"units": "baseline", "resolution": 1.0} ) ``` #### Specify the output format ```python results = segmentor.run( images=[...], ioconfig=ioconfig, output_type="zarr", # or "dict", "annotationstore", "qupath" save_dir="outputs/" ) ``` #### Update imports - `tiatoolbox.typing` → `tiatoolbox.type_hints` #### Install requirements - Python **3.10+** required - On Windows: install OpenSlide via `pip install openslide-bin` **Full Changelog:** v1.6.0...v2.0.0 --------- Signed-off-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> Co-authored-by: measty <20169086+measty@users.noreply.github.com> Co-authored-by: Jiaqi-Lv <60471431+Jiaqi-Lv@users.noreply.github.com> Co-authored-by: adamshephard <39619155+adamshephard@users.noreply.github.com> Co-authored-by: Mostafa Jahanifar <74412979+mostafajahanifar@users.noreply.github.com> Co-authored-by: John Pocock <John-P@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yijie Zhu <120978607+YijieZhu15@users.noreply.github.com> Co-authored-by: Aleksandar Acic <32873451+aacic@users.noreply.github.com> Co-authored-by: Abdol A <u2271662@live.warwick.ac.uk> Co-authored-by: Abishek <abishekraj6797@gmail.com> Co-authored-by: behnazelhaminia <30952176+behnazelhaminia@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Adam Shephard <adam.shephard@warwick.ac.uk> Co-authored-by: gozdeg <gozdegunesli@gmail.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: mbasheer04 <78800844+mbasheer04@users.noreply.github.com> Co-authored-by: vqdang <24943262+vqdang@users.noreply.github.com>
🔖 Release 2.0.0 (#1031) ## TIAToolbox v2.0.0 (2026-03-11) ### ✨ Major Updates and Feature Improvements #### ⚙️ Engine Redesign (PR #578) TIAToolbox 2.0.0 introduces a completely re-engineered inference engine designed for significant performance, scalability, and memory-efficiency improvements. #### Key Enhancements - A modern processing stack built on **Dask** (parallel/distributed execution) and **Zarr** (chunked, out-of-core storage) - **Standardised output formats** across all engines: - Python `dict` - **Zarr** - **AnnotationStore** (SQLite-backed) - **QuPath JSON** - Cleaner runtime behavior with reduced warning noise and a unified progress bar - More predictable memory usage through chunked streaming - Broader test coverage across engine components ### 🗺️ Improved QuPath Support Enhancements include: - Better handling of **GeoJSON** - Support for **multipoint geometries** (#841) - Improved semantic output helpers: - `dict_to_store_semantic_segmentor` (#926) - OME-TIFF probability overlays (#929) ### 🔬 New Nucleus Detection Engine A dedicated nucleus detection pipeline has been added, built on the redesigned engine for improved accuracy and efficient large-scale processing. #### 🧠 KongNet Model Family TIAToolbox 2.0.0 introduces **KongNet**, a high-performance architecture that achieved top results across multiple international challenges: - 🥇 **1st place: MONKEY Challenge (overall detection)** - 🥇 **1st place: MIDOG (mitosis detection)** - ⭐ Top-tier performance on **PUMA** Multiple pretrained variants are available (CoNIC, PanNuke, MONKEY, PUMA, MIDOG), each with standardised IO configurations. ### 🧬 Expanded Foundation Model Support Additional foundation models are now supported (#906), broadening the range of high-capacity architectures available for feature extraction and downstream tasks. ### 🖼️ SAM Segmentation in TIAViz TIAViz now integrates Meta’s Segment Anything Model (SAM), enabling: - Interactive segmentation - Rapid region extraction - Exploratory annotation workflows Simplified SAM usage (#968) streamlines its integration into analysis pipelines. ### 🧩 Enhanced WSIReader & Metadata Handling Major improvements include: - More robust cross-vendor **metadata extraction** (#1001) - **Multichannel image support** (PR #825) for immunofluorescence and non-RGB modalities - Simplified Windows installation using `openslide-bin` (no manual DLL steps) - macOS Tileserver fix (#976) - Improved DICOM reading (#934) ### ☁️ New Cloud-Native Reader: FsspecJSONWSIReader (PR #897) A new reader supporting **fsspec-compatible filesystems**, enabling seamless access to WSIs stored on: - S3 - GCS - Azure - HPC clusters - Any fsspec-supported backend This enables cloud-native and distributed data workflows. Contributed by @aacic ### 🤗 Pretrained Models Migrated to Hugging Face All pretrained models and sample assets have been migrated (#945, #983), improving: - Download reliability - Versioning and reproducibility - Caching and CI integration - Licensing clarity per model family ### 🛡️ Security, Compatibility & Tooling #### 🔐 Security & Dependency Updates - Dependency upgrades - Internal security improvements - Explicit workflow permissions added (#1021, #1023) #### 🐍 Python Version Support - **Dropped:** Python **3.9** - **Added:** Python **3.13** - **Supported:** Python 3.10–3.13 - Updated CUDA wheel source to **cu126** #### 🛠️ Developer Tooling & CI/CD - Expanded **mypy** type-checking coverage (#912, #931, #935, #951) - Updated pre-commit hooks and general formatting - CI uses **CPU-only PyTorch** for faster, more reliable builds (#974, #979) - Updated pip install workflow (#1013) - Added new **Python 3.13 Docker images** (#1014, #1019) ### 🧹 Bug Fixes & Stability Improvements - Fixed multi-GPU behaviour with `torch.compile` (#923) - Fixed DICOM reading issue (#934) - Fixed annotation contour handling with holes (#956) - Fixed consecutive annotation load bug (#927) - Fixed SCCNN model issues (#970) - Fixed MapDe `dist_filter` shape issue (#914) - Improved notebook reliability on Colab (#1026–#1030) - macOS TileServer issues resolved (#976) ### 🧭 Migration Guide for Users #### 🔄 Updating from 1.x to 2.0.0 #### Update calls: replace `.predict()` with `.run()` ```python # Old results = segmentor.predict(imgs=[...], ioconfig=config) # New results = segmentor.run(images=[...], ioconfig=config) ``` #### Use `patch_mode`: replace `mode="patch"` with `patch_mode=True` and `mode="tile"` or "wsi" with `patch_mode=False` ```python # Old results = segmentor.predict(imgs=[...], mode="patch", ioconfig=config) # New results = segmentor.run(images=[...], patch_mode=True, ioconfig=config) ``` ```python # Old results = segmentor.predict(imgs=[...], mode="wsi", ioconfig=config) # New results = segmentor.run(images=[...], patch_mode=False, ioconfig=config) ``` #### Use the new I/O configs ```python from tiatoolbox.models.engine.io_config import IOSegmentorConfig config = IOSegmentorConfig( patch_input_shape=(256, 256), stride_shape=(240, 240), input_resolutions=[{"resolution": 0.25, "units": "mpp"}], save_resolution={"units": "baseline", "resolution": 1.0} ) ``` #### Specify the output format ```python results = segmentor.run( images=[...], ioconfig=ioconfig, output_type="zarr", # or "dict", "annotationstore", "qupath" save_dir="outputs/" ) ``` #### Update imports - `tiatoolbox.typing` → `tiatoolbox.type_hints` #### Install requirements - Python **3.10+** required - On Windows: install OpenSlide via `pip install openslide-bin` **Full Changelog:** v1.6.0...v2.0.0 --------- Signed-off-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> Co-authored-by: measty <20169086+measty@users.noreply.github.com> Co-authored-by: Jiaqi-Lv <60471431+Jiaqi-Lv@users.noreply.github.com> Co-authored-by: adamshephard <39619155+adamshephard@users.noreply.github.com> Co-authored-by: Mostafa Jahanifar <74412979+mostafajahanifar@users.noreply.github.com> Co-authored-by: John Pocock <John-P@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yijie Zhu <120978607+YijieZhu15@users.noreply.github.com> Co-authored-by: Aleksandar Acic <32873451+aacic@users.noreply.github.com> Co-authored-by: Abdol A <u2271662@live.warwick.ac.uk> Co-authored-by: Abishek <abishekraj6797@gmail.com> Co-authored-by: behnazelhaminia <30952176+behnazelhaminia@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Adam Shephard <adam.shephard@warwick.ac.uk> Co-authored-by: gozdeg <gozdegunesli@gmail.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: mbasheer04 <78800844+mbasheer04@users.noreply.github.com> Co-authored-by: vqdang <24943262+vqdang@users.noreply.github.com>
Summary
This PR fundamentally refactors TIAToolbox's model/engine infrastructure into a unified, optimized architecture with a consistent
run()method interface across all engines. It introduces efficient zarr/dask-based processing for large-scale WSI analysis, multiple flexible output formats, and three state-of-the-art pre-trained models: GrandQC, Tissue Mask, and KongNet. Additionally, improved CLIs, comprehensive test coverage, and updated documentation ensure a smooth developer experience.What's New
1. Unified Engine Architecture
EngineABCbase class providing a standardized interface for all enginesEngineABCand implement the consistentrun()methodtiatoolbox.models.enginesmodule2. Optimized Data Processing
3. Flexible Output Types
dict,zarr,annotationstore,qupathJSON4. Enhanced Model Architectures
Improved Core Architectures:
HoverNet&HoverNetPlus- Updated for Dask-aware postprocessing with offset-aware instance handlingSCCNN&MAPDE- Switched to overlap-aware peak detection for improved accuracyMicroNet- Enhanced with Dask support and standardized output dictionariesUNet- Aligned inference output handling and added postprocessing standardizationVanilla architectures- Refactored backbone registries and shared postprocessing utilities5. New Engine Implementations
PatchPredictor- Redesigned withEngineABCbase classDeepFeatureExtractor- Updated API for foundation models (UNI, Prov-GigaPath, H-optimus-0) with zarr outputMultiTaskSegmentor- Enhanced performance for multi-task learning scenariosNucleusDetector- Complete nucleus detection and localization engine across various tissue typesNucleusInstanceSegmentor- Instance-level nucleus segmentation with updated interfaceSemanticSegmentor- Semantic segmentation engine with flexible output options6. New Pre-trained Models
GrandQC
Tissue Mask (EfficientUNet-based)
KongNet
7. Enhanced Configuration
ModelIOConfigABCfor input/output specificationsIOPatchPredictorConfigandIOSegmentorConfigreturn_probabilitiesoption added to engine parameterspost_process_cache_modefor WSI-level algorithm execution8. Improved CLI Infrastructure
semantic-segmentor,multitask-segmentor,nucleus-detector,deep-feature-extractorpatch-predictor,nucleus-instance-segmentmigrated to newrun()APIKey Changes
API Changes:
merge_predictionsoption from engines (replaced with more efficient architecture)save_wsi_outputparameter (handled automatically after post-processing)EngineABCRunParamsinfer_wsi()method for WSI inference supportNucleusDetectorprovides efficient nucleus detection with centroid mapping and post-processing_get_model_attr()for compatibility checksPerformance Improvements:
compile_modelnow moved toEngineABCinitialization phase_calculate_scale_factorfor proper resolution scalingclass_dictdefinition for multi-task segmentationpatch_predictions_as_annotationsnow loops onpatch_coordsinstead ofclass_probsfor efficiencyUtility Updates:
_get_zarr_array()a public functionget_zarr_array()inmiscmoduledetect_peaks_dask,apply_nms, etc. inarchitecture/utils.pyTest Coverage:
tests/engines/)Documentation:
Data Source Updates:
Dependencies:
dask>=2026.1.2for distributed computation and lazy evaluationipywidgets>=8.1.7for notebook interactions and progress visualizationMigration Notes
Users upgrading to this version should:
run()method instead ofpredict()dict)patch_mode=Falsefor WSI processingsave_dirwhen usingzarrorannotationstoreoutput typesNucleusDetectorengine with pre-trained modelstiatoolbox.models.enginetotiatoolbox.models.enginesExample Usage