def vad_gmm_evaluate_frames(ref_annotations_list, hyp_annotations_list, samp_period, model_list, mode='sequence'): m_list = open(model_list,'r') labels = [] for m in m_list: labels.append(m.rstrip('\r\n')) conf_matrix = evaluate_gmm_classifier.evaluate_results_list(ref_annotations_list, hyp_annotations_list, samp_period, labels, mode) return(conf_matrix)
def test_gmm_classification(models=None, n_samples=10000, working_dir=os.getcwd(), apply_hlda=False, hlda_nuisance_dims=2, do_not_generate_features=False): test_percentage = 0.2 samp_period = 0.01 generate_features = not do_not_generate_features if not os.path.exists(working_dir): os.makedirs(working_dir) fea_dir = os.path.join(working_dir, 'features') lab_dir = os.path.join(working_dir, 'lab') list_dir = os.path.join(working_dir, 'lists') model_dir = os.path.join(working_dir, 'models') results_dir = os.path.join(working_dir, 'results') if not os.path.exists(list_dir): os.makedirs(list_dir) if not os.path.exists(fea_dir): os.makedirs(fea_dir) if not os.path.exists(lab_dir): os.makedirs(lab_dir) if not os.path.exists(model_dir): os.makedirs(model_dir) if not os.path.exists(results_dir): os.makedirs(results_dir) # Create a list of the model names model_list = os.path.join(working_dir,'models.list') ml = open(model_list,'w') labels = [] for md in models: ml.write('{}\n'.format(md.name)) labels.append(md.name) ml.close() tst_file_list = os.path.join(list_dir,'test_files.list') trn_file_list = os.path.join(list_dir,'train_files.list') if generate_features: fea_file_names = write_feature_files(models, n_samples, fea_dir, lab_dir) n_fea_files = len(fea_file_names) logging.info('Number of feature files: {}'.format(n_fea_files)) n_train_files = int(round(n_fea_files*(1-test_percentage))) trn_list = open(trn_file_list,'w') for f_n in fea_file_names[0:n_train_files]: trn_list.write("{}\n".format(os.path.join(fea_dir,f_n))) trn_list.close() tst_list = open(tst_file_list,'w') for f_n in fea_file_names[n_train_files:n_fea_files-1]: tst_list.write("{}\n".format(os.path.join(fea_dir,f_n))) tst_list.close() n_mixes = models[0].n_components n_dims = models[0].means.shape[1] train_gmm_classifier.train_M_sized_gmm_classifier(n_mixes, n_dims, 'USER', trn_file_list, model_list, lab_dir, model_dir, apply_hlda, hlda_nuisance_dims) model_file = os.path.join(model_dir,'newMacros') test_gmm_classifier.test_gmm_classifier(tst_file_list, model_list, model_file, results_dir) ref_annotations_list = os.path.join(list_dir,'labels.list') hyp_annotations_list = os.path.join(list_dir,'hyp.list') lists.create_corresponding_list_assert(tst_file_list,lab_dir,ref_annotations_list,'lab') lists.create_corresponding_list_assert(tst_file_list,results_dir,hyp_annotations_list,'rec') conf_matrix = evaluate_gmm_classifier.evaluate_results_list(ref_annotations_list, hyp_annotations_list, samp_period, labels) logging.info('Confusion matrix: {}'.format(conf_matrix))
def test_gmm_classification(models=None, n_samples=10000, working_dir=os.getcwd(), apply_hlda=False, hlda_nuisance_dims=2, do_not_generate_features=False): test_percentage = 0.2 samp_period = 0.01 generate_features = not do_not_generate_features if not os.path.exists(working_dir): os.makedirs(working_dir) fea_dir = os.path.join(working_dir, 'features') lab_dir = os.path.join(working_dir, 'lab') list_dir = os.path.join(working_dir, 'lists') model_dir = os.path.join(working_dir, 'models') results_dir = os.path.join(working_dir, 'results') if not os.path.exists(list_dir): os.makedirs(list_dir) if not os.path.exists(fea_dir): os.makedirs(fea_dir) if not os.path.exists(lab_dir): os.makedirs(lab_dir) if not os.path.exists(model_dir): os.makedirs(model_dir) if not os.path.exists(results_dir): os.makedirs(results_dir) # Create a list of the model names model_list = os.path.join(working_dir, 'models.list') ml = open(model_list, 'w') labels = [] for md in models: ml.write('{}\n'.format(md.name)) labels.append(md.name) ml.close() tst_file_list = os.path.join(list_dir, 'test_files.list') trn_file_list = os.path.join(list_dir, 'train_files.list') if generate_features: fea_file_names = write_feature_files(models, n_samples, fea_dir, lab_dir) n_fea_files = len(fea_file_names) logging.info('Number of feature files: {}'.format(n_fea_files)) n_train_files = int(round(n_fea_files * (1 - test_percentage))) trn_list = open(trn_file_list, 'w') for f_n in fea_file_names[0:n_train_files]: trn_list.write("{}\n".format(os.path.join(fea_dir, f_n))) trn_list.close() tst_list = open(tst_file_list, 'w') for f_n in fea_file_names[n_train_files:n_fea_files - 1]: tst_list.write("{}\n".format(os.path.join(fea_dir, f_n))) tst_list.close() n_mixes = models[0].n_components n_dims = models[0].means.shape[1] train_gmm_classifier.train_M_sized_gmm_classifier(n_mixes, n_dims, 'USER', trn_file_list, model_list, lab_dir, model_dir, apply_hlda, hlda_nuisance_dims) model_file = os.path.join(model_dir, 'newMacros') test_gmm_classifier.test_gmm_classifier(tst_file_list, model_list, model_file, results_dir) ref_annotations_list = os.path.join(list_dir, 'labels.list') hyp_annotations_list = os.path.join(list_dir, 'hyp.list') lists.create_corresponding_list_assert(tst_file_list, lab_dir, ref_annotations_list, 'lab') lists.create_corresponding_list_assert(tst_file_list, results_dir, hyp_annotations_list, 'rec') conf_matrix = evaluate_gmm_classifier.evaluate_results_list( ref_annotations_list, hyp_annotations_list, samp_period, labels) logging.info('Confusion matrix: {}'.format(conf_matrix))