提交 c16bdb55 编写于 作者: Y Yibing Liu

Add more comments in model conf and make it more concise

上级 f5811ba4
...@@ -12,37 +12,20 @@ def stacked_lstmp_model(hidden_dim, ...@@ -12,37 +12,20 @@ def stacked_lstmp_model(hidden_dim,
parallel=False, parallel=False,
is_train=True, is_train=True,
class_num=1749): class_num=1749):
feature = fluid.layers.data( """ The model for DeepASR. The main structure is composed of stacked
name="feature", shape=[-1, 120 * 11], dtype="float32", lod_level=1) identical LSTMP (LSTM with recurrent projection) layers.
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. Args:
avg_cost, acc = pd() hidden_dim(int): The hidden state's dimension of the LSTMP layer.
avg_cost = fluid.layers.mean(x=avg_cost) proj_dim(int): The projection size of the LSTMP layer.
acc = fluid.layers.mean(x=acc) stacked_num(int): The number of stacked LSTMP layers.
else: parallel(bool): Run in parallel or not, default `False`.
prediction, avg_cost, acc = _net_conf(feature, label, hidden_dim, is_train(bool): Run in training phase or not, default `True`.
proj_dim, stacked_num, class_num, class_dim(int): The number of output classes.
is_train) """
return prediction, avg_cost, acc
# network configuration
def _net_conf(feature, label, hidden_dim, proj_dim, stacked_num, class_num, def _net_conf(feature, label):
is_train):
seq_conv1 = fluid.layers.sequence_conv( seq_conv1 = fluid.layers.sequence_conv(
input=feature, input=feature,
num_filters=1024, num_filters=1024,
...@@ -88,3 +71,31 @@ def _net_conf(feature, label, hidden_dim, proj_dim, stacked_num, class_num, ...@@ -88,3 +71,31 @@ def _net_conf(feature, label, hidden_dim, proj_dim, stacked_num, class_num,
avg_cost = fluid.layers.mean(x=cost) avg_cost = fluid.layers.mean(x=cost)
acc = fluid.layers.accuracy(input=prediction, label=label) acc = fluid.layers.accuracy(input=prediction, label=label)
return prediction, avg_cost, acc return prediction, avg_cost, acc
# data feeder
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:
# When the execution place is specified to CUDAPlace, the program will
# run on all $CUDA_VISIBLE_DEVICES GPUs. Otherwise the program will
# run on all CPU devices.
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_)
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)
return prediction, avg_cost, acc
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册