def load_model(spk_id_list, architecture, task, threshold, id): iv_model_paths = [ os.path.join(model_dir, spk_id + ".iv") for spk_id in spk_id_list ] gmm_model_paths = [ os.path.join(model_dir, spk_id + ".gmm") for spk_id in spk_id_list ] iv_model_list = [] gmm_model_list = [] for path in iv_model_paths: with open(path, "rb") as reader: model = pickle.load(reader) iv_model_list.append(model) for path in gmm_model_paths: with open(path, "rb") as reader: model = pickle.load(reader) gmm_model_list.append(model) ubm = os.path.join(pre_model_dir, "final.dubm") if architecture == IV: if task == OSI: model = iv_OSI(id, iv_model_list, threshold=threshold) elif task == CSI: model = iv_CSI(id, iv_model_list) else: model = iv_SV(id, iv_model_list[0], threshold=threshold) else: if task == OSI: model = gmm_OSI(id, gmm_model_list, ubm, threshold=threshold) elif task == CSI: model = gmm_CSI(id, gmm_model_list) else: model = gmm_SV(id, gmm_model_list[0], ubm, threshold=threshold) return model
for path in iv_model_paths: with open(path, "rb") as reader: model = pickle.load(reader) iv_model_list.append(model) for path in gmm_model_paths: with open(path, "rb") as reader: model = pickle.load(reader) gmm_model_list.append(model) pre_model_dir = "pre-models" ubm = os.path.join(pre_model_dir, "final.dubm") ''' Test for ivector-PLDA-based CSI ''' group_id = "test-iv-CSI" iv_csi_model = iv_CSI(group_id, iv_model_list) spk_ids = np.array(iv_csi_model.spk_ids) audio_list = [] target_label_list = [] spk_iter = os.listdir(test_dir) for spk_id in spk_iter: target_label = np.argwhere(spk_ids == spk_id).flatten()[0] spk_dir = os.path.join(test_dir, spk_id) audio_iter = os.listdir(spk_dir) for i, audio_name in enumerate(audio_iter): path = os.path.join(spk_dir, audio_name) _, audio = read(path) audio_list.append(audio)