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

Function collate_meta_tensor_fn

monai/data/utils.py:419–435  ·  view source on GitHub ↗

Collate a sequence of meta tensor into a single batched metatensor. This is called by `collage_meta_tensor` and so should not be used as a collate function directly in dataloaders.

(batch, *, collate_fn_map=None)

Source from the content-addressed store, hash-verified

417
418
419def collate_meta_tensor_fn(batch, *, collate_fn_map=None):
420 """
421 Collate a sequence of meta tensor into a single batched metatensor. This is called by `collage_meta_tensor`
422 and so should not be used as a collate function directly in dataloaders.
423 """
424 from torch.utils.data._utils.collate import collate_tensor_fn # imported here for pylint/mypy issues
425
426 collated = collate_tensor_fn(batch)
427
428 meta_dicts = [i.meta or TraceKeys.NONE for i in batch]
429 common_ = set.intersection(*[set(d.keys()) for d in meta_dicts if isinstance(d, dict)])
430 if common_:
431 meta_dicts = [{k: d[k] for k in common_} if isinstance(d, dict) else TraceKeys.NONE for d in meta_dicts]
432 collated.meta = default_collate(meta_dicts)
433 collated.applied_operations = [i.applied_operations or TraceKeys.NONE for i in batch]
434 collated.is_batch = True
435 return collated
436
437
438def collate_meta_tensor(batch):

Callers 1

collate_meta_tensorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…