Class BatchSampler

java.lang.Object
ai.djl.training.dataset.BatchSampler
All Implemented Interfaces:
Sampler

public class BatchSampler extends Object implements Sampler
BatchSampler is a Sampler that returns a single epoch over the data.

BatchSampler wraps another Sampler.SubSampler to yield a mini-batch of indices.

  • Constructor Details

    • BatchSampler

      public BatchSampler(Sampler.SubSampler subSampler, int batchSize)
      Creates a new instance of BatchSampler that samples from the given Sampler.SubSampler, and yields a mini-batch of indices.

      The last batch will not be dropped. The size of the last batch maybe smaller than batch size in case the size of the dataset is not a multiple of batch size.

      Parameters:
      subSampler - the Sampler.SubSampler to sample from
      batchSize - the required batch size
    • BatchSampler

      public BatchSampler(Sampler.SubSampler subSampler, int batchSize, boolean dropLast)
      Creates a new instance of BatchSampler that samples from the given Sampler.SubSampler, and yields a mini-batch of indices.
      Parameters:
      subSampler - the Sampler.SubSampler to sample from
      batchSize - the required batch size
      dropLast - whether the BatchSampler should drop the last few samples in case the size of the dataset is not a multiple of batch size
  • Method Details