Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
95141467
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
95141467
编写于
6月 05, 2018
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ParallelDo example for benchmark/fluid
上级
6ada5f48
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
18 deletion
+52
-18
benchmark/fluid/fluid_benchmark.py
benchmark/fluid/fluid_benchmark.py
+5
-0
benchmark/fluid/models/mnist.py
benchmark/fluid/models/mnist.py
+24
-9
benchmark/fluid/models/resnet.py
benchmark/fluid/models/resnet.py
+22
-7
benchmark/fluid/models/stacked_dynamic_lstm.py
benchmark/fluid/models/stacked_dynamic_lstm.py
+1
-2
未找到文件。
benchmark/fluid/fluid_benchmark.py
浏览文件 @
95141467
...
...
@@ -69,6 +69,11 @@ def parse_args():
type
=
int
,
default
=
1
,
help
=
'If gpus > 1, will use ParallelExecutor to run, else use Executor.'
)
parser
.
add_argument
(
'--cpus'
,
type
=
int
,
default
=
1
,
help
=
'If cpus > 1, will use ParallelDo to run, else use Executor.'
)
parser
.
add_argument
(
'--data_set'
,
type
=
str
,
...
...
benchmark/fluid/models/mnist.py
浏览文件 @
95141467
...
...
@@ -69,15 +69,30 @@ def get_model(args):
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
[
1
,
28
,
28
],
dtype
=
DTYPE
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
# Train program
predict
=
cnn_model
(
images
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
# Evaluator
batch_size_tensor
=
fluid
.
layers
.
create_tensor
(
dtype
=
'int64'
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
,
total
=
batch_size_tensor
)
if
args
.
device
==
'CPU'
and
args
.
cpus
>
1
:
places
=
fluid
.
layers
.
get_places
(
args
.
cpus
)
pd
=
fluid
.
layers
.
ParallelDo
(
places
)
with
pd
.
do
():
predict
=
cnn_model
(
pd
.
read_input
(
images
))
label
=
pd
.
read_input
(
label
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
)
pd
.
write_output
(
avg_cost
)
pd
.
write_output
(
batch_acc
)
avg_cost
,
batch_acc
=
pd
()
avg_cost
=
fluid
.
layers
.
mean
(
avg_cost
)
batch_acc
=
fluid
.
layers
.
mean
(
batch_acc
)
else
:
# Train program
predict
=
cnn_model
(
images
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
# Evaluator
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
)
# inference program
inference_program
=
fluid
.
default_main_program
().
clone
()
...
...
benchmark/fluid/models/resnet.py
浏览文件 @
95141467
...
...
@@ -132,18 +132,33 @@ def get_model(args):
input
=
fluid
.
layers
.
data
(
name
=
'data'
,
shape
=
dshape
,
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
predict
=
model
(
input
,
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
batch_size_tensor
=
fluid
.
layers
.
create_tensor
(
dtype
=
'int64'
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
,
total
=
batch_size_tensor
)
if
args
.
device
==
'CPU'
and
args
.
cpus
>
1
:
places
=
fluid
.
layers
.
get_places
(
args
.
cpus
)
pd
=
fluid
.
layers
.
ParallelDo
(
places
)
with
pd
.
do
():
predict
=
model
(
pd
.
read_input
(
input
),
class_dim
)
label
=
pd
.
read_input
(
label
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
)
pd
.
write_output
(
avg_cost
)
pd
.
write_output
(
batch_acc
)
avg_cost
,
batch_acc
=
pd
()
avg_cost
=
fluid
.
layers
.
mean
(
avg_cost
)
batch_acc
=
fluid
.
layers
.
mean
(
batch_acc
)
else
:
predict
=
model
(
input
,
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
predict
,
label
=
label
)
inference_program
=
fluid
.
default_main_program
().
clone
()
with
fluid
.
program_guard
(
inference_program
):
inference_program
=
fluid
.
io
.
get_inference_program
(
target_vars
=
[
batch_acc
,
batch_size_tensor
])
target_vars
=
[
batch_acc
])
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
0.01
,
momentum
=
0.9
)
...
...
benchmark/fluid/models/stacked_dynamic_lstm.py
浏览文件 @
95141467
...
...
@@ -101,9 +101,8 @@ def get_model(args):
loss
=
fluid
.
layers
.
mean
(
x
=
loss
)
# add acc
batch_size_tensor
=
fluid
.
layers
.
create_tensor
(
dtype
=
'int64'
)
batch_acc
=
fluid
.
layers
.
accuracy
(
input
=
logit
,
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
\
shape
=
[
1
],
dtype
=
'int64'
)
,
total
=
batch_size_tensor
)
shape
=
[
1
],
dtype
=
'int64'
))
inference_program
=
fluid
.
default_main_program
().
clone
()
with
fluid
.
program_guard
(
inference_program
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录