-
Notifications
You must be signed in to change notification settings - Fork 2
/
justkeydding_ensemble.py
51 lines (48 loc) · 1.42 KB
/
justkeydding_ensemble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
import dataset
import sys
import joblib
import os
from optimizer import ensembler
tonic_names = [
'C', 'C#', 'D', 'Eb',
'E', 'F', 'F#', 'G',
'Ab', 'A', 'Bb', 'B',
]
def key_name(key_number):
mode = 'major' if key_number < 12 else 'minor'
tonic = tonic_names[key_number % 12]
return '{}\t{}'.format(tonic, mode)
if __name__ == '__main__':
if len(sys.argv) != 2:
print('You need to provide an input file')
exit()
filename = sys.argv[1]
model = 'pre-trained.joblib'
if not os.path.exists(model):
print('You need to train a model first')
exit()
key_profiles = [
'aarden_essen',
'temperley',
'krumhansl_kessler',
'bellman_budge',
'albrecht_shanahan1',
'albrecht_shanahan2',
'sapp',
'simple_natural_minor',
'simple_harmonic_minor',
'simple_melodic_minor',]
key_transitions = [
'ktg_exponential5',
'ktg_exponential10',
'ktg_exponential15',]
mixed_profiles = False
ens = ensembler.Ensembler(key_profiles, key_transitions)
features = ens.evaluate(filename, mixed_profiles)
features = [f for l in features for f in l]
feature_array = np.array(features).reshape(1, -1)
feature_array = dataset.feature_scaling(feature_array)
clf = joblib.load(model)
prediction = clf.predict(feature_array)[0]
print(key_name(prediction))