Skip to content

Commit ecd2aab

Browse files
committed
WIP fix tests
1 parent 339d216 commit ecd2aab

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

bioimageio/core/digest_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ def _import_from_file_impl(
127127
)
128128

129129
if importlib_spec is None:
130-
raise ImportError(f"Failed to import {source}.")
130+
raise ImportError(f"Failed to import {source}")
131131

132132
module = importlib.util.module_from_spec(importlib_spec)
133133
assert importlib_spec.loader is not None
134134
importlib_spec.loader.exec_module(module)
135135

136136
except Exception as e:
137-
raise ImportError(f"Failed to import {source} .") from e
137+
raise ImportError(f"Failed to import {source}") from e
138138
else:
139139
sys.modules[module_name] = module # cache this module
140140

tests/test_bioimageio_collection.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import requests
55
from pydantic import HttpUrl
66

7-
from bioimageio.spec import InvalidDescr, ValidationContext
7+
from bioimageio.spec import InvalidDescr
88
from bioimageio.spec.common import Sha256
99
from tests.utils import ParameterSet, expensive_test
1010

@@ -42,25 +42,34 @@ def yield_bioimageio_yaml_urls() -> Iterable[ParameterSet]:
4242
"affable-shark/1.1", # onnx weights expect fixed input shape
4343
"affectionate-cow/0.1.0", # custom dependencies
4444
"ambitious-sloth/1.2", # requires inferno
45+
"committed-turkey/1.2", # error deserializing VarianceScaling
46+
"creative-panda/1", # error deserializing Conv2D
4547
"dazzling-spider/0.1.0", # requires careamics
46-
"dynamic-t-rex/1", # model.v0_4.ScaleLinearKwargs with axes
48+
"discreete-rooster/1", # error deserializing VarianceScaling
49+
"dynamic-t-rex/1", # needs update to 0.5 for scale_linear with axes processing
50+
"easy-going-sauropod/1", # CPU implementation of Conv3D currently only supports the NHWC tensor format.
4751
"efficient-chipmunk/1", # needs plantseg
4852
"famous-fish/0.1.0", # list index out of range `fl[3]`
4953
"greedy-whale/1", # batch size is actually limited to 1
5054
"happy-elephant/0.1.0", # list index out of range `fl[3]`
55+
"happy-honeybee/0.1.0", # requires biapy
56+
"heroic-otter/0.1.0", # requires biapy
5157
"humorous-crab/1", # batch size is actually limited to 1
5258
"humorous-fox/0.1.0", # requires careamics
5359
"humorous-owl/1", # error deserializing GlorotUniform
54-
"noisy-ox/1", # batch size is actually limited to 1
55-
"stupendous-sheep/1.2",
56-
"wild-rhino/0.1.0", # requires careamics
5760
"idealistic-turtle/0.1.0", # requires biapy
61+
"impartial-shark/1", # error deserializing VarianceScaling
5862
"intelligent-lion/0.1.0", # requires biapy
63+
"joyful-deer/1", # needs update to 0.5 for scale_linear with axes processing
5964
"merry-water-buffalo/0.1.0", # requires biapy
60-
"venomous-swan/0.1.0", # requires biapy
61-
"heroic-otter/0.1.0", # requires biapy
65+
"naked-microbe/1", # unknown layer Convolution2D
66+
"noisy-ox/1", # batch size is actually limited to 1
67+
"non-judgemental-eagle/1", # error deserializing GlorotUniform
68+
"straightforward-crocodile/1", # needs update to 0.5 for scale_linear with axes processing
6269
"stupendous-sheep/1.1", # requires relativ import of attachment
63-
"commited-turkey/1.2", # error deserializng VarianceScaling
70+
"stupendous-sheep/1.2",
71+
"venomous-swan/0.1.0", # requires biapy
72+
"wild-rhino/0.1.0", # requires careamics
6473
}
6574

6675

@@ -76,8 +85,7 @@ def test_rdf(
7685

7786
from bioimageio.core import load_description_and_test
7887

79-
with ValidationContext():
80-
descr = load_description_and_test(descr_url, sha256=sha, stop_early=True)
88+
descr = load_description_and_test(descr_url, sha256=sha, stop_early=True)
8189

8290
assert not isinstance(descr, InvalidDescr)
8391
assert (

tests/test_proc_ops.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ def tid():
2121
def test_scale_linear(tid: MemberId):
2222
from bioimageio.core.proc_ops import ScaleLinear
2323

24-
offset = xr.DataArray([1, 2, 42], dims=("c"))
25-
gain = xr.DataArray([1, 2, 3], dims=("c"))
26-
data = xr.DataArray(np.arange(6).reshape((1, 2, 3)), dims=("x", "y", "c"))
24+
offset = xr.DataArray([1, 2, 42], dims=("channel",))
25+
gain = xr.DataArray([1, 2, 3], dims=("channel",))
26+
data = xr.DataArray(np.arange(6).reshape((1, 2, 3)), dims=("x", "y", "channel"))
2727
sample = Sample(members={tid: Tensor.from_xarray(data)}, stat={}, id=None)
2828

2929
op = ScaleLinear(input=tid, output=tid, offset=offset, gain=gain)
3030
op(sample)
3131

32-
expected = xr.DataArray(np.array([[[1, 4, 48], [4, 10, 57]]]), dims=("x", "y", "c"))
32+
expected = xr.DataArray(
33+
np.array([[[1, 4, 48], [4, 10, 57]]]), dims=("x", "y", "channel")
34+
)
3335
xr.testing.assert_allclose(expected, sample.members[tid].data, rtol=1e-5, atol=1e-7)
3436

3537

@@ -84,10 +86,10 @@ def test_zero_mean_unit_variance_fixed(tid: MemberId):
8486
op = FixedZeroMeanUnitVariance(
8587
tid,
8688
tid,
87-
mean=xr.DataArray([3, 4, 5], dims=("c")),
88-
std=xr.DataArray([2.44948974, 2.44948974, 2.44948974], dims=("c")),
89+
mean=xr.DataArray([3, 4, 5], dims=("channel",)),
90+
std=xr.DataArray([2.44948974, 2.44948974, 2.44948974], dims=("channel",)),
8991
)
90-
data = xr.DataArray(np.arange(9).reshape((1, 3, 3)), dims=("b", "c", "x"))
92+
data = xr.DataArray(np.arange(9).reshape((1, 3, 3)), dims=("b", "channel", "x"))
9193
expected = xr.DataArray(
9294
np.array(
9395
[
@@ -124,7 +126,7 @@ def test_zero_mean_unit_variance_fixed2(tid: MemberId):
124126
def test_zero_mean_unit_across_axes(tid: MemberId):
125127
from bioimageio.core.proc_ops import ZeroMeanUnitVariance
126128

127-
data = xr.DataArray(np.arange(18).reshape((2, 3, 3)), dims=("c", "x", "y"))
129+
data = xr.DataArray(np.arange(18).reshape((2, 3, 3)), dims=("channel", "x", "y"))
128130

129131
op = ZeroMeanUnitVariance(
130132
tid,
@@ -136,7 +138,8 @@ def test_zero_mean_unit_across_axes(tid: MemberId):
136138
sample.stat = compute_measures(op.required_measures, [sample])
137139

138140
expected = xr.concat(
139-
[(data[i : i + 1] - data[i].mean()) / data[i].std() for i in range(2)], dim="c"
141+
[(data[i : i + 1] - data[i].mean()) / data[i].std() for i in range(2)],
142+
dim="channel",
140143
)
141144
op(sample)
142145
xr.testing.assert_allclose(expected, sample.members[tid].data, rtol=1e-5, atol=1e-7)
@@ -146,7 +149,7 @@ def test_binarize(tid: MemberId):
146149
from bioimageio.core.proc_ops import Binarize
147150

148151
op = Binarize(tid, tid, threshold=14)
149-
data = xr.DataArray(np.arange(30).reshape((2, 3, 5)), dims=("x", "y", "c"))
152+
data = xr.DataArray(np.arange(30).reshape((2, 3, 5)), dims=("x", "y", "channel"))
150153
sample = Sample(members={tid: Tensor.from_xarray(data)}, stat={}, id=None)
151154
expected = xr.zeros_like(data)
152155
expected[{"x": slice(1, None)}] = 1
@@ -158,7 +161,7 @@ def test_binarize2(tid: MemberId):
158161
from bioimageio.core.proc_ops import Binarize
159162

160163
shape = (3, 32, 32)
161-
axes = ("c", "y", "x")
164+
axes = ("channel", "y", "x")
162165
np_data = np.random.rand(*shape)
163166
data = xr.DataArray(np_data, dims=axes)
164167

@@ -188,7 +191,7 @@ def test_clip(tid: MemberId):
188191
def test_combination_of_op_steps_with_dims_specified(tid: MemberId):
189192
from bioimageio.core.proc_ops import ZeroMeanUnitVariance
190193

191-
data = xr.DataArray(np.arange(18).reshape((2, 3, 3)), dims=("c", "x", "y"))
194+
data = xr.DataArray(np.arange(18).reshape((2, 3, 3)), dims=("channel", "x", "y"))
192195
sample = Sample(members={tid: Tensor.from_xarray(data)}, stat={}, id=None)
193196
op = ZeroMeanUnitVariance(
194197
tid,
@@ -239,7 +242,7 @@ def test_scale_mean_variance(tid: MemberId, axes: Optional[Tuple[AxisId, ...]]):
239242
from bioimageio.core.proc_ops import ScaleMeanVariance
240243

241244
shape = (3, 32, 46)
242-
ipt_axes = ("c", "y", "x")
245+
ipt_axes = ("channel", "y", "x")
243246
np_data = np.random.rand(*shape)
244247
ipt_data = xr.DataArray(np_data, dims=ipt_axes)
245248
ref_data = xr.DataArray((np_data * 2) + 3, dims=ipt_axes)

0 commit comments

Comments
 (0)