Skip to content

Commit

Permalink
attempt at mode check in one class
Browse files Browse the repository at this point in the history
  • Loading branch information
ctr26 committed Nov 16, 2023
1 parent 7b86d31 commit a946b1f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bioimageio/spec/model/v0_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ class ZeroMeanUnitVarianceKwargs(ProcessingKwargs):
eps: Annotated[float, Interval(gt=0, le=0.1)] = 1e-6
"""epsilon for numeric stability: `out = (tensor - mean) / (std + eps)`."""

@model_validator(mode="after")
def validate_axes_based_on_mode(self)-> Self:
mode = self.mode
axes = self.axes

if mode == "per_sample":
# In 'per_sample' mode, ensure batch axis is not included in 'axes'
if axes and 'batch' in axes:
raise ValueError("Batch axis should not be included in 'axes' for 'per_sample' mode.")
elif mode == "per_dataset":
# In 'per_dataset' mode, check if batch axis handling is appropriate
# Implement any specific logic you need here
if axes and 'batch' not in axes:
raise ValueError("Batch axis must be included in 'axes' for 'per_dataset' mode.")
return self


class ZeroMeanUnitVariance(ProcessingBase):
"""Subtract mean and divide by variance."""
Expand Down

0 comments on commit a946b1f

Please sign in to comment.