Skip to content

Commit 767441d

Browse files
committed
copy code from old PR
1 parent 67ef0da commit 767441d

File tree

5 files changed

+329
-10
lines changed

5 files changed

+329
-10
lines changed

docs/pretrained.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ The input output configuration is as follows:
353353
ioconfig = IOPatchPredictorConfig(
354354
patch_input_shape=(31, 31),
355355
stride_shape=(8, 8),
356-
input_resolutions=[{"resolution": 0.25, "units": "mpp"}]
356+
input_resolutions=[{"resolution": 0.5, "units": "mpp"}]
357357
)
358358
359359
@@ -369,7 +369,7 @@ The input output configuration is as follows:
369369
ioconfig = IOPatchPredictorConfig(
370370
patch_input_shape=(252, 252),
371371
stride_shape=(150, 150),
372-
input_resolutions=[{"resolution": 0.25, "units": "mpp"}]
372+
input_resolutions=[{"resolution": 0.5, "units": "mpp"}]
373373
)
374374
375375
@@ -393,7 +393,7 @@ The input output configuration is as follows:
393393
ioconfig = IOPatchPredictorConfig(
394394
patch_input_shape=(31, 31),
395395
stride_shape=(8, 8),
396-
input_resolutions=[{"resolution": 0.25, "units": "mpp"}]
396+
input_resolutions=[{"resolution": 0.5, "units": "mpp"}]
397397
)
398398
399399
@@ -409,7 +409,7 @@ The input output configuration is as follows:
409409
ioconfig = IOPatchPredictorConfig(
410410
patch_input_shape=(252, 252),
411411
stride_shape=(150, 150),
412-
input_resolutions=[{"resolution": 0.25, "units": "mpp"}]
412+
input_resolutions=[{"resolution": 0.5, "units": "mpp"}]
413413
)
414414
415415
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""Tests for NucleusDetector."""
2+
3+
import pathlib
4+
import shutil
5+
6+
import pandas as pd
7+
import pytest
8+
9+
from tiatoolbox.models.engine.nucleus_detector import (
10+
IONucleusDetectorConfig,
11+
NucleusDetector,
12+
)
13+
from tiatoolbox.utils import env_detection as toolbox_env
14+
15+
ON_GPU = not toolbox_env.running_on_ci() and toolbox_env.has_gpu()
16+
17+
18+
def _rm_dir(path):
19+
"""Helper func to remove directory."""
20+
if pathlib.Path(path).exists():
21+
shutil.rmtree(path, ignore_errors=True)
22+
23+
24+
def check_output(path):
25+
"""Check NucleusDetector output."""
26+
coordinates = pd.read_csv(path)
27+
assert coordinates.x[0] == pytest.approx(53, abs=2)
28+
assert coordinates.x[1] == pytest.approx(55, abs=2)
29+
assert coordinates.y[0] == pytest.approx(107, abs=2)
30+
assert coordinates.y[1] == pytest.approx(127, abs=2)
31+
32+
33+
def test_nucleus_detector_engine(remote_sample, tmp_path):
34+
"""Test for nucleus detection engine."""
35+
mini_wsi_svs = pathlib.Path(remote_sample("wsi4_512_512_svs"))
36+
37+
nucleus_detector = NucleusDetector(pretrained_model="mapde-conic")
38+
_ = nucleus_detector.predict(
39+
[mini_wsi_svs],
40+
mode="wsi",
41+
save_dir=tmp_path / "output",
42+
on_gpu=ON_GPU,
43+
)
44+
45+
check_output(tmp_path / "output" / "0.locations.0.csv")
46+
47+
_rm_dir(tmp_path / "output")
48+
49+
ioconfig = IONucleusDetectorConfig(
50+
input_resolutions=[{"units": "mpp", "resolution": 0.5}],
51+
output_resolutions=[{"units": "mpp", "resolution": 0.5}],
52+
save_resolution=None,
53+
patch_input_shape=[252, 252],
54+
patch_output_shape=[252, 252],
55+
stride_shape=[150, 150],
56+
)
57+
58+
nucleus_detector = NucleusDetector(pretrained_model="mapde-conic")
59+
_ = nucleus_detector.predict(
60+
[mini_wsi_svs],
61+
mode="wsi",
62+
save_dir=tmp_path / "output",
63+
on_gpu=ON_GPU,
64+
ioconfig=ioconfig,
65+
)
66+
67+
check_output(tmp_path / "output" / "0.locations.0.csv")

tiatoolbox/data/pretrained_model.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ mapde-crchisto:
815815
threshold_abs: 250
816816
num_classes: 1
817817
ioconfig:
818-
class: semantic_segmentor.IOSegmentorConfig
818+
class: io_config.IOSegmentorConfig
819819
kwargs:
820820
input_resolutions:
821821
- { "units": "mpp", "resolution": 0.5 }
@@ -837,7 +837,7 @@ mapde-conic:
837837
threshold_abs: 205
838838
num_classes: 1
839839
ioconfig:
840-
class: semantic_segmentor.IOSegmentorConfig
840+
class: io_config.IOSegmentorConfig
841841
kwargs:
842842
input_resolutions:
843843
- { "units": "mpp", "resolution": 0.5 }
@@ -860,7 +860,7 @@ sccnn-crchisto:
860860
threshold_abs: 0.20
861861
patch_output_shape: [ 13, 13 ]
862862
ioconfig:
863-
class: semantic_segmentor.IOSegmentorConfig
863+
class: io_config.IOSegmentorConfig
864864
kwargs:
865865
input_resolutions:
866866
- { "units": "mpp", "resolution": 0.5 }
@@ -883,7 +883,7 @@ sccnn-conic:
883883
threshold_abs: 0.05
884884
patch_output_shape: [ 13, 13 ]
885885
ioconfig:
886-
class: semantic_segmentor.IOSegmentorConfig
886+
class: io_config.IOSegmentorConfig
887887
kwargs:
888888
input_resolutions:
889889
- { "units": "mpp", "resolution": 0.5 }
@@ -903,7 +903,7 @@ nuclick_original-pannuke:
903903
num_input_channels: 5
904904
num_output_channels: 1
905905
ioconfig:
906-
class: semantic_segmentor.IOSegmentorConfig
906+
class: io_config.IOSegmentorConfig
907907
kwargs:
908908
input_resolutions:
909909
- {'units': 'baseline', 'resolution': 0.25}
@@ -925,7 +925,7 @@ nuclick_light-pannuke:
925925
decoder_block: [3,3]
926926
skip_type: "add"
927927
ioconfig:
928-
class: semantic_segmentor.IOSegmentorConfig
928+
class: io_config.IOSegmentorConfig
929929
kwargs:
930930
input_resolutions:
931931
- {'units': 'baseline', 'resolution': 0.25}

tiatoolbox/models/engine/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
from . import (
44
engine_abc,
5+
nucleus_detector,
56
nucleus_instance_segmentor,
67
patch_predictor,
78
semantic_segmentor,
89
)
910

1011
__all__ = [
1112
"engine_abc",
13+
"nucleus_detector",
1214
"nucleus_instance_segmentor",
1315
"patch_predictor",
1416
"semantic_segmentor",

0 commit comments

Comments
 (0)