Class BatchSampler

  • All Implemented Interfaces:
    Sampler

    public class BatchSampler
    extends java.lang.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 Detail

      • 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 Detail

      • getBatchSize

        public int getBatchSize()
        Returns the batch size of the Sampler.
        Specified by:
        getBatchSize in interface Sampler
        Returns:
        the batch size of the Sampler, -1 if batch size is not fixed