def fit_adap(data, ubm, save_path): print('Generating GMMs...') msa = em.GMMMachine(64, 60) egy = em.GMMMachine(64, 60) msa_trainer = em.MAP_GMMTrainer(ubm, relevance_factor=10) egy_trainer = em.MAP_GMMTrainer(ubm, relevance_factor=10) em.train(msa_trainer, msa, data['f'], max_iterations=14, convergence_threshold=0.001) em.train(egy_trainer, egy, data['m'], max_iterations=14, convergence_threshold=0.001) msa.save(HDF5File(save_path + 'msa.h5', 'w')) egy.save(HDF5File(save_path + 'egy.h5', 'w'))
def predict_ubm(data, model_path): try: msa = em.GMMMachine(HDF5File(model_path + 'msa.h5')) egy = em.GMMMachine(HDF5File(model_path + 'egy.h5')) # ubm = joblib.load(model_path + 'ubm.joblib') # msa = joblib.load(model_path + 'msa.joblib') # egy = joblib.load(model_path + 'egy.joblib') except: print("Model not found.") exit() return { 'm': map(lambda x: (msa.log_likelihood(x), egy.log_likelihood(x)), data['m']), 'f': map(lambda x: (msa.log_likelihood(x), egy.log_likelihood(x)), data['f']) }
def fit_ubm(switch_data, non_switch_data, num_components, save_path): print('Generating UBM...') all_data = np.concatenate((switch_data, non_switch_data)) ubm = em.GMMMachine(num_components, all_data.shape[1]) ubm_trainer = em.ML_GMMTrainer(True, True, True) em.train(ubm_trainer, ubm, all_data, max_iterations=12, convergence_threshold=0.001) ubm.save(HDF5File(save_path + 'ubm.h5', 'w')) return ubm
def fit_ubm(data, save_path): print('Generating UBM...') all_data = np.concatenate((data['m'], data['f'])) ubm = em.GMMMachine(64, 60) ubm_trainer = em.ML_GMMTrainer(True, True, True) em.train(ubm_trainer, ubm, all_data, max_iterations=12, convergence_threshold=0.001) ubm.save(HDF5File(save_path + 'ubm.h5', 'w')) # ubm = GaussianMixture(128, covariance_type='diag', init_params='random', warm_start=True, max_iter=12, verbose=1).fit(all_data) # joblib.dump(ubm, save_path + 'ubm.joblib') return ubm
def fit_adap(switch_data, non_switch_data, ubm, num_components, save_path): print('Generating GMMs...') switch_gmm = em.GMMMachine(num_components, switch_data.shape[1]) # non_switch_gmm = em.GMMMachine(num_components, switch_data.shape[1]) switch_trainer = em.MAP_GMMTrainer(ubm, relevance_factor=10, update_variances=False, update_weights=False) # non_switch_trainer = em.MAP_GMMTrainer(ubm, relevance_factor=10, update_variances=False, update_weights=False) em.train(switch_trainer, switch_gmm, switch_data, max_iterations=14, convergence_threshold=0.001) # em.train(non_switch_trainer, non_switch_gmm, non_switch_data, max_iterations=14, # convergence_threshold=0.001) switch_gmm.save(HDF5File(save_path + 'switch.h5', 'w')) # non_switch_gmm.save(HDF5File(save_path + 'non_switch.h5', 'w')) return switch_gmm
help='Path to load model from, must end in .joblib') args = parser.parse_args() if __name__ == '__main__': if args.extract: data.extract_with_test_utterance(args.window * 16, args.num_features) if args.train: switch_data, non_switch_data = data.load(args.window, args.num_features) ubm = classify.fit_ubm(switch_data, non_switch_data, args.num_components, args.save_path) switch_gmm = classify.fit_adap(switch_data, non_switch_data, ubm, args.num_components, args.save_path) if args.test: test_data = data.load_qual_test() # switch_data, non_switch_data = data.load(args.window, args.num_features, test=True) if not args.train: try: switch_gmm = em.GMMMachine( HDF5File(args.load_path + 'switch.h5')) # non_switch_gmm = em.GMMMachine(HDF5File(args.load_path + 'non_switch.h5')) except: print("Models not found.") exit() ll = classify.switch_ll(test_data, switch_gmm) evaluate.qual_test(ll, 1) # scores = classify.predict(switch_data, non_switch_data, switch_gmm, non_switch_gmm) # Y,Y_pred = evaluate.get_predictions(scores) # evaluate.evaluate(Y, Y_pred) # evaluate.confusion_matrix(Y, Y_pred)