Skip to content

Commit 187c141

Browse files
committed
minor refactoring for typing
Signed-off-by: Arthur Dujardin <[email protected]>
1 parent 5509d98 commit 187c141

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

monai/data/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,12 @@ def decollate_batch(batch, detach: bool = True, pad=True, fill_value=None):
621621
"""
622622
if batch is None:
623623
return batch
624-
if isinstance(batch, (float, int, str, bytes)):
624+
if isinstance(batch, (float, int, str, bytes)) or (
625+
type(batch).__module__ == "numpy" and not isinstance(batch, Iterable)
626+
):
625627
return batch
626-
if type(batch).__module__ == "numpy":
627-
if not isinstance(batch, Iterable):
628-
return batch
629-
if batch.ndim == 0:
630-
return batch.item() if detach else batch
628+
if isinstance(batch, np.ndarray) and batch.ndim == 0:
629+
return batch.item() if detach else batch
631630
if isinstance(batch, torch.Tensor):
632631
if detach:
633632
batch = batch.detach()

0 commit comments

Comments
 (0)