Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
d9edd6ef
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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):
return
[
as_numpy
(
t
)
for
t
in
tensor
]
assert
isinstance
(
tensor
,
core
.
LoDTensor
)
lod
=
tensor
.
lod
()
tensor_data
=
np
.
array
(
tensor
)
if
len
(
lod
)
==
0
:
ans
=
tensor_data
else
:
raise
RuntimeError
(
"LoD Calculate lacks unit tests and buggy"
)
# elif len(lod) == 1:
# ans = []
# 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
if
len
(
lod
)
>
0
:
raise
RuntimeError
(
"Some of your featched tensors hold LoD information.
\
They can not be completely cast to Python ndarray.
\
Please set the parameter 'return_numpy' as 'False' to
\
return LoDTensor itself directly."
)
return
np
.
array
(
tensor
)
def
has_feed_operators
(
block
,
feed_targets
,
feed_holder_name
):
...
...
@@ -306,7 +292,6 @@ class Executor(object):
core
.
get_fetch_variable
(
scope
,
fetch_var_name
,
i
)
for
i
in
xrange
(
len
(
fetch_list
))
]
if
return_numpy
:
outs
=
as_numpy
(
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(
"min"
:
0.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
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
name
=
"Out1"
,
shape
=
[
10
,
2
],
dtype
=
"float32"
,
lod_level
=
1
)
out2
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
name
=
"Out2"
,
shape
=
[
10
,
1
],
dtype
=
"float32"
,
lod_level
=
1
)
create_shuffle_reader_op
=
block
.
append_op
(
type
=
"create_shuffle_reader"
,
inputs
=
{
"UnderlyingReader"
:
random_reader
},
outputs
=
{
"Out"
:
shuffle_reader
},
attrs
=
{
"buffer_size"
:
7
})
batch_reader
=
block
.
create_var
(
type
=
fluid
.
core
.
VarDesc
.
VarType
.
READER
,
name
=
"BatchReader"
)
batch_reader
.
desc
.
set_lod_levels
([
1
,
1
])
create_batch_reader_op
=
block
.
append_op
(
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
(
type
=
"read"
,
inputs
=
{
"Reader"
:
random_reader
},
type
=
"read"
,
inputs
=
{
"Reader"
:
batch_reader
},
outputs
=
{
"Out"
:
[
out1
,
out2
]})
place
=
fluid
.
CPUPlace
()
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
(
0
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录