shuffle

paddle.fluid.io.shuffle(reader, buf_size)[source]

paddle.fluid.io.shuffle ( shuffle ) is recommended to use, and paddle.reader.shuffle is an alias.

This API creates a decorated reader that outputs the shuffled data.

The output data from the origin reader will be saved into a buffer, and then shuffle the data. The size of buffer is determined by argument buf_size.

Parameters
  • reader (callable) – the original reader whose data will be shuffled.

  • buf_size (int) – the size of shuffled buffer.

Returns

a decorated reader.

Return type

callable

Examples

import paddle.fluid as fluid

def reader():
    for i in range(5):
        yield i
shuffled_reader = fluid.io.shuffle(reader, 3)
for e in shuffled_reader():
    print(e)
# outputs are 0~4 unordered arrangement