forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synchronize api cn develop 0823 (PaddlePaddle#1126)
* modify fluid.rst and layers.rst and gen_doc.py * synchronize api_cn of develop 0823,test=document_preview * update io_cn.rst * delete ComposeNotAligned_cn.rst
- Loading branch information
Showing
29 changed files
with
1,151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. _cn_api_fluid_is_compiled_with_cuda: | ||
|
||
is_compiled_with_cuda | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.is_compiled_with_cuda() | ||
检查 ``whl`` 包是否可以被用来在GPU上运行模型 | ||
|
||
返回:支持gpu则为True,否则为False。 | ||
|
||
返回类型:out(boolean) | ||
|
||
**示例代码** | ||
|
||
.. code-block:: python | ||
import paddle.fluid as fluid | ||
support_gpu = fluid.is_compiled_with_cuda() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. _cn_api_fluid_io_Fake: | ||
|
||
Fake | ||
------------------------------- | ||
|
||
.. py:class:: paddle.fluid.io.Fake | ||
Fakereader将缓存它读取的第一个数据,并将其输出data_num次。它用于缓存来自真实reader的数据,并将其用于速度测试。 | ||
|
||
参数: | ||
- **reader** – 原始读取器。 | ||
- **data_num** – reader产生数据的次数 。 | ||
|
||
返回: 一个Fake读取器 | ||
|
||
|
||
**代码示例** | ||
|
||
.. code-block:: python | ||
def reader(): | ||
for i in range(10): | ||
yield i | ||
fake_reader = Fake()(reader, 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.. _cn_api_fluid_io_PipeReader: | ||
|
||
PipeReader | ||
------------------------------- | ||
|
||
.. py:class:: paddle.fluid.io.PipeReader | ||
PipeReader从命令中通过流来读取数据,把数据存在一个pipe缓存中,并重定向到解析器中解析,返回预先设计格式的数据。 | ||
|
||
你可以使用标准的Linux命令或者调用其他程序来读取数据,从HDFS, Ceph, URL, AWS S3等等。 | ||
|
||
.. code-block:: python | ||
cmd = "hadoop fs -cat /path/to/some/file" | ||
cmd = "cat sample_file.tar.gz" | ||
cmd = "curl http://someurl" | ||
cmd = "python print_s3_bucket.py" | ||
**代码示例** | ||
|
||
.. code-block:: python | ||
def example_reader(): | ||
for f in myfiles: | ||
pr = PipeReader("cat %s"%f) | ||
for l in pr.get_line(): | ||
sample = l.split(" ") | ||
yield sample | ||
.. py:method:: get_line(cut_lines=True,line_break='\n') | ||
参数: | ||
- **cut_lines** (bool) - 给行分割缓存 | ||
- **line_break** (string) - 行分隔符,比如'\n'或者'\r' | ||
|
||
返回: 行或者字节缓存 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.. _cn_api_fluid_io_batch: | ||
|
||
batch | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.batch(reader, batch_size, drop_last=False) | ||
该层是一个batched reader。 | ||
|
||
参数: | ||
- **reader** (Variable)-读取数据的数据reader | ||
- **batch_size** (int)-批尺寸 | ||
- **drop_last** (bool) - 如果最后一个batch不等于batch_size,则drop最后一个batch。 | ||
|
||
返回:batched reader | ||
|
||
返回类型:callable | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.. _cn_api_fluid_io_buffered: | ||
|
||
buffered | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.buffered(reader, size) | ||
创建一个缓存数据读取器,它读取数据并且存储进缓存区,从缓存区读取数据将会加速,只要缓存不是空的。 | ||
|
||
参数: | ||
- **reader** (callable) – 读取数据的reader | ||
- **size** (int) – 最大buffer的大小 | ||
|
||
返回:缓存的reader(读取器) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.. _cn_api_fluid_io_cache: | ||
|
||
cache | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.cache(reader) | ||
缓存reader数据到内存中,小心此方法可能会花长时间来处理数据,并且会占用大量内存。 ``reader()`` 只能被调用一次。 | ||
|
||
参数: | ||
- **reader** (callable) – 读取数据的reader,每次都会yields数据。 | ||
|
||
返回:每次都会从内存中yields数据的一个装饰reader。 | ||
|
||
返回类型:生成器 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _cn_api_fluid_io_chain: | ||
|
||
chain | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.chain(*readers) | ||
创建一个数据读取器,输出为输入数据读取器链接到一起的结果,如果输入如下: | ||
|
||
[0, 0, 0] | ||
|
||
[1, 1, 1] | ||
|
||
[2, 2, 2] | ||
|
||
输出将会为[0, 0, 0, 1, 1, 1, 2, 2, 2]. | ||
|
||
参数: | ||
- **readers** – 输入reader | ||
|
||
返回:新的数据reader。 | ||
|
||
返回类型:callable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.. _cn_api_fluid_io_compose: | ||
|
||
composs | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.compose(*readers, **kwargs) | ||
创建一个数据读取器,输出为输入数据读取器组合到一起的结果,如果输入如下: | ||
|
||
(1,2) 3 (4,5) | ||
|
||
输出将会为(1,2,3,4,5)。 | ||
|
||
参数: | ||
- **readers** – 要组合的输入reader | ||
- **check_alignment** (bool) - 若为True,将会检查输入readers是否正确的对准,若为False,将不会检查是否对准并且不会跟踪输出,默认为True。 | ||
|
||
返回:新的数据reader。 | ||
|
||
Raises:ComposeNotAligned - 输出readers没有对齐,当check_alignment设置为False时将不会raise。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.. _cn_api_fluid_io_firstn: | ||
|
||
firstn | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.firstn(reader, n) | ||
限制reader可以返回的最大样本数。 | ||
|
||
参数: | ||
- **reader** (callable) – 要读取的数据读取器。 | ||
- **n** (int) – 返回的最大样本数 。 | ||
|
||
返回: 装饰reader | ||
|
||
返回类型: callable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. _cn_api_fluid_io_map_readers: | ||
|
||
map_readers | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.map_readers(func, *readers) | ||
创建使用每个数据读取器的输出作为参数输出函数返回值的数据读取器。 | ||
|
||
参数: | ||
- **func** - 使用的函数. 函数类型应为(Sample) => Sample | ||
- **readers** - 其输出将用作func参数的reader。 | ||
|
||
类型:callable | ||
|
||
返回: 被创建数据的读取器 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _cn_api_fluid_io_multiprocess_reader: | ||
|
||
multiprocess_reader | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.multiprocess_reader(readers, use_pipe=True, queue_size=1000) | ||
多进程reader使用python多进程从reader中读取数据,然后使用multi process.queue或multi process.pipe合并所有数据。进程号等于输入reader的编号,每个进程调用一个reader。 | ||
|
||
multiprocess.queue需要/dev/shm的rw访问权限,某些平台不支持。 | ||
|
||
您需要首先创建多个reader,这些reader应该相互独立,这样每个进程都可以独立工作。 | ||
|
||
**代码示例** | ||
|
||
.. code-block:: python | ||
reader0 = reader(["file01", "file02"]) | ||
reader1 = reader(["file11", "file12"]) | ||
reader1 = reader(["file21", "file22"]) | ||
reader = multiprocess_reader([reader0, reader1, reader2], | ||
queue_size=100, use_pipe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.. _cn_api_fluid_io_shuffle: | ||
|
||
shuffle | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.shuffle(reader, buffer_size) | ||
创建一个特殊的数据读取器,它的输出数据会被重洗(shuffle)。由原始读取器创建的迭代器得到的输出将会被暂存到shuffle缓存区,其后 | ||
会对其进行重洗运算。shuffle缓存区的大小由参数 ``buffer_size`` 决定。 | ||
|
||
参数: | ||
- **reader** (callable) – 输出会被shuffle的原始reader | ||
- **buffer_size** (int) – 进行shuffle的buffer的大小 | ||
|
||
返回:其输出会被shuffle的一个reader(读取器) | ||
|
||
返回类型:callable | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
import paddle.fluid as fluid | ||
raw_reader = fluid.layers.io.open_files(filenames=['./data1.recordio', | ||
'./data2.recordio'], | ||
shapes=[(3,224,224), (1,)], | ||
lod_levels=[0, 0], | ||
dtypes=['float32', 'int64'], | ||
thread_num=2, | ||
buffer_size=2) | ||
batch_reader = fluid.layers.batch(reader=raw_reader, batch_size=5) | ||
shuffle_reader = fluid.io.shuffle(reader=batch_reader, buffer_size=5000) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.. _cn_api_fluid_io_xmap_readers: | ||
|
||
xmap_readers | ||
------------------------------- | ||
|
||
.. py:function:: paddle.fluid.io.xmap_readers(mapper, reader, process_num, buffer_size, order=False) | ||
通过多线程方式,通过用户自定义的映射器mapper来映射reader返回的样本(到输出队列)。 | ||
|
||
参数: | ||
- **mapper** (callable) - 一种映射reader数据的函数。 | ||
- **reader** (callable) - 产生数据的reader。 | ||
- **process_num** (int) - 用于处理样本的线程数目。 | ||
- **buffer_size** (int) - 存有待读取数据的队列的大小。 | ||
- **order** (bool) - 是否保持原始reader的数据顺序。 默认为False。 | ||
|
||
返回:一个将原数据进行映射后的decorated reader。 | ||
|
||
返回类型: callable |
Oops, something went wrong.