Skip to content

Commit 418c750

Browse files
authored
Merge pull request #359 from bioimage-io/fix-tiling
Fix critical bug in predict with tiling
2 parents cc6ff24 + 06c27fc commit 418c750

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

bioimageio/core/prediction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,16 @@ def check_tiling(tiling):
330330
# override metadata defaults with provided dict
331331
if isinstance(tiling, dict):
332332
for key in ["halo", "tile", "scale"]:
333-
default_tiling.update(tiling.get(key, dict()))
333+
default_tiling[key].update(tiling.get(key, dict()))
334334
tiling = default_tiling
335335
check_tiling(tiling)
336+
336337
elif isinstance(tiling, bool) and not tiling:
337338
raise NotImplementedError("Should be unreachable")
339+
338340
else:
339341
raise ValueError(f"Invalid argument for tiling: {tiling}")
342+
340343
return tiling
341344

342345

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
packages=find_namespace_packages(exclude=["tests"]), # Required
2828
install_requires=[
29-
"bioimageio.spec==0.4.9.*",
29+
"bioimageio.spec==0.4.9",
3030
"imageio>=2.5",
3131
"numpy",
3232
"ruamel.yaml",

tests/test_bioimageio_spec_version.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ def test_bioimageio_spec_version():
2626
# get currently pinned bioimageio.spec version
2727
meta = metadata("bioimageio.core")
2828
req = meta["Requires-Dist"]
29-
assert req.startswith("bioimageio.spec (==")
30-
pmaj, pmin, ppatch, *asterisk_and_rest = req[len("bioimageio.spec (==") :].split(".")
31-
assert asterisk_and_rest[0].startswith(
32-
"*"
33-
), "bioimageio.spec version should be pinned down to patch, e.g. '0.4.9.*'"
29+
print(req)
30+
assert req.startswith("bioimageio.spec ==")
31+
spec_ver = req[len("bioimageio.spec ==") :]
32+
assert spec_ver.count(".") == 2
33+
pmaj, pmin, ppatchand_and_post = spec_ver.split(".")
34+
assert (ppatchand_and_post.isdigit() or ppatchand_and_post[:-1].isdigit()) and (
35+
ppatchand_and_post[-1] == "*" or ppatchand_and_post[-1].isdigit()
36+
), "bioimageio.spec version should be pinned down to patch, e.g. '0.4.9*'"
37+
38+
ppatch = ppatchand_and_post[:-1] if ppatchand_and_post[-1] == "*" else ppatchand_and_post
3439
pinned = Version(f"{pmaj}.{pmin}.{ppatch}")
3540

3641
assert pinned >= released, "bioimageio.spec pinned to an old version!"

tests/test_prediction.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def check_result():
110110
check_result()
111111

112112
# test with fixed padding
113-
predict_image(
114-
model, in_path, out_path, padding={"x": original_shape[0], "y": original_shape[1], "mode": "fixed"}
115-
)
113+
predict_image(model, in_path, out_path, padding={"x": original_shape[0], "y": original_shape[1], "mode": "fixed"})
116114
check_result()
117115

118116
# test with automated padding
@@ -135,7 +133,7 @@ def test_predict_image_with_padding_channel_last(stardist, tmp_path):
135133
_test_predict_with_padding(stardist, tmp_path)
136134

137135

138-
def _test_predict_image_with_tiling(model, tmp_path, exp_mean_deviation):
136+
def _test_predict_image_with_tiling(model, tmp_path: Path, exp_mean_deviation):
139137
from bioimageio.core.prediction import predict_image
140138

141139
spec = load_resource_description(model)
@@ -168,27 +166,27 @@ def check_result():
168166

169167
# prediction with tiling with the parameters above may not be suited for any model
170168
# so we only run it for the pytorch unet2d here
171-
def test_predict_image_with_tiling_1(unet2d_nuclei_broad_model, tmp_path):
169+
def test_predict_image_with_tiling_1(unet2d_nuclei_broad_model, tmp_path: Path):
172170
_test_predict_image_with_tiling(unet2d_nuclei_broad_model, tmp_path, 0.012)
173171

174172

175-
def test_predict_image_with_tiling_2(unet2d_diff_output_shape, tmp_path):
176-
_test_predict_image_with_tiling(unet2d_diff_output_shape, tmp_path, 0.012)
173+
def test_predict_image_with_tiling_2(unet2d_diff_output_shape, tmp_path: Path):
174+
_test_predict_image_with_tiling(unet2d_diff_output_shape, tmp_path, 0.06)
177175

178176

179-
def test_predict_image_with_tiling_3(shape_change_model, tmp_path):
177+
def test_predict_image_with_tiling_3(shape_change_model, tmp_path: Path):
180178
_test_predict_image_with_tiling(shape_change_model, tmp_path, 0.012)
181179

182180

183-
def test_predict_image_with_tiling_channel_last(stardist, tmp_path):
181+
def test_predict_image_with_tiling_channel_last(stardist, tmp_path: Path):
184182
_test_predict_image_with_tiling(stardist, tmp_path, 0.13)
185183

186184

187-
def test_predict_image_with_tiling_fixed_output_shape(unet2d_fixed_shape, tmp_path):
185+
def test_predict_image_with_tiling_fixed_output_shape(unet2d_fixed_shape, tmp_path: Path):
188186
_test_predict_image_with_tiling(unet2d_fixed_shape, tmp_path, 0.025)
189187

190188

191-
def test_predict_images(unet2d_nuclei_broad_model, tmp_path):
189+
def test_predict_images(unet2d_nuclei_broad_model, tmp_path: Path):
192190
from bioimageio.core.prediction import predict_images
193191

194192
n_images = 5

0 commit comments

Comments
 (0)