Skip to content

Commit 0cc0539

Browse files
committed
resolve data dep size when adding data to MetaBlock
1 parent 5dc6b3a commit 0cc0539

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

bioimageio/core/block.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Halo,
1717
HaloLike,
1818
PadMode,
19+
SliceInfo,
1920
TotalNumberOfBlocks,
2021
)
2122
from .tensor import Tensor
@@ -34,6 +35,7 @@ def inner_data(self):
3435

3536
def __post_init__(self):
3637
super().__post_init__()
38+
assert not any(v == -1 for v in self.sample_shape.values()), self.sample_shape
3739
for a, s in self.data.sizes.items():
3840
slice_ = self.inner_slice[a]
3941
halo = self.halo.get(a, Halo(0, 0))
@@ -65,6 +67,27 @@ def get_transformed(
6567
) -> Self:
6668
raise NotImplementedError
6769

70+
@classmethod
71+
def from_meta(cls, meta: BlockMeta, data: Tensor) -> Self:
72+
return cls(
73+
sample_shape={
74+
k: data.tagged_shape[k] if v == -1 else v
75+
for k, v in meta.sample_shape.items()
76+
},
77+
inner_slice={
78+
k: (
79+
SliceInfo(start=v.start, stop=data.tagged_shape[k])
80+
if v.stop == -1
81+
else v
82+
)
83+
for k, v in meta.inner_slice.items()
84+
},
85+
halo=meta.halo,
86+
block_index=meta.block_index,
87+
blocks_in_sample=meta.blocks_in_sample,
88+
data=data,
89+
)
90+
6891

6992
def split_tensor_into_blocks(
7093
tensor: Tensor,

bioimageio/core/sample.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,7 @@ def with_data(self, data: PerMember[Tensor], *, stat: Stat) -> SampleBlock:
254254
sample_shape=self.sample_shape,
255255
sample_id=self.sample_id,
256256
blocks={
257-
m: Block(
258-
sample_shape=self.sample_shape[m],
259-
inner_slice=b.inner_slice,
260-
halo=b.halo,
261-
block_index=b.block_index,
262-
blocks_in_sample=b.blocks_in_sample,
263-
data=data[m],
264-
)
265-
for m, b in self.blocks.items()
257+
m: Block.from_meta(b, data=data[m]) for m, b in self.blocks.items()
266258
},
267259
stat=stat,
268260
block_index=self.block_index,

0 commit comments

Comments
 (0)