Skip to content

Commit 02b3ab1

Browse files
Merge pull request #169 from bioimage-io/fix-deepij-conf
Fix issues with build_model with deepimagej config
2 parents 1fd5447 + 3ebd161 commit 02b3ab1

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

bioimageio/core/build_spec/build_model.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,19 @@ def _get_deepimagej_config(export_folder, sample_inputs, sample_outputs, pixel_s
323323

324324
if any(preproc is not None for preproc in preprocessing):
325325
assert len(preprocessing) == 1
326-
preprocess_ij = [_get_deepimagej_macro(name, kwargs) for name, kwargs in preprocessing[0].items()]
326+
preprocess_ij = [
327+
_get_deepimagej_macro(name, kwargs, export_folder) for name, kwargs in preprocessing[0].items()
328+
]
327329
attachments = [preproc["kwargs"] for preproc in preprocess_ij]
328330
else:
329331
preprocess_ij = [{"spec": None}]
330332
attachments = None
331333

332334
if any(postproc is not None for postproc in postprocessing):
333335
assert len(postprocessing) == 1
334-
postprocess_ij = [_get_deepimagej_macro(name, kwargs) for name, kwargs in postprocessing[0].items()]
336+
postprocess_ij = [
337+
_get_deepimagej_macro(name, kwargs, export_folder) for name, kwargs in postprocessing[0].items()
338+
]
335339
if attachments is None:
336340
attachments = [postproc["kwargs"] for postproc in postprocess_ij]
337341
else:
@@ -609,7 +613,7 @@ def build_model(
609613
else:
610614
assert len(pixel_sizes) == n_inputs
611615
for pix_size, axes in zip(pixel_sizes, spatial_axes):
612-
assert isinstance(pixel_sizes, dict)
616+
assert isinstance(pix_size, dict)
613617
assert set(pix_size.keys()) == set(axes)
614618

615619
#
@@ -730,17 +734,6 @@ def build_model(
730734
if tmp_source is not None:
731735
os.remove(tmp_source)
732736

733-
# breakpoint()
734-
# debugging: for some reason this causes a validation error for the sample_input / output,
735-
# although they are passed in the same format as test inputs / outputs:
736-
# (Pdb) model.sample_inputs
737-
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/sample_input_0.tif')]
738-
# (Pdb) model.sample_outputs
739-
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/sample_output_0.tif')]
740-
# (Pdb) model.test_inputs
741-
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/test_input.npy')]
742-
# (Pdb) model.test_outputs
743-
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/test_output.npy')]
744737
model = load_raw_resource_description(model_package)
745738
return model
746739

tests/build_spec/test_build_spec.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def _test_build_spec(
3636
dep_file = None if model_spec.dependencies is missing else resolve_source(model_spec.dependencies.file, root)
3737
authors = [{"name": auth.name, "affiliation": auth.affiliation} for auth in model_spec.authors]
3838
covers = resolve_source(model_spec.covers, root)
39+
preprocessing = [
40+
None if input_.preprocessing == missing else {preproc.name: preproc.kwargs for preproc in input_.preprocessing}
41+
for input_ in model_spec.inputs
42+
]
43+
postprocessing = [
44+
None if output.postprocessing == missing else {preproc.name: preproc.kwargs for preproc in output.preprocessing}
45+
for output in model_spec.outputs
46+
]
3947
kwargs = dict(
4048
source=model_source,
4149
model_kwargs=model_spec.kwargs,
@@ -53,6 +61,8 @@ def _test_build_spec(
5361
cite=cite,
5462
root=model_spec.root_path,
5563
weight_type=weight_type_,
64+
preprocessing=preprocessing,
65+
postprocessing=postprocessing,
5666
output_path=out_path,
5767
add_deepimagej_config=add_deepimagej_config,
5868
)
@@ -63,6 +73,8 @@ def _test_build_spec(
6373
kwargs["output_reference"] = ["input"]
6474
kwargs["output_scale"] = [[1.0, 1.0, 1.0, 1.0]]
6575
kwargs["output_offset"] = [[0.0, 0.0, 0.0, 0.0]]
76+
if add_deepimagej_config:
77+
kwargs["pixel_sizes"] = [{"x": 5.0, "y": 5.0}]
6678

6779
build_model(**kwargs)
6880
assert out_path.exists()

0 commit comments

Comments
 (0)