Skip to content

Commit 662c33c

Browse files
Merge pull request #486 from bioimage-io/fix_processing
Fix processing kwargs
2 parents f490d72 + 3a9b2eb commit 662c33c

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ As a dependency it is included in [bioimageio.core](https://github.com/bioimage-
147147
| BIOIMAGEIO_CACHE_WARNINGS_LIMIT | "3" | Maximum number of warnings generated for simple cache hits. |
148148
149149
## Changelog
150+
#### bioimageio.spec tbd
151+
- make pre-/postprocessing kwargs `mode` and `axes` always optional for model RDF 0.3 and 0.4
152+
150153
#### bioimageio.spec 0.4.8post1
151154
- add `axes` and `eps` to `scale_mean_var`
152155

bioimageio/spec/model/v0_3/schema.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def validate_processing_kwargs(self, data, **kwargs):
7171
axes = data["axes"]
7272
processing_list = data.get(self.processing_name, [])
7373
for processing in processing_list:
74-
name = processing.name
7574
kwargs = processing.kwargs or {}
7675
kwarg_axes = kwargs.get("axes", "")
7776
if any(a not in axes for a in kwarg_axes):
@@ -94,17 +93,22 @@ class clip(SharedProcessingSchema):
9493
class scale_linear(SharedProcessingSchema):
9594
bioimageio_description = "Fixed linear scaling."
9695
axes = fields.Axes(
97-
required=True,
9896
valid_axes="czyx",
9997
bioimageio_description="The subset of axes to scale jointly. "
10098
"For example xy to scale the two image axes for 2d data jointly. "
10199
"The batch axis (b) is not valid here.",
102100
)
103101
gain = fields.Array(
104-
fields.Float(), missing=fields.Float(missing=1.0), bioimageio_description="multiplicative factor"
102+
fields.Float(),
103+
bioimageio_maybe_required=True,
104+
missing=fields.Float(missing=1.0),
105+
bioimageio_description="multiplicative factor",
105106
) # todo: check if gain match input axes
106107
offset = fields.Array(
107-
fields.Float(), missing=fields.Float(missing=0.0), bioimageio_description="additive term"
108+
fields.Float(),
109+
bioimageio_maybe_required=True,
110+
missing=fields.Float(missing=0.0),
111+
bioimageio_description="additive term",
108112
) # todo: check if offset match input axes
109113

110114
@validates_schema
@@ -140,9 +144,8 @@ class sigmoid(SharedProcessingSchema):
140144

141145
class zero_mean_unit_variance(SharedProcessingSchema):
142146
bioimageio_description = "Subtract mean and divide by variance."
143-
mode = fields.ProcMode(required=True)
147+
mode = fields.ProcMode()
144148
axes = fields.Axes(
145-
required=True,
146149
valid_axes="czyx",
147150
bioimageio_description="The subset of axes to normalize jointly. For example xy to normalize the two image "
148151
"axes for 2d data jointly. The batch axis (b) is not valid here.",
@@ -164,12 +167,12 @@ class zero_mean_unit_variance(SharedProcessingSchema):
164167

165168
@validates_schema
166169
def mean_and_std_match_mode(self, data, **kwargs):
167-
if data["mode"] == "fixed" and ("mean" not in data or "std" not in data):
170+
if data.get("mode", "fixed") == "fixed" and ("mean" not in data or "std" not in data):
168171
raise ValidationError(
169172
"`kwargs` for 'zero_mean_unit_variance' preprocessing with `mode` 'fixed' require additional "
170173
"`kwargs`: `mean` and `std`."
171174
)
172-
elif data["mode"] != "fixed" and ("mean" in data or "std" in data):
175+
elif data.get("mode", "fixed") != "fixed" and ("mean" in data or "std" in data):
173176
raise ValidationError(
174177
"`kwargs`: `mean` and `std` for 'zero_mean_unit_variance' preprocessing are only valid for `mode` 'fixed'."
175178
)
@@ -189,9 +192,8 @@ class Preprocessing(Processing):
189192

190193
class scale_range(SharedProcessingSchema):
191194
bioimageio_description = "Scale with percentiles."
192-
mode = fields.ProcMode(required=True, valid_modes=("per_dataset", "per_sample"))
195+
mode = fields.ProcMode(valid_modes=("per_dataset", "per_sample"))
193196
axes = fields.Axes(
194-
required=True,
195197
valid_axes="czyx",
196198
bioimageio_description="The subset of axes to normalize jointly. For example xy to normalize the two image "
197199
"axes for 2d data jointly. The batch axis (b) is not valid here.",
@@ -245,7 +247,7 @@ class scale_range(Preprocessing.scale_range):
245247

246248
class scale_mean_variance(SharedProcessingSchema):
247249
bioimageio_description = "Scale the tensor s.t. its mean and variance match a reference tensor."
248-
mode = fields.ProcMode(required=True, valid_modes=("per_dataset", "per_sample"))
250+
mode = fields.ProcMode(valid_modes=("per_dataset", "per_sample"))
249251
reference_tensor = fields.String(
250252
required=True,
251253
validate=field_validators.Predicate("isidentifier"),

bioimageio/spec/shared/schema.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ def warn(self, field: str, msg: str):
4949
class SharedProcessingSchema(Schema):
5050
"""Used to generate Pre- and Postprocessing documentation.
5151
52-
Define Pre-/Postprocessing schemas in the Preprocessing/Postprocessing schema that inherite from this class
53-
and they will be rendered in the documentation."""
52+
Define Pre-/Postprocessing operator schemas in the Preprocessing/Postprocessing schema that inherit from this class,
53+
and they will be rendered in the documentation (scripts/generate_processing_docs.py).
54+
55+
example: bioimageio.spec.model.v0_3.schema.Processing.binarize
56+
"""
5457

5558
bioimageio_description: ClassVar[str]
5659

0 commit comments

Comments
 (0)