def load_dataset(self, csv='./dataset/tess/dataset.csv'): handle = open(csv, 'r') rawlines = handle.read().split('\n') handle.close() datalist = [line.split(',') for line in rawlines] shuffle(datalist) processed_x = [] processed_y = [] for filename, target_emotion in datalist: if filename in ['YAF_germ_angry.wav']: continue rate, signal = wav.read('./dataset/tess/' + target_emotion + '/' + filename) filter_bank_feature = log_filter_bank(signal, rate) processed_x.append(filter_bank_feature[:self.num_sample, :]) processed_y.append(self.EMOTIONS[target_emotion]) # print('\nemotion:', target_emotion) # print(filter_bank_feature[:self.num_sample, :]) processed_x = np.array(processed_x).reshape(-1, self.num_sample, 26, 1) processed_y = np_utils.to_categorical(processed_y) train_data_ratio = 0.9 num_train_data = int(len(datalist) * train_data_ratio) self.train_data_x = processed_x[:num_train_data] self.train_data_y = processed_y[:num_train_data] self.test_data_x = processed_x[num_train_data:] self.test_data_y = processed_y[num_train_data:]
def load_dataset2(self, csv='./dataset/input.csv'): handle = open(csv, 'r') rawlines = handle.read().split('\n') handle.close() datalist = [line.split(',') for line in rawlines] shuffle(datalist) cnt = 0 processed_x = [] processed_y = [] for url, target_emotion in datalist: if url in ['YAF_germ_angry.wav']: continue if cnt == 1560: break #print(url,cnt) rate, signal = wav.read('./dataset/tess/' + url) filter_bank_feature = log_filter_bank(signal, rate) #filter_bank_feature = preprocessor.process('./dataset/tess/'+url) #processed_x.append(filter_bank_feature) processed_x.append(filter_bank_feature[:self.num_sample, :]) processed_y.append(self.EMOTIONS[target_emotion]) cnt = cnt + 1 processed_x = np.array(processed_x).reshape(-1, self.num_sample, 26, 1) processed_y = np_utils.to_categorical(processed_y) train_data_ratio = 0.9 num_train_data = int(len(datalist) * train_data_ratio) self.train_data_x = processed_x[:num_train_data] self.train_data_y = processed_y[:num_train_data] self.test_data_x = processed_x[num_train_data:] self.test_data_y = processed_y[num_train_data:] print(len(self.train_data_x)) print(len(self.train_data_y))
def process(path, num_sample=32): rate, signal = wav.read(path) filter_bank_feature = log_filter_bank(signal, rate) return filter_bank_feature[:num_sample, :]
shuffle(datalist) train_data_ratio = 0.9 num_train_data = int(len(datalist) * train_data_ratio) train_datalist = datalist[:num_train_data] test_datalist = datalist[num_train_data:] x_train = [] y_train = [] num_sample = 32 for filename, target_emotion in train_datalist: if filename in ['YAF_germ_angry.wav']: continue # mfcc 처리 rate, signal = wav.read(DATA_STATIC_PATH + target_emotion + '/' + filename) filter_bank_feature = log_filter_bank(signal, rate) # 트레이닝 데이터 생성 x_train.append(filter_bank_feature[:num_sample, :]) # x_train.append(filter_bank_feature[1:3, :]) y_train.append(EMOTIONS[target_emotion]) x_train = np.array(x_train).reshape(-1, num_sample, 26, 1) y_train = np_utils.to_categorical(y_train) x_test = [] y_test = [] for filename, target_emotion in test_datalist: if filename in ['YAF_germ_angry.wav']: continue