From 53590937fd6bb3a83d47e53a0423c791b0a71717 Mon Sep 17 00:00:00 2001 From: GreenGarnets Date: Fri, 24 Jan 2020 17:23:29 +0900 Subject: [PATCH] dataset cache & add STFT --- .gitignore | 4 +++ __pycache__/dataset.cpython-36.pyc | Bin 4221 -> 4957 bytes dataset.py | 41 +++++++++++++++++++++++++-- net/__pycache__/model.cpython-36.pyc | Bin 1826 -> 1743 bytes net/model.py | 17 ++++------- train.py | 13 ++++----- 6 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee9a45a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/cache +/data +/data_test +/model diff --git a/__pycache__/dataset.cpython-36.pyc b/__pycache__/dataset.cpython-36.pyc index edefce004de28f859f2fc0ffca6e543be7d0552f..e82a8262cfb54ef4e2497429c2f993c4eb284ebf 100644 GIT binary patch delta 2176 zcmZt{OKclObY|9TuQ#^iq-p+Yt(K4yx+Vx?=%18eqA`e zoKEZCe|qZXFGmUagX~)h;1}TYe){lu@2z+<+sc|*N;u((=2&ao9FK6Vd8jpEPDD6u z9yTX05uW7wJ;L!&3ul&e~IrIeT_ML4#f;Mmk`0RgKBpycMj_ zlXNBE^yw5&-6N*P(;$!uKB3pO5pd*lA~GMbALw}SBRe{m21*#0mZ;k@q>jkIeh5Y% zCX_x+j{#wuFhUF}4h2E%rJJ)rflc%m7Za#(7(kd1w%fF-wwOdx3Q3C7mWC?u5HSV7 zOmsG-yD67;k+WhNdHYTc&Z*5l9EV4ei|~0UAxVS!WI(s5WDUiqi1`>ewc?ZzJ-4&E zi#bo^R&z~fU35IF(Ck<|Uvrvv+iKa!TP>HDN+n}Yp^^jfwp-}gppXZD^W}0ML{60o zrLu7b380Pm`Rm=qZsmrd@0~GZ3)|bUTssdw=FcoG=Fpxe zis;U%at_QrR_J#@Lv}=Uqfir_R;9h!a=YNdo`fq<+bTpB_Z%@|A#1x~48x8x6Y6^g z3>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Ws6s5s%3*t(n)5p;*eZ7U`GA`^Ppo~ diff --git a/dataset.py b/dataset.py index ab61879..f6baf31 100644 --- a/dataset.py +++ b/dataset.py @@ -14,7 +14,7 @@ import librosa import librosa.display -import tqdm +from tqdm import tqdm from scipy.fftpack import fft from scipy import signal @@ -81,13 +81,46 @@ def targetToTensor(self, target): def music_load(filename) : + ''' y, sr = librosa.load(filename, sr=44100) y_ = np.zeros(int(44100*0.04)-int(len(y)%int(44100*0.04))) y = np.hstack([y,y_]) y = np.reshape(y, (-1, int(sr/100)*4 )) + y = torch.from_numpy(y) + print(a.shape) + ''' + y = np.load(filename) + y = torch.from_numpy(y) + + return y + + def music_cache_make(filelist) : + #f = codecs.open("music_cache_data","w") + + for filename in tqdm(filelist): + y, sr = librosa.load("./data_test/songs/" + filename+"/nofx.ogg", sr=44100) + y_ = np.zeros(int(44100*0.04)-int(len(y)%int(44100*0.04))) + y = np.hstack([y,y_]) + + y = np.reshape(y, (-1, int(sr/100)*4 )) + #print(y.shape) + + a = [] + for i in range(0, y.shape[0]) : + y1 = np.abs(librosa.stft(y[i], n_fft = 1764, hop_length=2048, win_length = 441)) + y2 = np.abs(librosa.stft(y[i], n_fft = 1764, hop_length=2048, win_length = 882)) + y3 = np.abs(librosa.stft(y[i], n_fft = 1764, hop_length=2048, win_length = 1764)) + + a.append(np.array([y1,y2,y3]).tolist()) + #if i == 200 : print(np.array([y1,y2,y3])) + + a = np.array(a) + #print(a.shape) + np.save("./cache/"+filename,a) + return y def timeStamp(filename, term) : @@ -220,6 +253,8 @@ def timeStamp(filename, term) : return return_timestamp if __name__ == "__main__": - y, sr = librosa.load("./data/songs/rootsphere_lastnote/nofx.ogg", sr=44100) - KshDataset.timeStamp("./data/songs/rootsphere_lastnote/exh.ksh", y.shape[0]) + filenames = os.listdir("./data_test/songs/") + KshDataset.music_cache_make(filenames) + #y, sr = librosa.load("./data/songs/rootsphere_lastnote/nofx.ogg", sr=44100) + #KshDataset.timeStamp("./data/songs/rootsphere_lastnote/exh.ksh", y.shape[0]) #print(y.shape[0]//441) \ No newline at end of file diff --git a/net/__pycache__/model.cpython-36.pyc b/net/__pycache__/model.cpython-36.pyc index 8870c40aff645d22e081341bc11f3a5568158db2..6536f1042fc5ebb48c9318c2152a3304a1cde076 100644 GIT binary patch delta 739 zcma)3&ubGw6rMLT`=iZn8jDydjR~k|EY^b%{0}T11nJ#z-5G7-wy854Yb7?qo-363 z2SmZMc=lfq?{oE(zd-QRHwh#j3Uy)L%zW?rzW3hj=lZX7{eGG*KlpOz>9|J7Z}QI< zoUR|GwUajzRJ2bk0;FVpjw_HLDJ~|N?ZVAqc6tVDEkHCl zp%otyu{>wfIU6|)IrbZ@ji)NfPXgqHGOPgisPZ+I&}HG1%zcnGtNI_R^di;x++y{M zWap|@P}RWZqKe|+mn6X_j2}-JKJny(5BQR#!(8o^()+3qruR!8ioC}k(1#J&@BHX;=-sFn)m&s=50yfvZg73uMOvBN>_9p0 z-Svj&Fx|w>!CS`$!&0~KG7D`FM=u8YFw?S&7jp#zftcE_!ISYVpH79yi_Dl@6@?HB zaR>A@%}K9reb`N2?o%EX{Tdj&S<0e#PhDbR31 rInep8vqiX5zm2#HrFzrLmA-3#hRw#J|LLi1|AwulhcR4*geEIzg5jq= delta 690 zcmaJ-&ubGw6n<}JcDLE?Ce?;Uf|?qC;3Bj_K?D!I2%@M^y}J!N+cqIIWj6iE`UB?N zL!E!1c1Do_4TH6y1q4!XQVip#Pfea$M=^sEFszL$NP9rQogz|9$3tTurGtPf}Y zeYpvO5ZVxxO`p9hd5=|RtFzthIZ0=8=b>5S3BEF)`LmCrfJIXl_sX_d4lT%0<6A}< z=FF^!{b^gKPu0oSd=occsH>FsJe6h}jjgmNvgSdmu3Ma|nuTz$$H`0Gpvy4S2a2_h z+HENLh%VV21z 1 : - pred = model(input[i:i+tmp_batch-1],tmp_batch-1) + pred = model(input[i:i+tmp_batch-1]) loss = criterion(pred.squeeze(), target[i:i+tmp_batch-1].squeeze()) loss.backward() @@ -165,8 +165,7 @@ def main(): #model.to(torch.device("cpu")) for filename in tqdm(valnames): full_filename = os.path.join(valname, filename) - input = KshDataset.music_load(full_filename + '/nofx.ogg') - input = input.reshape(input.shape[0], 1, -1) + input = KshDataset.music_load("./cache/" + filename+'.npy') input = input.to(device, dtype=torch.float) target = KshDataset.timeStamp(full_filename + '/exh.ksh', input.shape[0])