added who data method

master
Malar Kannan 2017-10-17 19:04:07 +05:30
parent 8ae5104201
commit 51a6d6e804
1 changed files with 28 additions and 11 deletions

View File

@ -54,15 +54,32 @@ def sunflower_pairs_data():
te_y = np.array(x_pos_test.shape[0]*[[1,0]]) te_y = np.array(x_pos_test.shape[0]*[[1,0]])
tr_pairs = np.array([x_pos_train,x_neg_train]).reshape(x_pos_train.shape[0],2,max_samples,sample_size) tr_pairs = np.array([x_pos_train,x_neg_train]).reshape(x_pos_train.shape[0],2,max_samples,sample_size)
te_pairs = np.array([x_pos_test,x_neg_test]).reshape(x_pos_test.shape[0],2,max_samples,sample_size) te_pairs = np.array([x_pos_test,x_neg_test]).reshape(x_pos_test.shape[0],2,max_samples,sample_size)
# x_data.shape
# y_data.shape
# train_test_split(x_data,y_data,test_size=0.33)[].shape
# len(train_test_split(x_data,y_data,test_size=0.33))
# sunflowers.loc[:,'file'][0]
# generate_aiff_spectrogram('outputs/sunflowers-Alex-150-normal-589.aiff')
# sunflowers[sunflowers['variant'] == 'phoneme']
# sunflowers[sunflowers['variant'] == 'normal']
# for s in sunflowers.values:
# print(s)
#return train_test_split(x_data,y_data,test_size=0.33)
return tr_pairs,te_pairs,tr_y,te_y return tr_pairs,te_pairs,tr_y,te_y
def speech_pairs_data(audio_group):
audio_samples = pd.read_csv('./outputs/'+audio_group+'.csv',names=['word','voice','rate','variant','file'])
audio_samples.loc[:,'file'] = audio_samples.loc[:,'file'].apply(lambda x:'outputs/'+audio_group+'/'+x).apply(generate_aiff_spectrogram)
y_data = audio_samples['variant'].apply(lambda x:x=='normal').values
max_samples = audio_samples['file'].apply(lambda x:x.shape[0]).max()
sample_size = audio_samples['file'][0].shape[1]
audio_samples_pos = audio_samples[audio_samples['variant'] == 'normal'].reset_index(drop=True)
audio_samples_neg = audio_samples[audio_samples['variant'] == 'phoneme'].reset_index(drop=True)
def append_zeros(spgr):
return np.lib.pad(spgr,[(0, max_samples-spgr.shape[0]), (0,0)],'median')
def create_data(sf):
sample_count = sf['file'].shape[0]
pad_sun = sf['file'].apply(append_zeros).values
x_data = np.vstack(pad_sun).reshape((sample_count,max_samples,sample_size))
return x_data
x_data_pos = create_data(audio_samples_pos)
x_data_neg = create_data(audio_samples_neg)
x_pos_train, x_pos_test, x_neg_train, x_neg_test =train_test_split(x_data_pos,x_data_neg,test_size=0.33)
tr_y = np.array(x_pos_train.shape[0]*[[1,0]])
te_y = np.array(x_pos_test.shape[0]*[[1,0]])
tr_pairs = np.array([x_pos_train,x_neg_train]).reshape(x_pos_train.shape[0],2,max_samples,sample_size)
te_pairs = np.array([x_pos_test,x_neg_test]).reshape(x_pos_test.shape[0],2,max_samples,sample_size)
return tr_pairs,te_pairs,tr_y,te_y
if __name__ == '__main__':
print(speech_pairs_data())