Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
193c587
:sparkles: Define `SemanticSegmentor` with the New `EngineABC`
shaneahmed Sep 20, 2024
113fb6b
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Nov 20, 2024
44e4b8c
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Nov 21, 2024
7e8d78b
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Nov 22, 2024
1ea6c80
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Dec 3, 2024
d0b86a5
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jan 3, 2025
399827a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 3, 2025
333264a
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jan 24, 2025
c84099b
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jan 24, 2025
16a632f
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Feb 5, 2025
e03db92
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Feb 21, 2025
13cc94a
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 3, 2025
dd83117
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 4, 2025
967dba1
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 7, 2025
40e79a1
:hammer: Add `run` method to SemanticSegmentor
shaneahmed Mar 7, 2025
85922ff
:memo: Update docstring
shaneahmed Mar 7, 2025
bda0581
:recycle: Refactor resolution to input_resolutions.
shaneahmed Mar 7, 2025
a643ea6
:recycle: Use `input_resolutions` instead of resolution
shaneahmed Mar 7, 2025
7eed649
:recycle: Use `input_resolutions` instead of resolution
shaneahmed Mar 7, 2025
3dff881
:white_check_mark: Add test to cli.
shaneahmed Mar 7, 2025
52ed249
Merge branch 'dev-use-input-resolutions' into dev-define-semantic-seg…
shaneahmed Mar 7, 2025
03e07e6
:white_check_mark: Add SemanticSegmentor patch_mode test.
shaneahmed Mar 7, 2025
a37e71d
:bug: Fix `unet` architecture
shaneahmed Mar 8, 2025
94a747f
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 8, 2025
987927d
Merge branch 'dev-define-engines-abc' into dev-use-input-resolutions
shaneahmed Mar 8, 2025
92bc813
:bug: Fix `test_datset` architecture
shaneahmed Mar 8, 2025
bddd956
Merge branch 'dev-use-input-resolutions' into dev-define-semantic-seg…
shaneahmed Mar 8, 2025
facf461
:white_check_mark: Add postproc to segmentation.
shaneahmed Mar 12, 2025
2b342f4
Merge remote-tracking branch 'origin/dev-define-semantic-segmentor' i…
shaneahmed Mar 12, 2025
6f9d412
:recycle: Move argmax postprocessing to utils.
shaneahmed Mar 12, 2025
91a45b3
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 14, 2025
8a95948
:white_check_mark: Check for cache_mode with zarr output.
shaneahmed Mar 17, 2025
cf5b50e
:white_check_mark: Update script for annotation store
shaneahmed Mar 18, 2025
816a568
:construction: Update script for annotation store
shaneahmed Mar 18, 2025
2f88cb7
:construction: Update script for annotation store
shaneahmed Mar 19, 2025
91d134d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 19, 2025
9204604
:bug: Fix saving annotation properties
shaneahmed Mar 19, 2025
84fdd2f
:bug: Fix TID252 Prefer absolute imports over relative imports
shaneahmed Mar 19, 2025
16e3f91
:bug: Test mask to store from #918
shaneahmed Mar 21, 2025
b7862c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 21, 2025
a495daf
:bug: Fix AnnotationStore display
shaneahmed Mar 28, 2025
355af0d
:fire: Remove unnecessary test
shaneahmed Mar 31, 2025
9e30cb9
:wastebasket: Clean up code for saving to AnnotationStore
shaneahmed Mar 31, 2025
d9e8f92
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Mar 31, 2025
9011a8f
:bug: Fix mypy checks
shaneahmed Apr 3, 2025
9e1c218
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Apr 3, 2025
136f9f2
:memo: Add comments
shaneahmed Apr 9, 2025
854e2b8
:white_check_mark: Update single and multipoint behaviour
shaneahmed Apr 10, 2025
fb56920
:white_check_mark: Add tests for correct annotation type
shaneahmed Apr 10, 2025
221e53b
:stethoscope: Add checks for correct patch size.
shaneahmed Apr 10, 2025
f69ac89
:white_check_mark: Add tests for incorrect image patch input.
shaneahmed Apr 10, 2025
e9ed0a9
:bug: Fix tests for io config delegation.
shaneahmed Apr 10, 2025
c1b06d5
:package: Add sample image for semantic_segmentor tests.
shaneahmed Apr 10, 2025
211d39d
:bug: Fix conversion for single and two points annotations.
shaneahmed Apr 10, 2025
f2b4678
:bug: Fix semantic segmentor test
shaneahmed Apr 10, 2025
388bbc6
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Apr 10, 2025
56e195c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2025
c904626
:bug: Fix `ruff` errors.
shaneahmed Apr 10, 2025
fae76f8
Merge remote-tracking branch 'origin/dev-define-semantic-segmentor' i…
shaneahmed Apr 10, 2025
7ce679c
:bug: Fix offset values
shaneahmed Apr 10, 2025
f613cef
:bug: Fix tests
shaneahmed Apr 10, 2025
45a5737
:white_check_mark: Add tests for input numpy array
shaneahmed Apr 11, 2025
ab4e93b
:white_check_mark: Add tests to improve coverage.
shaneahmed Apr 11, 2025
a3174dc
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Apr 25, 2025
322d32e
:memo: Fix typos
shaneahmed Apr 25, 2025
fc89d81
:sparkles: Save `probabilities` to `tiff`
shaneahmed Apr 25, 2025
4abcd6f
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed May 9, 2025
2f60b97
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed May 14, 2025
22db63f
:bug: Fix bugs after merge
shaneahmed May 15, 2025
fe0f0ad
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed May 19, 2025
5972fac
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jun 9, 2025
f2aa349
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jun 10, 2025
d3f6790
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jun 19, 2025
893abcb
:rewind: Revert padding with zeros in the output.
shaneahmed Jun 19, 2025
7cb05c2
:fire: Remove `mode` option from WSIPatchDataset
shaneahmed Jun 20, 2025
d032ebf
:hammer: Add patch_output_shape to WSIPatchDataset
shaneahmed Jun 20, 2025
a469c0f
:bulb: Add no cover to TYPE_CHECKING
shaneahmed Jun 20, 2025
51ba746
:hammer: Add `patch_output_shape` support.
shaneahmed Jun 20, 2025
49b997f
:hammer: Add output_locations as an attribute to SemanticSegmentor.
shaneahmed Jun 20, 2025
8f38244
:bug: Fix checking attribute for outputs in WSIPatchDataset
shaneahmed Jun 20, 2025
60e6959
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Jun 24, 2025
c6926f1
:twisted_rightwards_arrows: Merge dev-define-engine into dev-define-s…
shaneahmed Jul 9, 2025
31bb170
:memo: Fix `SemanticSegmentorRunParams`
shaneahmed Jul 10, 2025
db4788f
:alien: Add dataloader as an attribute to EngineABC
shaneahmed Jul 10, 2025
bfd02b5
:sparkles: Add merge_predictions and save to zarr
shaneahmed Jul 10, 2025
d08146e
:white_check_mark: Add test for coverage
shaneahmed Jul 10, 2025
ed52e08
:white_check_mark: Using small image for faster run
shaneahmed Jul 11, 2025
4f353f8
:white_check_mark: Improve Tests for WSI output
shaneahmed Jul 11, 2025
2b790b8
:white_check_mark: Improve Tests for WSI output
shaneahmed Jul 11, 2025
ceeda81
:white_check_mark: Add test for a large image
shaneahmed Jul 24, 2025
fe9f2e3
:lipstick: Add a function to misc to return an appropriate tqdm object.
shaneahmed Jul 24, 2025
7d02703
:lipstick: Add a function to misc to return an appropriate tqdm object.
shaneahmed Jul 24, 2025
efe0c80
:lipstick: Add a function to misc to return an appropriate tqdm object.
shaneahmed Jul 24, 2025
6d9b3c7
:zap: Improve patch output merging.
shaneahmed Jul 24, 2025
4fa584f
:sparkles: Add saving to AnnotationStore
shaneahmed Jul 24, 2025
3aaed3e
:fire: Purge old semantic_segmentor.py
shaneahmed Jul 24, 2025
6ccb300
:rewind: Add `DeepFeatureExtractor`.
shaneahmed Jul 25, 2025
3dd28bc
:rewind: Add `DeepFeatureExtractor`.
shaneahmed Jul 25, 2025
7651eda
:bug: Fix SemanticSegmentor import
shaneahmed Jul 25, 2025
a2d7fb8
:lipstick: Cosmetic changes
shaneahmed Jul 25, 2025
6296069
:zap: Using larger chunk size improves performance.
shaneahmed Jul 25, 2025
358c67e
:zap: Optimize performance
shaneahmed Jul 28, 2025
84a21cf
:bug: Fix tests
shaneahmed Jul 28, 2025
30621fc
:bug: Fix tests
shaneahmed Jul 29, 2025
55780a7
:fire: Remove smart_divide
shaneahmed Jul 29, 2025
8ab5293
:construction: Use dask for processing.
shaneahmed Jul 29, 2025
ef3c9f6
:construction: Use dask for processing.
shaneahmed Jul 29, 2025
61aee15
:bug: Fix bug saving annotation store.
shaneahmed Jul 29, 2025
4699643
:white_check_mark: Add test for TypeError
shaneahmed Jul 30, 2025
67fc4e2
:bug: Fix saving to zarr output
shaneahmed Jul 30, 2025
621adb5
:bug: Fix saving to annotationstore output
shaneahmed Jul 30, 2025
1d6b877
:zap: Improve merge performance
shaneahmed Jul 30, 2025
33d3c97
:zap: Using dask compute
shaneahmed Jul 31, 2025
2ab6238
:zap: Udate EngineABC for delayed compute.
shaneahmed Jul 31, 2025
2fd6623
:test_tube: Failing checks.
shaneahmed Aug 4, 2025
22fa379
:white_check_mark: Check tests for new dask based implementation.
shaneahmed Aug 4, 2025
69ce1b4
:fire: Remove self.keys
shaneahmed Aug 4, 2025
c39eece
:white_check_mark: Update for PatchPredictor
shaneahmed Aug 4, 2025
aa7e0c8
:bug: Fix bugs related to dictionary output.
shaneahmed Aug 4, 2025
e0f90f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2025
759d68e
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Aug 4, 2025
c4988c2
:bug: Fix ruff bug
shaneahmed Aug 4, 2025
4c4eff0
:white_check_mark: Fix failing test
shaneahmed Aug 4, 2025
70d7845
:bug: Fix bug and update documentation.
shaneahmed Aug 4, 2025
9ab67b0
:bug: Fix prepare_engines_save_dir
shaneahmed Aug 5, 2025
a7db423
:bug: Fix out_ shape
shaneahmed Aug 5, 2025
7f5d767
:memo: Update EngineABC documentation.
shaneahmed Aug 5, 2025
c05d0f3
:memo: Update _initialize_model_ioconfig documentation.
shaneahmed Aug 5, 2025
b12344b
:memo: Update get_dataloader documentation.
shaneahmed Aug 5, 2025
df1908a
:memo: Update _update_model_output documentation.
shaneahmed Aug 5, 2025
56db667
:memo: Update _get_coordinates documentation.
shaneahmed Aug 5, 2025
2561aad
:memo: Update process_batch documentation.
shaneahmed Aug 5, 2025
08c3dd5
:memo: Update infer_patches and post_process_patches.
shaneahmed Aug 5, 2025
6340091
:memo: Update save_predictions documentation.
shaneahmed Aug 5, 2025
5c63b3f
:memo: Update infer_wsi documentation.
shaneahmed Aug 5, 2025
b310930
:memo: Update post_process_wsi documentation.
shaneahmed Aug 5, 2025
52f3c8d
:memo: Update _load_ioconfig documentation.
shaneahmed Aug 5, 2025
ae7e4d6
:memo: Update _update_ioconfig documentation.
shaneahmed Aug 5, 2025
9f16e58
:memo: Update _validate_images_masks and _validate_input_numbers docu…
shaneahmed Aug 5, 2025
39e42a5
:memo: Update _update_run_params documentation.
shaneahmed Aug 5, 2025
8814001
:memo: Update _run_patch_mode documentation.
shaneahmed Aug 5, 2025
addce82
:memo: Update _calculate_scale_factor documentation.
shaneahmed Aug 5, 2025
4e748cd
:memo: Update _run_wsi_mode documentation.
shaneahmed Aug 5, 2025
6d882f4
:memo: Update run documentation.
shaneahmed Aug 5, 2025
1c57b55
:memo: Update engine_abc.py documentation.
shaneahmed Aug 5, 2025
3de2392
:memo: Update PatchPredictor __init__ documentation.
shaneahmed Aug 5, 2025
fe6d52e
:memo: Update PredictorRunParams documentation.
shaneahmed Aug 5, 2025
efc8106
:memo: Update PredictorRunParams documentation.
shaneahmed Aug 5, 2025
65939a0
:memo: Update post_process_patches documentation.
shaneahmed Aug 5, 2025
ba0bbba
:memo: Update post_process_wsi documentation.
shaneahmed Aug 5, 2025
9ad2d54
:memo: Update _update_run_params documentation.
shaneahmed Aug 5, 2025
0fae659
:memo: Update run documentation.
shaneahmed Aug 5, 2025
f813ffd
- Update semantic_segmentor.py using dask
shaneahmed Aug 5, 2025
3730fef
:bug: Fix unet test
shaneahmed Aug 6, 2025
dc3e6e1
:zap: Use basic loop to update.
shaneahmed Aug 6, 2025
edde87a
:fire: Remove intermediate calculation
shaneahmed Aug 6, 2025
29aeb1b
:fire: Remove unnecessary function
shaneahmed Aug 6, 2025
b22c303
:fire: Remove unnecessary function
shaneahmed Aug 6, 2025
d49c3d9
:fire: Remove unnecessary code
shaneahmed Aug 6, 2025
e9ac4e2
Merge remote-tracking branch 'origin/dev-define-semantic-segmentor' i…
shaneahmed Aug 7, 2025
daa1559
:zap: Update Segmentation Merge Code
shaneahmed Aug 7, 2025
04b9716
:zap: Update fcn_resnet50_unet-bcss stride shape
shaneahmed Aug 8, 2025
53792a7
:zap: Add merge_all to semantic_segmentor.py
shaneahmed Aug 8, 2025
4efa83d
:zap: Update SemanticSegmentor for merging logic
shaneahmed Aug 8, 2025
d202756
:memo: Fix annotations
shaneahmed Aug 8, 2025
f1b622e
:zap: Implement hybrid approach
shaneahmed Aug 11, 2025
daf7202
:memo: Update `infer_patches` documentation
shaneahmed Aug 11, 2025
45c6815
:memo: Update `__init__` documentation
shaneahmed Aug 11, 2025
a54ff40
:memo: Update `merge_all` documentation
shaneahmed Aug 11, 2025
ce6c8c0
:memo: Update `SemanticSegmentorRunParams` documentation
shaneahmed Aug 11, 2025
eed51a5
:memo: Update `SemanticSegmentor` documentation
shaneahmed Aug 11, 2025
3804524
:memo: Update `get_dataloader` documentation
shaneahmed Aug 11, 2025
6310ab5
:memo: Update `infer_wsi` documentation
shaneahmed Aug 11, 2025
f97a55c
:memo: Update `save_predictions` documentation
shaneahmed Aug 11, 2025
9f9a709
:memo: Update `run` documentation
shaneahmed Aug 11, 2025
775aa0a
:fire: Remove cache_mode
shaneahmed Aug 11, 2025
ee80501
:fire: Remove feature_extractor.py.
shaneahmed Aug 11, 2025
6e8819f
:zap: Rechunking strategy
shaneahmed Aug 12, 2025
fe060dd
:twisted_rightwards_arrows: Merge `dev-engine-abc` into `dev-define-s…
shaneahmed Aug 12, 2025
37ac626
:bug: Fix error after merge
shaneahmed Aug 12, 2025
5cda7c2
:bug: Fix error after merge
shaneahmed Aug 12, 2025
3150e32
:rewind: Revert previous commit
shaneahmed Aug 12, 2025
1b957d2
:zap: Improved run on bcss dataset by 4 times.
shaneahmed Aug 12, 2025
677284b
:recycle: Rename functions for clarity
shaneahmed Aug 13, 2025
b1763c9
:zap: Improve performance.
shaneahmed Aug 13, 2025
81d1d05
:white_check_mark: Improve coverage and address deepsource bugs
shaneahmed Aug 13, 2025
80691d1
:bug: Fix deepsource error
shaneahmed Aug 13, 2025
5b4a505
:zap: Move model to device in _update_run_params
shaneahmed Aug 13, 2025
708e706
:white_check_mark: Add tests to improve coverage
shaneahmed Aug 13, 2025
cf70c97
🔧 Add Zarr-based Caching and Memory-Aware Patch Merging for WSI Infer…
shaneahmed Aug 22, 2025
1a85193
:bug: Fix deepsource errors
shaneahmed Aug 22, 2025
021feba
:label: Fix Type annotations
shaneahmed Aug 22, 2025
fa0c281
:recycle: Rename num_loader_workers to num_workers
shaneahmed Aug 22, 2025
3a6f68f
:rewind: Rewind changes to MicroNet as it uses HoVerNetPostProcessing.
shaneahmed Aug 22, 2025
da65e78
:memo: Update EngineABCRunParams docstring
shaneahmed Aug 22, 2025
d87656d
:memo: Update EngineABC docstring
shaneahmed Aug 22, 2025
a3cb783
:memo: Update get_dataloader docstring
shaneahmed Aug 22, 2025
d85405f
:memo: Update docstrings
shaneahmed Aug 22, 2025
ba28d91
:memo: Update docstrings
shaneahmed Aug 22, 2025
0242512
:memo: Update patch_predictor.py docstrings
shaneahmed Aug 22, 2025
7f148f4
:white_check_mark: Add test for dask length threshold
shaneahmed Aug 22, 2025
1db4e41
:memo: Add docstrings for semantic_segmentor.py
shaneahmed Aug 23, 2025
7cc2577
:fire: Clean up unnecessary code
shaneahmed Aug 27, 2025
eeb99df
:bug: Remove extra input to function.
shaneahmed Aug 27, 2025
a51bab2
:zap: Use optimized chunk size
shaneahmed Aug 27, 2025
ff2e1bb
:sparkles: Add support for annotationstore
shaneahmed Aug 27, 2025
5997671
:bug: Fix concatenation
shaneahmed Aug 27, 2025
96676c8
:sparkles: Add CLI interface
shaneahmed Aug 27, 2025
eca8fc8
:white_check_mark: Add tests for improved coverage
shaneahmed Aug 27, 2025
6e809f9
:fire: Remove unnecessary code.
shaneahmed Aug 28, 2025
e0f9405
:white_check_mark: Add checks for misc functions.
shaneahmed Aug 28, 2025
5b0d6d5
:bug: Fix bug for non-overlapping regions and add tests
shaneahmed Aug 28, 2025
6c6bceb
:bulb: Address @Copilot comments
shaneahmed Aug 29, 2025
2130d90
:fire: Remove unnecessary tests
shaneahmed Aug 29, 2025
6eeb8a2
:memo: Update docstring
shaneahmed Aug 29, 2025
ee2d339
:bug: Fix missing support for WSIReader.
shaneahmed Sep 2, 2025
7e26b78
:bug: Fix deepsource error - simplify if statement
shaneahmed Sep 2, 2025
7d363e8
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Sep 2, 2025
24eeff1
:goal_net: Raise an error if `return_labels` is True and `patch_mode`…
shaneahmed Sep 11, 2025
610d355
:art: Use a variable instead of multiple calculations
shaneahmed Sep 11, 2025
5125146
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
shaneahmed Sep 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ aiohttp>=3.8.1
albumentations>=1.3.0
bokeh>=3.1.1, <3.6.0
Click>=8.1.3, <8.2.0
dask>=0.12.1
defusedxml>=0.7.1
filelock>=3.9.0
flask>=2.2.2
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def sample_wsi_dict(remote_sample: Callable) -> dict:
"wsi4_4k_4k_svs",
"wsi3_20k_20k_pred",
"wsi4_4k_4k_pred",
"wsi4_1k_1k_svs",
]
return {name: remote_sample(name) for name in file_names}

Expand Down
65 changes: 22 additions & 43 deletions tests/engines/test_engine_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import logging
import shutil
from pathlib import Path
from typing import TYPE_CHECKING, NoReturn
from typing import NoReturn

import numpy as np
import pytest
import torch
import torchvision.models as torch_models
from typing_extensions import Unpack

Expand All @@ -26,8 +27,7 @@
)
from tiatoolbox.models.engine.io_config import ModelIOConfigABC

if TYPE_CHECKING:
import torch.nn
device = "cuda:0" if torch.cuda.is_available() else "cpu"


class TestEngineABC(EngineABC):
Expand Down Expand Up @@ -69,6 +69,8 @@ def post_process_wsi(
"""Post process WSI output."""
return super().post_process_wsi(
raw_predictions=raw_predictions,
prediction_shape=(self.batch_size, 1),
prediction_dtype=int,
**kwargs,
)

Expand All @@ -79,7 +81,7 @@ def infer_wsi(
**kwargs: dict,
) -> dict | np.ndarray:
"""Test infer_wsi."""
return super().infer_wsi(
return super().infer_wsi( # skipcq: PYL-E1121
dataloader,
save_path,
**kwargs,
Expand Down Expand Up @@ -362,7 +364,7 @@ def test_engine_run_with_verbose() -> NoReturn:
out = eng.run(
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),
labels=list(range(10)),
on_gpu=False,
device=device,
)

assert "probabilities" in out
Expand Down Expand Up @@ -457,37 +459,6 @@ def test_patch_pred_zarr_store(tmp_path: pytest.TempPathFactory) -> NoReturn:
)


def test_cache_mode_patches(tmp_path: pytest.TempPathFactory) -> NoReturn:
"""Test the caching mode."""
save_dir = tmp_path / "patch_output"

eng = TestEngineABC(model="alexnet-kather100k")
out = eng.run(
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),
on_gpu=False,
save_dir=save_dir,
overwrite=True,
cache_mode=True,
)
assert out.exists(), "Zarr output file does not exist"

output_file_name = "output2.zarr"
cache_size = 4
out = eng.run(
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),
on_gpu=False,
save_dir=save_dir,
overwrite=True,
cache_mode=True,
cache_size=4,
batch_size=8,
output_file=output_file_name,
)
assert out.stem == output_file_name.split(".")[0]
assert eng.batch_size == cache_size
assert out.exists(), "Zarr output file does not exist"


def test_get_dataloader(sample_svs: Path) -> None:
"""Test the get_dataloader function."""
eng = TestEngineABC(model="alexnet-kather100k")
Expand Down Expand Up @@ -521,7 +492,7 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)
eng = TestEngineABC(model=model)

kwargs = {
"patch_input_shape": [512, 512],
"patch_input_shape": [224, 224],
"input_resolutions": [{"units": "mpp", "resolution": 1.75}],
}
with caplog.at_level(logging.WARNING):
Expand All @@ -537,7 +508,7 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)

# test providing config / full input info for non pretrained models
ioconfig = ModelIOConfigABC(
patch_input_shape=(512, 512),
patch_input_shape=(224, 224),
stride_shape=(256, 256),
input_resolutions=[{"resolution": 1.35, "units": "mpp"}],
)
Expand All @@ -547,7 +518,7 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)
save_dir=f"{tmp_path}/dump",
ioconfig=ioconfig,
)
assert eng._ioconfig.patch_input_shape == (512, 512)
assert eng._ioconfig.patch_input_shape == (224, 224)
assert eng._ioconfig.stride_shape == (256, 256)
assert eng._ioconfig.input_resolutions == [{"resolution": 1.35, "units": "mpp"}]
shutil.rmtree(tmp_path / "dump", ignore_errors=True)
Expand All @@ -558,15 +529,15 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)
save_dir=f"{tmp_path}/dump",
**kwargs,
)
assert eng._ioconfig.patch_input_shape == [512, 512]
assert eng._ioconfig.stride_shape == [512, 512]
assert eng._ioconfig.patch_input_shape == [224, 224]
assert eng._ioconfig.stride_shape == [224, 224]
assert eng._ioconfig.input_resolutions == [{"resolution": 1.75, "units": "mpp"}]
shutil.rmtree(tmp_path / "dump", ignore_errors=True)

# test overwriting pretrained ioconfig
eng = TestEngineABC(model="alexnet-kather100k")
eng.run(
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),
images=np.zeros((10, 300, 300, 3), dtype=np.uint8),
patch_input_shape=(300, 300),
stride_shape=(300, 300),
input_resolutions=[{"units": "baseline", "resolution": 1.99}],
Expand All @@ -580,7 +551,7 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)
shutil.rmtree(tmp_path / "dump", ignore_errors=True)

eng.run(
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),
images=np.zeros((10, 300, 300, 3), dtype=np.uint8),
patch_input_shape=(300, 300),
stride_shape=(300, 300),
input_resolutions=None,
Expand Down Expand Up @@ -618,3 +589,11 @@ def test_io_config_delegation(tmp_path: Path, caplog: pytest.LogCaptureFixture)
stride_shape=(1, 1),
input_resolutions=_kwargs["input_resolutions"],
)


def test_save_predictions_incorrect_output_type() -> None:
"""Engine should raise TypeError if incorrect output type is requested."""
eng = TestEngineABC(model="alexnet-kather100k")

with pytest.raises(TypeError, match=r".*Unsupported output type.* "):
eng.save_predictions({"predictions": np.zeros((20, 9))}, output_type="random")
11 changes: 8 additions & 3 deletions tests/engines/test_patch_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _test_predictor_output(
cache_mode=cache_mode,
save_dir=save_dir,
output_type=output_type,
return_probabilities=True,
)

if tmp_path is not None:
Expand Down Expand Up @@ -188,6 +189,7 @@ def test_patch_predictor_api(
output = predictor.run(
inputs,
device="cpu",
return_probabilities=True,
)
assert sorted(output.keys()) == ["predictions", "probabilities"]
assert len(output["probabilities"]) == 2
Expand All @@ -198,10 +200,11 @@ def test_patch_predictor_api(
inputs,
labels=["1", "a"],
return_labels=True,
return_probabilities=True,
)
assert sorted(output.keys()) == sorted(["labels", "predictions", "probabilities"])
assert len(output["probabilities"]) == len(output["labels"])
assert output["labels"].tolist() == ["1", "a"]
assert list(output["labels"]) == ["1", "a"]
shutil.rmtree(save_dir_path, ignore_errors=True)

# test loading user weight
Expand Down Expand Up @@ -234,10 +237,12 @@ def test_patch_predictor_api(
labels=[1, 2],
return_labels=True,
ioconfig=ioconfig,
return_probabilities=True,
num_workers=1,
)
assert sorted(output.keys()) == sorted(["labels", "predictions", "probabilities"])
assert len(output["probabilities"]) == len(output["labels"])
assert output["labels"].tolist() == [1, 2]
assert list(output["labels"]) == [1, 2]


def test_wsi_predictor_api(
Expand Down Expand Up @@ -274,6 +279,7 @@ def test_wsi_predictor_api(
images=[mini_wsi_svs, mini_wsi_jpg],
masks=[mini_wsi_msk, mini_wsi_msk],
patch_mode=False,
return_probabilities=True,
**_kwargs,
)

Expand Down Expand Up @@ -324,7 +330,6 @@ def test_patch_predictor_kather100k_output(
classification_check=[6, 3],
)

# cache mode
for model, expected_prob in pretrained_info.items():
_test_predictor_output(
inputs,
Expand Down
Loading
Loading