Table Of Contents
Table Of Contents

class, batch_size, last_batch='keep')[source]

Wraps over another Sampler and return mini-batches of samples.

  • sampler (Sampler) – The source Sampler.

  • batch_size (int) – Size of mini-batch.

  • last_batch ({'keep', 'discard', 'rollover'}) –

    Specifies how the last batch is handled if batch_size does not evenly divide sequence length.

    If ‘keep’, the last batch will be returned directly, but will contain less element than batch_size requires.

    If ‘discard’, the last batch will be discarded.

    If ‘rollover’, the remaining elements will be rolled over to the next iteration.


>>> sampler =
>>> batch_sampler =, 3, 'keep')
>>> list(batch_sampler)
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
__init__(sampler, batch_size, last_batch='keep')[source]

Initialize self. See help(type(self)) for accurate signature.


__init__(sampler, batch_size[, last_batch])

Initialize self.