Shortcuts

mmengine.dataset.default_collate

mmengine.dataset.default_collate(data_batch)[source]

Convert list of data sampled from dataset into a batch of data, of which type consistent with the type of each data_itement in data_batch.

Different from pseudo_collate(), default_collate will stack tensor contained in data_batch into a batched tensor with the first dimension batch size, and then move input tensor to the target device.

Different from default_collate in pytorch, default_collate will not process BaseDataElement.

This code is referenced from: Pytorch default_collate.

Note

default_collate only accept input tensor with the same shape.

Parameters:

data_batch (Sequence) – Data sampled from dataset.

Returns:

Data in the same format as the data_itement of data_batch, of which tensors have been stacked, and ndarray, int, float have been converted to tensors.

Return type:

Any