Skip to content

Commit 55ed672

Browse files
Merge pull request #193 from bioimage-io/cosmetics
Update prediction with tiling
2 parents 4ba2e2c + 491f675 commit 55ed672

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

bioimageio/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
save_raw_resource_description,
1111
serialize_raw_resource_description,
1212
)
13+
from .prediction_pipeline import create_prediction_pipeline
14+
from .prediction import predict_image, predict_images

bioimageio/core/prediction.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def _predict_with_tiling_impl(
197197
outputs: List[xr.DataArray],
198198
tile_shapes: List[dict],
199199
halos: List[dict],
200+
verbose: bool = False,
200201
):
201202
if len(inputs) > 1:
202203
raise NotImplementedError("Tiling with multiple inputs not implemented yet")
@@ -224,6 +225,11 @@ def load_tile(tile):
224225
pad_right = [tile[ax].start == 0 if ax in "xyz" else None for ax in input_axes]
225226
return inp, pad_right
226227

228+
if verbose:
229+
shape = {ax: sh for ax, sh in zip(prediction_pipeline.input_specs[0].axes, input_.shape)}
230+
n_tiles = int(np.prod([np.ceil(float(shape[ax]) / tsh) for ax, tsh in tile_shape.items()]))
231+
tiles = tqdm(tiles, total=n_tiles, desc="prediction with tiling")
232+
227233
# we need to use padded prediction for the individual tiles in case the
228234
# border tiles don't match the requested tile shape
229235
padding = {ax: tile_shape[ax] + 2 * halo[ax] for ax in input_axes if ax in "xyz"}
@@ -400,13 +406,15 @@ def predict_with_tiling(
400406
prediction_pipeline: PredictionPipeline,
401407
inputs: Union[xr.DataArray, List[xr.DataArray], Tuple[xr.DataArray]],
402408
tiling: Union[bool, Dict[str, Dict[str, int]]],
409+
verbose: bool = False,
403410
) -> List[xr.DataArray]:
404411
"""Run prediction with tiling for a single set of input(s) with a bioimage.io model.
405412
406413
Args:
407414
prediction_pipeline: the prediction pipeline for the input model.
408415
inputs: the input(s) for this model represented as xarray data.
409416
tiling: the tiling settings. Pass True to derive from the model spec.
417+
verbose: whether to print the prediction progress.
410418
"""
411419
if not tiling:
412420
raise ValueError
@@ -451,6 +459,7 @@ def predict_with_tiling(
451459
outputs,
452460
tile_shapes=[tiling["tile"]], # todo: update tiling for multiple inputs/outputs
453461
halos=[tiling["halo"]],
462+
verbose=verbose,
454463
)
455464

456465
return outputs

0 commit comments

Comments
 (0)