Spaces:
Runtime error
Runtime error
Update src/music/pipeline/encoded2rep.py
Browse files
src/music/pipeline/encoded2rep.py
CHANGED
@@ -45,44 +45,45 @@ def encoded2rep(encoded_path, rep_path=None, return_rep=False, verbose=False, le
|
|
45 |
|
46 |
error_msg = 'Error in music transformer mapping.'
|
47 |
if verbose: print(' ' * level + 'Mapping to final music representations')
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
86 |
|
87 |
if __name__ == "__main__":
|
88 |
representation = encoded2rep("/home/cedric/Documents/pianocktail/data/music/encoded/single_videos_midi_processed_encoded/chris_dawson_all_of_me_.pickle")
|
|
|
45 |
|
46 |
error_msg = 'Error in music transformer mapping.'
|
47 |
if verbose: print(' ' * level + 'Mapping to final music representations')
|
48 |
+
# try:
|
49 |
+
error_msg += ' Error in encoded file loading?'
|
50 |
+
with open(encoded_path, 'rb') as f:
|
51 |
+
data = pickle.load(f)
|
52 |
+
performance = [str(w) for w in data['main'] if w != 1]
|
53 |
+
assert len(performance) % 5 == 0
|
54 |
+
if(len(performance) == 0):
|
55 |
+
error_msg += " Error: No midi messages in primer file"
|
56 |
+
assert False
|
57 |
+
error_msg += ' Nope, error in tokenization?'
|
58 |
+
perf = ' '.join(performance)
|
59 |
+
# tokenized = torch.IntTensor(TOKENIZER.encode(perf)).unsqueeze(dim=0)
|
60 |
+
error_msg += ' Nope. Maybe in performance encoding?'
|
61 |
+
# reps = []
|
62 |
+
# for i_chunk in range(min(tokenized.shape[1] // 510 - 1, 8)):
|
63 |
+
# chunk_tokenized = tokenized[:, i_chunk * 510: (i_chunk + 1) * 510 + 2]
|
64 |
+
# rep = MODEL(chunk_tokenized)
|
65 |
+
# reps.append(rep.detach().numpy())
|
66 |
+
# representation = np.mean(reps, axis=0)
|
67 |
+
p = [int(p) for p in perf.split(' ')]
|
68 |
+
# print('PERF:', np.sum(p), perf)
|
69 |
+
representation = MODEL.encode(perf)
|
70 |
+
# print('model weights sum: ', np.sum([param.detach().data.numpy().sum() for param in list(MODEL.parameters())]))
|
71 |
+
# print('reprep', representation)
|
72 |
+
error_msg += ' Nope. Saving performance?'
|
73 |
+
np.savetxt(rep_path, representation)
|
74 |
+
error_msg += ' Nope.'
|
75 |
+
if verbose: print(' ' * (level + 2) + 'Success.')
|
76 |
+
if return_rep:
|
77 |
+
return rep_path, representation, ''
|
78 |
+
else:
|
79 |
+
return rep_path, ''
|
80 |
+
|
81 |
+
#except:
|
82 |
+
# if verbose: print(' ' * (level + 2) + f'Failed with error: {error_msg}')
|
83 |
+
# if return_rep:
|
84 |
+
# return None, None, error_msg
|
85 |
+
#else:
|
86 |
+
# return None, error_msg
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
representation = encoded2rep("/home/cedric/Documents/pianocktail/data/music/encoded/single_videos_midi_processed_encoded/chris_dawson_all_of_me_.pickle")
|