changed back to [0,1] normal

This commit is contained in:
k
2025-10-15 02:19:33 -04:00
parent 1a66f31048
commit 78ece6996f
2 changed files with 13 additions and 13 deletions

22
data.py
View File

@@ -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
"""