MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / decorate_sample_list_generator

Method decorate_sample_list_generator

python/paddle/base/reader.py:1495–1566  ·  view source on GitHub ↗

Set the data source of the PyReader object. The provided :code:`reader` should be a Python generator, which yields list(numpy.ndarray) typed batched data. :code:`places` must be set when the PyReader object is iterable. Args: reader (generator)

(self, reader, places=None)

Source from the content-addressed store, hash-verified

1493 )
1494
1495 def decorate_sample_list_generator(self, reader, places=None):
1496 '''
1497 Set the data source of the PyReader object.
1498
1499 The provided :code:`reader` should be a Python generator,
1500 which yields list(numpy.ndarray) typed batched data.
1501
1502 :code:`places` must be set when the PyReader object is iterable.
1503
1504 Args:
1505 reader (generator): Python generator that yields
1506 list(numpy.ndarray)-typed batched data.
1507 places (None|list(CUDAPlace)|list(CPUPlace)): place list. Must
1508 be provided when PyReader is iterable.
1509
1510 Example:
1511 .. code-block:: pycon
1512
1513 >>> import paddle
1514 >>> import paddle.base as base
1515 >>> import numpy as np
1516
1517 >>> paddle.enable_static()
1518
1519 >>> EPOCH_NUM = 3
1520 >>> ITER_NUM = 15
1521 >>> BATCH_SIZE = 3
1522
1523 >>> def network(image, label):
1524 ... # User-defined network, here is an example of softmax regression.
1525 ... predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
1526 ... return paddle.nn.functional.cross_entropy(
1527 ... input=predict,
1528 ... label=label,
1529 ... reduction='none',
1530 ... use_softmax=False,
1531 ... )
1532
1533 >>> def random_image_and_label_generator(height, width):
1534 ... def generator():
1535 ... for i in range(ITER_NUM):
1536 ... fake_image = np.random.uniform(
1537 ... low=0,
1538 ... high=255,
1539 ... size=[height, width],
1540 ... )
1541 ... fake_label = np.ones([1])
1542 ... yield fake_image, fake_label
1543 ...
1544 ... return generator
1545
1546 >>> image = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')
1547 >>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
1548 >>> reader = base.io.PyReader(feed_list=[image, label], capacity=4, iterable=True)
1549
1550 >>> user_defined_generator = random_image_and_label_generator(784, 784)
1551 >>> reader.decorate_sample_list_generator(
1552 ... paddle.batch(user_defined_generator, batch_size=BATCH_SIZE),

Callers 11

run_mainMethod · 0.95
_check_mlpMethod · 0.95
run_dygraphMethod · 0.95
test_returnlistMethod · 0.95
test_mnist_float32Method · 0.95
_check_mlpMethod · 0.95
do_pyreader_trainingMethod · 0.80
do_pyreader_trainingMethod · 0.80
do_pyreader_trainingMethod · 0.80
do_pyreader_trainingMethod · 0.80

Calls 1

Tested by 6

run_mainMethod · 0.76
_check_mlpMethod · 0.76
run_dygraphMethod · 0.76
test_returnlistMethod · 0.76
test_mnist_float32Method · 0.76
_check_mlpMethod · 0.76