@@ -65,6 +65,21 @@ def __getitem__(self, index):
6565 return {"image" : MetaTensor (x = image , meta = metadata ), "pred" : index + 1 }
6666
6767
68+ class FloatLocationDataset (TestDataset ):
69+ """A test fixture whose probability-map locations are floats.
70+
71+ The bundled WSI datasets emit integer locations, so this stands in for a third-party
72+ dataset that does not, which the handler still has to index the probability map with.
73+ """
74+
75+ __test__ = False # indicate to pytest that this class is not intended for collection
76+
77+ def __init__ (self , name , size ):
78+ super ().__init__ (name , size )
79+ for sample in self .data :
80+ sample [ProbMapKeys .LOCATION .value ] = sample [ProbMapKeys .LOCATION .value ].astype (float )
81+
82+
6883class TestEvaluator (Evaluator ):
6984 __test__ = False # indicate to pytest that this class is not intended for collection
7085
@@ -73,10 +88,7 @@ def _iteration(self, engine, batchdata):
7388
7489
7590class TestHandlerProbMapGenerator (unittest .TestCase ):
76- @parameterized .expand ([TEST_CASE_0 , TEST_CASE_1 , TEST_CASE_2 ])
77- def test_prob_map_generator (self , name , size ):
78- # set up dataset
79- dataset = TestDataset (name , size )
91+ def run_and_check (self , dataset , name , size ):
8092 batch_size = 2
8193 data_loader = DataLoader (dataset , batch_size = batch_size )
8294
@@ -106,6 +118,14 @@ def inference(engine, batch):
106118 self .assertListEqual (np .vstack (prob_map .nonzero ()).T .tolist (), [[i , i + 1 ] for i in range (size )])
107119 self .assertListEqual (prob_map [prob_map .nonzero ()].tolist (), [i + 1 for i in range (size )])
108120
121+ @parameterized .expand ([TEST_CASE_0 , TEST_CASE_1 , TEST_CASE_2 ])
122+ def test_prob_map_generator (self , name , size ):
123+ self .run_and_check (TestDataset (name , size ), name , size )
124+
125+ @parameterized .expand ([TEST_CASE_0 , TEST_CASE_1 , TEST_CASE_2 ])
126+ def test_prob_map_generator_float_locations (self , name , size ):
127+ self .run_and_check (FloatLocationDataset (name , size ), name , size )
128+
109129
110130if __name__ == "__main__" :
111131 unittest .main ()
0 commit comments