Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
a6ef41f3
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看板
未验证
提交
a6ef41f3
编写于
9月 03, 2018
作者:
C
chengduo
提交者:
GitHub
9月 03, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix high level api bug on release-0.15 (#13164)
* fix high level API(Inference) bug * patch the unit tests
上级
c5763c12
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
110 addition
and
40 deletion
+110
-40
python/paddle/fluid/inferencer.py
python/paddle/fluid/inferencer.py
+3
-4
python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py
.../image_classification/test_image_classification_resnet.py
+28
-8
python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py
...api/image_classification/test_image_classification_vgg.py
+27
-10
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py
...-level-api/recognize_digits/test_recognize_digits_conv.py
+24
-9
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py
...h-level-api/recognize_digits/test_recognize_digits_mlp.py
+28
-9
未找到文件。
python/paddle/fluid/inferencer.py
浏览文件 @
a6ef41f3
...
...
@@ -98,10 +98,9 @@ class Inferencer(object):
raise
ValueError
(
"inputs should be a map of {'input_name': input_var}"
)
with
executor
.
scope_guard
(
self
.
scope
):
results
=
self
.
exe
.
run
(
self
.
inference_program
,
feed
=
inputs
,
fetch_list
=
[
self
.
predict_var
],
with
self
.
_prog_and_scope_guard
():
results
=
self
.
exe
.
run
(
feed
=
inputs
,
fetch_list
=
[
self
.
predict_var
.
name
],
return_numpy
=
return_numpy
)
return
results
...
...
python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py
浏览文件 @
a6ef41f3
...
...
@@ -16,7 +16,9 @@ from __future__ import print_function
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
numpy
import
os
import
cifar10_small_test_set
...
...
@@ -89,7 +91,7 @@ def optimizer_func():
return
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
def
train
(
use_cuda
,
train_program
,
params_dirname
):
def
train
(
use_cuda
,
train_program
,
para
llel
,
para
ms_dirname
):
BATCH_SIZE
=
128
EPOCH_NUM
=
1
...
...
@@ -116,7 +118,10 @@ def train(use_cuda, train_program, params_dirname):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
trainer
=
fluid
.
Trainer
(
train_func
=
train_program
,
optimizer_func
=
optimizer_func
,
place
=
place
)
train_func
=
train_program
,
optimizer_func
=
optimizer_func
,
place
=
place
,
parallel
=
parallel
)
trainer
.
train
(
reader
=
train_reader
,
...
...
@@ -125,10 +130,13 @@ def train(use_cuda, train_program, params_dirname):
feed_order
=
[
'pixel'
,
'label'
])
def
infer
(
use_cuda
,
inference_program
,
params_dirname
=
None
):
def
infer
(
use_cuda
,
inference_program
,
para
llel
,
para
ms_dirname
=
None
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
,
parallel
=
parallel
)
# The input's dimension of conv should be 4-D or 5-D.
# Use normilized image pixels as input data, which should be in the range
...
...
@@ -139,22 +147,34 @@ def infer(use_cuda, inference_program, params_dirname=None):
print
(
"infer results: "
,
results
)
def
main
(
use_cuda
):
def
main
(
use_cuda
,
parallel
):
if
use_cuda
and
not
fluid
.
core
.
is_compiled_with_cuda
():
return
save_path
=
"image_classification_resnet.inference.model"
os
.
environ
[
'CPU_NUM'
]
=
str
(
4
)
train
(
use_cuda
=
use_cuda
,
train_program
=
train_network
,
params_dirname
=
save_path
)
params_dirname
=
save_path
,
parallel
=
parallel
)
# FIXME(zcd): in the inference stage, the number of
# input data is one, it is not appropriate to use parallel.
if
parallel
and
use_cuda
:
return
os
.
environ
[
'CPU_NUM'
]
=
str
(
1
)
infer
(
use_cuda
=
use_cuda
,
inference_program
=
inference_network
,
params_dirname
=
save_path
)
params_dirname
=
save_path
,
parallel
=
parallel
)
if
__name__
==
'__main__'
:
for
use_cuda
in
(
False
,
True
):
main
(
use_cuda
=
use_cuda
)
for
parallel
in
(
False
,
True
):
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
continue
main
(
use_cuda
=
use_cuda
,
parallel
=
parallel
)
python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py
浏览文件 @
a6ef41f3
...
...
@@ -16,7 +16,9 @@ from __future__ import print_function
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
numpy
import
os
import
cifar10_small_test_set
...
...
@@ -68,7 +70,7 @@ def optimizer_func():
return
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
def
train
(
use_cuda
,
train_program
,
params_dirname
):
def
train
(
use_cuda
,
train_program
,
para
llel
,
para
ms_dirname
):
BATCH_SIZE
=
128
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
...
...
@@ -93,7 +95,10 @@ def train(use_cuda, train_program, params_dirname):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
trainer
=
fluid
.
Trainer
(
train_func
=
train_program
,
place
=
place
,
optimizer_func
=
optimizer_func
)
train_func
=
train_program
,
place
=
place
,
optimizer_func
=
optimizer_func
,
parallel
=
parallel
)
trainer
.
train
(
reader
=
train_reader
,
...
...
@@ -102,10 +107,13 @@ def train(use_cuda, train_program, params_dirname):
feed_order
=
[
'pixel'
,
'label'
])
def
infer
(
use_cuda
,
inference_program
,
params_dirname
=
None
):
def
infer
(
use_cuda
,
inference_program
,
para
llel
,
para
ms_dirname
=
None
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
,
parallel
=
parallel
)
# The input's dimension of conv should be 4-D or 5-D.
# Use normilized image pixels as input data, which should be in the range
...
...
@@ -116,22 +124,31 @@ def infer(use_cuda, inference_program, params_dirname=None):
print
(
"infer results: "
,
results
)
def
main
(
use_cuda
):
if
use_cuda
and
not
fluid
.
core
.
is_compiled_with_cuda
():
return
def
main
(
use_cuda
,
parallel
):
save_path
=
"image_classification_vgg.inference.model"
os
.
environ
[
'CPU_NUM'
]
=
str
(
4
)
train
(
use_cuda
=
use_cuda
,
train_program
=
train_network
,
params_dirname
=
save_path
)
params_dirname
=
save_path
,
parallel
=
parallel
)
# FIXME(zcd): in the inference stage, the number of
# input data is one, it is not appropriate to use parallel.
if
parallel
and
use_cuda
:
return
os
.
environ
[
'CPU_NUM'
]
=
str
(
1
)
infer
(
use_cuda
=
use_cuda
,
inference_program
=
inference_network
,
params_dirname
=
save_path
)
params_dirname
=
save_path
,
parallel
=
parallel
)
if
__name__
==
'__main__'
:
for
use_cuda
in
(
False
,
True
):
main
(
use_cuda
=
use_cuda
)
for
parallel
in
(
False
,
True
):
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
continue
main
(
use_cuda
=
use_cuda
,
parallel
=
parallel
)
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py
浏览文件 @
a6ef41f3
...
...
@@ -64,14 +64,14 @@ def optimizer_func():
return
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
def
train
(
use_cuda
,
train_program
,
params_dirname
):
def
train
(
use_cuda
,
train_program
,
para
llel
,
para
ms_dirname
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
trainer
=
fluid
.
Trainer
(
train_func
=
train_program
,
place
=
place
,
optimizer_func
=
optimizer_func
,
parallel
=
True
)
parallel
=
parallel
)
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
...
...
@@ -108,11 +108,14 @@ def train(use_cuda, train_program, params_dirname):
feed_order
=
[
'img'
,
'label'
])
def
infer
(
use_cuda
,
inference_program
,
params_dirname
=
None
):
def
infer
(
use_cuda
,
inference_program
,
para
llel
,
para
ms_dirname
=
None
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
,
parallel
=
parallel
)
batch_size
=
1
tensor_img
=
numpy
.
random
.
uniform
(
-
1.0
,
1.0
,
...
...
@@ -123,20 +126,32 @@ def infer(use_cuda, inference_program, params_dirname=None):
print
(
"infer results: "
,
results
[
0
])
def
main
(
use_cuda
):
def
main
(
use_cuda
,
parallel
):
params_dirname
=
"recognize_digits_conv.inference.model"
# call train() with is_local argument to run distributed train
os
.
environ
[
'CPU_NUM'
]
=
str
(
4
)
train
(
use_cuda
=
use_cuda
,
train_program
=
train_program
,
params_dirname
=
params_dirname
)
params_dirname
=
params_dirname
,
parallel
=
parallel
)
# FIXME(zcd): in the inference stage, the number of
# input data is one, it is not appropriate to use parallel.
if
parallel
and
use_cuda
:
return
os
.
environ
[
'CPU_NUM'
]
=
str
(
1
)
infer
(
use_cuda
=
use_cuda
,
inference_program
=
inference_program
,
params_dirname
=
params_dirname
)
params_dirname
=
params_dirname
,
parallel
=
parallel
)
if
__name__
==
'__main__'
:
# for use_cuda in (False, True):
main
(
use_cuda
=
core
.
is_compiled_with_cuda
())
for
use_cuda
in
(
False
,
True
):
for
parallel
in
(
False
,
True
):
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
continue
main
(
use_cuda
=
use_cuda
,
parallel
=
parallel
)
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py
浏览文件 @
a6ef41f3
...
...
@@ -16,6 +16,7 @@ from __future__ import print_function
import
argparse
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
paddle
import
sys
import
numpy
...
...
@@ -50,11 +51,14 @@ def optimizer_func():
return
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
def
train
(
use_cuda
,
train_program
,
params_dirname
):
def
train
(
use_cuda
,
train_program
,
params_dirname
,
parallel
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
trainer
=
fluid
.
Trainer
(
train_func
=
train_program
,
place
=
place
,
optimizer_func
=
optimizer_func
)
train_func
=
train_program
,
place
=
place
,
optimizer_func
=
optimizer_func
,
parallel
=
parallel
)
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
...
...
@@ -86,11 +90,14 @@ def train(use_cuda, train_program, params_dirname):
feed_order
=
[
'img'
,
'label'
])
def
infer
(
use_cuda
,
inference_program
,
params_dirname
=
None
):
def
infer
(
use_cuda
,
inference_program
,
para
llel
,
para
ms_dirname
=
None
):
place
=
fluid
.
CUDAPlace
(
0
)
if
use_cuda
else
fluid
.
CPUPlace
()
inferencer
=
fluid
.
Inferencer
(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
,
parallel
=
parallel
)
batch_size
=
1
tensor_img
=
numpy
.
random
.
uniform
(
-
1.0
,
1.0
,
...
...
@@ -101,20 +108,32 @@ def infer(use_cuda, inference_program, params_dirname=None):
print
(
"infer results: "
,
results
[
0
])
def
main
(
use_cuda
):
def
main
(
use_cuda
,
parallel
):
params_dirname
=
"recognize_digits_mlp.inference.model"
# call train() with is_local argument to run distributed train
os
.
environ
[
'CPU_NUM'
]
=
str
(
4
)
train
(
use_cuda
=
use_cuda
,
train_program
=
train_program
,
params_dirname
=
params_dirname
)
params_dirname
=
params_dirname
,
parallel
=
parallel
)
# FIXME(zcd): in the inference stage, the number of
# input data is one, it is not appropriate to use parallel.
if
parallel
and
use_cuda
:
return
os
.
environ
[
'CPU_NUM'
]
=
str
(
1
)
infer
(
use_cuda
=
use_cuda
,
inference_program
=
inference_program
,
params_dirname
=
params_dirname
)
params_dirname
=
params_dirname
,
parallel
=
parallel
)
if
__name__
==
'__main__'
:
# for use_cuda in (False, True):
main
(
use_cuda
=
False
)
for
use_cuda
in
(
False
,
True
):
for
parallel
in
(
False
,
True
):
if
use_cuda
and
not
core
.
is_compiled_with_cuda
():
continue
main
(
use_cuda
=
use_cuda
,
parallel
=
parallel
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录