Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,12 @@ def decollate_batch(batch, detach: bool = True, pad=True, fill_value=None):
type(batch).__module__ == "numpy" and not isinstance(batch, Iterable)
):
return batch
# if scalar tensor/array, return the item itself.
if getattr(batch, "ndim", -1) == 0 and hasattr(batch, "item"):
return batch.item() if detach else batch
if isinstance(batch, torch.Tensor):
if detach:
batch = batch.detach()
if batch.ndim == 0:
return batch.item() if detach else batch
out_list = torch.unbind(batch, dim=0)
# if of type MetaObj, decollate the metadata
if isinstance(batch, MetaObj):
Expand Down
Loading