Skip to content

Commit c7480ee

Browse files
Update tests WIP
1 parent a8cff5e commit c7480ee

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

tests/test_prediction.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ def test_predict_image_with_weight_format(unet2d_fixed_shape_or_not, tmpdir):
5757
assert_array_almost_equal(res, exp, decimal=4)
5858

5959

60-
def test_predict_image_with_padding(unet2d_fixed_shape_or_not, tmp_path):
61-
any_model = unet2d_fixed_shape_or_not # todo: replace 'unet2d_fixed_shape_or_not' with 'any_model'
60+
def _test_predict_with_padding(model, tmp_path):
6261
from bioimageio.core.prediction import predict_image
6362

64-
spec = load_resource_description(any_model)
63+
spec = load_resource_description(model)
6564
assert isinstance(spec, Model)
6665
image = np.load(str(spec.test_inputs[0]))[0, 0]
6766
original_shape = image.shape
@@ -79,24 +78,35 @@ def check_result():
7978
assert res.shape == image.shape
8079

8180
# test with dynamic padding
82-
predict_image(any_model, in_path, out_path, padding={"x": 8, "y": 8, "mode": "dynamic"})
81+
predict_image(model, in_path, out_path, padding={"x": 8, "y": 8, "mode": "dynamic"})
8382
check_result()
8483

8584
# test with fixed padding
8685
predict_image(
87-
any_model, in_path, out_path, padding={"x": original_shape[0], "y": original_shape[1], "mode": "fixed"}
86+
model, in_path, out_path, padding={"x": original_shape[0], "y": original_shape[1], "mode": "fixed"}
8887
)
8988
check_result()
9089

9190
# test with automated padding
92-
predict_image(any_model, in_path, out_path, padding=True)
91+
predict_image(model, in_path, out_path, padding=True)
9392
check_result()
9493

9594

96-
def test_predict_image_with_tiling(unet2d_nuclei_broad_model, tmp_path):
95+
# prediction with padding with the parameters above may not be suted for any model
96+
# so we only run it for the pytorch unet2d here
97+
def test_predict_image_with_padding(unet2d_fixed_shape_or_not, tmp_path):
98+
_test_predict_with_padding(unet2d_fixed_shape_or_not, tmp_path)
99+
100+
101+
# TODO need stardist model
102+
# def test_predict_image_with_padding_channel_last(stardist_model, tmp_path):
103+
# _test_predict_with_padding(stardist_model, tmp_path)
104+
105+
106+
def _test_predict_image_with_tiling(model, tmp_path):
97107
from bioimageio.core.prediction import predict_image
98108

99-
spec = load_resource_description(unet2d_nuclei_broad_model)
109+
spec = load_resource_description(model)
100110
assert isinstance(spec, Model)
101111
inputs = spec.test_inputs
102112
assert len(inputs) == 1
@@ -114,14 +124,23 @@ def check_result():
114124

115125
# with tiling config
116126
tiling = {"halo": {"x": 32, "y": 32}, "tile": {"x": 256, "y": 256}}
117-
predict_image(unet2d_nuclei_broad_model, inputs, [out_path], tiling=tiling)
127+
predict_image(model, inputs, [out_path], tiling=tiling)
118128
check_result()
119129

120130
# with tiling determined from spec
121-
predict_image(unet2d_nuclei_broad_model, inputs, [out_path], tiling=True)
131+
predict_image(model, inputs, [out_path], tiling=True)
122132
check_result()
123133

124134

135+
def test_predict_image_with_tiling(unet2d_nuclei_broad_model, tmp_path):
136+
_test_predict_image_with_tiling(unet2d_nuclei_broad_model, tmp_path)
137+
138+
139+
# TODO need stardist model
140+
# def test_predict_image_with_tiling_channel_last(stardist_model, tmp_path):
141+
# _test_predict_image_with_tiling(stardist_model, tmp_path)
142+
143+
125144
def test_predict_images(unet2d_nuclei_broad_model, tmp_path):
126145
from bioimageio.core.prediction import predict_images
127146

0 commit comments

Comments
 (0)