Skip to content

[Cherry-pick] add paddle.batch version-2.1 doc (#3646) #3649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/api/paddle/batch_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. _cn_api_paddle_batch:

batch
-------------------------------

.. py:function:: paddle.batch(reader, batch_size, drop_last=False)

该接口是一个reader的装饰器。返回的reader将输入reader的数据打包成指定的batch_size大小的批处理数据(batched data)。

.. warning::
不推荐使用这个API,如有数据加载需求推荐使用支持多进程并发加速的 ``paddle.io.DataLoader``

参数
::::::::::::

- **reader** (generator)- 读取数据的数据reader。
- **batch_size** (int)- 批尺寸。
- **drop_last** (bool) - 若设置为True,则当最后一个batch不等于batch_size时,丢弃最后一个batch;若设置为False,则不会。默认值为False。

返回
::::::::::::
batched reader

返回类型
::::::::::::
generator

代码示例
::::::::::::

.. code-block:: python

import paddle

def reader():
for i in range(10):
yield i
batch_reader = paddle.batch(reader, batch_size=2)

for data in batch_reader():
print(data)

# 输出为:
# [0, 1]
# [2, 3]
# [4, 5]
# [6, 7]
# [8, 9]