Skip to content

simplify list_data_collate and collate_meta_tensor using collate #5917

@wyli

Description

@wyli

the generic collate API is implemented in pytorch

pytorch/pytorch#85748

def collate(batch, *, collate_fn_map: Optional[Dict[Union[Type, Tuple[Type, ...]], Callable]] = None):
    r"""
        General collate function that handles collection type of element within each batch
        and opens function registry to deal with specific element types. `default_collate_fn_map`
        provides default collate functions for tensors, numpy arrays, numbers and strings.

probably the monai helper functions could be simplified:

MONAI/monai/data/utils.py

Lines 448 to 451 in 50c3f32

def list_data_collate(batch: Sequence):
"""
Enhancement for PyTorch DataLoader default collate.
If dataset already returns a list of batch data that generated in transforms, need to merge all data to 1 list.

MONAI/monai/data/utils.py

Lines 427 to 430 in 50c3f32

def collate_meta_tensor(batch):
"""collate a sequence of meta tensor sequences/dictionaries into
a single batched metatensor or a dictionary of batched metatensor"""
if not isinstance(batch, Sequence):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions