Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d9edd6ef
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
d9edd6ef
编写于
2月 08, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine error msg and add unittest for cpp reader
上级
b1869f16
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
38 deletion
+35
-38
python/paddle/v2/fluid/executor.py
python/paddle/v2/fluid/executor.py
+7
-22
python/paddle/v2/fluid/tests/test_cpp_reader.py
python/paddle/v2/fluid/tests/test_cpp_reader.py
+28
-16
未找到文件。
python/paddle/v2/fluid/executor.py
浏览文件 @
d9edd6ef
...
@@ -47,27 +47,13 @@ def as_numpy(tensor):
...
@@ -47,27 +47,13 @@ def as_numpy(tensor):
return
[
as_numpy
(
t
)
for
t
in
tensor
]
return
[
as_numpy
(
t
)
for
t
in
tensor
]
assert
isinstance
(
tensor
,
core
.
LoDTensor
)
assert
isinstance
(
tensor
,
core
.
LoDTensor
)
lod
=
tensor
.
lod
()
lod
=
tensor
.
lod
()
tensor_data
=
np
.
array
(
tensor
)
if
len
(
lod
)
>
0
:
if
len
(
lod
)
==
0
:
raise
RuntimeError
(
ans
=
tensor_data
"Some of your featched tensors hold LoD information.
\
else
:
They can not be completely cast to Python ndarray.
\
raise
RuntimeError
(
"LoD Calculate lacks unit tests and buggy"
)
Please set the parameter 'return_numpy' as 'False' to
\
# elif len(lod) == 1:
return LoDTensor itself directly."
)
# ans = []
return
np
.
array
(
tensor
)
# idx = 0
# while idx < len(lod) - 1:
# ans.append(tensor_data[lod[idx]:lod[idx + 1]])
# idx += 1
# else:
# for l in reversed(lod):
# ans = []
# idx = 0
# while idx < len(l) - 1:
# ans.append(tensor_data[l[idx]:l[idx + 1]])
# idx += 1
# tensor_data = ans
# ans = tensor_data
return
ans
def
has_feed_operators
(
block
,
feed_targets
,
feed_holder_name
):
def
has_feed_operators
(
block
,
feed_targets
,
feed_holder_name
):
...
@@ -306,7 +292,6 @@ class Executor(object):
...
@@ -306,7 +292,6 @@ class Executor(object):
core
.
get_fetch_variable
(
scope
,
fetch_var_name
,
i
)
core
.
get_fetch_variable
(
scope
,
fetch_var_name
,
i
)
for
i
in
xrange
(
len
(
fetch_list
))
for
i
in
xrange
(
len
(
fetch_list
))
]
]
if
return_numpy
:
if
return_numpy
:
outs
=
as_numpy
(
outs
)
outs
=
as_numpy
(
outs
)
return
outs
return
outs
python/paddle/v2/fluid/tests/test_cpp_reader.py
浏览文件 @
d9edd6ef
...
@@ -32,31 +32,43 @@ create_random_data_generator_op = block.append_op(
...
@@ -32,31 +32,43 @@ create_random_data_generator_op = block.append_op(
"min"
:
0.0
,
"min"
:
0.0
,
"max"
:
1.0
"max"
:
1.0
})
})
shuffle_reader
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
READER
,
name
=
"ShuffleReader"
)
shuffle_reader
.
desc
.
set_lod_levels
([
0
,
0
])
out1
=
block
.
create_var
(
create_shuffle_reader_op
=
block
.
append_op
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
type
=
"create_shuffle_reader"
,
name
=
"Out1"
,
inputs
=
{
"UnderlyingReader"
:
random_reader
},
shape
=
[
10
,
2
],
outputs
=
{
"Out"
:
shuffle_reader
},
dtype
=
"float32"
,
attrs
=
{
"buffer_size"
:
7
})
lod_level
=
1
)
out2
=
block
.
create_var
(
batch_reader
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
type
=
fluid
.
core
.
VarDesc
.
VarType
.
READER
,
name
=
"BatchReader"
)
name
=
"Out2"
,
batch_reader
.
desc
.
set_lod_levels
([
1
,
1
])
shape
=
[
10
,
1
],
dtype
=
"float32"
,
create_batch_reader_op
=
block
.
append_op
(
lod_level
=
1
)
type
=
"create_batch_reader"
,
inputs
=
{
"UnderlyingReader"
:
shuffle_reader
},
outputs
=
{
"Out"
:
batch_reader
},
attrs
=
{
"batch_size"
:
10
})
out1
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
name
=
"Out1"
)
out2
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
name
=
"Out2"
)
read_op
=
block
.
append_op
(
read_op
=
block
.
append_op
(
type
=
"read"
,
type
=
"read"
,
inputs
=
{
"Reader"
:
batch_reader
},
inputs
=
{
"Reader"
:
random_reader
},
outputs
=
{
"Out"
:
[
out1
,
out2
]})
outputs
=
{
"Out"
:
[
out1
,
out2
]})
place
=
fluid
.
CPUPlace
()
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
[
res1
,
res2
]
=
exe
.
run
(
prog
,
fetch_list
=
[
out1
,
out2
])
[
res1
,
res2
]
=
exe
.
run
(
prog
,
fetch_list
=
[
out1
,
out2
],
return_numpy
=
False
)
test_pass
=
res1
.
lod
()
==
[
range
(
0
,
11
)]
and
res1
.
lod
()
==
[
range
(
0
,
11
)
]
and
np
.
array
(
res1
).
shape
==
(
10
,
2
)
and
np
.
array
(
res2
).
shape
==
(
10
,
1
)
if
len
(
res1
)
==
0
or
len
(
res2
)
==
0
:
if
not
test_pass
:
exit
(
1
)
exit
(
1
)
exit
(
0
)
exit
(
0
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录