label_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/mono/tsc/sd/' for s in Utility.char_range('a', 'z'): set_label_path = '{}/{}/'.format(label_path, s) set_dct_path = '{}/{}/'.format(outpath, s) Utility.make_directory(set_dct_path) for x in range(1, 51): name = 'tscsd{}{}'.format(s, Utility.fill_zero(x, 2)) file_path = '{}/{}.lab'.format(set_label_path, name) if not Utility.is_file_exist(file_path): continue dur_list, names = PoGUtility.gen_dur_and_name_list( file_path, name) if len(dur_list) != len(names): print name # print names dct_list = [] for n in names: if n in syl_dict: if incl_zero == 'not_include_zero_coeff': dct_list.append(syl_dict[n][1:num_coeff]) else: dct_list.append(syl_dict[n]) else:
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] original = config['original'] koriyama_gen = config['koriyama_gen'] figure_path = config['figure_path'] ph_in_syl_object_path = config['phone_in_syllable_object_path'] stress = config['stress'] original_vuv = config['original_vuv'] p_in_s_file = Utility.load_obj(ph_in_syl_object_path) vuv = np.load('{}/class.npy'.format(config['vuv_path'])) if mask == 'original': vuv = original_vuv #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) if len(lf0_cov) > len(vuv): for i in range(len(lf0_cov)-len(vuv)): vuv.append(-1, axis=0) elif len(lf0_cov) < len(vuv): vuv = vuv[0:len(lf0_cov)] lf0_var = np.sum(var, axis=0) lf0_mean = np.array( [ lf0_mean[:,0], lf0_mean[:,1], lf0_mean[:,2] ] ) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part(lf0_var, lf0_w, lf0_cov) L = linalg.cholesky(frame_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B) # lf0 = lf0_gen_with_vuv(lf0, vuv) print lf0.shape frame_lf0_nomask = np.copy(lf0) # lf0 = lf0_gen_with_vuv(lf0, vuv) lf0[lf0<1] = np.nan frame_lf0 = np.copy(lf0) #----------Syllable level--------# dur_list, names = PoGUtility.gen_dur_and_name_list(label_path, name) # print np.sum(dur_list) if np.sum(dur_list) < len(original): dur_list[0] = dur_list[0] + len(original)-np.sum(dur_list) # print np.sum(dur_list) syl_mean = np.load('{}/mean.npy'.format(syllable_base_path)) syl_cov = np.load('{}/cov.npy'.format(syllable_base_path)) syl_cov = np.identity(len(syl_cov)) s_mean = syl_mean var = np.load('{}'.format(syllable_var_path)) syl_var = np.sum(var, axis=0) temp_mean = [] for i in range( len(syl_mean[0]) ): temp_mean.append( syl_mean[:,i] ) syl_mean = np.array(temp_mean) syl_w = PoGUtility.generate_DCT_W_without_consonant_on_stress_vuv_head_tail(len(lf0_cov), dur_list, num_coeff, p_in_s_file, stress, vuv) syl_B = beta * PoGUtility.cal_sum_of_mean_part(syl_var, syl_w, syl_cov, syl_mean) syl_A = beta * PoGUtility.cal_sum_of_weight_part(syl_var, syl_w, syl_cov) #----------Combine Model--------# L = linalg.cholesky(frame_A + syl_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B + syl_B) # print lf0.shape lf0[lf0<1] = np.nan PlotUtility.plot([lf0, original, frame_lf0_nomask], ['Multi', 'original', 'Single'], '{}/{}_no_mask.eps'.format(figure_path, name)) lf0 = lf0_gen_with_vuv(lf0, vuv) lf0[lf0<1] = np.nan frame_lf0 = lf0_gen_with_vuv(frame_lf0, vuv) frame_lf0[frame_lf0<1] = np.nan np.save(outfilepath, lf0) print min(lf0) PlotUtility.plot([lf0, original, frame_lf0], ['Multi', 'original', 'Single'], '{}/{}_multi.eps'.format(figure_path, name)) #----------Combine Model--------# o = [] for data_dct, dur in zip(s_mean, dur_list): i_dct = PoGUtility.generate_inverse_DCT(data_dct, dur) o = o + i_dct o = np.concatenate( (np.zeros(len(original)-len(o)), np.array(o)) , axis=0) # o = lf0_gen_with_vuv(o, vuv) o[o<=1] = np.nan # print o.shape PlotUtility.plot([o, original, lf0, frame_lf0], ['dct', 'original', 'Multi', 'frame_lf0'], '{}/{}_dct.eps'.format(figure_path, name)) pass
def cal_lf0(config): base_path = config['base_path'] label_path = config['label_path'] name = config['name'] outfilepath = config['outfilepath'] var_path = config['var_path'] syllable_base_path = config['syllable_base_path'] syllable_var_path = config['syllable_var_path'] original = config['original'] koriyama_gen = config['koriyama_gen'] figure_path = config['figure_path'] vuv = np.load('{}/class.npy'.format(config['vuv_path'])) #--------Frame-------# lf0_mean = np.load('{}/mean.npy'.format(base_path)) lf0_cov = np.load('{}/cov.npy'.format(base_path)) var = np.load('{}'.format(var_path)) lf0_var = np.sum(var, axis=0) lf0_mean = np.array( [ lf0_mean[:,0], lf0_mean[:,1], lf0_mean[:,2] ] ) lf0_w = PoGUtility.generate_W_for_GPR_generate_features(len(lf0_cov), vuv) frame_B = alpha * PoGUtility.cal_sum_of_mean_part(lf0_var, lf0_w, lf0_cov, lf0_mean) frame_A = alpha * PoGUtility.cal_sum_of_weight_part(lf0_var, lf0_w, lf0_cov) L = linalg.cholesky(frame_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B) lf0 = lf0_gen_with_vuv(lf0, vuv) print lf0.shape lf0[lf0<0] = np.nan frame_lf0 = lf0 #----------Syllable level--------# dur_list, names = PoGUtility.gen_dur_and_name_list(label_path, name) # print np.sum(dur_list) if np.sum(dur_list) < len(original): dur_list[0] = dur_list[0] + len(original)-np.sum(dur_list) # print np.sum(dur_list) syl_mean = np.load('{}/mean.npy'.format(syllable_base_path)) syl_cov = np.load('{}/cov.npy'.format(syllable_base_path)) s_mean = syl_mean var = np.load('{}'.format(syllable_var_path)) syl_var = np.sum(var, axis=0) temp_mean = [] for i in range( len(syl_mean[0]) ): temp_mean.append( syl_mean[:,i] ) syl_mean = np.array(temp_mean) syl_w = PoGUtility.generate_DCT_W_with_vuv(len(lf0_cov), dur_list, num_coeff, vuv) syl_B = beta * PoGUtility.cal_sum_of_mean_part(syl_var, syl_w, syl_cov, syl_mean) syl_A = beta * PoGUtility.cal_sum_of_weight_part(syl_var, syl_w, syl_cov) # print syl_B # Utility.write_to_file_line_by_line('./syl_B.txt', syl_B) # Utility.write_to_file_line_by_line('./syl_A.txt', syl_A) #----------Combine Model--------# L = linalg.cholesky(frame_A + syl_A, lower=True) lf0 = linalg.cho_solve((L, True) , frame_B + syl_B) # lf0 = np.dot( # inv(frame_A + syl_A), # frame_B + syl_B # ) lf0 = lf0_gen_with_vuv(lf0, vuv) # print lf0.shape lf0[lf0<0] = np.nan np.save(outfilepath, lf0) PlotUtility.plot([lf0, original, frame_lf0], ['Multi', 'original', 'Single'], '{}/{}_multi.eps'.format(figure_path, name)) #----------Combine Model--------# o = [] for data_dct, dur in zip(s_mean, dur_list): i_dct = PoGUtility.generate_inverse_DCT(data_dct, dur) o = o + i_dct o = np.concatenate( (np.zeros(len(original)-len(o)), np.array(o)) , axis=0) o = lf0_gen_with_vuv(o, vuv) o[o<0] = np.nan # print o.shape PlotUtility.plot([o, original, lf0], ['dct', 'original', 'Multi'], '{}/{}_dct.eps'.format(figure_path, name)) pass