Skip to content

Commit

Permalink
Merge pull request #385 from bioimage-io/fix_data_dep_size
Browse files Browse the repository at this point in the history
Fix data dep size
  • Loading branch information
FynnBe authored Apr 30, 2024
2 parents 5dc6b3a + 4137282 commit 92e8f43
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.idea/
.tox/
*.egg-info/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ The model specification and its validation tools can be found at <https://github

## Changelog

### 0.6.2

* Fix [#384](https://github.com/bioimage-io/core-bioimage-io-python/issues/384)

### 0.6.1

* Fix [#378](https://github.com/bioimage-io/core-bioimage-io-python/pull/378) (with [#379](https://github.com/bioimage-io/core-bioimage-io-python/pull/379))*
Expand Down
2 changes: 1 addition & 1 deletion bioimageio/core/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.6.1"
"version": "0.6.2"
}
23 changes: 23 additions & 0 deletions bioimageio/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Halo,
HaloLike,
PadMode,
SliceInfo,
TotalNumberOfBlocks,
)
from .tensor import Tensor
Expand All @@ -34,6 +35,7 @@ def inner_data(self):

def __post_init__(self):
super().__post_init__()
assert not any(v == -1 for v in self.sample_shape.values()), self.sample_shape
for a, s in self.data.sizes.items():
slice_ = self.inner_slice[a]
halo = self.halo.get(a, Halo(0, 0))
Expand Down Expand Up @@ -65,6 +67,27 @@ def get_transformed(
) -> Self:
raise NotImplementedError

@classmethod
def from_meta(cls, meta: BlockMeta, data: Tensor) -> Self:
return cls(
sample_shape={
k: data.tagged_shape[k] if v == -1 else v
for k, v in meta.sample_shape.items()
},
inner_slice={
k: (
SliceInfo(start=v.start, stop=data.tagged_shape[k])
if v.stop == -1
else v
)
for k, v in meta.inner_slice.items()
},
halo=meta.halo,
block_index=meta.block_index,
blocks_in_sample=meta.blocks_in_sample,
data=data,
)


def split_tensor_into_blocks(
tensor: Tensor,
Expand Down
18 changes: 8 additions & 10 deletions bioimageio/core/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,16 @@ def get_member_halo(m: MemberId, round: Callable[[float], int]):

def with_data(self, data: PerMember[Tensor], *, stat: Stat) -> SampleBlock:
return SampleBlock(
sample_shape=self.sample_shape,
sample_shape={
m: {
a: data[m].tagged_shape[a] if s == -1 else s
for a, s in member_shape.items()
}
for m, member_shape in self.sample_shape.items()
},
sample_id=self.sample_id,
blocks={
m: Block(
sample_shape=self.sample_shape[m],
inner_slice=b.inner_slice,
halo=b.halo,
block_index=b.block_index,
blocks_in_sample=b.blocks_in_sample,
data=data[m],
)
for m, b in self.blocks.items()
m: Block.from_meta(b, data=data[m]) for m, b in self.blocks.items()
},
stat=stat,
block_index=self.block_index,
Expand Down

0 comments on commit 92e8f43

Please sign in to comment.