def train_plda(iv_file, train_list, val_list, preproc_file, epochs, ml_md, md_epochs, output_path, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None vcr_args = VCR.filter_args(**kwargs) vcr_train = VCR(iv_file, train_list, preproc, **vcr_args) x, class_ids = vcr_train.read() x_val = None class_ids_val = None if val_list is not None: vcr_val = VCR(iv_file, val_list, preproc, **vcr_args) x_val, class_ids_val = vcr_val.read() t1 = time.time() plda_args = F.filter_train_args(**kwargs) model = F.create_plda(**plda_args) elbos = model.fit(x, class_ids, x_val=x_val, class_ids_val=class_ids_val, epochs=epochs, ml_md=ml_md, md_epochs=md_epochs) logging.info('Elapsed time: %.2f s.' % (time.time()-t1)) model.save(output_path) elbo = np.vstack(elbos) num = np.arange(epochs) elbo = np.vstack((num, elbo)).T elbo_path=os.path.splitext(output_path)[0] + '.csv' np.savetxt(elbo_path, elbo, delimiter=',')
def eval_plda(iv_file, ndx_file, enroll_file, test_subseg2orig_file, preproc_file, model_file, score_file, plda_type, **kwargs): logging.info('loading data') if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None tdr = TDR(iv_file, ndx_file, enroll_file, None, test_subseg2orig_file, preproc) x_e, x_t, enroll, ndx, orig_seg = tdr.read() logging.info('loading plda model: %s' % (model_file)) model = F.load_plda(plda_type, model_file) t1 = time.time() logging.info('computing llr') scores = model.llr_1vs1(x_e, x_t) dt = time.time() - t1 num_trials = len(enroll) * x_t.shape[0] logging.info('scoring elapsed time: %.2f s. elapsed time per trial: %.2f ms.' % (dt, dt/num_trials*1000)) logging.info('combine cluster scores') scores = combine_diar_scores(ndx, orig_seg, scores) logging.info('saving scores to %s' % (score_file)) s = TrialScores(enroll, ndx.seg_set, scores) s = s.align_with_ndx(ndx) s.save_txt(score_file)
def eval_plda(iv_file, ndx_file, enroll_file, test_file, preproc_file, model_file, score_file, plda_type, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None tdr_args = TDR.filter_args(**kwargs) tdr = TDR(iv_file, ndx_file, enroll_file, test_file, preproc, **tdr_args) x_e, x_t, enroll, ndx = tdr.read() model = F.load_plda(plda_type, model_file) t1 = time.time() scores = model.llr_1vs1(x_e, x_t) dt = time.time() - t1 num_trials = x_e.shape[0] * x_t.shape[0] logging.info('Elapsed time: %.2f s. Elapsed time per trial: %.2f ms.' % (dt, dt/num_trials*1000)) s = TrialScores(enroll, ndx.seg_set, scores) s.save(score_file)
def eval_plda(iv_file, ndx_file, enroll_file, test_file, preproc_file, model_file, score_file, pool_method, **kwargs): if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None tdr_args = TDR.filter_args(**kwargs) tdr = TDR(iv_file, ndx_file, enroll_file, test_file, preproc, **tdr_args) x_e, x_t, enroll, ndx = tdr.read() enroll, ids_e = np.unique(enroll, return_inverse=True) model = F.load_plda(plda_type, model_file) t1 = time.time() scores = model.llr_Nvs1(x_e, x_t, method=pool_method, ids1=ids_e) dt = time.time() - t1 num_trials = len(enroll) * x_t.shape[0] logging.info('Elapsed time: %.2f s. Elapsed time per trial: %.2f ms.' % (dt, dt / num_trials * 1000)) s = TrialScores(enroll, ndx.seg_set, scores) s.save(score_file)
def eval_plda(iv_file, ndx_file, enroll_file, test_subseg2orig_file, preproc_file, coh_iv_file, coh_list, coh_nbest, coh_nbest_discard, model_file, score_file, plda_type, **kwargs): logging.info('loading data') if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None tdr = TDR(iv_file, ndx_file, enroll_file, None, test_subseg2orig_file, preproc) x_e, x_t, enroll, ndx, orig_seg = tdr.read() logging.info('loading plda model: %s' % (model_file)) model = F.load_plda(plda_type, model_file) t1 = time.time() logging.info('computing llr') scores = model.llr_1vs1(x_e, x_t) dt = time.time() - t1 num_trials = len(enroll) * x_t.shape[0] logging.info( 'scoring elapsed time: %.2f s. elapsed time per trial: %.2f ms.' % (dt, dt / num_trials * 1000)) logging.info('loading cohort data') vr = VR(coh_iv_file, coh_list, preproc) x_coh = vr.read() t2 = time.time() logging.info('score cohort vs test') scores_coh_test = model.llr_1vs1(x_coh, x_t) logging.info('score enroll vs cohort') scores_enr_coh = model.llr_1vs1(x_e, x_coh) dt = time.time() - t2 logging.info('cohort-scoring elapsed time: %.2f s.' % (dt)) t2 = time.time() logging.info('apply s-norm') snorm = SNorm(nbest=coh_nbest, nbest_discard=coh_nbest_discard) scores = snorm.predict(scores, scores_coh_test, scores_enr_coh) dt = time.time() - t2 logging.info('s-norm elapsed time: %.2f s.' % (dt)) dt = time.time() - t1 logging.info( ('total-scoring elapsed time: %.2f s. ' 'elapsed time per trial: %.2f ms.') % (dt, dt / num_trials * 1000)) logging.info('combine cluster scores') scores = combine_diar_scores(ndx, orig_seg, scores) logging.info('saving scores to %s' % (score_file)) s = TrialScores(enroll, ndx.seg_set, scores) s = s.align_with_ndx(ndx) s.save_txt(score_file)
def tracking_plda(iv_file, ndx_file, enroll_file, segments_file, preproc_file, model_file, rttm_file, plda_type, **kwargs): logging.info('loading data') if preproc_file is not None: preproc = TransformList.load(preproc_file) else: preproc = None tdr = TDR(iv_file, ndx_file, enroll_file, segments_file, preproc) x_e, x_t, enroll, ndx_seg, ext_segments = tdr.read() logging.info('loading plda model: %s' % (model_file)) model = F.load_plda(plda_type, model_file) t1 = time.time() logging.info('computing llr') scores = model.llr_1vs1(x_e, x_t) dt = time.time() - t1 num_trials = len(enroll) * x_t.shape[0] logging.info( 'scoring elapsed time: %.2f s. elapsed time per trial: %.2f ms.' % (dt, dt / num_trials * 1000)) scores = TrialScores(enroll, ndx_seg.seg_set, scores) new_ext_segment_ids, ext_segment_ids, model_ids, scores = flatten_segment_scores( ndx_seg, scores) new_ext_segments = prepare_output_ext_segments(ext_segments, new_ext_segment_ids, ext_segment_ids, model_ids, scores) new_ext_segments.save(rttm_file + '_es') rttm = RTTM.create_spkdiar_from_ext_segments(new_ext_segments) rttm.save(rttm_file)
parser=argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, fromfile_prefix_chars='@', description='Eval PLDA with diarization in test') parser.add_argument('--iv-file', dest='iv_file', required=True) parser.add_argument('--ndx-file', dest='ndx_file', required=True) #parser.add_argument('--diar-ndx-file', dest='diar_ndx_file', required=True) parser.add_argument('--enroll-file', dest='enroll_file', required=True) #parser.add_argument('--diar2orig', dest='diar2orig', required=True) parser.add_argument('--test-subseg2orig-file', dest='test_subseg2orig_file', required=True) parser.add_argument('--preproc-file', dest='preproc_file', default=None) TDR.add_argparse_args(parser) F.add_argparse_eval_args(parser) parser.add_argument('--score-file', dest='score_file', required=True) parser.add_argument('-v', '--verbose', dest='verbose', default=1, choices=[0, 1, 2, 3], type=int) args=parser.parse_args() config_logger(args.verbose) del args.verbose logging.debug(args) eval_plda(**vars(args))
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=',')
if __name__ == "__main__": parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, fromfile_prefix_chars='@', description='Train Back-end with adaptation') parser.add_argument('--iv-file', dest='iv_file', required=True) parser.add_argument('--train-list', dest='train_list', required=True) parser.add_argument('--adapt-iv-file', dest='adapt_iv_file', required=True) parser.add_argument('--adapt-list', dest='adapt_list', required=True) VCR.add_argparse_args(parser) F.add_argparse_train_args(parser) parser.add_argument('--output-path', dest='output_path', required=True) parser.add_argument('--lda-dim', dest='lda_dim', type=int, default=None) parser.add_argument('--w-mu', dest='w_mu', type=float, default=1) parser.add_argument('--w-b', dest='w_B', type=float, default=1) parser.add_argument('--w-w', dest='w_W', type=float, default=1) parser.add_argument('-v', '--verbose', dest='verbose', default=1, choices=[0, 1, 2, 3], type=int) args = parser.parse_args()