Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
68999b6c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
68999b6c
编写于
12月 16, 2019
作者:
C
Chen Weihang
提交者:
GitHub
12月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify dygraph data loader code, test=develop (#21722)
上级
9c481e12
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
52 deletion
+10
-52
python/paddle/fluid/data_feeder.py
python/paddle/fluid/data_feeder.py
+0
-48
python/paddle/fluid/reader.py
python/paddle/fluid/reader.py
+10
-4
未找到文件。
python/paddle/fluid/data_feeder.py
浏览文件 @
68999b6c
...
@@ -502,51 +502,3 @@ class DataFeeder(object):
...
@@ -502,51 +502,3 @@ class DataFeeder(object):
"not implemented"
)
"not implemented"
)
return
__reader_creator__
return
__reader_creator__
class
NumpyToLoDTensorConverter
(
object
):
def
__init__
(
self
,
place
):
self
.
place
=
place
self
.
data
=
[]
self
.
_reset
()
def
_reset
(
self
):
self
.
data
=
[]
def
feed
(
self
,
data
):
self
.
data
.
append
(
data
)
def
done
(
self
):
arr
=
numpy
.
array
(
self
.
data
)
t
=
core
.
LoDTensor
()
t
.
set
(
arr
,
self
.
place
)
self
.
_reset
()
return
t
class
DygraphListTensorProvider
(
object
):
def
__init__
(
self
,
generator
,
place
):
self
.
generator
=
generator
self
.
converters
=
[]
if
place
:
if
isinstance
(
place
,
(
core
.
CUDAPlace
,
core
.
CPUPlace
)):
self
.
place
=
place
else
:
raise
ValueError
(
"Please specify a valid place values
\
such as core.CPUPlace or core.CUDAPlace"
)
else
:
self
.
place
=
_current_expected_place
()
def
_read_data
(
self
,
iterable
,
place
):
for
items
in
iterable
:
if
len
(
self
.
converters
)
<
len
(
items
):
for
_
in
items
:
self
.
converters
.
append
(
NumpyToLoDTensorConverter
(
place
))
for
each_converter
,
each_slot
in
six
.
moves
.
zip
(
self
.
converters
,
items
):
each_converter
.
feed
(
each_slot
)
yield
[
c
.
done
()
for
c
in
self
.
converters
]
def
__call__
(
self
):
for
batch
in
self
.
generator
():
yield
list
(
self
.
_read_data
(
batch
,
self
.
place
))
python/paddle/fluid/reader.py
浏览文件 @
68999b6c
...
@@ -21,7 +21,7 @@ import threading
...
@@ -21,7 +21,7 @@ import threading
import
paddle
import
paddle
from
.framework
import
Program
,
Variable
,
program_guard
,
default_main_program
,
default_startup_program
,
in_dygraph_mode
,
cpu_places
from
.framework
import
Program
,
Variable
,
program_guard
,
default_main_program
,
default_startup_program
,
in_dygraph_mode
,
cpu_places
from
.executor
import
global_scope
from
.executor
import
global_scope
from
.data_feeder
import
DataFeeder
,
BatchedTensorProvider
,
DygraphListTensorProvider
from
.data_feeder
import
DataFeeder
,
BatchedTensorProvider
from
.layers.io
import
monkey_patch_reader_methods
,
_copy_reader_var_
,
double_buffer
from
.layers.io
import
monkey_patch_reader_methods
,
_copy_reader_var_
,
double_buffer
from
.unique_name
import
UniqueNameGenerator
from
.unique_name
import
UniqueNameGenerator
import
logging
import
logging
...
@@ -545,11 +545,17 @@ class GeneratorLoader(DataLoaderBase):
...
@@ -545,11 +545,17 @@ class GeneratorLoader(DataLoaderBase):
def
set_sample_list_generator
(
self
,
reader
,
places
=
None
):
def
set_sample_list_generator
(
self
,
reader
,
places
=
None
):
if
in_dygraph_mode
():
if
in_dygraph_mode
():
provider
=
DygraphListTensorProvider
(
reader
,
places
)
def
__tensor_reader_impl__
():
def
__tensor_reader_impl__
():
for
slots
in
provider
():
for
batch
in
reader
():
yield
slots
[
0
]
slots
=
[]
for
items
in
batch
:
for
i
,
item
in
enumerate
(
items
):
if
len
(
slots
)
<
len
(
items
):
slots
.
append
([
item
])
else
:
slots
[
i
].
append
(
item
)
yield
slots
else
:
else
:
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
feeder
=
DataFeeder
(
feeder
=
DataFeeder
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录