mindspore.dataset.dataloader.BatchSampler

View Source On Gitee
class mindspore.dataset.dataloader.BatchSampler(sampler, batch_size, drop_last)[source]

A sampler that generates mini-batch indices each time.

Parameters
  • sampler (Union[Sampler, Iterable]) – Sampler for generating indices.

  • batch_size (int) – The size of the mini batch.

  • drop_last (bool) – Whether to discard the last batch of data if the batch is smaller than batch_size .

Examples

>>> from mindspore.dataset.dataloader import BatchSampler, SequentialSampler
>>>
>>> dataset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> sequential_sampler = SequentialSampler(dataset)
>>> batch_sampler = BatchSampler(sequential_sampler, 2, False)