69 lines
3.5 KiB
Python
69 lines
3.5 KiB
Python
|
|
import pandas as pd
|
||
|
|
import numpy as np
|
||
|
|
from spectro_gen import generate_aiff_spectrogram
|
||
|
|
from sklearn.model_selection import train_test_split
|
||
|
|
import tensorflow as tf
|
||
|
|
|
||
|
|
def sunflower_data():
|
||
|
|
audio_samples = pd.read_csv('./outputs/audio.csv',names=['word','voice','rate','variant','file'])
|
||
|
|
sunflowers = audio_samples.loc[audio_samples['word'] == 'sunflowers'].reset_index(drop=True)
|
||
|
|
sunflowers.loc[:,'file'] = sunflowers.loc[:,'file'].apply(lambda x:'outputs/'+x).apply(generate_aiff_spectrogram)
|
||
|
|
y_data = sunflowers['variant'].apply(lambda x:x=='normal').values
|
||
|
|
max_samples = sunflowers['file'].apply(lambda x:x.shape[0]).max()
|
||
|
|
sample_size = sunflowers['file'][0].shape[1]
|
||
|
|
sample_count = sunflowers['file'].shape[0]
|
||
|
|
sunflowers['file'][0].shape[0]
|
||
|
|
def append_zeros(spgr):
|
||
|
|
orig = spgr.shape[0]
|
||
|
|
return np.lib.pad(spgr,[(0, max_samples-orig), (0,0)],'median')
|
||
|
|
pad_sun = sunflowers['file'].apply(append_zeros).values
|
||
|
|
x_data = np.vstack(pad_sun).reshape((sample_count,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)
|
||
|
|
|
||
|
|
|
||
|
|
def sunflower_pairs_data():
|
||
|
|
audio_samples = pd.read_csv('./outputs/audio.csv',names=['word','voice','rate','variant','file'])
|
||
|
|
sunflowers = audio_samples.loc[audio_samples['word'] == 'sunflowers'].reset_index(drop=True)
|
||
|
|
sunflowers.loc[:,'file'] = sunflowers.loc[:,'file'].apply(lambda x:'outputs/'+x).apply(generate_aiff_spectrogram)
|
||
|
|
y_data = sunflowers['variant'].apply(lambda x:x=='normal').values
|
||
|
|
max_samples = sunflowers['file'].apply(lambda x:x.shape[0]).max()
|
||
|
|
sample_size = sunflowers['file'][0].shape[1]
|
||
|
|
sunflowers_pos = sunflowers[sunflowers['variant'] == 'normal'].reset_index(drop=True)
|
||
|
|
sunflowers_neg = sunflowers[sunflowers['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(sunflowers_pos)
|
||
|
|
x_data_neg = create_data(sunflowers_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)
|
||
|
|
# 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
|