def evaluate(original_file, test_file): ori_arr = read_file_test(original_file, 13, ) test_arr = read_file_test(test_file, 13) ori_energy = ori_arr[:,0] test_energy = test_arr[:,0] ori_arr = ori_arr[:,1:13]#normalise_mfcc(ori_arr) # take 12 coefficients test_arr = test_arr[:,1:13] #test_arr = normalise_mfcc(test_arr) #print test_arr.max() subtract = (ori_arr - test_arr) ** 2 rms = sqrt(subtract.sum()) #/(ori_arr.shape[0] * ori_arr.shape[1]) #print rms #, ori_arr.shape[0] * ori_arr.shape[1] #subtract = (ori_arr - test_arr) #print subtract.max() [m,n] = ori_arr.shape a = ori_arr.reshape(1,m*n) b = test_arr.reshape(1,m*n) #print a #print b #print np.corrcoef(a,b)[0,1] return np.corrcoef(a,b)[0,1] return rms
def get_position(filename): arr = read_file_test(filename, num_features) #0:13, enegy+MFCC, 13:49, articulotory position position = arr[:,13:13 + 12] # position at i #print position.max(), position.min() if '10ms' in artic_dir: return interpolate_10(position) elif '20ms' in artic_dir: return interpolate_20(position) else: return interpolate_50(position)
def _testing_original_file(self, test_dir, type_data): dnn_predict_dir = '/home/danglab/3P/' + self.hidden_layer +'SQR/' + self.artic + type_data + 'test_' + str(self.test_number) + '/' if not os.path.exists(dnn_predict_dir): os.makedirs(dnn_predict_dir) for afile in self.missing_filename_list: test_arr, factors = read_file_test(test_dir + afile + '_in.txt', self.n_input_f, "factors") #read a missing_feature energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.n_input_f] self._write_predict_2_file(dnn_predict_dir + afile + '.txt', energy, self.predict(test_arr), factors) # write result to file
def evaluate(original_file, test_file): #print original_file #print test_file ori_arr, factors = read_file_test(original_file, 13, "factors") test_arr = read_file_test(test_file, 13) ori_arr = ori_arr[:,1:13] * factors #normalise_mfcc(ori_arr) # take 12 coefficients #print ori_arr test_arr = test_arr[:,1:13] #print test_arr subtract = (ori_arr - test_arr) ** 2 rms = sqrt(subtract.sum()) #/(ori_arr.shape[0] * ori_arr.shape[1]) [m,n] = ori_arr.shape a = ori_arr.reshape(1,m*n) b = test_arr.reshape(1,m*n) return np.corrcoef(a,b)[0,1] return rms
def _testing_aritc_interpolation(self, test_dir): dnn_predict_dir = '/home/danglab/Results/PhonemicRestoration/' + self.hidden_layer + 'space/artic_inter/'+'test_' + str(self.test_number) + '/10ms/' if not os.path.exists(dnn_predict_dir): os.makedirs(dnn_predict_dir) for afile in self.missing_filename_list: test_arr, factors = read_file_test(test_dir + afile + '_10ms_in.txt', self.n_input_f, "factors") #read a missing_feature #print factors energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.n_input_f] #test_arr[:,12:self.n_input_f] = 0 # remove articulatory data self._write_predict_2_file(dnn_predict_dir + afile + '.txt', energy, self.predict(test_arr), factors) # write result to file
def _testing_DNN(self): if self.space: test_dir = "/home/danglab/Phong/features_3p/Space/" else: test_dir = "/home/danglab/Phong/features_3p/Noise/" for type_test in sorted(os.listdir(test_dir)): if not type_test.endswith("zip"): type_test_dir = test_dir + type_test + "/" print type_test_dir dnn_predict_dir = ( "/home/danglab/3P/" + self.hidden_layer + "SQR/" + self.artic + "test_" + str(self.test_number) + "/" + type_test + "/" ) if not os.path.exists(dnn_predict_dir): os.makedirs(dnn_predict_dir) print type_test duration = type_test.split("_")[1] # 50ms, 100ms # listtest = sorted(os.listdir(type_test_dir)) # for afile in listtest: for prefix_file in self.missing_filename_list: afile = prefix_file + "_" + duration + "_in.txt" test_arr, factors = read_file_test( type_test_dir + afile, self.n_input_f, "factors" ) # read a missing_feature find_ = [m.start() for m in re.finditer("_", afile)] energy = test_arr[:, 0] # ko cho energy vao DNN test_arr = test_arr[:, 1 : self.n_input_f] # print factors self._write_predict_2_file( dnn_predict_dir + afile.replace(afile[find_[4] : len(afile) - 4], ""), energy, self.predict(test_arr), factors, ) # write result to file
def write_features(filename, position, vec, acc, res_file): file_feature = open(res_file, 'w') acoustic_feature, factors = read_file_test(filename, 37, "factor") # energy , mfcc, del,del-del #mfcc = acoustic_feature[:,0:13] #delta = acoustic_feature[:,13:25] #delta_delta = acoustic_feature[:,25:37] min_nframes = min(acoustic_feature.shape[0],position.shape[0]) #print min_nframes #list_feature = [] file_feature.write('%s \n' %(factors)) for fa in xrange(min_nframes): frame_feature = np.concatenate((acoustic_feature[fa,:], position[fa,:], vec[fa,:], acc[fa,:]), axis = 0) #print frame_feature.shape for i in frame_feature: file_feature.write("%s " %(i)) file_feature.write("\n") file_feature.close()
def _testing_noise_space(self, test_dir, type_data): for type_test in sorted(os.listdir(test_dir)): if (not type_test.endswith('zip')) and 'output' not in type_test: type_test_dir = test_dir + type_test + '/' print type_test_dir dnn_predict_dir = '/home/danglab/3P/' + self.hidden_layer +'SQR/' + self.artic + type_data + 'test_' + str(self.test_number) + '/' + type_test + '/' if not os.path.exists(dnn_predict_dir): os.makedirs(dnn_predict_dir) print type_test duration = type_test.split('_')[1] # 50ms, 100ms #listtest = sorted(os.listdir(type_test_dir)) #for afile in listtest: for prefix_file in self.missing_filename_list: afile = prefix_file + '_' + duration + '_in.txt' test_arr, factors = read_file_test(type_test_dir + afile, self.n_input_f, "factors") #read a missing_feature find_ = [m.start() for m in re.finditer('_', afile)] energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.n_input_f] #print factors self._write_predict_2_file(dnn_predict_dir + afile.replace(afile[find_[4]:len(afile)-4],''), energy, self.predict(test_arr), factors) # write result to file
def _testing_DNN(self): # if self.space: # test_dir = '/home/danglab/Phong/features_3p/Space/' # else: # test_dir = '/home/danglab/Phong/features_3p/Noise/' test_dir = '/home/danglab/Phong/features_3p/origin/input/' dnn_predict_dir = '/home/danglab/3P/' + self.hidden_layer +'SQR/' + self.artic + 'test_' + str(self.test_number) + '/' if not os.path.exists(dnn_predict_dir): os.makedirs(dnn_predict_dir) #listtest = sorted(os.listdir(type_test_dir)) #for afile in listtest: for afile in self.missing_filename_list: test_arr, factors = read_file_test(test_dir + afile + '_in.txt', self.n_input_f, "factors") #read a missing_feature energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.n_input_f] #print factors self._write_predict_2_file(dnn_predict_dir + afile.replace('_in',''), energy, self.predict(test_arr), factors) # write result to file