def evaluate(original_file, 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 #exit() 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_original_file(self, test_dir, type_data): dnn_predict_dir = '/home/danglab/Results/PR_ver2/' + type_data + 'no_EMA/'+'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.feature_dim_in, "factors") #read a missing_feature #print factors energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.feature_dim_in] self._write_predict_missing(dnn_predict_dir + afile + '.txt', energy, test_arr, factors) # write result to file
def _testing_aritc_interpolation(self, test_dir): dnn_predict_dir = '/home/danglab/Results/New_PR/' + '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.feature_dim_in, "factors") #read a missing_feature #print factors energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.feature_dim_in] test_arr[:,12:self.feature_dim_in] = 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 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) [m,n] = ori_arr.shape #print m,n ori_arr = ori_arr[:,1:13] * factors #normalise_mfcc(ori_arr) # take 12 coefficients test_arr = test_arr[:,1:13] subtract = (ori_arr - test_arr) ** 2 #subtract = (ori_arr[2:m-3,:] - test_arr[2:m-3,:]) ** 2 rms = sqrt(subtract.sum()) #/(ori_arr.shape[0] * ori_arr.shape[1]) #print #print ori_arr[m-3] #print test_arr[m-3] #print subtract[m-3] #exit() #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_original_file(self, test_dir, type_data): dnn_predict_dir = '/home/danglab/Results/New_PR/' + type_data + 'full_EMA/'+'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.feature_dim_in, "factors") #read a missing_feature #print factors energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.feature_dim_in] if "full_EMA" not in dnn_predict_dir: print "no_ema" test_arr[:,12:self.feature_dim_in] = 0 # remove articulatory data test_arr = self._stack_segment_test(test_arr) print test_arr.shape self._write_predict_2_file(dnn_predict_dir + afile + '.txt', energy, self.predict(test_arr), factors) # write result to file
def _testing_space(self, test_dir, type_data): dnn_predict_dir = '/home/danglab/Results/New_PR/' + type_data + 'full_EMA/'+'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 + '_20ms_in.txt', self.feature_dim_in, "factors") #read a missing_feature #print factors energy = test_arr[:,0] #ko cho energy vao DNN test_arr = test_arr[:,1:self.feature_dim_in] if "full_EMA" not in dnn_predict_dir: print "no_ema" test_arr[:,12:self.feature_dim_in] = 0 # remove articulatory data test_arr = self._stack_segment_test(test_arr) #position 0,2,4,6,... is missing audio, only test these parts test_missing_part = test_arr[0:test_arr.shape[0]:2] # lay nhung frame bi mat du lieu no_missing_part = test_arr[1:test_arr.shape[0]:2] print test_missing_part.shape, no_missing_part.shape, test_arr.shape self._write_predict_missing(dnn_predict_dir + afile + '.txt', energy, self.predict(test_missing_part), no_missing_part, factors) # write result to file
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/Results/New_PR/' + type_data + 'SP_no_EMA/'+'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.feature_dim_in, "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.feature_dim_in] #test_arr[:,12:self.n_input_f] = 0 # remove articulatory data #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 get_data(filename): arr = read_file_test(filename, num_features) # 0:13, enegy+MFCC, 13:49, articulotory position # position = arr[:,13:13 + 12] # position at i return arr[:, 0], arr[:, 1:13], arr[:, 13 : 13 + 12]