Skip to content

Commit b7df6bc

Browse files
committed
Merge branch 'main' into extend_test_resources
# Conflicts: # bioimageio/core/resource_tests.py
2 parents 4640c78 + 78fa57f commit b7df6bc

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

bioimageio/core/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.5.3post2"
2+
"version": "0.5.5"
33
}

bioimageio/core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
serialize_raw_resource_description,
1212
)
1313
from .prediction_pipeline import create_prediction_pipeline
14-
from .prediction import predict_image, predict_images
14+
from .prediction import predict_image, predict_images, predict_with_padding, predict_with_tiling
15+
from .resource_tests import check_input_shape, check_output_shape, test_resource

bioimageio/core/build_spec/build_model.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import hashlib
33
import os
44
from pathlib import Path
5-
from typing import Any, Dict, List, Optional, Tuple, Union
5+
from typing import Any, Dict, List, Optional, Union
66
from warnings import warn
77

88
import imageio
99
import numpy as np
1010
import requests
11+
import tifffile
1112

1213
import bioimageio.spec as spec
1314
import bioimageio.spec.model as model_spec
@@ -21,12 +22,6 @@
2122
except ImportError:
2223
from typing_extensions import get_args # type: ignore
2324

24-
# need tifffile for writing the deepimagej config
25-
# we probably always have this, but wrap into an ImportGuard just in case
26-
try:
27-
import tifffile
28-
except ImportError:
29-
tifffile = None
3025

3126
#
3227
# utility functions to build the spec from python
@@ -419,35 +414,40 @@ def get_size(fname, axes):
419414

420415
def _write_sample_data(input_paths, output_paths, input_axes, output_axes, pixel_sizes, export_folder: Path):
421416
def write_im(path, im, axes, pixel_size=None):
422-
assert tifffile is not None, "need tifffile for writing deepimagej config"
423417
assert len(axes) == im.ndim, f"{len(axes), {im.ndim}}"
424418
assert im.ndim in (4, 5), f"{im.ndim}"
425419

426420
# convert the image to expects (Z)CYX axis order
427421
if im.ndim == 4:
428422
assert set(axes) == {"b", "x", "y", "c"}, f"{axes}"
429-
axes_ij = "cyxb"
423+
resolution_axes_ij = "cyxb"
430424
else:
431425
assert set(axes) == {"b", "x", "y", "z", "c"}, f"{axes}"
432-
axes_ij = "zcyxb"
426+
resolution_axes_ij = "bzcyx"
427+
428+
def addMissingAxes(im_axes):
429+
needed_axes = ["b", "c", "x", "y", "z", "s"]
430+
for ax in needed_axes:
431+
if ax not in im_axes:
432+
im_axes += ax
433+
return im_axes
434+
435+
axes_ij = "bzcyxs"
436+
# Expand the image to ImageJ dimensions
437+
im = np.expand_dims(im, axis=tuple(range(len(axes), len(axes_ij))))
433438

434-
axis_permutation = tuple(axes.index(ax) for ax in axes_ij)
439+
axis_permutation = tuple(addMissingAxes(axes).index(ax) for ax in axes_ij)
435440
im = im.transpose(axis_permutation)
436-
# expand to TZCYXS
437-
if len(axes_ij) == 4: # add singleton t and z axis
438-
im = im[None, None]
439-
else: # add singeton z axis
440-
im = im[None]
441441

442442
if pixel_size is None:
443443
resolution = None
444444
else:
445-
spatial_axes = list(set(axes_ij) - set("bc"))
446-
resolution = tuple(1.0 / pixel_size[ax] for ax in axes_ij if ax in spatial_axes)
445+
spatial_axes = list(set(resolution_axes_ij) - set("bc"))
446+
resolution = tuple(1.0 / pixel_size[ax] for ax in resolution_axes_ij if ax in spatial_axes)
447447
# does not work for double
448448
if np.dtype(im.dtype) == np.dtype("float64"):
449449
im = im.astype("float32")
450-
tifffile.imsave(path, im, imagej=True, resolution=resolution)
450+
tifffile.imwrite(path, im, imagej=True, resolution=resolution)
451451

452452
sample_in_paths = []
453453
for i, (in_path, axes) in enumerate(zip(input_paths, input_axes)):

bioimageio/core/prediction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def check_padding(padding):
186186
def predict_with_padding(
187187
prediction_pipeline: PredictionPipeline,
188188
inputs: Union[xr.DataArray, List[xr.DataArray], Tuple[xr.DataArray]],
189-
padding: Union[bool, Dict[str, int]],
189+
padding: Union[bool, Dict[str, int]] = True,
190190
pad_right: bool = True,
191191
) -> List[xr.DataArray]:
192192
"""Run prediction with padding for a single set of input(s) with a bioimage.io model.
@@ -308,7 +308,7 @@ def check_tiling(tiling):
308308
def predict_with_tiling(
309309
prediction_pipeline: PredictionPipeline,
310310
inputs: Union[xr.DataArray, List[xr.DataArray], Tuple[xr.DataArray]],
311-
tiling: Union[bool, Dict[str, Dict[str, int]]],
311+
tiling: Union[bool, Dict[str, Dict[str, int]]] = True,
312312
verbose: bool = False,
313313
) -> List[xr.DataArray]:
314314
"""Run prediction with tiling for a single set of input(s) with a bioimage.io model.

bioimageio/core/resource_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_model(
4141
)
4242

4343

44-
def _validate_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
44+
def check_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
4545
if isinstance(shape_spec, list):
4646
if shape != tuple(shape_spec):
4747
return False
@@ -62,7 +62,7 @@ def _validate_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
6262
return True
6363

6464

65-
def _validate_output_shape(shape: Tuple[int, ...], shape_spec, input_shapes) -> bool:
65+
def check_output_shape(shape: Tuple[int, ...], shape_spec, input_shapes) -> bool:
6666
if isinstance(shape_spec, list):
6767
return shape == tuple(shape_spec)
6868
elif isinstance(shape_spec, ImplicitOutputShape):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"ruamel.yaml",
3333
"tqdm",
3434
"xarray",
35-
"tifffile<=2022.4.8", # fixes Syntax error; see https://github.com/bioimage-io/core-bioimage-io-python/pull/259
35+
"tifffile"
3636
],
3737
include_package_data=True,
3838
extras_require={

0 commit comments

Comments
 (0)