Skip to content

Commit d82cc3d

Browse files
committed
improve test coverage
1 parent fd692da commit d82cc3d

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

tests/models/test_arch_grandqc.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""Unit test package for GrandQC Tissue Model."""
22

3-
from collections.abc import Callable
4-
from pathlib import Path
5-
63
import numpy as np
74
import torch
85

@@ -13,12 +10,12 @@
1310
from tiatoolbox.models.architecture.grandqc import TissueDetectionModel
1411
from tiatoolbox.models.engine.io_config import IOSegmentorConfig
1512
from tiatoolbox.utils.misc import select_device
16-
from tiatoolbox.wsicore.wsireader import WSIReader
13+
from tiatoolbox.wsicore.wsireader import VirtualWSIReader
1714

1815
ON_GPU = False
1916

2017

21-
def test_functional_grandqc(remote_sample: Callable) -> None:
18+
def test_functional_grandqc() -> None:
2219
"""Test for GrandQC model."""
2320
# test fetch pretrained weights
2421
pretrained_weights = fetch_pretrained_weights("grandqc_tissue_detection_mpp10")
@@ -40,9 +37,10 @@ def test_functional_grandqc(remote_sample: Callable) -> None:
4037
assert model.num_output_channels == 2
4138

4239
# test inference
43-
mini_wsi_svs = Path(remote_sample("wsi2_4k_4k_svs"))
44-
reader = WSIReader.open(mini_wsi_svs)
45-
read_kwargs = {"resolution": 10.0, "units": "mpp", "coord_space": "resolution"}
40+
generator = np.random.default_rng(1337)
41+
test_image = generator.integers(0, 256, size=(2048, 2048, 3), dtype=np.uint8)
42+
reader = VirtualWSIReader.open(test_image)
43+
read_kwargs = {"resolution": 0, "units": "level", "coord_space": "resolution"}
4644
batch = np.array(
4745
[
4846
reader.read_bounds((0, 0, 512, 512), **read_kwargs),
@@ -52,3 +50,21 @@ def test_functional_grandqc(remote_sample: Callable) -> None:
5250
batch = torch.from_numpy(batch)
5351
output = model.infer_batch(model, batch, device=select_device(on_gpu=ON_GPU))
5452
assert output.shape == (2, 512, 512, 2)
53+
54+
55+
def test_grandqc_preproc_postproc() -> None:
56+
"""Test GrandQC preproc and postproc functions."""
57+
model = TissueDetectionModel(num_input_channels=3, num_output_channels=2)
58+
59+
generator = np.random.default_rng(1337)
60+
# test preproc
61+
dummy_image = generator.integers(0, 256, size=(512, 512, 3), dtype=np.uint8)
62+
preproc_image = model.preproc(dummy_image)
63+
assert preproc_image.shape == dummy_image.shape
64+
assert preproc_image.dtype == np.float64
65+
66+
# test postproc
67+
dummy_output = generator.random(size=(512, 512, 2), dtype=np.float32)
68+
postproc_image = model.postproc(dummy_output)
69+
assert postproc_image.shape == (512, 512)
70+
assert postproc_image.dtype == np.int64

tiatoolbox/models/architecture/grandqc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import TYPE_CHECKING, Any
66

7-
if TYPE_CHECKING:
7+
if TYPE_CHECKING: # pragma: no cover
88
from collections.abc import Mapping
99

1010
import cv2

0 commit comments

Comments
 (0)