Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
20d3af62
P
Paddle
项目概览
夏有凉风,冬有雪
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
20d3af62
编写于
1月 25, 2018
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable the dependency.
上级
f6f7102b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
54 addition
and
14 deletion
+54
-14
paddle/inference/inference.cc
paddle/inference/inference.cc
+1
-1
paddle/inference/tests/book/CMakeLists.txt
paddle/inference/tests/book/CMakeLists.txt
+7
-4
paddle/inference/tests/book/test_inference_recognize_digits.cc
...e/inference/tests/book/test_inference_recognize_digits.cc
+1
-1
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
+45
-8
未找到文件。
paddle/inference/inference.cc
浏览文件 @
20d3af62
...
...
@@ -75,7 +75,7 @@ void InferenceEngine::GenerateLoadProgram(const std::string& dirname) {
framework
::
BlockDesc
*
load_block
=
load_program_
->
MutableBlock
(
0
);
for
(
auto
*
var
:
global_block
->
AllVars
())
{
if
(
IsParameter
(
var
))
{
LOG
(
INFO
)
<<
"parameter's name: "
<<
var
->
Name
();
VLOG
(
3
)
<<
"parameter's name: "
<<
var
->
Name
();
framework
::
VarDesc
*
new_var
=
load_block
->
Var
(
var
->
Name
());
new_var
->
SetShape
(
var
->
Shape
());
...
...
paddle/inference/tests/book/CMakeLists.txt
浏览文件 @
20d3af62
add_executable
(
test_inference_recognize_digits_mlp test_inference_recognize_digits_mlp.cc
)
set
(
PYTHON_TESTS_DIR
${
PADDLE_SOURCE_DIR
}
/python/paddle/v2/fluid/tests
)
add_executable
(
test_inference_recognize_digits test_inference_recognize_digits.cc
)
target_circle_link_libraries
(
test_inference_recognize_digits
_mlp
test_inference_recognize_digits
ARCHIVE_START
paddle_fluid
ARCHIVE_END
...
...
@@ -8,6 +9,8 @@ target_circle_link_libraries(
gflags
)
add_test
(
NAME test_inference_recognize_digits_mlp
COMMAND test_inference_recognize_digits
_mlp
--dirname=
${
PADDLE_SOURCE_DIR
}
/python/paddle/v2/fluid/tests
/book/recognize_digits_mlp.inference.model
COMMAND test_inference_recognize_digits
--dirname=
${
PYTHON_TESTS_DIR
}
/book/recognize_digits_mlp.inference.model
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
)
set_tests_properties
(
test_inference_recognize_digits_mlp
PROPERTIES DEPENDS test_recognize_digits_mlp_cpu
)
paddle/inference/tests/book/test_inference_recognize_digits
_mlp
.cc
→
paddle/inference/tests/book/test_inference_recognize_digits.cc
浏览文件 @
20d3af62
...
...
@@ -20,7 +20,7 @@ limitations under the License. */
DEFINE_string
(
dirname
,
""
,
"Directory of the inference model."
);
TEST
(
inference
,
recognize_digits
_mlp
)
{
TEST
(
inference
,
recognize_digits
)
{
if
(
FLAGS_dirname
.
empty
())
{
LOG
(
FATAL
)
<<
"Usage: ./example --dirname=path/to/your/model"
;
}
...
...
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
浏览文件 @
20d3af62
...
...
@@ -45,8 +45,9 @@ BATCH_SIZE = 64
def
loss_net
(
hidden
,
label
):
prediction
=
fluid
.
layers
.
fc
(
input
=
hidden
,
size
=
10
,
act
=
'softmax'
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
return
fluid
.
layers
.
mean
(
x
=
loss
),
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
avg_loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
acc
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
return
prediction
,
avg_loss
,
acc
def
mlp
(
img
,
label
):
...
...
@@ -73,8 +74,7 @@ def conv_net(img, label):
return
loss_net
(
conv_pool_2
,
label
)
def
main
():
args
=
parse_arg
()
def
train
(
args
,
save_dirname
=
None
):
print
(
"recognize digits with args: {0}"
.
format
(
" "
.
join
(
sys
.
argv
[
1
:])))
img
=
fluid
.
layers
.
data
(
name
=
'img'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
...
...
@@ -91,7 +91,8 @@ def main():
with
pd
.
do
():
img_
=
pd
.
read_input
(
img
)
label_
=
pd
.
read_input
(
label
)
for
o
in
net_conf
(
img_
,
label_
):
prediction
,
avg_loss
,
acc
=
net_conf
(
img_
,
label_
)
for
o
in
[
avg_loss
,
acc
]:
pd
.
write_output
(
o
)
avg_loss
,
acc
=
pd
()
...
...
@@ -99,7 +100,7 @@ def main():
avg_loss
=
fluid
.
layers
.
mean
(
x
=
avg_loss
)
acc
=
fluid
.
layers
.
mean
(
x
=
acc
)
else
:
avg_loss
,
acc
=
net_conf
(
img
,
label
)
prediction
,
avg_loss
,
acc
=
net_conf
(
img
,
label
)
test_program
=
fluid
.
default_main_program
().
clone
()
...
...
@@ -137,7 +138,10 @@ def main():
acc_val
=
numpy
.
array
(
acc_set
).
mean
()
avg_loss_val
=
numpy
.
array
(
avg_loss_set
).
mean
()
if
float
(
acc_val
)
>
0.85
:
# test acc > 85%
exit
(
0
)
if
save_dirname
is
not
None
:
fluid
.
io
.
save_inference_model
(
save_dirname
,
[
"img"
],
[
prediction
],
exe
)
return
else
:
print
(
'PassID {0:1}, BatchID {1:04}, Test Loss {2:2.2}, Acc {3:2.2}'
.
...
...
@@ -145,5 +149,38 @@ def main():
float
(
avg_loss_val
),
float
(
acc_val
)))
def
infer
(
args
,
save_dirname
=
None
):
if
save_dirname
is
None
:
return
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_cuda
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
# Use fluid.io.load_inference_model to obtain the inference program desc,
# the feed_target_names (the names of variables that will be feeded
# data using feed operators), and the fetch_targets (variables that
# we want to obtain data from using fetch operators).
[
inference_program
,
feed_target_names
,
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
save_dirname
,
exe
)
if
args
.
nn_type
==
'mlp'
:
tensor_img
=
numpy
.
random
.
rand
(
1
,
28
,
28
).
astype
(
"float32"
)
else
:
tensor_img
=
numpy
.
random
.
rand
(
1
,
1
,
28
,
28
).
astype
(
"float32"
)
# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# and results will contain a list of data corresponding to fetch_targets.
results
=
exe
.
run
(
inference_program
,
feed
=
{
feed_target_names
[
0
]:
tensor_img
},
fetch_list
=
fetch_targets
)
print
(
"infer results: "
,
results
[
0
])
if
__name__
==
'__main__'
:
main
()
args
=
parse_arg
()
if
not
args
.
use_cuda
and
not
args
.
parallel
:
save_dirname
=
"recognize_digits_"
+
args
.
nn_type
+
".inference.model"
else
:
save_dirname
=
None
train
(
args
,
save_dirname
)
infer
(
args
,
save_dirname
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录