Revision: 6064
Author: dhdfu
Date: 2006-08-25 12:54:41 -0700 (Fri, 25 Aug 2006)
ViewCVS: http://svn.sourceforge.net/cmusphinx/?rev=6064&view=rev
Log Message:
-----------
Add support for concatenating adjacent frames of "raw" features (for LDA), and add a unit test for this and other feature stuff
Modified Paths:
--------------
trunk/sphinxbase/configure.in
trunk/sphinxbase/src/libsphinxfeat/feat.c
Added Paths:
-----------
trunk/sphinxbase/test/unit/test_feat/
trunk/sphinxbase/test/unit/test_feat/Makefile.am
trunk/sphinxbase/test/unit/test_feat/_test_feat.res
trunk/sphinxbase/test/unit/test_feat/_test_feat.test
trunk/sphinxbase/test/unit/test_feat/test_feat.c
Modified: trunk/sphinxbase/configure.in
===================================================================
--- trunk/sphinxbase/configure.in 2006-08-25 18:36:00 UTC (rev 6063)
+++ trunk/sphinxbase/configure.in 2006-08-25 19:54:41 UTC (rev 6064)
@@ -183,6 +183,7 @@
test/unit/test_case/Makefile
test/unit/test_hash/Makefile
test/unit/test_matrix/Makefile
+test/unit/test_feat/Makefile
test/regression/Makefile
test/regression/test-cepview.sh
test/regression/test-sphinx_fe-dither-seed.sh
@@ -190,4 +191,4 @@
test/regression/test-sphinx_fe.sh
])
-chmod +x test/regression/*.sh
\ No newline at end of file
+chmod +x test/regression/*.sh
Modified: trunk/sphinxbase/src/libsphinxfeat/feat.c
===================================================================
--- trunk/sphinxbase/src/libsphinxfeat/feat.c 2006-08-25 18:36:00 UTC (rev 6063)
+++ trunk/sphinxbase/src/libsphinxfeat/feat.c 2006-08-25 19:54:41 UTC (rev 6064)
@@ -641,7 +641,7 @@
f[i] = w[i] - _w[i];
}
-void
+static void
feat_1s_c_d_dd_cep2feat(feat_t * fcb, float32 ** mfc, float32 ** feat)
{
float32 *f;
@@ -689,6 +689,26 @@
}
}
+static void
+feat_copy(feat_t * fcb, float32 ** mfc, float32 ** feat)
+{
+ int32 win, i, j;
+
+ win = feat_window_size(fcb);
+
+ /* Concatenate input features */
+ for (i = -win; i <= win; ++i) {
+ uint32 spos = 0;
+
+ for (j = 0; j < feat_n_stream(fcb); ++j) {
+ memcpy(feat[j] + ((i + win) * feat_stream_len(fcb, j)),
+ mfc[i] + spos,
+ feat_stream_len(fcb, j) * sizeof(float32));
+ spos += feat_stream_len(fcb, j);
+ }
+ }
+}
+
feat_t *
feat_init(char *type, char *cmn, char *varnorm, char *agc, int32 breport)
{
@@ -779,16 +799,25 @@
}
else {
/*
- * Generic definition: Format should be %d,%d,%d,...,%d (i.e., comma separated
- * list of feature stream widths; #items = #streams).
+ * Generic definition: Format should be %d,%d,%d,...,%d (i.e.,
+ * comma separated list of feature stream widths; #items =
+ * #streams). An optional window size (frames will be
+ * concatenated) is also allowed, which can be specified with
+ * a colon after the list of feature streams.
*/
l = strlen(type);
k = 0;
- for (i = 1; i < l - 1; i++)
+ for (i = 1; i < l - 1; i++) {
if (type[i] == ',') {
type[i] = ' ';
k++;
}
+ else if (type[i] == ':') {
+ type[i] = '\0';
+ fcb->window_size = atoi(type + i + 1);
+ break;
+ }
+ }
k++; /* Presumably there are (#commas+1) streams */
fcb->n_stream = k;
fcb->stream_len = (int32 *) ckd_calloc(k, sizeof(int32));
@@ -797,12 +826,20 @@
strp = type;
i = 0;
fcb->out_dim = 0;
+ fcb->cepsize = 0;
+ fcb->cepsize_used = 0;
while (sscanf(strp, "%s%n", wd, &l) == 1) {
strp += l;
if ((i >= fcb->n_stream)
|| (sscanf(wd, "%d", &(fcb->stream_len[i])) != 1)
|| (fcb->stream_len[i] <= 0))
E_FATAL("Bad feature type argument\n");
+ /* Input size before windowing */
+ fcb->cepsize += fcb->stream_len[i];
+ fcb->cepsize_used += fcb->stream_len[i];
+ if (fcb->window_size > 0)
+ fcb->stream_len[i] *= (fcb->window_size * 2 + 1);
+ /* Output size after windowing */
fcb->out_dim += fcb->stream_len[i];
i++;
}
@@ -810,10 +847,7 @@
E_FATAL("Bad feature type argument\n");
/* Input is already the feature stream */
- fcb->cepsize = feat_stream_len_sum(fcb);
- fcb->cepsize_used = feat_stream_len_sum(fcb);
- fcb->window_size = 0;
- fcb->compute_feat = NULL;
+ fcb->compute_feat = feat_copy;
}
fcb->cmn_struct = cmn_init();
@@ -842,24 +876,20 @@
fcb->tmpcepbuf = NULL;
fcb->out_dim = fcb->stream_len[0];
- if (fcb->cepsize > 0) {
- fcb->cepbuf = (float32 **) ckd_calloc_2d(LIVEBUFBLOCKSIZE,
- feat_cepsize(fcb),
- sizeof(float32));
- if (!fcb->cepbuf)
- E_FATAL("Unable to allocate cepbuf ckd_calloc_2d(%ld,%d,%d)\n",
- LIVEBUFBLOCKSIZE, feat_cepsize(fcb), sizeof(float32));
- }
- if (fcb->window_size > 0) {
- fcb->tmpcepbuf =
- (float32 **) ckd_calloc_2d(2 * feat_window_size(fcb) + 1,
- feat_cepsize(fcb), sizeof(float32));
- if (!fcb->tmpcepbuf)
- E_FATAL
- ("Unable to allocate tmpcepbuf ckd_calloc_2d(%ld,%d,%d)\n",
- 2 * feat_window_size(fcb) + 1, feat_cepsize(fcb),
- sizeof(float32));
- }
+ fcb->cepbuf = (float32 **) ckd_calloc_2d(LIVEBUFBLOCKSIZE,
+ feat_cepsize(fcb),
+ sizeof(float32));
+ if (!fcb->cepbuf)
+ E_FATAL("Unable to allocate cepbuf ckd_calloc_2d(%ld,%d,%d)\n",
+ LIVEBUFBLOCKSIZE, feat_cepsize(fcb), sizeof(float32));
+ fcb->tmpcepbuf =
+ (float32 **) ckd_calloc_2d(2 * feat_window_size(fcb) + 1,
+ feat_cepsize(fcb), sizeof(float32));
+ if (!fcb->tmpcepbuf)
+ E_FATAL
+ ("Unable to allocate tmpcepbuf ckd_calloc_2d(%ld,%d,%d)\n",
+ 2 * feat_window_size(fcb) + 1, feat_cepsize(fcb),
+ sizeof(float32));
return fcb;
}
@@ -1045,15 +1075,9 @@
#endif
/* Create feature vectors */
- if (fcb->compute_feat) {
- for (i = win; i < nfr - win; i++)
- fcb->compute_feat(fcb, mfc + i, feat[i - win]);
+ for (i = win; i < nfr - win; i++) {
+ fcb->compute_feat(fcb, mfc + i, feat[i - win]);
}
- else {
- for (i = win; i < nfr - win; i++)
- memcpy(feat[i - win][0], mfc[i],
- feat_cepsize_used(fcb) * sizeof(float32));
- }
#if 0
E_INFO("After dynamic coefficients computation. \n");
@@ -1118,10 +1142,13 @@
if (beginutt) {
/* Replicate first frame into the first win frames */
for (i = 0; i < win; i++) {
+ /* FIXME: This makes no sense at all!!! */
+#if 0
if (nfr >= win + 1)
memcpy(cepbuf[i], uttcep[0 + i + 1],
cepsize * sizeof(float32));
else
+#endif
memcpy(cepbuf[i], uttcep[0], cepsize * sizeof(float32));
}
fcb->bufpos = win;
Added: trunk/sphinxbase/test/unit/test_feat/Makefile.am
===================================================================
--- trunk/sphinxbase/test/unit/test_feat/Makefile.am (rev 0)
+++ trunk/sphinxbase/test/unit/test_feat/Makefile.am 2006-08-25 19:54:41 UTC (rev 6064)
@@ -0,0 +1,15 @@
+check_PROGRAMS = test_feat
+
+test_feat_SRCS = test_feat.c
+
+INCLUDES = \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/include
+
+LDADD = ${top_builddir}/src/libsphinxutil/libsphinxutil.la \
+ ${top_builddir}/src/libsphinxfeat/libsphinxfeat.la -lm
+
+
+TESTS = $(wildcard _*.test)
+
+
Property changes on: trunk/sphinxbase/test/unit/test_feat/Makefile.am
___________________________________________________________________
Name: svn:mime-type
+ text/x-makefile
Name: svn:eol-style
+ native
Added: trunk/sphinxbase/test/unit/test_feat/_test_feat.res
===================================================================
--- trunk/sphinxbase/test/unit/test_feat/_test_feat.res (rev 0)
+++ trunk/sphinxbase/test/unit/test_feat/_test_feat.res 2006-08-25 19:54:41 UTC (rev 6064)
@@ -0,0 +1,18 @@
+15.114 -1.424 -0.953 0.186 -0.656 -0.226 -0.105 -0.412 -0.024 -0.091 -0.124 -0.158 -0.197
+14.729 -1.313 -0.892 0.140 -0.676 -0.089 -0.313 -0.422 -0.058 -0.101 -0.100 -0.128 -0.123
+14.502 -1.351 -1.028 -0.189 -0.718 -0.139 -0.121 -0.365 -0.139 -0.154 0.041 0.009 -0.073
+14.557 -1.676 -0.864 0.118 -0.445 -0.168 -0.069 -0.503 -0.013 0.007 -0.056 -0.075 -0.237
+14.665 -1.498 -0.582 0.209 -0.487 -0.247 -0.142 -0.439 0.059 -0.058 -0.265 -0.109 -0.196
+15.025 -1.199 -0.607 0.235 -0.499 -0.080 -0.062 -0.554 -0.209 -0.124 -0.445 -0.352 -0.400
+15.114 -1.424 -0.953 0.186 -0.656 -0.226 -0.105 -0.412 -0.024 -0.091 -0.124 -0.158 -0.197 15.114 -1.424 -0.953 0.186 -0.656 -0.226 -0.105 -0.412 -0.024 -0.091 -0.124 -0.158 -0.197 14.729 -1.313 -0.892 0.140 -0.676 -0.089 -0.313 -0.422 -0.058 -0.101 -0.100 -0.128 -0.123
+15.114 -1.424 -0.953 0.186 -0.656 -0.226 -0.105 -0.412 -0.024 -0.091 -0.124 -0.158 -0.197 14.729 -1.313 -0.892 0.140 -0.676 -0.089 -0.313 -0.422 -0.058 -0.101 -0.100 -0.128 -0.123 14.502 -1.351 -1.028 -0.189 -0.718 -0.139 -0.121 -0.365 -0.139 -0.154 0.041 0.009 -0.073
+14.729 -1.313 -0.892 0.140 -0.676 -0.089 -0.313 -0.422 -0.058 -0.101 -0.100 -0.128 -0.123 14.502 -1.351 -1.028 -0.189 -0.718 -0.139 -0.121 -0.365 -0.139 -0.154 0.041 0.009 -0.073 14.557 -1.676 -0.864 0.118 -0.445 -0.168 -0.069 -0.503 -0.013 0.007 -0.056 -0.075 -0.237
+14.502 -1.351 -1.028 -0.189 -0.718 -0.139 -0.121 -0.365 -0.139 -0.154 0.041 0.009 -0.073 14.557 -1.676 -0.864 0.118 -0.445 -0.168 -0.069 -0.503 -0.013 0.007 -0.056 -0.075 -0.237 14.665 -1.498 -0.582 0.209 -0.487 -0.247 -0.142 -0.439 0.059 -0.058 -0.265 -0.109 -0.196
+14.557 -1.676 -0.864 0.118 -0.445 -0.168 -0.069 -0.503 -0.013 0.007 -0.056 -0.075 -0.237 14.665 -1.498 -0.582 0.209 -0.487 -0.247 -0.142 -0.439 0.059 -0.058 -0.265 -0.109 -0.196 15.025 -1.199 -0.607 0.235 -0.499 -0.080 -0.062 -0.554 -0.209 -0.124 -0.445 -0.352 -0.400
+14.665 -1.498 -0.582 0.209 -0.487 -0.247 -0.142 -0.439 0.059 -0.058 -0.265 -0.109 -0.196 15.025 -1.199 -0.607 0.235 -0.499 -0.080 -0.062 -0.554 -0.209 -0.124 -0.445 -0.352 -0.400 15.025 -1.199 -0.607 0.235 -0.499 -0.080 -0.062 -0.554 -0.209 -0.124 -0.445 -0.352 -0.400
+15.114 -1.424 -0.953 0.186 -0.656 -0.226 -0.105 -0.412 -0.024 -0.091 -0.124 -0.158 -0.197 -0.612 0.073 -0.075 -0.375 -0.062 0.087 -0.016 0.047 -0.115 -0.063 0.165 0.167 0.124 -0.172 -0.363 0.028 -0.022 0.231 -0.079 0.244 -0.081 0.045 0.108 0.044 0.053 -0.114
+14.729 -1.313 -0.892 0.140 -0.676 -0.089 -0.313 -0.422 -0.058 -0.101 -0.100 -0.128 -0.123 -0.557 -0.252 0.089 -0.068 0.211 0.058 0.036 -0.091 0.011 0.098 0.068 0.083 -0.040 0.163 -0.147 0.446 0.398 0.231 -0.108 -0.021 -0.074 0.198 0.096 -0.306 -0.118 -0.123
+14.502 -1.351 -1.028 -0.189 -0.718 -0.139 -0.121 -0.365 -0.139 -0.154 0.041 0.009 -0.073 -0.449 -0.074 0.371 0.023 0.169 -0.021 -0.037 -0.027 0.083 0.033 -0.141 0.049 0.001 0.853 0.366 0.196 0.163 -0.034 -0.049 0.215 -0.041 -0.162 -0.121 -0.413 -0.307 -0.237
+14.557 -1.676 -0.864 0.118 -0.445 -0.168 -0.069 -0.503 -0.013 0.007 -0.056 -0.075 -0.237 0.296 0.114 0.285 0.095 0.177 0.009 0.251 -0.132 -0.151 -0.023 -0.345 -0.224 -0.277 0.972 0.226 0.050 0.401 0.050 0.080 0.096 -0.162 -0.153 -0.003 -0.345 -0.410 -0.328
+14.665 -1.498 -0.582 0.209 -0.487 -0.247 -0.142 -0.439 0.059 -0.058 -0.265 -0.109 -0.196 0.523 0.152 0.421 0.424 0.219 0.059 0.059 -0.189 -0.070 0.030 -0.486 -0.361 -0.327 0.172 0.363 -0.028 0.022 -0.231 0.079 -0.244 0.081 -0.045 -0.108 -0.044 -0.053 0.114
+15.025 -1.199 -0.607 0.235 -0.499 -0.080 -0.062 -0.554 -0.209 -0.124 -0.445 -0.352 -0.400 0.468 0.477 0.257 0.117 -0.054 0.088 0.007 -0.051 -0.196 -0.131 -0.389 -0.277 -0.163 -0.163 0.147 -0.446 -0.398 -0.231 0.108 0.021 0.074 -0.198 -0.096 0.306 0.118 0.123
Property changes on: trunk/sphinxbase/test/unit/test_feat/_test_feat.res
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/sphinxbase/test/unit/test_feat/_test_feat.test
===================================================================
--- trunk/sphinxbase/test/unit/test_feat/_test_feat.test (rev 0)
+++ trunk/sphinxbase/test/unit/test_feat/_test_feat.test 2006-08-25 19:54:41 UTC (rev 6064)
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+./test_feat > _test_feat.out
+diff _test_feat.out _test_feat.res >/dev/null 2>&1
+rm -f _test_feat.out
Property changes on: trunk/sphinxbase/test/unit/test_feat/_test_feat.test
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/sphinxbase/test/unit/test_feat/test_feat.c
===================================================================
--- trunk/sphinxbase/test/unit/test_feat/test_feat.c (rev 0)
+++ trunk/sphinxbase/test/unit/test_feat/test_feat.c 2006-08-25 19:54:41 UTC (rev 6064)
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "feat.h"
+#include "ckd_alloc.h"
+
+const float32 data[6][13] = {
+ { 15.114, -1.424, -0.953, 0.186, -0.656, -0.226, -0.105, -0.412, -0.024, -0.091, -0.124, -0.158, -0.197},
+ { 14.729, -1.313, -0.892, 0.140, -0.676, -0.089, -0.313, -0.422, -0.058, -0.101, -0.100, -0.128, -0.123},
+ { 14.502, -1.351, -1.028, -0.189, -0.718, -0.139, -0.121, -0.365, -0.139, -0.154, 0.041, 0.009, -0.073},
+ { 14.557, -1.676, -0.864, 0.118, -0.445, -0.168, -0.069, -0.503, -0.013, 0.007, -0.056, -0.075, -0.237},
+ { 14.665, -1.498, -0.582, 0.209, -0.487, -0.247, -0.142, -0.439, 0.059, -0.058, -0.265, -0.109, -0.196},
+ { 15.025, -1.199, -0.607, 0.235, -0.499, -0.080, -0.062, -0.554, -0.209, -0.124, -0.445, -0.352, -0.400},
+};
+
+int
+main(int argc, char *argv[])
+{
+ feat_t *fcb;
+ float32 **in_feats, ***out_feats;
+ int32 i, j;
+
+ /* Test "raw" features without concatenation */
+ fcb = feat_init(strdup("13"), "none", "no", "none", 1);
+
+ in_feats = (float32 **)ckd_alloc_2d_ptr(6, 13, data, sizeof(float32));
+ out_feats = (float32 ***)ckd_calloc_3d(6, 1, 13, sizeof(float32));
+ feat_s2mfc2feat_block(fcb, in_feats, 6, 1, 1, out_feats);
+
+ for (i = 0; i < 6; ++i) {
+ for (j = 0; j < 13; ++j) {
+ printf("%.3f ", out_feats[i][0][j]);
+ }
+ printf("\n");
+ }
+ feat_free(fcb);
+
+ /* Test "raw" features with concatenation */
+ fcb = feat_init(strdup("13:1"), "none", "no", "none", 1);
+
+ in_feats = (float32 **)ckd_alloc_2d_ptr(6, 13, data, sizeof(float32));
+ out_feats = (float32 ***)ckd_calloc_3d(8, 1, 39, sizeof(float32));
+ feat_s2mfc2feat_block(fcb, in_feats, 6, 1, 1, out_feats);
+
+ for (i = 0; i < 6; ++i) {
+ for (j = 0; j < 39; ++j) {
+ printf("%.3f ", out_feats[i][0][j]);
+ }
+ printf("\n");
+ }
+ feat_free(fcb);
+
+ /* Test 1s_c_d_dd features */
+ fcb = feat_init(strdup("1s_c_d_dd"), "none", "no", "none", 1);
+ feat_s2mfc2feat_block(fcb, in_feats, 6, 1, 1, out_feats);
+
+ for (i = 0; i < 6; ++i) {
+ for (j = 0; j < 39; ++j) {
+ printf("%.3f ", out_feats[i][0][j]);
+ }
+ printf("\n");
+ }
+
+ /* Verify that the deltas are correct. */
+ for (i = 2; i < 4; ++i) {
+ for (j = 0; j < 13; ++j) {
+ if (fabs(out_feats[i][0][13+j] -
+ (out_feats[i+2][0][j]
+ - out_feats[i-2][0][j])) > 0.01) {
+ printf("Delta mismatch in [%d][%d]\n", i, j);
+ return 1;
+ }
+ }
+ }
+ feat_free(fcb);
+
+ return 0;
+}
Property changes on: trunk/sphinxbase/test/unit/test_feat/test_feat.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|