Skip to content

Commit

Permalink
WIP add model_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Nov 20, 2023
1 parent 3e57ef4 commit 6c9bf0f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bioimageio/core/model_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from functools import singledispatch
from typing import Any, List, Union

import numpy as np
import xarray as xr
from numpy.typing import NDArray

from bioimageio.spec.model import v0_4, v0_5
from bioimageio.spec.utils import download

# @singledispatch
# def is_valid_tensor(description: object, tensor: Union[NDArray[Any], xr.DataArray]) -> bool:
# raise NotImplementedError(type(description))

# is_valid_tensor.register
# def _(description: v0_4.InputTensor, tensor: Union[NDArray[Any], xr.DataArray]):


@singledispatch
def get_test_input_tensors(model: object) -> List[xr.DataArray]:
raise NotImplementedError(type(model))


@get_test_input_tensors.register
def _(model: v0_4.Model):
data = [np.load(download(ipt).path) for ipt in model.test_inputs]
assert all(isinstance(d, np.ndarray) for d in data)


# @get_test_input_tensors.register
# def _(model: v0_5.Model):

0 comments on commit 6c9bf0f

Please sign in to comment.