Package ai.djl.training.dataset
Class BatchSampler
- java.lang.Object
-
- ai.djl.training.dataset.BatchSampler
-
- All Implemented Interfaces:
Sampler
public class BatchSampler extends java.lang.Object implements Sampler
BatchSampleris aSamplerthat returns a single epoch over the data.BatchSamplerwraps anotherSampler.SubSamplerto yield a mini-batch of indices.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ai.djl.training.dataset.Sampler
Sampler.SubSampler
-
-
Constructor Summary
Constructors Constructor Description BatchSampler(Sampler.SubSampler subSampler, int batchSize)Creates a new instance ofBatchSamplerthat samples from the givenSampler.SubSampler, and yields a mini-batch of indices.BatchSampler(Sampler.SubSampler subSampler, int batchSize, boolean dropLast)Creates a new instance ofBatchSamplerthat samples from the givenSampler.SubSampler, and yields a mini-batch of indices.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetBatchSize()Returns the batch size of theSampler.java.util.Iterator<java.util.List<java.lang.Long>>sample(RandomAccessDataset dataset)Fetches an iterator that iterates through the givenRandomAccessDatasetin mini-batches of indices.
-
-
-
Constructor Detail
-
BatchSampler
public BatchSampler(Sampler.SubSampler subSampler, int batchSize)
Creates a new instance ofBatchSamplerthat samples from the givenSampler.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- theSampler.SubSamplerto sample frombatchSize- the required batch size
-
BatchSampler
public BatchSampler(Sampler.SubSampler subSampler, int batchSize, boolean dropLast)
Creates a new instance ofBatchSamplerthat samples from the givenSampler.SubSampler, and yields a mini-batch of indices.- Parameters:
subSampler- theSampler.SubSamplerto sample frombatchSize- the required batch sizedropLast- whether theBatchSamplershould drop the last few samples in case the size of the dataset is not a multiple of batch size
-
-
Method Detail
-
sample
public java.util.Iterator<java.util.List<java.lang.Long>> sample(RandomAccessDataset dataset)
Fetches an iterator that iterates through the givenRandomAccessDatasetin mini-batches of indices.- Specified by:
samplein interfaceSampler- Parameters:
dataset- theRandomAccessDatasetto sample from- Returns:
- an iterator that iterates through the given
RandomAccessDatasetin mini-batches of indices
-
getBatchSize
public int getBatchSize()
Returns the batch size of theSampler.- Specified by:
getBatchSizein interfaceSampler- Returns:
- the batch size of the
Sampler, -1 if batch size is not fixed
-
-