mxnet.gluon.data.sampler¶
Dataset sampler.
Classes
|
Wraps over another Sampler and return mini-batches of samples. |
|
Samples elements from a Dataset for which fn returns True. |
|
Samples elements from [0, length) at fixed intervals. |
|
Samples elements from [0, length) randomly without replacement. |
|
Base class for samplers. |
|
Samples elements from [start, start+length) sequentially. |
- class mxnet.gluon.data.sampler.BatchSampler(sampler, batch_size, last_batch='keep')[source]¶
Bases:
SamplerWraps over another Sampler and return mini-batches of samples.
- Parameters:
sampler (Sampler) – The source Sampler.
batch_size (int) – Size of mini-batch.
last_batch ({'keep', 'discard', 'rollover'}) –
Specifies how the last batch is handled if batch_size does not evenly divide sequence length.
If ‘keep’, the last batch will be returned directly, but will contain less element than batch_size requires.
If ‘discard’, the last batch will be discarded.
If ‘rollover’, the remaining elements will be rolled over to the next iteration.
Examples
>>> sampler = gluon.data.SequentialSampler(10) >>> batch_sampler = gluon.data.BatchSampler(sampler, 3, 'keep') >>> list(batch_sampler) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
- class mxnet.gluon.data.sampler.FilterSampler(fn, dataset)[source]¶
Bases:
SamplerSamples elements from a Dataset for which fn returns True.
- Parameters:
fn (callable) – A callable function that takes a sample and returns a boolean
dataset (Dataset) – The dataset to filter.
- class mxnet.gluon.data.sampler.IntervalSampler(length, interval, rollover=True)[source]¶
Bases:
SamplerSamples elements from [0, length) at fixed intervals.
- Parameters:
length (int) – Length of the sequence.
interval (int) – The number of items to skip between two samples.
rollover (bool, default True) – Whether to start again from the first skipped item after reaching the end. If true, this sampler would start again from the first skipped item until all items are visited. Otherwise, iteration stops when end is reached and skipped items are ignored.
Examples
>>> sampler = contrib.data.IntervalSampler(13, interval=3) >>> list(sampler) [0, 3, 6, 9, 12, 1, 4, 7, 10, 2, 5, 8, 11] >>> sampler = contrib.data.IntervalSampler(13, interval=3, rollover=False) >>> list(sampler) [0, 3, 6, 9, 12]
- class mxnet.gluon.data.sampler.RandomSampler(length)[source]¶
Bases:
SamplerSamples elements from [0, length) randomly without replacement.
- Parameters:
length (int) – Length of the sequence.