Skip to content
Permalink
Browse files

added -cvnstatic for self mean, static variance normalization for fil…

…e input
  • Loading branch information...
nitslp-ri committed Mar 27, 2019
1 parent 1a545d9 commit a55b46e7c0d95c427f5f3ba88d9a7e14c3e82a80
0 gramtools/mkdfa/mkdfa.py 100644 → 100755
No changes.
@@ -176,6 +176,10 @@ typedef struct __jconf_am__ {
* CMN: MAP weight for initial cepstral mean on (-cmnmapweight)
*/
float cmn_map_weight;
/**
* CMN: TRUE if static CMN/CVN only applies CVN at file input
*/
boolean cmn_static_cvn_only;

} analysis;

@@ -586,6 +586,12 @@ typedef struct __mfcc_calc__ {
*/
CMNWork *wrk;

/**
* TRUE if static CMN/CVN only applies CVN at file input
*
*/
boolean static_cvn_only;

} cmn;

/**
@@ -154,6 +154,7 @@ jconf_set_default_values_am(JCONF_AM *j)
j->analysis.cmn_update = TRUE;
j->analysis.cmnsave_filename = NULL;
j->analysis.cmn_map_weight = 100.0;
j->analysis.cmn_static_cvn_only = FALSE;
j->frontend.ss_alpha = DEF_SSALPHA;
j->frontend.ss_floor = DEF_SSFLOOR;
j->frontend.sscalc = FALSE;
@@ -71,6 +71,7 @@ j_mfcccalc_new(JCONF_AM *amconf)
mfcc->cmn.update = amconf->analysis.cmn_update;
mfcc->cmn.save_filename = amconf->analysis.cmnsave_filename;
mfcc->cmn.map_weight = amconf->analysis.cmn_map_weight;
mfcc->cmn.static_cvn_only = amconf->analysis.cmn_static_cvn_only;
mfcc->frontend.ss_alpha = amconf->frontend.ss_alpha;
mfcc->frontend.ss_floor = amconf->frontend.ss_floor;
mfcc->frontend.sscalc = amconf->frontend.sscalc;
@@ -239,6 +239,11 @@ j_jconf_finalize(Jconf *jconf)
jlog("ERROR: m_chkparam: with \"-cmnstatic\", the static cepstral mean (and variance) should be given by \"-cmnload\"\n");
ok_p = FALSE;
}
if (am->analysis.cmn_static_cvn_only == TRUE && am->analysis.cmnload_filename == NULL) {
/* cvnstatic, no cmnload : error */
jlog("ERROR: m_chkparam: with \"-cvnstatic\", the static cepstral variance (and mean) should be given by \"-cmnload\"\n");
ok_p = FALSE;
}
if (jconf->decodeopt.realtime_flag == FALSE) {
if (am->analysis.map_cmn == TRUE && am->analysis.cmnload_filename != NULL) {
/* no cmnstatic, cmnload on buffered input : assume cmnstatic */
@@ -878,6 +878,7 @@ mfcc_config_is_same(JCONF_AM *amconf, MFCCCalc *mfcc)
if (s1 == s2 || (s1 && s2 && strmatch(s1, s2))) {
if (amconf->analysis.cmn_update == mfcc->cmn.update
&& amconf->analysis.map_cmn == mfcc->cmn.map_cmn
&& amconf->analysis.cmn_static_cvn_only == mfcc->cmn.static_cvn_only
&& amconf->analysis.cmn_map_weight == mfcc->cmn.map_weight) {
if (amconf->frontend.ss_alpha == mfcc->frontend.ss_alpha
&& amconf->frontend.ss_floor == mfcc->frontend.ss_floor
@@ -1433,6 +1434,7 @@ j_final_fusion(Recog *recog)
jlog("ERROR: m_fusion: failed to read initial cepstral mean from \"%s\"\n", mfcc->cmn.load_filename);
return FALSE;
}
mfcc->cmn.wrk->static_cvn_only = mfcc->cmn.static_cvn_only;
} else {
jlog("WARNING: m_fusion: CMN load file specified but AM not require it, ignored\n");
}
@@ -188,7 +188,7 @@ print_mfcc_info(FILE *fp, MFCCCalc *mfcc, Jconf *jconf)
jlog(" beginning data weight = %6.2f\n", mfcc->cmn.map_weight);
}
} else {
if (mfcc->cmn.loaded) {
if (mfcc->cmn.loaded && mfcc->cmn.static_cvn_only == FALSE) {
jlog("with a static mean\n");
jlog(" static mean from file = %s\n", mfcc->cmn.load_filename);
} else {
@@ -1152,6 +1152,11 @@ opt_parse(int argc, char *argv[], char *cwd, Jconf *jconf)
if (!check_section(jconf, argv[i], JCONF_OPT_AM)) return FALSE;
jconf->amnow->analysis.map_cmn = FALSE;
jconf->amnow->analysis.cmn_update = FALSE;
jconf->amnow->analysis.cmn_static_cvn_only = FALSE;
continue;
} else if (strmatch(argv[i],"-cvnstatic")) { /* static variance but left mean dynamic on buffered input */
if (!check_section(jconf, argv[i], JCONF_OPT_AM)) return FALSE;
jconf->amnow->analysis.cmn_static_cvn_only = TRUE;
continue;
} else if (strmatch(argv[i],"-cmnmapweight")) { /* CMN weight for MAP */
if (!check_section(jconf, argv[i], JCONF_OPT_AM)) return FALSE;
@@ -206,9 +206,10 @@ j_output_argument_help(FILE *fp)
fprintf(fp, " [-ssfloor value] spectral floor for SS (%f)\n", jconf->am_root->frontend.ss_floor);
fprintf(fp, " [-zmeanframe/-nozmeanframe] frame-wise DC removal like HTK(OFF)\n");
fprintf(fp, " [-usepower/-nousepower] use power in fbank analysis (OFF)\n");
fprintf(fp, " [-cmnload file] load initial CMN param from file on startup\n");
fprintf(fp, " [-cmnsave file] save CMN param to file after each input\n");
fprintf(fp, " [-cmnstatic] no MAP, use static CMN (use with -cmnload)\n");
fprintf(fp, " [-cmnload file] load initial CMN/CVN param from file on startup\n");
fprintf(fp, " [-cmnsave file] save CMN/CVN param to file after each input\n");
fprintf(fp, " [-cmnstatic] no MAP, use static CMN/CVN (use with -cmnload)\n");
fprintf(fp, " [-cvnstatic] use static CVN only (use with -cmnload)\n");
fprintf(fp, " [-cmnnoupdate] not update initial param while recog. (use with -cmnload)\n");
fprintf(fp, " [-cmnmapweight] weight value of initial cm for MAP-CMN (%6.2f)\n", jconf->am_root->analysis.cmn_map_weight);
fprintf(fp, " [-cvn] cepstral variance normalisation (%s)\n", jconf->amnow->analysis.para.cvn ? "on" : "off");
@@ -199,6 +199,7 @@ typedef struct {
CMEAN all; ///< Work area to hold all cepstral mean and variance
boolean loaded_from_file; ///< TRUE if loaded from file
boolean do_map; ///< TRUE when perform MAP-CMN
boolean static_cvn_only; ///< TRUE when perform static CVN only on buffered input
} CMNWork;

/**
@@ -259,10 +259,17 @@ void MVN(float **mfcc, int frame_num, Value *para, CMNWork *c)
float *mfcc_mean, *mfcc_sd;
float x;
int basedim;
boolean static_cvn_only_flag;

basedim = para->mfcc_dim + (para->c0 ? 1 : 0);

if (c != NULL && c->cmean_init_set) {
if (c != NULL && c->cmean_init_set && c->static_cvn_only == TRUE) {
static_cvn_only_flag = TRUE;
} else {
static_cvn_only_flag = FALSE;
}

if (c != NULL && c->cmean_init_set && static_cvn_only_flag == FALSE) {
/* has initial param, use it permanently */
for(t = 0; t < frame_num; t++){
if (para->cmn) {
@@ -277,8 +284,9 @@ void MVN(float **mfcc, int frame_num, Value *para, CMNWork *c)
return;
}


mfcc_mean = (float *)mycalloc(para->veclen, sizeof(float));
if (para->cvn) mfcc_sd = (float *)mycalloc(para->veclen, sizeof(float));
if (para->cvn && static_cvn_only_flag == FALSE) mfcc_sd = (float *)mycalloc(para->veclen, sizeof(float));

/* get mean */
for(i = 0; i < para->veclen; i++){
@@ -287,7 +295,7 @@ void MVN(float **mfcc, int frame_num, Value *para, CMNWork *c)
mfcc_mean[i] += mfcc[t][i];
mfcc_mean[i] /= (float)frame_num;
}
if (para->cvn) {
if (para->cvn && static_cvn_only_flag == FALSE) {
/* get standard deviation */
for(i = 0; i < para->veclen; i++){
mfcc_sd[i] = 0.0;
@@ -304,11 +312,16 @@ void MVN(float **mfcc, int frame_num, Value *para, CMNWork *c)
for(i = 0; i < basedim; i++) mfcc[t][i] -= mfcc_mean[i];
}
if (para->cvn) {
/* variance normalization (full MFCC) */
for(i = 0; i < para->veclen; i++) mfcc[t][i] /= mfcc_sd[i];
if (static_cvn_only_flag == TRUE) {
/* variance normalization (full MFCC, static) */
for(i = 0; i < para->veclen; i++) mfcc[t][i] /= sqrt(c->cvar_init[i]);
} else {
/* variance normalization (full MFCC) */
for(i = 0; i < para->veclen; i++) mfcc[t][i] /= mfcc_sd[i];
}
}
}

if (para->cvn) free(mfcc_sd);
if (para->cvn && static_cvn_only_flag == FALSE) free(mfcc_sd);
free(mfcc_mean);
}
@@ -278,6 +278,7 @@ CMN_realtime_new(Value *para, float weight, boolean map)
c->loaded_from_file = FALSE;

c->do_map = map;
c->static_cvn_only = FALSE;

if (c->var) {
for(i = 0; i < c->veclen; i++) c->all.mfcc_var[i] = 0.0;

0 comments on commit a55b46e

Please sign in to comment.
You can’t perform that action at this time.