mindspore.dataset.dataloader.default_collate

View Source On Gitee
mindspore.dataset.dataloader.default_collate(batch)[source]

Default function for concatenating a batch of data along the first dimension when batching is enabled in DataLoader.

This function uses a predefined mapping from data types to their corresponding collate functions to do the following type transformations, then collates the input batch according to the rules described in collate():

Parameters

batch (list) – A batch of data to be collated.

Returns

Any, the collated data.

Examples

>>> from mindspore.dataset.dataloader import default_collate
>>>
>>> default_collate([0, 1, 2])
Tensor(shape=[3], dtype=Int64, value= [0, 1, 2])
>>>
>>> default_collate([{"data": 0, "label": 2},
...                  {"data": 1, "label": 3}])
{'data': Tensor(shape=[2], dtype=Int64, value= [0, 1]), 'label': Tensor(shape=[2], dtype=Int64, value= [2, 3])}
>>>
>>> default_collate([(0, 3), (1, 4), (2, 5)])
[Tensor(shape=[3], dtype=Int64, value= [0, 1, 2]), Tensor(shape=[3], dtype=Int64, value= [3, 4, 5])]