MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / collate_meta_tensor

Function collate_meta_tensor

monai/data/utils.py:438–452  ·  view source on GitHub ↗

collate a sequence of meta tensor sequences/dictionaries into a single batched metatensor or a dictionary of batched metatensor

(batch)

Source from the content-addressed store, hash-verified

436
437
438def collate_meta_tensor(batch):
439 """collate a sequence of meta tensor sequences/dictionaries into
440 a single batched metatensor or a dictionary of batched metatensor"""
441 if not isinstance(batch, Sequence):
442 raise NotImplementedError()
443 elem_0 = first(batch)
444 if isinstance(elem_0, MetaObj):
445 return collate_meta_tensor_fn(batch)
446 if isinstance(elem_0, Mapping):
447 return {k: collate_meta_tensor([d[k] for d in batch]) for k in elem_0}
448 if isinstance(elem_0, (tuple, list)):
449 return [collate_meta_tensor([d[i] for d in batch]) for i in range(len(elem_0))]
450
451 # no more recursive search for MetaTensor
452 return default_collate(batch)
453
454
455def list_data_collate(batch: Sequence):

Callers

nothing calls this directly

Calls 2

firstFunction · 0.90
collate_meta_tensor_fnFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…