未验证 提交 36e3fcd5 编写于 作者: Y Yibing Liu 提交者: GitHub

Merge pull request #938 from zhxfl/new_config

New config
...@@ -8,6 +8,7 @@ import numpy as np ...@@ -8,6 +8,7 @@ import numpy as np
import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm 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_add_delta as trans_add_delta
import data_utils.augmentor.trans_splice as trans_splice import data_utils.augmentor.trans_splice as trans_splice
import data_utils.augmentor.trans_delay as trans_delay
class TestTransMeanVarianceNorm(unittest.TestCase): class TestTransMeanVarianceNorm(unittest.TestCase):
...@@ -112,5 +113,24 @@ class TestTransSplict(unittest.TestCase): ...@@ -112,5 +113,24 @@ class TestTransSplict(unittest.TestCase):
self.assertAlmostEqual(feature[i][j * 10 + k], cur_val) self.assertAlmostEqual(feature[i][j * 10 + k], cur_val)
class TestTransDelay(unittest.TestCase):
"""unittest TransDelay
"""
def test_perform(self):
label = np.zeros((10, 1), dtype="int64")
for i in xrange(10):
label[i][0] = i
trans = trans_delay.TransDelay(5)
(_, label, _) = trans.perform_trans((None, label, None))
for i in xrange(5):
self.assertAlmostEqual(label[i + 5][0], i)
for i in xrange(5):
self.assertAlmostEqual(label[i][0], 0)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import math
class TransDelay(object):
""" Delay label, and copy first label value in the front.
Attributes:
_delay_time : the delay frame num of label
"""
def __init__(self, delay_time):
"""init construction
Args:
delay_time : the delay frame num of label
"""
self._delay_time = delay_time
def perform_trans(self, sample):
"""
Args:
sample(object):input sample, contain feature numpy and label numpy, sample name list
Returns:
(feature, label, name)
"""
(feature, label, name) = sample
shape = label.shape
assert len(shape) == 2
label[self._delay_time:shape[0]] = label[0:shape[0] - self._delay_time]
for i in xrange(self._delay_time):
label[i][0] = label[self._delay_time][0]
return (feature, label, name)
...@@ -12,6 +12,7 @@ import paddle.fluid as fluid ...@@ -12,6 +12,7 @@ import paddle.fluid as fluid
import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm 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_add_delta as trans_add_delta
import data_utils.augmentor.trans_splice as trans_splice import data_utils.augmentor.trans_splice as trans_splice
import data_utils.augmentor.trans_delay as trans_delay
import data_utils.async_data_reader as reader import data_utils.async_data_reader as reader
from decoder.post_decode_faster import Decoder from decoder.post_decode_faster import Decoder
from data_utils.util import lodtensor_to_ndarray from data_utils.util import lodtensor_to_ndarray
...@@ -36,7 +37,7 @@ def parse_args(): ...@@ -36,7 +37,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--frame_dim', '--frame_dim',
type=int, type=int,
default=120 * 11, default=80,
help='Frame dimension of feature data. (default: %(default)d)') help='Frame dimension of feature data. (default: %(default)d)')
parser.add_argument( parser.add_argument(
'--stacked_num', '--stacked_num',
...@@ -179,7 +180,7 @@ def infer_from_ckpt(args): ...@@ -179,7 +180,7 @@ def infer_from_ckpt(args):
ltrans = [ ltrans = [
trans_add_delta.TransAddDelta(2, 2), trans_add_delta.TransAddDelta(2, 2),
trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var), trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var),
trans_splice.TransSplice() trans_splice.TransSplice(), trans_delay.TransDelay(5)
] ]
feature_t = fluid.LoDTensor() feature_t = fluid.LoDTensor()
......
...@@ -32,25 +32,23 @@ def stacked_lstmp_model(frame_dim, ...@@ -32,25 +32,23 @@ def stacked_lstmp_model(frame_dim,
# network configuration # network configuration
def _net_conf(feature, label): def _net_conf(feature, label):
seq_conv1 = fluid.layers.sequence_conv( conv1 = fluid.layers.conv2d(
input=feature, input=feature,
num_filters=1024, num_filters=32,
filter_size=3, filter_size=3,
filter_stride=1, stride=1,
bias_attr=True) padding=1,
bn1 = fluid.layers.batch_norm( bias_attr=True,
input=seq_conv1, act="relu")
act="sigmoid",
is_test=not is_train,
momentum=0.9,
epsilon=1e-05,
data_layout='NCHW')
stack_input = bn1 pool1 = fluid.layers.pool2d(
conv1, pool_size=3, pool_type="max", pool_stride=2, pool_padding=0)
stack_input = pool1
for i in range(stacked_num): for i in range(stacked_num):
fc = fluid.layers.fc(input=stack_input, fc = fluid.layers.fc(input=stack_input,
size=hidden_dim * 4, size=hidden_dim * 4,
bias_attr=True) bias_attr=None)
proj, cell = fluid.layers.dynamic_lstmp( proj, cell = fluid.layers.dynamic_lstmp(
input=fc, input=fc,
size=hidden_dim * 4, size=hidden_dim * 4,
...@@ -62,7 +60,6 @@ def stacked_lstmp_model(frame_dim, ...@@ -62,7 +60,6 @@ def stacked_lstmp_model(frame_dim,
proj_activation="tanh") proj_activation="tanh")
bn = fluid.layers.batch_norm( bn = fluid.layers.batch_norm(
input=proj, input=proj,
act="sigmoid",
is_test=not is_train, is_test=not is_train,
momentum=0.9, momentum=0.9,
epsilon=1e-05, epsilon=1e-05,
...@@ -80,7 +77,10 @@ def stacked_lstmp_model(frame_dim, ...@@ -80,7 +77,10 @@ def stacked_lstmp_model(frame_dim,
# data feeder # data feeder
feature = fluid.layers.data( feature = fluid.layers.data(
name="feature", shape=[-1, frame_dim], dtype="float32", lod_level=1) name="feature",
shape=[-1, 3, 11, frame_dim],
dtype="float32",
lod_level=1)
label = fluid.layers.data( label = fluid.layers.data(
name="label", shape=[-1, 1], dtype="int64", lod_level=1) name="label", shape=[-1, 1], dtype="int64", lod_level=1)
......
...@@ -13,6 +13,7 @@ import _init_paths ...@@ -13,6 +13,7 @@ import _init_paths
import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm 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_add_delta as trans_add_delta
import data_utils.augmentor.trans_splice as trans_splice import data_utils.augmentor.trans_splice as trans_splice
import data_utils.augmentor.trans_delay as trans_delay
import data_utils.async_data_reader as reader import data_utils.async_data_reader as reader
from model_utils.model import stacked_lstmp_model from model_utils.model import stacked_lstmp_model
from data_utils.util import lodtensor_to_ndarray from data_utils.util import lodtensor_to_ndarray
...@@ -87,7 +88,7 @@ def parse_args(): ...@@ -87,7 +88,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--max_batch_num', '--max_batch_num',
type=int, type=int,
default=10, default=11,
help='Maximum number of batches for profiling. (default: %(default)d)') help='Maximum number of batches for profiling. (default: %(default)d)')
parser.add_argument( parser.add_argument(
'--first_batches_to_skip', '--first_batches_to_skip',
...@@ -146,10 +147,10 @@ def profile(args): ...@@ -146,10 +147,10 @@ def profile(args):
ltrans = [ ltrans = [
trans_add_delta.TransAddDelta(2, 2), trans_add_delta.TransAddDelta(2, 2),
trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var), trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var),
trans_splice.TransSplice() trans_splice.TransSplice(), trans_delay.TransDelay(5)
] ]
data_reader = reader.AsyncDataReader(args.feature_lst, args.label_lst) data_reader = reader.AsyncDataReader(args.feature_lst, args.label_lst, -1)
data_reader.set_transformers(ltrans) data_reader.set_transformers(ltrans)
feature_t = fluid.LoDTensor() feature_t = fluid.LoDTensor()
......
...@@ -12,6 +12,7 @@ import paddle.fluid as fluid ...@@ -12,6 +12,7 @@ import paddle.fluid as fluid
import data_utils.augmentor.trans_mean_variance_norm as trans_mean_variance_norm 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_add_delta as trans_add_delta
import data_utils.augmentor.trans_splice as trans_splice import data_utils.augmentor.trans_splice as trans_splice
import data_utils.augmentor.trans_delay as trans_delay
import data_utils.async_data_reader as reader import data_utils.async_data_reader as reader
from data_utils.util import lodtensor_to_ndarray from data_utils.util import lodtensor_to_ndarray
from model_utils.model import stacked_lstmp_model from model_utils.model import stacked_lstmp_model
...@@ -33,7 +34,7 @@ def parse_args(): ...@@ -33,7 +34,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--frame_dim', '--frame_dim',
type=int, type=int,
default=120 * 11, default=80,
help='Frame dimension of feature data. (default: %(default)d)') help='Frame dimension of feature data. (default: %(default)d)')
parser.add_argument( parser.add_argument(
'--stacked_num', '--stacked_num',
...@@ -53,7 +54,7 @@ def parse_args(): ...@@ -53,7 +54,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
'--class_num', '--class_num',
type=int, type=int,
default=1749, default=3040,
help='Number of classes in label. (default: %(default)d)') help='Number of classes in label. (default: %(default)d)')
parser.add_argument( parser.add_argument(
'--pass_num', '--pass_num',
...@@ -157,6 +158,7 @@ def train(args): ...@@ -157,6 +158,7 @@ def train(args):
# program for test # program for test
test_program = fluid.default_main_program().clone() test_program = fluid.default_main_program().clone()
#optimizer = fluid.optimizer.Momentum(learning_rate=args.learning_rate, momentum=0.9)
optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate) optimizer = fluid.optimizer.Adam(learning_rate=args.learning_rate)
optimizer.minimize(avg_cost) optimizer.minimize(avg_cost)
...@@ -171,7 +173,7 @@ def train(args): ...@@ -171,7 +173,7 @@ def train(args):
ltrans = [ ltrans = [
trans_add_delta.TransAddDelta(2, 2), trans_add_delta.TransAddDelta(2, 2),
trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var), trans_mean_variance_norm.TransMeanVarianceNorm(args.mean_var),
trans_splice.TransSplice() trans_splice.TransSplice(5, 5), trans_delay.TransDelay(5)
] ]
feature_t = fluid.LoDTensor() feature_t = fluid.LoDTensor()
...@@ -220,6 +222,8 @@ def train(args): ...@@ -220,6 +222,8 @@ def train(args):
args.minimum_batch_size)): args.minimum_batch_size)):
# load_data # load_data
(features, labels, lod, name_lst) = batch_data (features, labels, lod, name_lst) = batch_data
features = np.reshape(features, (-1, 11, 3, args.frame_dim))
features = np.transpose(features, (0, 2, 1, 3))
feature_t.set(features, place) feature_t.set(features, place)
feature_t.set_lod([lod]) feature_t.set_lod([lod])
label_t.set(labels, place) label_t.set(labels, place)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册