11"""Unit test package for GrandQC Tissue Model."""
22
3- from collections .abc import Callable
4- from pathlib import Path
5-
63import numpy as np
74import torch
85
1310from tiatoolbox .models .architecture .grandqc import TissueDetectionModel
1411from tiatoolbox .models .engine .io_config import IOSegmentorConfig
1512from tiatoolbox .utils .misc import select_device
16- from tiatoolbox .wsicore .wsireader import WSIReader
13+ from tiatoolbox .wsicore .wsireader import VirtualWSIReader
1714
1815ON_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
0 commit comments