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

Bugfix: make optional pre-/postprocessing kwargs truly optional #623

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ To keep the bioimageio.spec Python package version in sync with the (model) desc

### bioimageio.spec Python package

#### bioimageio.spec 0.5.3.3 (not yet released)

* bugfix: allow optional pre- and postprocessing to be missing in an RDF (before it required an empty dict).

#### bioimageio.spec 0.5.3.2

* bugfix "reset known files if root changes" (#619)
Expand Down
16 changes: 9 additions & 7 deletions bioimageio/spec/model/v0_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
cast,
)

import imageio
import numpy as np
from annotated_types import Ge, Gt, Interval, MaxLen, MinLen, Predicate
from imageio.v3 import imread # pyright: ignore[reportUnknownVariableType]
from imageio.v3 import imread, imwrite # pyright: ignore[reportUnknownVariableType]
from numpy.typing import NDArray
from pydantic import (
Discriminator,
Expand Down Expand Up @@ -1255,10 +1254,13 @@ class InputTensorDescr(TensorDescrBase[InputAxis]):
def _validate_preprocessing_kwargs(self) -> Self:
axes_ids = [a.id for a in self.axes]
for p in self.preprocessing:
kwargs_axes: Union[Any, Sequence[Any]] = p.kwargs.get("axes", ())
kwargs_axes: Union[Any, Sequence[Any]] = p.kwargs.get("axes")
if kwargs_axes is None:
continue

if not isinstance(kwargs_axes, collections.abc.Sequence):
raise ValueError(
f"Expeted `preprocessing.i.kwargs.axes` to be a sequence, but got {type(kwargs_axes)}"
f"Expected `preprocessing.i.kwargs.axes` to be a sequence, but got {type(kwargs_axes)}"
)

if any(a not in axes_ids for a in kwargs_axes):
Expand Down Expand Up @@ -2945,10 +2947,10 @@ def create_diagonal_split_image(im0: NDArray[Any], im1: NDArray[Any]):
cover_folder = Path(mkdtemp())
if ipt_img.shape == out_img.shape:
covers = [cover_folder / "cover.png"]
imageio.imwrite(covers[0], create_diagonal_split_image(ipt_img, out_img))
imwrite(covers[0], create_diagonal_split_image(ipt_img, out_img))
else:
covers = [cover_folder / "input.png", cover_folder / "output.png"]
imageio.imwrite(covers[0], ipt_img)
imageio.imwrite(covers[1], out_img)
imwrite(covers[0], ipt_img)
imwrite(covers[1], out_img)

return covers
1 change: 1 addition & 0 deletions bioimageio/spec/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def format_loc(loc: Loc):

return f"{info}{self._format_md_table(details)}"

# TODO: fix bug which casuses extensive white space between the info table and details table
@no_type_check
def display(self) -> None:
formatted = self.format()
Expand Down
Loading