BatchSampler

Contents

BatchSampler#

class braintools.trainer.BatchSampler(sampler, batch_size, drop_last=False)#

Wraps a sampler to yield batches of indices.

Parameters:
  • sampler (Sampler) – Base sampler to wrap.

  • batch_size (int) – Size of each batch.

  • drop_last (bool) – Whether to drop the last incomplete batch.

Examples

>>> base_sampler = SequentialSampler(dataset)
>>> batch_sampler = BatchSampler(base_sampler, batch_size=32)
>>> for batch_indices in batch_sampler:
...     print(len(batch_indices))  # 32 (or less for last batch)