def save_enrolled_speakers(path, clients): # Save enrolled PLDA models to path. Helper.create_folder(path) for i, client in enumerate(clients): client.dump(path+'client-'+str(i)+'.npy') print('clients saved!') return
def save_enrolled_speakers(path, clients): # Save enrolled PLDA models to path. Helper.create_folder(path) for i, client in enumerate(clients): with bob.io.base.HDF5File(path + 'client-' + str(i) + '.hdf5', 'w') as f: client.save(f) print('clients saved!') return
def main(): # step 0. initial args = get_args() output_folder_path = Helper.create_folder(args.output_folder_path) logging.basicConfig( level = logging.DEBUG, \ filename = output_folder_path + 'log.txt', \ format = '%(asctime)s - %(name)s[%(filename)s:%(lineno)d] - %(levelname)s - %(message)s' \ ) ''' # step 1. construct training and test file-lists print('step1...') train_filename, test_filename = ['core.trn'], ['8conv.trn'] train_files, test_files = construct_data(args.data_path, args.trn_path, train_filename, test_filename) # step 2. extract mfcc print('step2...') train_features = extract_features(train_files, len(train_files['filename']), args.frame_size, args.overlap_size) test_features = extract_features(test_files, len(test_files['filename']), args.frame_size, args.overlap_size) Helper.save(train_features, 'train_core_all.pkl') Helper.save(test_features, 'test_features_all.pkl') ''' train_features = Helper.load('train_core_all.pkl') test_features = Helper.load('test_features_all.pkl') # step 3. preprocess print('step3...') train_features, test_features = preproces_features(train_features, test_features) # normalize train_features = extra_prepro(train_features, args.train_sep_num) # separate training data # #of speakers x 4 x 256 x 39 # step 4. training print('step4...') iv = IVector( \ number_of_gaussians = 128, \ gmm_training_iterations = 20, \ use_whitening = True, \ use_wccn = False, \ use_lda = True, \ lda_dim = 100, \ use_pinv = True, \ subspace_dimension_of_t = 300, tv_training_iterations = 5, \ use_plda = True, \ plda_dim_F = 50, \ plda_dim_G = 50, \ plda_training_iterations= 50, \ ) #iv.train_projector(train_features, output_folder_path + 'iv-all-plda-' + str(args.train_sep_num) + '.hdf5') iv.load_projector(output_folder_path + 'iv-all-plda.hdf5') # step 4.5 train autoencoder #train_iv = get_train_iv(train_features, iv, 'train_iv_all.npy') # shape: (#of speakers x 4) x 100 train_iv = numpy.load('train_iv_all.npy') train_autoencoder(train_iv) # step 5. enroll print('step5...') #clients = read_enrolled_speakers('clients-auto/', iv, len(test_features)) model_dir = tf.train.latest_checkpoint('ckpt/') clients = enroll_features(iv, model_dir, test_features, args.number_of_test_cases) #save_enrolled_speakers('clients-auto/', clients) # step 6. test print('step6...') scores, labels = test_features_(iv, model_dir, clients, test_features, args.number_of_test_cases) # step 7. summary print('step7...') p_scores, n_scores = scores[numpy.where(labels == True)].astype(numpy.double), scores[numpy.where(labels == False)[0]].astype(numpy.double) threshold = bob.measure.eer_threshold(n_scores, p_scores) far, frr = bob.measure.farfrr(n_scores, p_scores, threshold) Helper.output(output_folder_path + 'result.txt', 'threshold = %f, eer = %f%%, far = %f%%, frr = %f%%\n' % ( \ threshold, max(far, frr) * 100, far * 100, frr * 100)) Helper.generate_det_curve(p_scores, n_scores, output_folder_path + 'det_curve.png')