def train_gauss(iv_file, train_list, preproc_file, save_tlist, append_tlist, input_path, output_path, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None vr_args = VR.filter_args(**kwargs) vr = VR(iv_file, train_list, preproc, **vr_args) x = vr.read() t1 = time.time() model_args = Gaussianizer.filter_args(**kwargs) model = load_model(input_path, **model_args) model.fit(x) if save_tlist: if append_tlist and preproc is not None: preproc.append(model) model = preproc else: model = TransformList(model) model.save(output_path)
def train_pca(iv_file, train_list, preproc_file, save_tlist, append_tlist, input_path, output_path, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None vr_args = VR.filter_args(**kwargs) vr = VR(iv_file, train_list, preproc, **vr_args) x = vr.read() t1 = time.time() model_args = PCA.filter_args(**kwargs) model = load_model(input_path, **model_args) model.fit(x) logging.info('Elapsed time: %.2f s.' % (time.time() - t1)) if save_tlist: if append_tlist and preproc is not None: preproc.append(model) model = preproc else: model = TransformList(model) model.save(output_path)
def train_cw(iv_file, train_list, preproc_file, with_lnorm, save_tlist, append_tlist, input_path, output_path, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None vr_args = VR.filter_args(**kwargs) vr = VR(iv_file, train_list, preproc, **vr_args) x = vr.read() t1 = time.time() model_args = CentWhiten.filter_args(**kwargs) model = load_model(input_path, with_lnorm, **model_args) model.fit(x) logging.info('Elapsed time: %.2f s.' % (time.time()-t1)) x = model.predict(x) gauss=Normal(x_dim=x.shape[1]) gauss.fit(x=x) logging.debug(gauss.mu[:4]) logging.debug(gauss.Sigma[:4,:4]) if save_tlist: if append_tlist and preproc is not None: preproc.append(model) model = preproc else: model = TransformList(model) model.save(output_path)
def train_be(iv_file, train_list, adapt_iv_file, adapt_list, lda_dim, plda_type, y_dim, z_dim, epochs, ml_md, md_epochs, w_mu, w_B, w_W, output_path, **kwargs): # Read data logging.info('loading data') vcr_args = VCR.filter_args(**kwargs) vcr_train = VCR(iv_file, train_list, None, **vcr_args) x, class_ids = vcr_train.read() # Train LDA logging.info('train LDA') t1 = time.time() lda = LDA(lda_dim=lda_dim, name='lda') lda.fit(x, class_ids) x_lda = lda.predict(x) logging.info('LDA elapsed time: %.2f s.' % (time.time() - t1)) # Train centering and whitening logging.info('train length norm') t1 = time.time() lnorm = LNorm(name='lnorm') lnorm.fit(x_lda) x_ln = lnorm.predict(x_lda) logging.info('length norm elapsed time: %.2f s.' % (time.time() - t1)) # Train PLDA logging.info('train PLDA') t1 = time.time() plda = F.create_plda(plda_type, y_dim=y_dim, z_dim=z_dim, name='plda') elbo = plda.fit(x_ln, class_ids, epochs=epochs, ml_md=ml_md, md_epochs=md_epochs) logging.info('PLDA elapsed time: %.2f s.' % (time.time() - t1)) # Save models logging.info('saving models') preproc = TransformList(lda) preproc.append(lnorm) if not os.path.exists(output_path): os.makedirs(ouput_path) preproc.save(output_path + '/lda_lnorm.h5') plda.save(output_path + '/plda.h5') num = np.arange(epochs) elbo = np.vstack((num, elbo)).T np.savetxt(output_path + '/elbo.csv', elbo, delimiter=',') #adaptation vcr = VCR(adapt_iv_file, adapt_list, None) x, class_ids = vcr.read() x_lda = lda.predict(x) lnorm.update_T = False lnorm.fit(x_lda) preproc = TransformList(lda) preproc.append(lnorm) preproc.save(output_path + '/lda_lnorm_adapt.h5') x_ln = lnorm.predict(x_lda) plda_adapt = plda.copy() elbo = plda.fit(x_ln, class_ids, epochs=epochs) plda_adapt.weighted_avg_model(plda, w_mu, w_B, w_W) plda_adapt.save(output_path + '/plda_adapt.h5') num = np.arange(epochs) elbo = np.vstack((num, elbo)).T np.savetxt(output_path + '/elbo_adapt.csv', elbo, delimiter=',')