Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
09c6cef2
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
223
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
09c6cef2
编写于
2月 05, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapt model config to the parallel running
上级
60518979
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
35 deletion
+67
-35
fluid/DeepASR/model.py
fluid/DeepASR/model.py
+33
-6
fluid/DeepASR/profile.py
fluid/DeepASR/profile.py
+17
-11
fluid/DeepASR/train.py
fluid/DeepASR/train.py
+17
-18
未找到文件。
fluid/DeepASR/model.py
浏览文件 @
09c6cef2
...
...
@@ -9,11 +9,40 @@ import paddle.v2.fluid as fluid
def
stacked_lstmp_model
(
hidden_dim
,
proj_dim
,
stacked_num
,
class_num
=
1749
,
is_train
=
True
):
parallel
=
False
,
is_train
=
True
,
class_num
=
1749
):
feature
=
fluid
.
layers
.
data
(
name
=
"feature"
,
shape
=
[
-
1
,
120
*
11
],
dtype
=
"float32"
,
lod_level
=
1
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
if
parallel
:
places
=
fluid
.
layers
.
get_places
()
pd
=
fluid
.
layers
.
ParallelDo
(
places
)
with
pd
.
do
():
feat_
=
pd
.
read_input
(
feature
)
label_
=
pd
.
read_input
(
label
)
prediction
,
avg_cost
,
acc
=
_net_conf
(
feat_
,
label_
,
hidden_dim
,
proj_dim
,
stacked_num
,
class_num
,
is_train
)
for
out
in
[
avg_cost
,
acc
]:
pd
.
write_output
(
out
)
# get mean loss and acc through every devices.
avg_cost
,
acc
=
pd
()
avg_cost
=
fluid
.
layers
.
mean
(
x
=
avg_cost
)
acc
=
fluid
.
layers
.
mean
(
x
=
acc
)
else
:
prediction
,
avg_cost
,
acc
=
_net_conf
(
feature
,
label
,
hidden_dim
,
proj_dim
,
stacked_num
,
class_num
,
is_train
)
return
prediction
,
avg_cost
,
acc
def
_net_conf
(
feature
,
label
,
hidden_dim
,
proj_dim
,
stacked_num
,
class_num
,
is_train
):
seq_conv1
=
fluid
.
layers
.
sequence_conv
(
input
=
feature
,
num_filters
=
1024
,
...
...
@@ -57,9 +86,7 @@ def stacked_lstmp_model(hidden_dim,
if
not
is_train
:
return
feature
,
prediction
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
,
lod_level
=
1
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
prediction
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
return
prediction
,
label
,
avg_cost
acc
=
fluid
.
layers
.
accuracy
(
input
=
prediction
,
label
=
label
)
return
prediction
,
avg_cost
,
acc
fluid/DeepASR/profile.py
浏览文件 @
09c6cef2
...
...
@@ -10,16 +10,16 @@ import time
import
paddle.v2
as
paddle
import
paddle.v2.fluid
as
fluid
import
paddle.v2.fluid.profiler
as
profiler
import
data_utils.trans_mean_variance_norm
as
trans_mean_variance_norm
import
data_utils.trans_add_delta
as
trans_add_delta
import
data_utils.trans_splice
as
trans_splice
import
data_utils.
augmentor.
trans_mean_variance_norm
as
trans_mean_variance_norm
import
data_utils.
augmentor.
trans_add_delta
as
trans_add_delta
import
data_utils.
augmentor.
trans_splice
as
trans_splice
import
data_utils.data_reader
as
reader
from
model
import
stacked_lstmp_model
from
utils
import
print_arguments
,
lodtensor_to_ndarray
from
data_utils.util
import
lodtensor_to_ndarray
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
"
LSTM model benchmark
."
)
parser
=
argparse
.
ArgumentParser
(
"
Profiling for stacked LSTMP model
."
)
parser
.
add_argument
(
'--batch_size'
,
type
=
int
,
...
...
@@ -51,6 +51,8 @@ def parse_args():
default
=
'GPU'
,
choices
=
[
'CPU'
,
'GPU'
],
help
=
'The device type. (default: %(default)s)'
)
parser
.
add_argument
(
'--parallel'
,
action
=
'store_true'
,
help
=
'If set, run in parallel.'
)
parser
.
add_argument
(
'--mean_var'
,
type
=
str
,
...
...
@@ -91,6 +93,13 @@ def parse_args():
return
args
def
print_arguments
(
args
):
print
(
'----------- Configuration Arguments -----------'
)
for
arg
,
value
in
sorted
(
vars
(
args
).
iteritems
()):
print
(
'%s: %s'
%
(
arg
,
value
))
print
(
'------------------------------------------------'
)
def
profile
(
args
):
"""profile the training process"""
...
...
@@ -100,14 +109,12 @@ def profile(args):
if
not
args
.
num_batch_to_skip
>=
0
:
raise
ValueError
(
"arg 'num_batch_to_skip' must not be smaller than 0."
)
prediction
,
label
,
avg_cost
=
stacked_lstmp_model
(
args
.
hidden_dim
,
args
.
proj_dim
,
args
.
stacked_num
)
prediction
,
avg_cost
,
accuracy
=
stacked_lstmp_model
(
args
.
hidden_dim
,
args
.
proj_dim
,
args
.
stacked_num
,
args
.
parallel
)
adam_optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
args
.
learning_rate
)
adam_optimizer
.
minimize
(
avg_cost
)
accuracy
=
fluid
.
evaluator
.
Accuracy
(
input
=
prediction
,
label
=
label
)
place
=
fluid
.
CPUPlace
()
if
args
.
device
==
'CPU'
else
fluid
.
CUDAPlace
(
0
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
...
...
@@ -127,7 +134,6 @@ def profile(args):
sorted_key
=
None
if
args
.
sorted_key
is
'None'
else
args
.
sorted_key
with
profiler
.
profiler
(
args
.
device
,
sorted_key
)
as
prof
:
frames_seen
,
start_time
=
0
,
0.0
accuracy
.
reset
(
exe
)
for
batch_id
in
range
(
0
,
args
.
max_batch_num
):
if
args
.
num_batch_to_skip
==
batch_id
:
profiler
.
reset_profiler
()
...
...
@@ -148,7 +154,7 @@ def profile(args):
outs
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"feature"
:
res_feature
,
"label"
:
res_label
},
fetch_list
=
[
avg_cost
]
+
accuracy
.
metrics
,
fetch_list
=
[
avg_cost
,
accuracy
]
,
return_numpy
=
False
)
if
args
.
print_train_acc
:
...
...
fluid/DeepASR/train.py
浏览文件 @
09c6cef2
...
...
@@ -10,16 +10,16 @@ import time
import
paddle.v2
as
paddle
import
paddle.v2.fluid
as
fluid
import
paddle.v2.fluid.profiler
as
profiler
import
data_utils.trans_mean_variance_norm
as
trans_mean_variance_norm
import
data_utils.trans_add_delta
as
trans_add_delta
import
data_utils.trans_splice
as
trans_splice
import
data_utils.
augmentor.
trans_mean_variance_norm
as
trans_mean_variance_norm
import
data_utils.
augmentor.
trans_add_delta
as
trans_add_delta
import
data_utils.
augmentor.
trans_splice
as
trans_splice
import
data_utils.data_reader
as
reader
from
model
import
stacked_lstmp_model
from
utils
import
print_arguments
,
lodtensor_to_ndarray
from
data_utils.util
import
lodtensor_to_ndarray
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
"
LSTM model benchmark
."
)
parser
=
argparse
.
ArgumentParser
(
"
Training for stacked LSTMP model
."
)
parser
.
add_argument
(
'--batch_size'
,
type
=
int
,
...
...
@@ -61,6 +61,8 @@ def parse_args():
default
=
'GPU'
,
choices
=
[
'CPU'
,
'GPU'
],
help
=
'The device type. (default: %(default)s)'
)
parser
.
add_argument
(
'--parallel'
,
action
=
'store_true'
,
help
=
'If set, run in parallel.'
)
parser
.
add_argument
(
'--mean_var'
,
type
=
str
,
...
...
@@ -80,24 +82,22 @@ def parse_args():
return
args
def
print_arguments
(
args
):
print
(
'----------- Configuration Arguments -----------'
)
for
arg
,
value
in
sorted
(
vars
(
args
).
iteritems
()):
print
(
'%s: %s'
%
(
arg
,
value
))
print
(
'------------------------------------------------'
)
def
train
(
args
):
"""train in loop."""
prediction
,
label
,
avg_cost
=
stacked_lstmp_model
(
args
.
hidden_dim
,
args
.
proj_dim
,
args
.
stacked_num
)
prediction
,
avg_cost
,
accuracy
=
stacked_lstmp_model
(
args
.
hidden_dim
,
args
.
proj_dim
,
args
.
stacked_num
,
args
.
parallel
)
adam_optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
args
.
learning_rate
)
adam_optimizer
.
minimize
(
avg_cost
)
accuracy
=
fluid
.
evaluator
.
Accuracy
(
input
=
prediction
,
label
=
label
)
# clone from default main program
inference_program
=
fluid
.
default_main_program
().
clone
()
with
fluid
.
program_guard
(
inference_program
):
test_accuracy
=
fluid
.
evaluator
.
Accuracy
(
input
=
prediction
,
label
=
label
)
test_target
=
[
avg_cost
]
+
test_accuracy
.
metrics
+
test_accuracy
.
states
inference_program
=
fluid
.
io
.
get_inference_program
(
test_target
)
place
=
fluid
.
CPUPlace
()
if
args
.
device
==
'CPU'
else
fluid
.
CUDAPlace
(
0
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
...
...
@@ -115,7 +115,6 @@ def train(args):
res_label
=
fluid
.
LoDTensor
()
for
pass_id
in
xrange
(
args
.
pass_num
):
pass_start_time
=
time
.
time
()
accuracy
.
reset
(
exe
)
batch_id
=
0
while
True
:
# load_data
...
...
@@ -132,7 +131,7 @@ def train(args):
_
,
acc
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"feature"
:
res_feature
,
"label"
:
res_label
},
fetch_list
=
[
avg_cost
]
+
accuracy
.
metrics
,
fetch_list
=
[
avg_cost
,
accuracy
]
,
return_numpy
=
False
)
if
batch_id
>
0
and
(
batch_id
%
args
.
print_per_batches
==
0
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录