Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
ec38effc
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ec38effc
编写于
10月 08, 2018
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize fake, change it to a class instead a function. test=develop
上级
ebd9f7fc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
14 deletion
+26
-14
paddle/fluid/CMakeLists.txt
paddle/fluid/CMakeLists.txt
+1
-1
python/paddle/reader/decorator.py
python/paddle/reader/decorator.py
+24
-12
python/paddle/reader/tests/decorator_test.py
python/paddle/reader/tests/decorator_test.py
+1
-1
未找到文件。
paddle/fluid/CMakeLists.txt
浏览文件 @
ec38effc
...
...
@@ -14,4 +14,4 @@ if(WITH_INFERENCE)
add_subdirectory
(
inference
)
endif
()
add_subdirectory
(
train
)
#
add_subdirectory(train)
python/paddle/reader/decorator.py
浏览文件 @
ec38effc
...
...
@@ -15,7 +15,7 @@
__all__
=
[
'map_readers'
,
'buffered'
,
'compose'
,
'chain'
,
'shuffle'
,
'ComposeNotAligned'
,
'firstn'
,
'xmap_readers'
,
'PipeReader'
,
'multiprocess_reader'
,
'
f
ake'
'multiprocess_reader'
,
'
F
ake'
]
from
threading
import
Thread
...
...
@@ -506,25 +506,37 @@ class PipeReader:
break
def
fake
(
reader
,
data_num
):
class
Fake
(
object
):
"""
fake reader will cache the first data it read and yield it out for data_num times.
It is used to cache a data from real reader and use it for speed testing.
:param reader: the origin reader
:param data_num: times that this reader will yield data.
:return: a fake reader.
Examples:
.. code-block:: python
def reader():
for i in range(10):
yield i
fake_reader = Fake()(reader, 100)
"""
def
fake_reader
():
if
fake_reader
.
data
is
None
:
fake_reader
.
data
=
reader
().
next
()
while
fake_reader
.
yield_num
<
data_num
:
yield
fake_reader
.
data
fake_reader
.
yield_num
+=
1
fake_reader
.
yield_num
=
0
def
__init__
(
self
):
self
.
data
=
None
self
.
yield_num
=
0
fake_reader
.
data
=
None
fake_reader
.
yield_num
=
0
def
__call__
(
self
,
reader
,
data_num
):
def
fake_reader
():
if
self
.
data
is
None
:
self
.
data
=
reader
().
next
()
while
self
.
yield_num
<
data_num
:
yield
self
.
data
self
.
yield_num
+=
1
self
.
yield_num
=
0
return
fake_reader
return
fake_reader
python/paddle/reader/tests/decorator_test.py
浏览文件 @
ec38effc
...
...
@@ -210,7 +210,7 @@ class TestFakeReader(unittest.TestCase):
yield
i
data_num
=
100
fake_reader
=
paddle
.
reader
.
fake
(
reader
,
data_num
)
fake_reader
=
paddle
.
reader
.
Fake
()
(
reader
,
data_num
)
for
_
in
range
(
10
):
i
=
0
for
data
in
fake_reader
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录