Skip to content

Commit f9dba63

Browse files
committed
support decollate for numpy scalars
fix linter Signed-off-by: Arthur Dujardin <[email protected]> fix numpy decollate multi arrays Signed-off-by: Arthur Dujardin <[email protected]> fix linter Signed-off-by: Arthur Dujardin <[email protected]> fix numpy scalar support Signed-off-by: Arthur Dujardin <[email protected]> minor refactoring for typing Signed-off-by: Arthur Dujardin <[email protected]> convert scalar array to tensor Signed-off-by: Arthur Dujardin <[email protected]> update decollate item
1 parent f066edf commit f9dba63

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)