diff --git a/data.py b/data.py index b2cee4a..b77f312 100644 --- a/data.py +++ b/data.py @@ -6,13 +6,15 @@ import mlflow SAMPLE_RATE = 22050 -@mlflow.trace +#@mlflow.trace def process_file(file_path): """ Load 10 second chunks single song. """ y, sr = librosa.load(file_path, mono=True, sr=SAMPLE_RATE) - size = int(SAMPLE_RATE * 5) + if(not sr == SAMPLE_RATE): + return [] + size = int(SAMPLE_RATE * 10) sample_len = len(y) file_chunks = [] @@ -20,18 +22,19 @@ def process_file(file_path): end = start_pos + size if end <= sample_len: chunk = y[start_pos:end] - chunk = librosa.feature.melspectrogram(y=chunk,sr=SAMPLE_RATE) - chunk = ((librosa.amplitude_to_db(chunk,ref=np.max)+40)/40) + #chunk = librosa.feature.melspectrogram(y=chunk,sr=SAMPLE_RATE) + #chunk = ((librosa.amplitude_to_db(chunk,ref=np.max)+40)/40) file_chunks.append(chunk) return file_chunks -@mlflow.trace +#@mlflow.trace def load(): """ Load 10 second chunks of songs. """ audio = [] files = list(Path("./data/").glob("*.mp3")) + #files = files[:12] with Pool(cpu_count()) as pool: chunk_list = pool.map(process_file, files) for l in chunk_list: @@ -52,15 +55,12 @@ def audio_split(audio): x = librosa.feature.melspectrogram(y=x, sr=SAMPLE_RATE) y = librosa.feature.melspectrogram(y=y, sr=SAMPLE_RATE) - ma,mi = x.max(), x.min() - x = (x - mi) / (ma - mi) - - ma,mi = y.max(), y.min() - y = (y - mi) / (ma - mi) + x = ((librosa.amplitude_to_db(x,ref=np.max)+80)/80) + y = ((librosa.amplitude_to_db(y,ref=np.max)+80)/80) return x,y -def detaset(chunks): +def dataset(chunks): """ convert 10 second chunks to dataset """ diff --git a/show.py b/show.py index ffab934..b1b39c5 100644 --- a/show.py +++ b/show.py @@ -6,7 +6,7 @@ import mlflow SAMPLE_RATE = 22050 def logSpec(spec,e): - #spec = ((spec*40)-40) + spec = ((spec*80)-80) #spec = librosa.db_to_amplitude(spec) plt.figure(figsize=(10, 4)) librosa.display.specshow(spec, sr=SAMPLE_RATE, @@ -15,7 +15,7 @@ def logSpec(spec,e): plt.colorbar(format='%+2.0f dB') plt.title('Mel spectrogram') mlflow.log_figure(plt.gcf(), f"output_{e}.png") - #plt.close() + plt.close() def playSpec(spec): S = librosa.feature.inverse.mel_to_stft(spec, sr=SAMPLE_RATE)