SequenceSampler

class paddle.io. SequenceSampler ( data_source ) [source]

Iterate samples sequentially, yield 0, 1, 2, ..., len(data_source) -1 generally,

Parameters

data_source (Dataset) – dataset to sample, this could be an instance of paddle.io.Dataset other Python object which implemented __len__.

Returns

a Sampler yield sample index sequentially

Return type

Sampler

Examples

>>> from paddle.io import Dataset, SequenceSampler

>>> class RandomDataset(Dataset):
...     def __init__(self, num_samples):
...         self.num_samples = num_samples
...
...     def __getitem__(self, idx):
...         image = np.random.random([784]).astype('float32')
...         label = np.random.randint(0, 9, (1, )).astype('int64')
...         return image, label
...
...     def __len__(self):
...         return self.num_samples
...
>>> sampler = SequenceSampler(data_source=RandomDataset(100))

>>> for index in sampler:
...     print(index)
0
1
2
...
99

see paddle.io.Sampler