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.
Sampler.SubSampler
Constructor and Description |
---|
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. |
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. |
Modifier and Type | Method and Description |
---|---|
int |
getBatchSize()
Returns the batch size of the
Sampler . |
java.util.Iterator<java.util.List<java.lang.Long>> |
sample(RandomAccessDataset dataset)
Fetches an iterator that iterates through the given
RandomAccessDataset in
mini-batches of indices. |
public BatchSampler(Sampler.SubSampler subSampler, int batchSize)
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.
subSampler
- the Sampler.SubSampler
to sample frombatchSize
- the required batch sizepublic BatchSampler(Sampler.SubSampler subSampler, int batchSize, boolean dropLast)
BatchSampler
that samples from the given Sampler.SubSampler
, and yields a mini-batch of indices.subSampler
- the Sampler.SubSampler
to sample frombatchSize
- the required batch sizedropLast
- whether the BatchSampler
should drop the last few samples in case the
size of the dataset is not a multiple of batch sizepublic java.util.Iterator<java.util.List<java.lang.Long>> sample(RandomAccessDataset dataset)
RandomAccessDataset
in
mini-batches of indices.sample
in interface Sampler
dataset
- the RandomAccessDataset
to sample fromRandomAccessDataset
in
mini-batches of indicespublic int getBatchSize()
Sampler
.getBatchSize
in interface Sampler
Sampler
, -1 if batch size is not fixed