2121from monai .data import MetaTensor
2222from monai .inferers import sliding_window_inference
2323from monai .utils import optional_import
24- from tests .test_sliding_window_inference import TEST_CASES
24+ from tests .inferers . test_sliding_window_inference import TEST_CASES
2525
2626_ , has_tqdm = optional_import ("tqdm" )
2727
3636
3737
3838class TestSlidingWindowHoVerNetInference (unittest .TestCase ):
39-
4039 @parameterized .expand (TEST_CASES_PADDING )
4140 def test_sliding_window_with_padding (
4241 self , key , image_shape , roi_shape , sw_batch_size , overlap , mode , device , extra_input_padding
@@ -122,21 +121,19 @@ def compute(self, data):
122121 sigma_scale = 1.0 ,
123122 )
124123
125- expected = np .array (
124+ expected = np .array ([
126125 [
127126 [
128- [
129- [3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 ],
130- [3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 ],
131- [3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 ],
132- [3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 ],
133- [4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 ],
134- [4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 ],
135- [5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 ],
136- ]
127+ [3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 ],
128+ [3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 , 3.0000 ],
129+ [3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 , 3.3333 ],
130+ [3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 , 3.6667 ],
131+ [4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 , 4.3333 ],
132+ [4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 , 4.5000 ],
133+ [5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 , 5.0000 ],
137134 ]
138135 ]
139- )
136+ ] )
140137 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
141138 result = sliding_window_inference (
142139 inputs ,
@@ -150,31 +147,29 @@ def compute(self, data):
150147 sigma_scale = 1.0 ,
151148 progress = has_tqdm ,
152149 )
153- expected = np .array (
150+ expected = np .array ([
154151 [
155152 [
156- [
157- [3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 ],
158- [3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 ],
159- [3.3271625 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271625 ],
160- [3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 ],
161- [4.3271623 , 4.3271623 , 4.3271627 , 4.3271627 , 4.3271627 , 4.3271623 , 4.3271623 ],
162- [4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 ],
163- [4.9999995 , 5.0 , 5.0 , 5.0 , 5.0 , 5.0 , 4.9999995 ],
164- ]
153+ [3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 ],
154+ [3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 , 3.0 ],
155+ [3.3271625 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271623 , 3.3271625 ],
156+ [3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 , 3.6728377 ],
157+ [4.3271623 , 4.3271623 , 4.3271627 , 4.3271627 , 4.3271627 , 4.3271623 , 4.3271623 ],
158+ [4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 , 4.513757 ],
159+ [4.9999995 , 5.0 , 5.0 , 5.0 , 5.0 , 5.0 , 4.9999995 ],
165160 ]
166161 ]
167- )
162+ ] )
168163 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
169164
170165 result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "gaussian" , sigma_scale = 1.0 )(
171166 inputs , _Pred ().compute
172167 )
173168 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
174169
175- result = SlidingWindowHoVerNetInferer (
176- roi_shape , sw_batch_size , overlap = 0.5 , mode = "gaussian" , sigma_scale = [ 1.0 , 1.0 ]
177- )( inputs , _Pred (). compute )
170+ result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "gaussian" , sigma_scale = [ 1.0 , 1.0 ])(
171+ inputs , _Pred (). compute
172+ )
178173 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
179174
180175 result = SlidingWindowHoVerNetInferer (
@@ -205,9 +200,7 @@ def compute(data):
205200 expected = np .ones ((1 , 1 , 3 , 3 )) * - 6.0
206201 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
207202
208- result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 )(
209- inputs , compute
210- )
203+ result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 )(inputs , compute )
211204 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
212205
213206 def test_args_kwargs (self ):
@@ -245,9 +238,9 @@ def compute(data, test1, test2):
245238 expected = np .ones ((1 , 1 , 3 , 3 )) + 2.0
246239 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
247240
248- result = SlidingWindowHoVerNetInferer (
249- roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 , progress = has_tqdm
250- )( inputs , compute , t1 , test2 = t2 )
241+ result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 , progress = has_tqdm )(
242+ inputs , compute , t1 , test2 = t2
243+ )
251244 np .testing .assert_allclose (result .cpu ().numpy (), expected , rtol = 1e-4 )
252245
253246 @parameterized .expand (TEST_CASES_MULTIOUTPUT )
@@ -287,9 +280,9 @@ def compute_dict(data):
287280 for rr , _ in zip (result_dict , expected_dict ):
288281 np .testing .assert_allclose (result_dict [rr ].cpu ().numpy (), expected_dict [rr ], rtol = 1e-4 )
289282
290- result = SlidingWindowHoVerNetInferer (
291- roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 , progress = has_tqdm
292- )( inputs , compute )
283+ result = SlidingWindowHoVerNetInferer (roi_shape , sw_batch_size , overlap = 0.5 , mode = "constant" , cval = - 1 , progress = has_tqdm )(
284+ inputs , compute
285+ )
293286 for rr , ee in zip (result , expected ):
294287 np .testing .assert_allclose (rr .cpu ().numpy (), ee , rtol = 1e-4 )
295288
0 commit comments