Skip to content

Commit

Permalink
Merge pull request #271 from bioimage-io/update-pred
Browse files Browse the repository at this point in the history
Updates to prediction functionality etc
  • Loading branch information
constantinpape authored May 29, 2022
2 parents f241d3a + 200ba09 commit 79c4d9f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bioimageio/core/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.5.3post2"
"version": "0.5.4"
}
3 changes: 2 additions & 1 deletion bioimageio/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
serialize_raw_resource_description,
)
from .prediction_pipeline import create_prediction_pipeline
from .prediction import predict_image, predict_images
from .prediction import predict_image, predict_images, predict_with_padding, predict_with_tiling
from .resource_tests import check_input_shape, check_output_shape, test_resource
4 changes: 2 additions & 2 deletions bioimageio/core/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def check_padding(padding):
def predict_with_padding(
prediction_pipeline: PredictionPipeline,
inputs: Union[xr.DataArray, List[xr.DataArray], Tuple[xr.DataArray]],
padding: Union[bool, Dict[str, int]],
padding: Union[bool, Dict[str, int]] = True,
pad_right: bool = True,
) -> List[xr.DataArray]:
"""Run prediction with padding for a single set of input(s) with a bioimage.io model.
Expand Down Expand Up @@ -305,7 +305,7 @@ def check_tiling(tiling):
def predict_with_tiling(
prediction_pipeline: PredictionPipeline,
inputs: Union[xr.DataArray, List[xr.DataArray], Tuple[xr.DataArray]],
tiling: Union[bool, Dict[str, Dict[str, int]]],
tiling: Union[bool, Dict[str, Dict[str, int]]] = True,
verbose: bool = False,
) -> List[xr.DataArray]:
"""Run prediction with tiling for a single set of input(s) with a bioimage.io model.
Expand Down
8 changes: 4 additions & 4 deletions bioimageio/core/resource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_model(
)


def _validate_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
def check_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
if isinstance(shape_spec, list):
if shape != tuple(shape_spec):
return False
Expand All @@ -81,7 +81,7 @@ def _validate_input_shape(shape: Tuple[int, ...], shape_spec) -> bool:
return True


def _validate_output_shape(shape: Tuple[int, ...], shape_spec, input_shapes) -> bool:
def check_output_shape(shape: Tuple[int, ...], shape_spec, input_shapes) -> bool:
if isinstance(shape_spec, list):
return shape == tuple(shape_spec)
elif isinstance(shape_spec, ImplicitOutputShape):
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_resource(
assert len(inputs) == len(model.inputs) # should be checked by validation
input_shapes = {}
for idx, (ipt, ipt_spec) in enumerate(zip(inputs, model.inputs)):
if not _validate_input_shape(tuple(ipt.shape), ipt_spec.shape):
if not check_input_shape(tuple(ipt.shape), ipt_spec.shape):
raise ValidationError(
f"Shape {tuple(ipt.shape)} of test input {idx} '{ipt_spec.name}' does not match "
f"input shape description: {ipt_spec.shape}."
Expand All @@ -138,7 +138,7 @@ def test_resource(

assert len(expected) == len(model.outputs) # should be checked by validation
for idx, (out, out_spec) in enumerate(zip(expected, model.outputs)):
if not _validate_output_shape(tuple(out.shape), out_spec.shape, input_shapes):
if not check_output_shape(tuple(out.shape), out_spec.shape, input_shapes):
error = (error or "") + (
f"Shape {tuple(out.shape)} of test output {idx} '{out_spec.name}' does not match "
f"output shape description: {out_spec.shape}."
Expand Down

0 comments on commit 79c4d9f

Please sign in to comment.