bioimage-io / spec-bioimage-io

Specification for the bioimage.io model description file.
https://bioimage-io.github.io/spec-bioimage-io/
MIT License
18 stars 16 forks source link

Creation of processing operations #588

Closed constantinpape closed 4 months ago

constantinpape commented 4 months ago

The creation of (Pre)processing descriptions does not work as I would expect it.

I would expect the following code to work:

from bioimageio.spec.model.v0_5 import ScaleLinearDescr
from bioimageio.spec.model.v0_5 import ZeroMeanUnitVarianceDescr

# THIS WORKS
ScaleLinearDescr(kwargs={"gain": 1.1, "offset": 0.0})

# THIS FAILS
ZeroMeanUnitVarianceDescr(kwargs={"mode": "per_sample", "axes": "cyx", "mean": None, "std": None})

However, only the ScaleLinearDescr works.

ZeroMeanUnitVarianceDescr fails with these validation errors:

Traceback (most recent call last):
  File "/home/pape/Work/my_projects/torch-em/mre.py", line 8, in <module>
    ZeroMeanUnitVarianceDescr(kwargs={"mode": "per_sample", "axes": "cyx", "mean": None, "std": None})
  File "/home/pape/micromamba/envs/main/lib/python3.11/site-packages/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 4 validation errors for ZeroMeanUnitVarianceDescr
kwargs.axes
  'str' instances are not allowed as a Sequence value [type=sequence_str, input_value='cyx', input_type=str]
kwargs.mode
  Extra inputs are not permitted [type=extra_forbidden, input_value='per_sample', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden
kwargs.mean
  Extra inputs are not permitted [type=extra_forbidden, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden
kwargs.std
  Extra inputs are not permitted [type=extra_forbidden, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden

It's unclear to me why this fails since all these values should be valid according to https://github.com/bioimage-io/spec-bioimage-io/blob/main/bioimageio/spec/model/v0_4.py#L599 .

FynnBe commented 4 months ago

It's unclear to me why this fails since all these values should be valid according to https://github.com/bioimage-io/spec-bioimage-io/blob/main/bioimageio/spec/model/v0_4.py#L599 .

the docstring you're referring to is in model v0.4

In model v0.5 v0_4.ZeroMeanUnitVarianceDescr was split up into ZeroMeanUnitVarianceDescr that does not allow (fixed) mean and std values (use FixedZeroMeanUnitVarianceDescr or ScaleLinearDescr instead). Furthermore mode was removed and instead axes may or may not contain the batch axis, see https://github.com/bioimage-io/spec-bioimage-io/blob/0debec1daefdbbf01a1e609f2d5e48221972428a/bioimageio/spec/model/v0_5.py#L939-L946

Also note that the default channel axis id is now 'channel', if you haven't changed that "axes": "cyx" will also be invalid. (should be ('channel', 'y', 'x') instead)

constantinpape commented 4 months ago

Ok, that fixes it. Thanks!