core-bioimage-io-python icon indicating copy to clipboard operation
core-bioimage-io-python copied to clipboard

New predict command: how to pass input_block_shape?

Open constantinpape opened this issue 1 year ago • 3 comments

It's unclear how to pass the value for input_block_shape in order to specify a fixed tiling shape. The code

import bioimageio.core
import imageio.v3 as imageio
from xarray import DataArray

# For a reproducible example you can use the model test inputs.
# (I cannot easily figure out how to load them from the model ...)
image = imageio.imread("/home/pape/.cache/micro_sam/sample_data/livecell-2d-image.png")
model = bioimageio.core.load_description("hiding-tiger")

inputs = {model.inputs[0].name: DataArray(image[None, None], dims=("batch", "channel", "y", "x"))}

tile_shape = {"y": 512, "x": 512}
pred = bioimageio.core.predict(model=model, inputs=inputs, input_block_shape=tile_shape)

fails with

Traceback (most recent call last):
  File "/home/pape/Work/playground/bioimageio/new-pred/check_new_pred.py", line 13, in <module>
    pred = bioimageio.core.predict(model=model, inputs=inputs, input_block_shape=tile_shape)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape/Work/bioimageio/core-bioimage-io-python/bioimageio/core/prediction.py", line 100, in predict
    output = pp.predict_sample_with_fixed_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape/Work/bioimageio/core-bioimage-io-python/bioimageio/core/_prediction_pipeline.py", line 193, in predict_sample_with_fixed_blocking
    n_blocks, input_blocks = sample.split_into_blocks(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pape/Work/bioimageio/core-bioimage-io-python/bioimageio/core/sample.py", line 68, in split_into_blocks
    assert not (

constantinpape avatar Aug 22 '24 14:08 constantinpape