Commit 00ac5936 authored by Richard Vogl's avatar Richard Vogl
Browse files

save cached

parent 110008e3
......@@ -9,6 +9,8 @@ BEST_MODEL_FILE_NAME = 'best_model.npz'
SETTINGS_FILE_NAME = 'settings.npy'
LOSSES_FILE = 'losses.npy'
LIBROSA_PATH = os.path.join(DATASET_PATH, 'librosa_disklavier')
CACHED_DS_NAME = 'cached.npy'
if not os.path.exists(OUTPUT_PATH):
......
import numpy as np
import os
from piano_transcription import LIBROSA_PATH, CACHED_DS_NAME
# TODO remove this and load and use real data!
FEAT_SIZE = 482
......@@ -7,6 +8,7 @@ OUT_SIZE = 88
FULL_SEQ_LEN = 1000
NUM_SAMPLES_TRAIN = 8
NUM_SAMPLES_VALID = 2
NUM_SAMPLES_TEST = 5
def generate_random_sample():
......@@ -16,11 +18,13 @@ def generate_random_sample():
return feat, targ
def load_data(split_nr):
def load_ramdom_data():
feat_train = []
targ_train = []
feat_valid = []
targ_valid = []
feat_test = []
targ_test = []
for sample_idx in range(NUM_SAMPLES_TRAIN):
feat, targ = generate_random_sample()
......@@ -32,4 +36,40 @@ def load_data(split_nr):
feat_valid.append(feat)
targ_valid.append(targ)
return feat_train, targ_train, feat_valid, targ_valid, FULL_SEQ_LEN, FEAT_SIZE, OUT_SIZE
for sample_idx in range(NUM_SAMPLES_TEST):
feat, targ = generate_random_sample()
feat_test.append(feat)
targ_test.append(targ)
return feat_train, targ_train, feat_valid, targ_valid, feat_test, targ_test, FULL_SEQ_LEN, FEAT_SIZE, OUT_SIZE
def load_data():
data_dict = np.load(os.path.join(LIBROSA_PATH, CACHED_DS_NAME))
train_name_list = data_dict['train_name_list']
train_feat_list = data_dict['train_feat_list']
train_targ_list = data_dict['train_targ_list']
test_name_list = data_dict['test_name_list']
test_feat_list = data_dict['test_feat_list']
test_targ_list = data_dict['test_targ_list']
train_size = len(train_feat_list)
valid_size = int(train_size * 0.15)
valid_idx = np.random.choice(range(train_size), valid_size)
valid_name_list = train_name_list[valid_idx]
valid_feat_list = train_feat_list[valid_idx]
valid_targ_list = train_targ_list[valid_idx]
train_name_list = np.delete(train_name_list, valid_idx)
train_feat_list = np.delete(train_feat_list, valid_idx)
train_targ_list = np.delete(train_targ_list, valid_idx)
return train_feat_list, train_targ_list, valid_feat_list, valid_targ_list, test_feat_list, test_targ_list,
if __name__ == '__main__':
load_data()
import os
import numpy as np
from piano_transcription import DATASET_PATH
from piano_transcription import LIBROSA_PATH, CACHED_DS_NAME
from piano_transcription.data.features import extract_features
from midi2txt.midi_to_txt import midi_to_txt
from piano_transcription.data.annotations import compute_target_array_from_times, posprocess_annotations
......@@ -49,11 +49,10 @@ def prepare_librosa(origin_path):
test_name_list, test_feat_list, test_targ_list = get_feats_and_targs(test_audio_file_list, test_path, test_path)
np.save(os.path.join(origin_path, 'cached'), {'train_name_list': train_name_list, 'train_feat_list': train_feat_list,
'train_targ_list': train_targ_list,
'test_name_list': test_name_list, 'test_feat_list': test_feat_list,
'test_targ_list': test_targ_list})
np.savez(os.path.join(origin_path, CACHED_DS_NAME),
train_names=train_name_list, train_feats=train_feat_list, train_targs=train_targ_list,
test_names=test_name_list, test_feats=test_feat_list, test_targs=test_targ_list)
if __name__ == '__main__':
prepare_librosa(os.path.join(DATASET_PATH, 'librosa_disklavier'))
\ No newline at end of file
prepare_librosa(LIBROSA_PATH)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment