Skip to content

Commit 1e0a554

Browse files
committed
Support decollate for numpy scalars
Signed-off-by: Arthur Dujardin <arthurdujardin.dev@gmail.com>
1 parent c3a317d commit 1e0a554

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

monai/data/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ def decollate_batch(batch, detach: bool = True, pad=True, fill_value=None):
625625
type(batch).__module__ == "numpy" and not isinstance(batch, Iterable)
626626
):
627627
return batch
628+
if getattr(batch, "ndim", -1) == 0 and hasattr(batch, "item"):
629+
return batch.item() if detach else batch
628630
if isinstance(batch, torch.Tensor):
629631
if detach:
630632
batch = batch.detach()

0 commit comments

Comments
 (0)