-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/PaddlePaddle/models into…
… ctc_reader
- Loading branch information
Showing
25 changed files
with
2,967 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
120 changes: 120 additions & 0 deletions
120
fluid/DeepASR/data_utils/augmentor/tests/data/global_mean_var_search26kHr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
16.2845556399 11.6891798673 | ||
17.21509949 12.3788567902 | ||
18.1143704548 14.9912618017 | ||
19.2335963752 18.5419556172 | ||
19.9266772451 21.2768220522 | ||
19.8245737202 21.2347210705 | ||
19.5432940972 20.2784036567 | ||
19.4631271754 20.2934452329 | ||
19.3929919324 20.457971868 | ||
19.2924788362 20.3626439234 | ||
18.9207244502 19.9196569759 | ||
18.7202605641 19.5920276899 | ||
18.4844279398 19.2068349019 | ||
18.2670948624 18.8716893824 | ||
18.0929628855 18.5439666541 | ||
17.8428896026 18.0255891747 | ||
17.6646850635 17.473764296 | ||
17.4955705896 16.8966859471 | ||
17.3706720293 16.4294027467 | ||
17.2530867792 16.0514717623 | ||
17.1304341172 15.7234699057 | ||
17.0038353287 15.4344471514 | ||
16.902550309 15.1603287337 | ||
16.8375590047 14.9304337826 | ||
16.816287853 14.9119310513 | ||
16.828838265 15.0930023024 | ||
16.8602209498 15.3771992423 | ||
16.9101763812 15.6897991789 | ||
16.9466065143 15.9364556489 | ||
16.9486061956 16.0699417826 | ||
16.9041374104 16.0796970272 | ||
16.8410093699 16.0111444599 | ||
16.7045718836 15.7991985601 | ||
16.51128489 15.5208920129 | ||
16.3253910608 15.2603181921 | ||
16.1297317333 14.9499965958 | ||
15.903428372 14.5958280409 | ||
15.6131718105 14.2709618 | ||
15.1395035533 13.9993939893 | ||
14.4298229999 13.3841189151 | ||
0.0034970565424 0.246184766149 | ||
0.00501284154705 0.238484972472 | ||
0.00605942680019 0.269064381708 | ||
0.00687266156243 0.319479238011 | ||
0.00734065019253 0.371947383205 | ||
0.00718807218417 0.384426479694 | ||
0.00652195540212 0.384676838281 | ||
0.00660416525951 0.395543910317 | ||
0.00680202057642 0.400803979681 | ||
0.00659144183007 0.393228973031 | ||
0.00605294530423 0.385021118038 | ||
0.00590452969394 0.361763039625 | ||
0.00612315374687 0.346777773373 | ||
0.00582354093973 0.335802403976 | ||
0.00574556002554 0.320733728218 | ||
0.00612254485891 0.310153103033 | ||
0.00626733043219 0.299854747445 | ||
0.00567398408041 0.293353685493 | ||
0.00519236700706 0.287668810947 | ||
0.00529581474367 0.281479660772 | ||
0.00479019484082 0.27451415777 | ||
0.00486381039428 0.266294391154 | ||
0.00491126372868 0.258105116126 | ||
0.00452105305011 0.252926328298 | ||
0.00531483334271 0.250910887373 | ||
0.00546572110469 0.253302256977 | ||
0.00479544857908 0.258484183394 | ||
0.00422106426297 0.264582900173 | ||
0.00401824135188 0.268467945623 | ||
0.0041705465252 0.269699480291 | ||
0.00405239564143 0.270406162975 | ||
0.0040059737566 0.270407601782 | ||
0.00406426729317 0.267951582656 | ||
0.00416613791013 0.264543833042 | ||
0.00427847607653 0.26247798891 | ||
0.00428050903034 0.259635263243 | ||
0.00454842971786 0.255829377617 | ||
0.00393747552387 0.253802307025 | ||
0.00374143688909 0.251011478787 | ||
0.00335475310258 0.236543650856 | ||
0.000373194755312 0.0419494800709 | ||
0.000230909648678 0.0394102370205 | ||
0.000150840015851 0.0414956922398 | ||
8.44401840771e-05 0.0460502231327 | ||
-6.24759314572e-06 0.0528049937739 | ||
-8.82957758148e-05 0.055711244886 | ||
1.16795791952e-05 0.0563188428833 | ||
-1.68716267856e-05 0.0575232763711 | ||
-0.000112625308645 0.057979929947 | ||
-0.000122619090002 0.0564126233493 | ||
1.73569637319e-05 0.05522573909 | ||
6.49872782342e-05 0.0507353361334 | ||
4.17746389178e-05 0.0479568131253 | ||
5.13884475653e-05 0.0461253238047 | ||
1.8860115143e-05 0.0436860476919 | ||
-5.64317701105e-05 0.042516381059 | ||
-0.000136859948115 0.0413574820205 | ||
-7.00847019726e-05 0.0409516370727 | ||
-5.39392223336e-05 0.040441504085 | ||
-9.24897162815e-05 0.0397800398173 | ||
4.7104970622e-05 0.039046286243 | ||
6.24805896165e-06 0.0380185986602 | ||
-2.35272813418e-05 0.036851063786 | ||
5.88344154127e-05 0.0361640489242 | ||
-8.39162076993e-05 0.0357639427311 | ||
-0.000108702805776 0.0358774639538 | ||
3.22013961834e-06 0.0363644530435 | ||
9.43501518394e-05 0.0370309934774 | ||
0.000134406229423 0.0374972993343 | ||
3.84007008533e-05 0.037676222515 | ||
3.05989328157e-05 0.0379111939182 | ||
9.52201629091e-05 0.0380927209106 | ||
0.000102126083729 0.0379925358499 | ||
6.98628072264e-05 0.0377276252241 | ||
4.55782256339e-05 0.0375165468654 | ||
4.76370987786e-05 0.0371482526345 | ||
-2.24128832709e-05 0.0366810742947 | ||
0.000125621306953 0.036628355271 | ||
0.000134568666093 0.0364860461759 | ||
0.000159858844464 0.0345583593149 |
116 changes: 116 additions & 0 deletions
116
fluid/DeepASR/data_utils/augmentor/tests/test_data_trans.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import sys | ||
import unittest | ||
import numpy as np | ||
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 | ||
|
||
|
||
class TestTransMeanVarianceNorm(unittest.TestCase): | ||
"""unit test for TransMeanVarianceNorm | ||
""" | ||
|
||
def setUp(self): | ||
self._file_path = "./data_utils/augmentor/tests/data/" \ | ||
"global_mean_var_search26kHr" | ||
|
||
def test(self): | ||
feature = np.zeros((2, 120), dtype="float32") | ||
feature.fill(1) | ||
trans = trans_mean_variance_norm.TransMeanVarianceNorm(self._file_path) | ||
(feature1, label1) = trans.perform_trans((feature, None)) | ||
(mean, var) = trans.get_mean_var() | ||
feature_flat1 = feature1.flatten() | ||
feature_flat = feature.flatten() | ||
one = np.ones((1), dtype="float32") | ||
for idx, val in enumerate(feature_flat1): | ||
cur_idx = idx % 120 | ||
self.assertAlmostEqual(val, (one[0] - mean[cur_idx]) * var[cur_idx]) | ||
|
||
|
||
class TestTransAddDelta(unittest.TestCase): | ||
"""unit test TestTransAddDelta | ||
""" | ||
|
||
def test_regress(self): | ||
"""test regress | ||
""" | ||
feature = np.zeros((14, 120), dtype="float32") | ||
feature[0:5, 0:40].fill(1) | ||
feature[0 + 5, 0:40].fill(1) | ||
feature[1 + 5, 0:40].fill(2) | ||
feature[2 + 5, 0:40].fill(3) | ||
feature[3 + 5, 0:40].fill(4) | ||
feature[8:14, 0:40].fill(4) | ||
trans = trans_add_delta.TransAddDelta() | ||
feature = feature.reshape((14 * 120)) | ||
trans._regress(feature, 5 * 120, feature, 5 * 120 + 40, 40, 4, 120) | ||
trans._regress(feature, 5 * 120 + 40, feature, 5 * 120 + 80, 40, 4, 120) | ||
feature = feature.reshape((14, 120)) | ||
tmp_feature = feature[5:5 + 4, :] | ||
self.assertAlmostEqual(1.0, tmp_feature[0][0]) | ||
self.assertAlmostEqual(0.24, tmp_feature[0][119]) | ||
self.assertAlmostEqual(2.0, tmp_feature[1][0]) | ||
self.assertAlmostEqual(0.13, tmp_feature[1][119]) | ||
self.assertAlmostEqual(3.0, tmp_feature[2][0]) | ||
self.assertAlmostEqual(-0.13, tmp_feature[2][119]) | ||
self.assertAlmostEqual(4.0, tmp_feature[3][0]) | ||
self.assertAlmostEqual(-0.24, tmp_feature[3][119]) | ||
|
||
def test_perform(self): | ||
"""test perform | ||
""" | ||
feature = np.zeros((4, 40), dtype="float32") | ||
feature[0, 0:40].fill(1) | ||
feature[1, 0:40].fill(2) | ||
feature[2, 0:40].fill(3) | ||
feature[3, 0:40].fill(4) | ||
trans = trans_add_delta.TransAddDelta() | ||
(feature, label) = trans.perform_trans((feature, None)) | ||
self.assertAlmostEqual(feature.shape[0], 4) | ||
self.assertAlmostEqual(feature.shape[1], 120) | ||
self.assertAlmostEqual(1.0, feature[0][0]) | ||
self.assertAlmostEqual(0.24, feature[0][119]) | ||
self.assertAlmostEqual(2.0, feature[1][0]) | ||
self.assertAlmostEqual(0.13, feature[1][119]) | ||
self.assertAlmostEqual(3.0, feature[2][0]) | ||
self.assertAlmostEqual(-0.13, feature[2][119]) | ||
self.assertAlmostEqual(4.0, feature[3][0]) | ||
self.assertAlmostEqual(-0.24, feature[3][119]) | ||
|
||
|
||
class TestTransSplict(unittest.TestCase): | ||
"""unit test Test TransSplict | ||
""" | ||
|
||
def test_perfrom(self): | ||
feature = np.zeros((8, 10), dtype="float32") | ||
for i in xrange(feature.shape[0]): | ||
feature[i, :].fill(i) | ||
|
||
trans = trans_splice.TransSplice() | ||
(feature, label) = trans.perform_trans((feature, None)) | ||
self.assertEqual(feature.shape[1], 110) | ||
|
||
for i in xrange(8): | ||
nzero_num = 5 - i | ||
cur_val = 0.0 | ||
if nzero_num < 0: | ||
cur_val = i - 5 - 1 | ||
for j in xrange(11): | ||
if j <= nzero_num: | ||
for k in xrange(10): | ||
self.assertAlmostEqual(feature[i][j * 10 + k], cur_val) | ||
else: | ||
if cur_val < 7: | ||
cur_val += 1.0 | ||
for k in xrange(10): | ||
self.assertAlmostEqual(feature[i][j * 10 + k], cur_val) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import math | ||
import copy | ||
|
||
|
||
class TransAddDelta(object): | ||
""" add delta of feature data | ||
trans feature for shape(a, b) to shape(a, b * 3) | ||
Attributes: | ||
_norder(int): | ||
_window(int): | ||
""" | ||
|
||
def __init__(self, norder=2, nwindow=2): | ||
""" init construction | ||
Args: | ||
norder: default 2 | ||
nwindow: default 2 | ||
""" | ||
self._norder = norder | ||
self._nwindow = nwindow | ||
|
||
def perform_trans(self, sample): | ||
""" add delta for feature | ||
trans feature shape from (a,b) to (a, b * 3) | ||
Args: | ||
sample(object,tuple): contain feature numpy and label numpy | ||
Returns: | ||
(feature, label) | ||
""" | ||
(feature, label) = sample | ||
frame_dim = feature.shape[1] | ||
d_frame_dim = frame_dim * 3 | ||
head_filled = 5 | ||
tail_filled = 5 | ||
mat = np.zeros( | ||
(feature.shape[0] + head_filled + tail_filled, d_frame_dim), | ||
dtype="float32") | ||
#copy first frame | ||
for i in xrange(head_filled): | ||
np.copyto(mat[i, 0:frame_dim], feature[0, :]) | ||
|
||
np.copyto(mat[head_filled:head_filled + feature.shape[0], 0:frame_dim], | ||
feature[:, :]) | ||
|
||
# copy last frame | ||
for i in xrange(head_filled + feature.shape[0], mat.shape[0], 1): | ||
np.copyto(mat[i, 0:frame_dim], feature[feature.shape[0] - 1, :]) | ||
|
||
nframe = feature.shape[0] | ||
start = head_filled | ||
tmp_shape = mat.shape | ||
mat = mat.reshape((tmp_shape[0] * tmp_shape[1])) | ||
self._regress(mat, start * d_frame_dim, mat, | ||
start * d_frame_dim + frame_dim, frame_dim, nframe, | ||
d_frame_dim) | ||
self._regress(mat, start * d_frame_dim + frame_dim, mat, | ||
start * d_frame_dim + 2 * frame_dim, frame_dim, nframe, | ||
d_frame_dim) | ||
mat.shape = tmp_shape | ||
return (mat[head_filled:mat.shape[0] - tail_filled, :], label) | ||
|
||
def _regress(self, data_in, start_in, data_out, start_out, size, n, step): | ||
""" regress | ||
Args: | ||
data_in: in data | ||
start_in: start index of data_in | ||
data_out: out data | ||
start_out: start index of data_out | ||
size: frame dimentional | ||
n: frame num | ||
step: 3 * (frame num) | ||
Returns: | ||
None | ||
""" | ||
sigma_t2 = 0.0 | ||
delta_window = self._nwindow | ||
for t in xrange(1, delta_window + 1): | ||
sigma_t2 += t * t | ||
|
||
sigma_t2 *= 2.0 | ||
for i in xrange(n): | ||
fp1 = start_in | ||
fp2 = start_out | ||
for j in xrange(size): | ||
back = fp1 | ||
forw = fp1 | ||
sum = 0.0 | ||
for t in xrange(1, delta_window + 1): | ||
back -= step | ||
forw += step | ||
sum += t * (data_in[forw] - data_in[back]) | ||
|
||
data_out[fp2] = sum / sigma_t2 | ||
fp1 += 1 | ||
fp2 += 1 | ||
start_in += step | ||
start_out += step |
Oops, something went wrong.