diff --git a/fluid/DeepASR/data_utils/data_reader.py b/fluid/DeepASR/data_utils/data_reader.py index b08e7f55a45d7e0dd1550ad84c388c49867c93c1..f7bc9c6602f82c05fb7eff9a9c90b43f88cd02b1 100644 --- a/fluid/DeepASR/data_utils/data_reader.py +++ b/fluid/DeepASR/data_utils/data_reader.py @@ -225,8 +225,8 @@ class DataReader(object): @suppress_complaints(verbose=self._verbose) def ordered_processing_task(sample_info_queue, sample_queue, out_order): if self._verbose == 0: - signal.signal(signal.SIGTERM, suppress_signal()) - signal.signal(signal.SIGINT, suppress_signal()) + signal.signal(signal.SIGTERM, suppress_signal) + signal.signal(signal.SIGINT, suppress_signal) def read_bytes(fpath, start, size): f = open(fpath, 'r') diff --git a/fluid/DeepASR/model.py b/fluid/DeepASR/model_utils/model.py similarity index 92% rename from fluid/DeepASR/model.py rename to fluid/DeepASR/model_utils/model.py index 226a06b0a9673d38893341766c94deb36bf9f64b..4e29394a0a2ced700c99f3ea9fa516a9a58e1420 100644 --- a/fluid/DeepASR/model.py +++ b/fluid/DeepASR/model_utils/model.py @@ -9,12 +9,16 @@ import paddle.v2.fluid as fluid def stacked_lstmp_model(hidden_dim, proj_dim, stacked_num, + class_num, parallel=False, - is_train=True, - class_num=1749): + is_train=True): """ The model for DeepASR. The main structure is composed of stacked identical LSTMP (LSTM with recurrent projection) layers. + When running in training and validation phase, the feeding dictionary + is {'feature', 'label'}, fed by the LodTensor for feature data and + label data respectively. And in inference, only `feature` is needed. + Args: hidden_dim(int): The hidden state's dimension of the LSTMP layer. proj_dim(int): The projection size of the LSTMP layer. diff --git a/fluid/DeepASR/tools/_init_paths.py b/fluid/DeepASR/tools/_init_paths.py new file mode 100644 index 0000000000000000000000000000000000000000..228dbae6bf95231030c1858c4d30b49f162f46e2 --- /dev/null +++ b/fluid/DeepASR/tools/_init_paths.py @@ -0,0 +1,19 @@ +"""Add the parent directory to $PYTHONPATH""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os.path +import sys + + +def add_path(path): + if path not in sys.path: + sys.path.insert(0, path) + + +this_dir = os.path.dirname(__file__) + +# Add project path to PYTHONPATH +proj_path = os.path.join(this_dir, '..') +add_path(proj_path) diff --git a/fluid/DeepASR/profile.py b/fluid/DeepASR/tools/profile.py similarity index 95% rename from fluid/DeepASR/profile.py rename to fluid/DeepASR/tools/profile.py index 9f9cce0411159e5e2f20f0eb091a07d5dfe42caf..a45ce98acb3b70bfa8292c05fd52c85a3a3ddc48 100644 --- a/fluid/DeepASR/profile.py +++ b/fluid/DeepASR/tools/profile.py @@ -7,14 +7,14 @@ import numpy as np import argparse import time -import paddle.v2 as paddle import paddle.v2.fluid as fluid import paddle.v2.fluid.profiler as profiler +import _init_paths 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 model_utils.model import stacked_lstmp_model from data_utils.util import lodtensor_to_ndarray @@ -118,8 +118,12 @@ def profile(args): raise ValueError( "arg 'first_batches_to_skip' must not be smaller than 0.") - _, avg_cost, accuracy = stacked_lstmp_model(args.hidden_dim, args.proj_dim, - args.stacked_num, args.parallel) + _, avg_cost, accuracy = stacked_lstmp_model( + hidden_dim=args.hidden_dim, + proj_dim=args.proj_dim, + stacked_num=args.stacked_num, + class_num=1749, + parallel=args.parallel) adam_optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate) adam_optimizer.minimize(avg_cost) @@ -173,7 +177,6 @@ def profile(args): else: sys.stdout.write('.') sys.stdout.flush() - time_consumed = time.time() - start_time frames_per_sec = frames_seen / time_consumed print("\nTime consumed: %f s, performance: %f frames/s." % diff --git a/fluid/DeepASR/train.py b/fluid/DeepASR/train.py index b2584259742a4a995c2bb4dadf3b0b9acc80ec15..1c45f0a086332288760c359d9845aa94641cf7d7 100644 --- a/fluid/DeepASR/train.py +++ b/fluid/DeepASR/train.py @@ -8,15 +8,13 @@ import numpy as np import argparse import time -import paddle.v2 as paddle import paddle.v2.fluid as fluid -import paddle.v2.fluid.profiler as profiler 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 data_utils.util import lodtensor_to_ndarray -from model import stacked_lstmp_model +from model_utils.model import stacked_lstmp_model def parse_args(): @@ -116,8 +114,14 @@ def train(args): """train in loop. """ + # prediction, avg_cost, accuracy = stacked_lstmp_model(args.hidden_dim, + # args.proj_dim, args.stacked_num, class_num=1749, args.parallel) prediction, avg_cost, accuracy = stacked_lstmp_model( - args.hidden_dim, args.proj_dim, args.stacked_num, args.parallel) + hidden_dim=args.hidden_dim, + proj_dim=args.proj_dim, + stacked_num=args.stacked_num, + class_num=1749, + parallel=args.parallel) adam_optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate) adam_optimizer.minimize(avg_cost)