int Classemes_init(const Program_Options* _options) { char buffer[MAX_CHARACTERS_LINE]; int res; assert(_options); options = _options; /* load Phi */ Phi = (Matrix*) malloc(sizeof(Matrix)); sprintf(buffer, "%s%c"PHI_CLASSEMES_BF, options->parameters_dir, SYSTEM_PATH_SEPARATOR); res = read_float_matrix(Phi, buffer); if(res) { return ERROR_PARAMETERS_LOADING; } /* load Tau */ Tau = (Matrix*) malloc(sizeof(Matrix)); sprintf(buffer, "%s%c"TAU_CLASSEMES_BF, options->parameters_dir, SYSTEM_PATH_SEPARATOR); res = read_float_matrix(Tau, buffer); if(res) { return ERROR_PARAMETERS_LOADING; } return 0; }
bool Lab2VitMain::init_utt() { if (m_audioStrm.peek() == EOF) return false; m_idStr = read_float_matrix(m_audioStrm, m_inAudio); cout << "Processing utterance ID: " << m_idStr << endl; m_frontEnd.get_feats(m_inAudio, m_feats); if (m_feats.size2() != m_gmmSet.get_dim_count()) throw runtime_error("Mismatch in GMM and feat dim."); if (m_doAlign) { if (m_graphStrm.peek() == EOF) throw runtime_error("Mismatch in number of audio files " "and FSM's."); m_graph.read(m_graphStrm, m_idStr); } if (m_graph.get_gmm_count() > m_gmmSet.get_gmm_count()) throw runtime_error("Mismatch in number of GMM's between " "FSM and GmmSet."); m_gmmSet.calc_gmm_probs(m_feats, m_gmmProbs); // Initialize dynamic programming chart. m_chart.resize(m_feats.size1() + 1, m_graph.get_state_count()); m_chart.clear(); if (m_graph.get_start_state() < 0) throw runtime_error("Graph has no start state."); return true; }
bool Lab2TrainMain::init_utt() { if (m_audioStrm.peek() == EOF) return false; m_idStr = read_float_matrix(m_audioStrm, m_inAudio); m_frontEnd.get_feats(m_inAudio, m_feats); if (m_feats.size2() != m_gmmSet.get_dim_count()) throw runtime_error("Mismatch in GMM and feat dim."); if (m_alignStrm.peek() == EOF) throw runtime_error("Mismatch in number of audio files " "and alignments."); read_int_vector(m_alignStrm, m_gmmList, m_idStr); if (m_gmmList.size() != m_feats.size1()) throw runtime_error("Mismatch in alignment and feat lengths."); int gmmCnt = m_gmmSet.get_gmm_count(); int frmCnt = m_gmmList.size(); m_gmmCountList.clear(); for (int frmIdx = 0; frmIdx < frmCnt; ++frmIdx) { int gmmIdx = m_gmmList[frmIdx]; if ((gmmIdx < 0) || (gmmIdx >= gmmCnt)) throw runtime_error("Out of range GMM index."); m_gmmCountList.push_back(GmmCount(gmmIdx, frmIdx, 1.0)); } return true; }
void main_loop(const char** argv) { // Process command line arguments. map<string, string> params; process_cmd_line(argv, params); bool verbose = get_bool_param(params, "verbose"); // Load feature files for templates. // Get template label from matrix name. vector<string> templateLabelList; vector<matrix<double> > templateMatList; ifstream templateStrm( get_required_string_param(params, "template_file").c_str()); while (templateStrm.peek() != EOF) { templateMatList.push_back(matrix<double>()); string labelStr = read_float_matrix(templateStrm, templateMatList.back()); templateLabelList.push_back(labelStr); } templateStrm.close(); if (templateMatList.empty()) throw runtime_error("No templates supplied."); // Load correct label for each feature file, if present. vector<string> featLabelList; string labelFile = get_string_param(params, "feat_label_list"); if (!labelFile.empty()) read_string_list(labelFile, featLabelList); // The main loop. ifstream featStrm( get_required_string_param(params, "feat_file").c_str()); matrix<double> feats; unsigned templCnt = templateLabelList.size(); unsigned uttCnt = 0; unsigned correctCnt = 0; while (featStrm.peek() != EOF) { int uttIdx = uttCnt++; string idStr = read_float_matrix(featStrm, feats); // Find closest template. int bestTempl = -1; double bestScore = DBL_MAX; for (unsigned templIdx = 0; templIdx < templCnt; ++templIdx) { if (feats.size2() != templateMatList[templIdx].size2()) throw runtime_error("Mismatch in test/template feature dim."); double curScore = compute_distance(feats, templateMatList[templIdx]); if (verbose) cout << format(" %s: %.3f") % templateLabelList[templIdx] % curScore << endl; if (curScore < bestScore) bestScore = curScore, bestTempl = templIdx; } if (bestTempl < 0) throw runtime_error("No alignments found in DTW."); string hypLabel = (bestTempl >= 0) ? templateLabelList[bestTempl] : ""; if (!featLabelList.empty()) { // If have reference labels, print ref and hyp classes. if (uttIdx >= (int) featLabelList.size()) throw runtime_error("Mismatch in number of utterances " "and labels."); string refLabel = featLabelList[uttIdx]; cout << format("Reference: %s, Hyp: %s, Correct: %d") % refLabel % hypLabel % (hypLabel == refLabel) << endl; if (hypLabel == refLabel) ++correctCnt; } else // If don't have reference labels, just print hyp class. cout << hypLabel << " (" << idStr << ")" << endl; } featStrm.close(); if (!featLabelList.empty()) { // If have reference labels, print accuracy. unsigned errCnt = uttCnt - correctCnt; cout << format("Accuracy: %.2f%% (%d/%d), Error rate: %.2f%% (%d/%d)") % (100.0 * correctCnt / uttCnt) % correctCnt % uttCnt % (100.0 * errCnt / uttCnt) % errCnt % uttCnt << endl; } }