Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New predict command: how to pass input_block_shape? #414

Open
constantinpape opened this issue Aug 22, 2024 · 3 comments
Open

New predict command: how to pass input_block_shape? #414

constantinpape opened this issue Aug 22, 2024 · 3 comments
Assignees

Comments

@constantinpape
Copy link
Contributor

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 (
@FynnBe
Copy link
Member

FynnBe commented Aug 23, 2024

input_block_shape is annotated as Mapping[MemberId, Mapping[AxisId, int]]
so it expects {'input0': {AxisId("x"): 512, AxisId("y"): 512}}

I think we should improve handing of this argument in two ways:

  1. accept AxisLike axis ids (such that "x" would be a valid axis identifier as well)
  2. consider resolving unambiguous associations of axis ids to their input tensor ids, such that you attempted input would become valid

@constantinpape
Copy link
Contributor Author

I see. It works with {'input0': {AxisId("x"): 512, AxisId("y"): 512}}. (But then runs into other issues, I am gonna open another issue).

We can move ahead with this for now, but longer term I think we need to either:

  • simplify this (and other arguments) so that elementary python types are accepted
  • provide an extremely good documentation

otherwise I don't see much hope of any outside users picking this up ...

@FynnBe
Copy link
Member

FynnBe commented Aug 23, 2024

yes, we should make the API a bit more forgiving to improve user experience, as well as continue to expand the documentation 👍

Let's keep this issue open until at least the input arguments to predict allow for simple python types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants