// option "-paramtype" handler static boolean opt_paramtype(Jconf *jconf, char *arg[], int argnum) { short code; global_a->conf.vecnet_paramtype = param_str2code(arg[0]); return TRUE; }
/** * Read in global options. * * @param fp [in] file pointer * @param op [out] pointer to store the global options */ static void read_global_opt(FILE *fp, HTK_HMM_Options *op) { int i; short tmptype; int num; for (;;) { if (rdhmmdef_token == NULL) break; if (currentis("HMMSETID")) { /* <HMMSETID> */ read_token(fp); NoTokErr("missing HMMSETID argument"); } else if (currentis("STREAMINFO")) { /* <STREAMINFO> */ read_token(fp); NoTokErr("missing STREAMINFO num"); op->stream_info.num = atoi(rdhmmdef_token); /*DM("%d STREAMs:", op->stream_info.num);*/ if (op->stream_info.num > MAXSTREAMNUM) { jlog("Error: rdhmmdef_options: stream num exceeded %d\n", MAXSTREAMNUM); rderr(NULL); } for (i=0;i<op->stream_info.num;i++) { read_token(fp); NoTokErr("missing STREAMINFO vector size"); op->stream_info.vsize[i] = atoi(rdhmmdef_token); /*DM(" %d",op->stream_info.vsize[i]);*/ } /*DM("\n");*/ } else if (currentis("VECSIZE")) { /* <VECSIZE> */ read_token(fp); NoTokErr("missing VECSIZE value"); op->vec_size = atoi(rdhmmdef_token); /*DM("vector size: %d\n", op->vec_size);*/ } else if (currentis("MSDINFO")) { /* <MSDINFO> by HTS */ /* Julius can auto-detect MSD-HMM, so just skip this */ read_token(fp); NoTokErr("missing MSDINFO num"); num = atoi(rdhmmdef_token); for (i=0;i<num;i++) { read_token(fp); } } else { /* covariance matrix type */ for (i=0;optcov[i].name!=NULL;i++) { if (currentis(optcov[i].name)) { op->cov_type = optcov[i].type; /*DM("covariance matrix type: %s\n", optcov[i].desc);*/ goto optloop; } } /* duration type */ for (i=0;optdur[i].name!=NULL;i++) { if (currentis(optdur[i].name)) { op->dur_type = optdur[i].type; /*DM("duration type: %s\n", optdur[i].desc);*/ goto optloop; } } /* parameter type */ tmptype = param_str2code(rdhmmdef_token); if (tmptype != F_ERR_INVALID) { /* conv success */ op->param_type = tmptype; /*DM("param type: %s", param_code2str(buf, op->param_type, FALSE));*/ goto optloop; } else { /* nothing of above --- not option */ if(rdhmmdef_token[0] != '~') { jlog("Error: rdhmmdef_options: unknown option in header: %s\n", rdhmmdef_token); rderr("unknown option in header"); } return; } } optloop: read_token(fp); } }
/* parse DNN config file */ boolean dnn_config_file_parse(char *filename, JCONF_AM *am, Jconf *jconf) { FILE *fp; char buf[BUFLEN]; char *p, *pp; char *v; int i, n; boolean error_flag; char *cdir; if (am->dnn.wfile != NULL) { jlog("ERROR: dnn_config_file_parse: duplicated loading: %s\n", filename); return FALSE; } if ((fp = fopen(filename, "r")) == NULL) { jlog("ERROR: dnn_config_file_parse: failed to open %s\n", filename); return FALSE; } cdir = strcpy((char *)mymalloc(strlen(filename)+1), filename); get_dirname(cdir); if (cdir[0] == '\0') { free(cdir); cdir = NULL; } while (fgets_jconf(buf, BUFLEN, fp) != NULL) { if ((p = strchr(buf, '#')) != NULL) { *p = '\0'; } pp = &(buf[0]); while (*pp == ' ' || *pp == '\t') pp++; if (*pp == '\0') continue; p = strchr(pp, ' '); if (p == NULL) { jlog("ERROR: dnn_config_file_parse: wrong file format: %s\n", buf); if (cdir) free(cdir); fclose(fp); return FALSE; } v = p; while (*v == ' ') v++; *p = '\0'; if (strmatch(pp, "feature_type")) { am->dnn.paramtype = param_str2code(v); } else if (strmatch(pp, "feature_options")) { am->dnn.optionstring = strdup(v); } else if (strmatch(pp, "feature_len")) am->dnn.veclen = atoi(v); else if (strmatch(pp, "context_len")) am->dnn.contextlen = atoi(v); else if (strmatch(pp, "input_nodes")) am->dnn.inputnodes = atoi(v); else if (strmatch(pp, "output_nodes")) am->dnn.outputnodes = atoi(v); else if (strmatch(pp, "hidden_nodes")) am->dnn.hiddennodes = atoi(v); else if (strmatch(pp, "hidden_layers")) { am->dnn.hiddenlayernum = atoi(v); am->dnn.wfile = (char **)mymalloc(sizeof(char *) * am->dnn.hiddenlayernum); am->dnn.bfile = (char **)mymalloc(sizeof(char *) * am->dnn.hiddenlayernum); for (i = 0; i < am->dnn.hiddenlayernum; i++) { am->dnn.wfile[i] = NULL; am->dnn.bfile[i] = NULL; } } else if (pp[0] == 'W') { n = atoi(&(pp[1])); if (n > am->dnn.hiddenlayernum) { jlog("ERROR: dnn_config_file_parse: W%d > # of hidden_layers (%d)\n", n, am->dnn.hiddenlayernum); if (cdir) free(cdir); fclose(fp); return FALSE; } else if (n <= 0) { jlog("ERROR: dnn_config_file_parse: layer id should begin with 1\n"); if (cdir) free(cdir); fclose(fp); return FALSE; } am->dnn.wfile[n-1] = filepath(v, cdir); } else if (pp[0] == 'B') { n = atoi(&(pp[1])); if (n > am->dnn.hiddenlayernum) { jlog("ERROR: dnn_config_file_parse: B%d > # of hidden_layers (%d)\n", n, am->dnn.hiddenlayernum); if (cdir) free(cdir); fclose(fp); return FALSE; } else if (n <= 0) { jlog("ERROR: dnn_config_file_parse: layer id should begin with 1\n"); if (cdir) free(cdir); fclose(fp); return FALSE; } am->dnn.bfile[n-1] = filepath(v, cdir); } else if (strmatch(pp, "output_W")) am->dnn.output_wfile = filepath(v, cdir); else if (strmatch(pp, "output_B")) am->dnn.output_bfile = filepath(v, cdir); else if (strmatch(pp, "state_prior")) am->dnn.priorfile = filepath(v, cdir); else if (strmatch(pp, "state_prior_factor")) am->dnn.prior_factor = atof(v); else if (strmatch(pp, "batch_size")) am->dnn.batchsize = atoi(v); else if (strmatch(pp, "num_threads")) am->dnn.num_threads = atoi(v); else { jlog("ERROR: dnn_config_file_parse: unknown spec: %s %s\n", pp, v); if (cdir) free(cdir); fclose(fp); return FALSE; } } if (fclose(fp) == -1) { jlog("ERROR: dnn_config_file_parse: failed to close file\n"); if (cdir) free(cdir); return FALSE; } /* check validity */ error_flag = FALSE; for (i = 0; i < am->dnn.hiddenlayernum; i++) { if (am->dnn.wfile[i] == NULL) { jlog("ERROR: dnn_config_file_parse: no W file specified for hidden layer #%d\n", i + 1); error_flag = TRUE; } if (am->dnn.bfile[i] == NULL) { jlog("ERROR: dnn_config_file_parse: no B file specified for hidden layer #%d\n", i + 1); error_flag = TRUE; } } if (error_flag == TRUE) { if (cdir) free(cdir); return FALSE; } am->dnn.enabled = TRUE; /* load options */ if (am->dnn.optionstring) { if (config_string_parse_basedir(jconf->amnow->dnn.optionstring, jconf, cdir) == FALSE) { if (cdir) free(cdir); return FALSE; } } if (cdir) free(cdir); return TRUE; }