Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f95e05a3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
f95e05a3
编写于
2月 12, 2018
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine the inference unittests.
上级
899ba0d0
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
61 addition
and
25 deletion
+61
-25
paddle/fluid/inference/tests/book/CMakeLists.txt
paddle/fluid/inference/tests/book/CMakeLists.txt
+1
-1
paddle/fluid/inference/tests/book/test_inference_label_semantic_roles.cc
...ference/tests/book/test_inference_label_semantic_roles.cc
+36
-10
paddle/fluid/inference/tests/book/test_inference_understand_sentiment.cc
...ference/tests/book/test_inference_understand_sentiment.cc
+6
-1
python/paddle/v2/fluid/tests/book/test_label_semantic_roles.py
...n/paddle/v2/fluid/tests/book/test_label_semantic_roles.py
+0
-1
python/paddle/v2/fluid/tests/book/test_understand_sentiment.py
...n/paddle/v2/fluid/tests/book/test_understand_sentiment.py
+18
-12
未找到文件。
paddle/fluid/inference/tests/book/CMakeLists.txt
浏览文件 @
f95e05a3
...
@@ -30,5 +30,5 @@ inference_test(label_semantic_roles)
...
@@ -30,5 +30,5 @@ inference_test(label_semantic_roles)
inference_test
(
recognize_digits ARGS mlp
)
inference_test
(
recognize_digits ARGS mlp
)
inference_test
(
recommender_system
)
inference_test
(
recommender_system
)
#inference_test(rnn_encoder_decoder)
#inference_test(rnn_encoder_decoder)
inference_test
(
understand_sentiment
)
inference_test
(
understand_sentiment
ARGS conv lstm
)
inference_test
(
word2vec
)
inference_test
(
word2vec
)
paddle/fluid/inference/tests/book/test_inference_label_semantic_roles.cc
浏览文件 @
f95e05a3
...
@@ -32,16 +32,42 @@ TEST(inference, label_semantic_roles) {
...
@@ -32,16 +32,42 @@ TEST(inference, label_semantic_roles) {
paddle
::
framework
::
LoDTensor
word
,
predicate
,
ctx_n2
,
ctx_n1
,
ctx_0
,
ctx_p1
,
paddle
::
framework
::
LoDTensor
word
,
predicate
,
ctx_n2
,
ctx_n1
,
ctx_0
,
ctx_p1
,
ctx_p2
,
mark
;
ctx_p2
,
mark
;
paddle
::
framework
::
LoD
lod
{{
0
,
4
,
10
}};
paddle
::
framework
::
LoD
lod
{{
0
,
4
,
10
}};
int64_t
word_dict_len
=
44068
;
SetupLoDTensor
(
word
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
int64_t
predicate_dict_len
=
3162
;
SetupLoDTensor
(
int64_t
mark_dict_len
=
2
;
predicate
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
SetupLoDTensor
(
ctx_n2
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
SetupLoDTensor
(
word
,
SetupLoDTensor
(
ctx_n1
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
lod
,
SetupLoDTensor
(
ctx_0
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
static_cast
<
int64_t
>
(
0
),
SetupLoDTensor
(
ctx_p1
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
ctx_p2
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
SetupLoDTensor
(
predicate
,
SetupLoDTensor
(
mark
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
1
));
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
predicate_dict_len
-
1
));
SetupLoDTensor
(
ctx_n2
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
ctx_n1
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
ctx_0
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
ctx_p1
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
ctx_p2
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
SetupLoDTensor
(
mark
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
mark_dict_len
-
1
));
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
cpu_feeds
.
push_back
(
&
word
);
cpu_feeds
.
push_back
(
&
word
);
...
...
paddle/fluid/inference/tests/book/test_inference_understand_sentiment.cc
浏览文件 @
f95e05a3
...
@@ -31,7 +31,12 @@ TEST(inference, understand_sentiment) {
...
@@ -31,7 +31,12 @@ TEST(inference, understand_sentiment) {
paddle
::
framework
::
LoDTensor
words
;
paddle
::
framework
::
LoDTensor
words
;
paddle
::
framework
::
LoD
lod
{{
0
,
4
,
10
}};
paddle
::
framework
::
LoD
lod
{{
0
,
4
,
10
}};
SetupLoDTensor
(
words
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
10
));
int64_t
word_dict_len
=
5147
;
SetupLoDTensor
(
words
,
lod
,
static_cast
<
int64_t
>
(
0
),
static_cast
<
int64_t
>
(
word_dict_len
-
1
));
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
std
::
vector
<
paddle
::
framework
::
LoDTensor
*>
cpu_feeds
;
cpu_feeds
.
push_back
(
&
words
);
cpu_feeds
.
push_back
(
&
words
);
...
...
python/paddle/v2/fluid/tests/book/test_label_semantic_roles.py
浏览文件 @
f95e05a3
...
@@ -296,7 +296,6 @@ def infer(use_cuda, save_dirname=None):
...
@@ -296,7 +296,6 @@ def infer(use_cuda, save_dirname=None):
print
(
results
[
0
].
lod
())
print
(
results
[
0
].
lod
())
np_data
=
np
.
array
(
results
[
0
])
np_data
=
np
.
array
(
results
[
0
])
print
(
"Inference Shape: "
,
np_data
.
shape
)
print
(
"Inference Shape: "
,
np_data
.
shape
)
print
(
"Inference results: "
,
np_data
)
def
main
(
use_cuda
):
def
main
(
use_cuda
):
...
...
python/paddle/v2/fluid/tests/book/test_understand_sentiment.py
浏览文件 @
f95e05a3
...
@@ -93,7 +93,7 @@ def create_random_lodtensor(lod, place, low, high):
...
@@ -93,7 +93,7 @@ def create_random_lodtensor(lod, place, low, high):
return
res
return
res
def
train
(
word_dict
,
n
et_method
,
use_cuda
,
save_dirname
=
None
):
def
train
(
word_dict
,
n
n_type
,
use_cuda
,
save_dirname
=
None
):
BATCH_SIZE
=
128
BATCH_SIZE
=
128
PASS_NUM
=
5
PASS_NUM
=
5
dict_dim
=
len
(
word_dict
)
dict_dim
=
len
(
word_dict
)
...
@@ -102,6 +102,11 @@ def train(word_dict, net_method, use_cuda, save_dirname=None):
...
@@ -102,6 +102,11 @@ def train(word_dict, net_method, use_cuda, save_dirname=None):
data
=
fluid
.
layers
.
data
(
data
=
fluid
.
layers
.
data
(
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
name
=
"words"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
if
nn_type
==
"conv"
:
net_method
=
convolution_net
else
:
net_method
=
stacked_lstm_net
cost
,
acc_out
,
prediction
=
net_method
(
cost
,
acc_out
,
prediction
=
net_method
(
data
,
label
,
input_dim
=
dict_dim
,
class_dim
=
class_dim
)
data
,
label
,
input_dim
=
dict_dim
,
class_dim
=
class_dim
)
...
@@ -132,7 +137,7 @@ def train(word_dict, net_method, use_cuda, save_dirname=None):
...
@@ -132,7 +137,7 @@ def train(word_dict, net_method, use_cuda, save_dirname=None):
net_method
.
__name__
))
net_method
.
__name__
))
def
infer
(
use_cuda
,
save_dirname
=
None
):
def
infer
(
word_dict
,
use_cuda
,
save_dirname
=
None
):
if
save_dirname
is
None
:
if
save_dirname
is
None
:
return
return
...
@@ -146,10 +151,11 @@ def infer(use_cuda, save_dirname=None):
...
@@ -146,10 +151,11 @@ def infer(use_cuda, save_dirname=None):
[
inference_program
,
feed_target_names
,
[
inference_program
,
feed_target_names
,
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
save_dirname
,
exe
)
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
save_dirname
,
exe
)
word_dict_len
=
len
(
word_dict
)
lod
=
[
0
,
4
,
10
]
lod
=
[
0
,
4
,
10
]
word_dict
=
paddle
.
dataset
.
imdb
.
word_dict
()
tensor_words
=
create_random_lodtensor
(
tensor_words
=
create_random_lodtensor
(
lod
,
place
,
low
=
0
,
high
=
len
(
word_dict
)
-
1
)
lod
,
place
,
low
=
0
,
high
=
word_dict_len
-
1
)
# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# and results will contain a list of data corresponding to fetch_targets.
# and results will contain a list of data corresponding to fetch_targets.
...
@@ -164,15 +170,15 @@ def infer(use_cuda, save_dirname=None):
...
@@ -164,15 +170,15 @@ def infer(use_cuda, save_dirname=None):
print
(
"Inference results: "
,
np_data
)
print
(
"Inference results: "
,
np_data
)
def
main
(
word_dict
,
n
et_method
,
use_cuda
):
def
main
(
word_dict
,
n
n_type
,
use_cuda
):
if
use_cuda
and
not
fluid
.
core
.
is_compiled_with_cuda
():
if
use_cuda
and
not
fluid
.
core
.
is_compiled_with_cuda
():
return
return
# Directory for saving the trained model
# Directory for saving the trained model
save_dirname
=
"understand_sentiment.inference.model"
save_dirname
=
"understand_sentiment
_"
+
nn_type
+
"
.inference.model"
train
(
word_dict
,
n
et_method
,
use_cuda
,
save_dirname
)
train
(
word_dict
,
n
n_type
,
use_cuda
,
save_dirname
)
infer
(
use_cuda
,
save_dirname
)
infer
(
word_dict
,
use_cuda
,
save_dirname
)
class
TestUnderstandSentiment
(
unittest
.
TestCase
):
class
TestUnderstandSentiment
(
unittest
.
TestCase
):
...
@@ -191,19 +197,19 @@ class TestUnderstandSentiment(unittest.TestCase):
...
@@ -191,19 +197,19 @@ class TestUnderstandSentiment(unittest.TestCase):
def
test_conv_cpu
(
self
):
def
test_conv_cpu
(
self
):
with
self
.
new_program_scope
():
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
n
et_method
=
convolution_net
,
use_cuda
=
False
)
main
(
self
.
word_dict
,
n
n_type
=
"conv"
,
use_cuda
=
False
)
def
test_stacked_lstm_cpu
(
self
):
def
test_stacked_lstm_cpu
(
self
):
with
self
.
new_program_scope
():
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
n
et_method
=
stacked_lstm_net
,
use_cuda
=
False
)
main
(
self
.
word_dict
,
n
n_type
=
"lstm"
,
use_cuda
=
False
)
def
test_conv_gpu
(
self
):
def
test_conv_gpu
(
self
):
with
self
.
new_program_scope
():
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
n
et_method
=
convolution_net
,
use_cuda
=
True
)
main
(
self
.
word_dict
,
n
n_type
=
"conv"
,
use_cuda
=
True
)
def
test_stacked_lstm_gpu
(
self
):
def
test_stacked_lstm_gpu
(
self
):
with
self
.
new_program_scope
():
with
self
.
new_program_scope
():
main
(
self
.
word_dict
,
n
et_method
=
stacked_lstm_net
,
use_cuda
=
True
)
main
(
self
.
word_dict
,
n
n_type
=
"lstm"
,
use_cuda
=
True
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录