-
Notifications
You must be signed in to change notification settings - Fork 18
/
settings.py
416 lines (367 loc) · 10.5 KB
/
settings.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
import math
import time
import os
import numpy as np
# This is where you should put your midi files
source_folder = 'data/original/'
# fast way to import data once you have preprocessed them and saved in a pickle file
pickle_load_path = 'pickles/'
#------------------------------------
# Generation parameters
#------------------------------------
# Generation parameters
temperature = 1.0
sample_method = 'choice'
cutoff_sample_threshold = 0.0
number_of_tries = 1
#if there is velocity information (for every played note) but no held notes:
#then you can figure out which notes are played or held
#a note is held if the velocity is below a threshold, which is the following parameter
#------------------------------------
# Import parameters
#------------------------------------
velocity_threshold_such_that_it_is_a_played_note = 0.5
override_sampled_pitches_based_on_velocity_info = True
do_not_sample_in_evaluation = True
# Folder names or file names will be classified by those labels
classes = ['style1', 'style2'] #list of strings like 'Bach', 'Mozart'. Name a folder in your source_folder like that and make sure there are no files with that name
#whether to include unknown classes as a third class
include_unknown = False
if include_unknown:
num_classes = len(classes) + 1
else:
num_classes = len(classes)
#wheter to exclude files with tags from classes
only_unknown = False
#Wheter to run the evaluations on the train set
test_train_set = False
t = str(int(round(time.time())))
#activate the fast route to not always have to preprocess midi files
load_from_pickle_instead_of_midi = False
save_imported_midi_as_pickle = True
if save_imported_midi_as_pickle:
pickle_store_folder = 'pickles/' + t + "/" #folder where pickles are stored (!= where loaded)
if not os.path.exists(pickle_store_folder):
os.makedirs(pickle_store_folder)
save_anything = True
split_equally_to_train_and_test = True
test_fraction = 0.1
save_preprocessed_midi = False
smaller_training_set_factor = 1.0 #multiply training set size by that factor (if higher than 1.0, will have unbalanced dataset if split_equally_to_train_and_test)
high_crop = 84 #where to cut off high notes. 84 = C6
low_crop = 24#where to cut off low notes. 24=C1
num_notes = 128 #constant for MIDI
new_num_notes = high_crop - low_crop #the actual number of pitches to use
SMALLEST_NOTE = 16 #set this to 16, if you want to include 16th notes as smallest notes. has to be a multiple of 4
MAXIMAL_NUMBER_OF_VOICES_PER_TRACK = 1 #will get overriden if there are less tracks than num_voices for a file
MAX_VELOCITY = 127.
max_songs = 100000 #if you want to reduce the maximum number of midi files to import, set this lower
equal_mini_songs = False #set this to true, if you want to remove imported songs if one class has higher
#we set this to True for MIDI-VAE, but think it's best for you to start with False
attach_instruments = False
include_only_monophonic_instruments = False
#the number of monophonic instrument tracks you want your final model to have
max_voices = 4
instrument_attach_method = '1hot-category' #'khot-instrument'
instrument_dim = 0
if instrument_attach_method == '1hot-category':
instrument_dim = 16
elif instrument_attach_method == 'khot-category':
instrument_dim = 4
elif instrument_attach_method == '1hot-instrument':
instrument_dim = 128
elif instrument_attach_method == 'khot-instrument':
instrument_dim = 7
#wheter to try song-completion, removing all but one track from the input and try to predict max_voice target pitches
song_completion = False
#------------------------------------
# VAE parameters (for vae_training and vae_evaluation)
#------------------------------------
input_length = 16
output_length = 16
lstm_size = 256
latent_dim = 256
batch_size = 256
learning_rate = 0.0002#1e-05 #1e-06
beta = 0.1
epsilon_std = 0.01
save_step = 10
shuffle_train_set = True
bidirectional = False
num_layers_encoder = 2
num_layers_decoder = 2
use_embedding = False
embedding_dim = 0
decode = True
optimizer = 'Adam' #Adam, #RMSprop
vae_loss = 'categorical_crossentropy'
activity_regularizer = None
reset_states = True
include_composer_feature = False
if include_composer_feature:
composer_length = num_classes
else:
composer_length = 0
include_composer_decoder = True
composer_weight = 0.1
if include_composer_decoder:
num_composers = num_classes
else:
num_composers = 0
split_lstm_vector = True
output_length *= max_voices
if not song_completion:
input_length *= max_voices
else:
max_voices = 1
history = True
include_silent_note = True
if use_embedding:
assert(include_silent_note)
if include_silent_note:
silent_dim = 1
else:
silent_dim = 0
activation = 'softmax'
cell_type = 'GRU' #can be 'GRU', 'LSTM', SimpleRNN
silent_weight = 1.0 #set to 1.0 if disabled
teacher_force = False
epsilon_factor = 0.0 # set to nonzero if you really know what you are doing
#epsilon_factor = np.log(epsilon_std * epsilon_std)
#use epsilon_factor to scale the log_var by adding epsilon_factor to it
#this makes sure that sigma of the prior is at the same scale as the sigma that will be used to calculate z
extra_layer = True
lstm_activation = 'tanh'
lstm_state_activation = 'tanh'
decoder_additional_input = False
decoder_additional_input_dim = 0
decoder_input_composer = False
if decoder_input_composer:
decoder_additional_input = True
decoder_additional_input_dim += num_classes
signature_vector_length = 15
append_signature_vector_to_latent = False
if append_signature_vector_to_latent:
decoder_additional_input = True
decoder_additional_input_dim += signature_vector_length
# use instrument roll encoder and decoder
meta_instrument= True
meta_instrument_dim = instrument_dim
meta_instrument_length = max_voices
meta_instrument_activation = 'softmax'
meta_instrument_weight = 0.1
if not attach_instruments:
instrument_dim = 0
signature_decoder = False
signature_dim = signature_vector_length
signature_activation = 'tanh'
signature_weight = 1.0
# use additional decoder at pitch output or instrument output to enforce mutual information with z
composer_decoder_at_notes_output=False
composer_decoder_at_notes_weight=1.0
composer_decoder_at_notes_activation='softmax'
composer_decoder_at_instrument_output=False
composer_decoder_at_instrument_weight=1.0
composer_decoder_at_instrument_activation='softmax'
if composer_decoder_at_notes_output or composer_decoder_at_instrument_output or include_composer_decoder:
num_composers = num_classes
else:
num_composers = 0
input_dim = new_num_notes + composer_length + silent_dim + instrument_dim
output_dim = new_num_notes+silent_dim + instrument_dim
# use velocity roll
meta_velocity=True
meta_velocity_length=output_length
meta_velocity_activation='sigmoid'
meta_velocity_weight=1.0
#use held notes roll
meta_held_notes=False
meta_held_notes_length=output_length
meta_held_notes_activation='softmax'
meta_held_notes_weight=0.1
combine_velocity_and_held_notes=False
if combine_velocity_and_held_notes:
meta_held_notes = False
# use next pitch roll
meta_next_notes=False
meta_next_notes_output_length=output_length
meta_next_notes_weight=0.1
meta_next_notes_teacher_force=False #Not implemented in vae_training or vae_evaluation
activation_before_splitting='tanh'
epochs = 2000
test_step = 1
verbose = True
show_plot = False
save_plot = True
load_previous_checkpoint = False
previous_epoch = -1
previous_checkpoint_path = 'models/autoencode/vae/1519767462-_inlen_256_outlen_256_beta_0.01_lr_0.0002_lstmsize_256_latent_256_trainsize_859_testsize_99_shifted_True_epsstd_0.001/'
prior_mean=0.0
prior_std=1.0
#------------------------------------
# Additional stuff
#------------------------------------
instrument_names = [
#piano
'Acoustic Grand Piano',
'Bright Acoustic Piano',
'Electric Grand Piano',
'Honky-tonk Piano',
'Electric Piano 1',
'Electric Piano 2',
'Harpsichord',
'Clavinet',
#chromatic percussion
'Celesta',
'Glockenspiel',
'Music Box',
'Vibraphone',
'Marimba',
'Xylophone',
'Tubular Bells',
'Dulcimer',
#Organs
'Drawbar Organ',
'Percussive Organ',
'Rock Organ',
'Church Organ',
'Reed Organ',
'Accordion',
'Harmonica',
'Tango Accordion',
#Guitar
'Acoustic Guitar (nylon)',
'Acoustic Guitar (steel)',
'Electric Guitar (jazz)',
'Electric Guitar (clean)',
'Electric Guitar (muted)',
'Overdriven Guitar',
'Distortion Guitar',
'Guitar Harmonics',
#Bass[edit]
'Acoustic Bass',
'Electric Bass (finger)',
'Electric Bass (pick)',
'Fretless Bass',
'Slap Bass 1',
'Slap Bass 2',
'Synth Bass 1',
'Synth Bass 2',
#Strings[edit]
'Violin',
'Viola',
'Cello',
'Contrabass',
'Tremolo Strings',
'Pizzicato Strings',
'Orchestral Harp',
'Timpani',
#Ensemble[edit]
'String Ensemble 1',
'String Ensemble 2',
'Synth Strings 1',
'Synth Strings 2',
'Choir Aahs',
'Voice Oohs',
'Synth Choir',
'Orchestra Hit',
#Brass[edit]
'Trumpet',
'Trombone',
'Tuba',
'Muted Trumpet',
'French Horn',
'Brass Section',
'Synth Brass 1',
'Synth Brass 2',
#Reed[edit]
'Soprano Sax',
'Alto Sax',
'Tenor Sax',
'Baritone Sax',
'Oboe',
'English Horn',
'Bassoon',
'Clarinet',
#Pipe[edit]
'Piccolo',
'Flute',
'Recorder',
'Pan Flute',
'Blown bottle',
'Shakuhachi',
'Whistle',
'Ocarina',
#Synth Lead[edit]
'Lead 1 (square)',
'Lead 2 (sawtooth)',
'Lead 3 (calliope)',
'Lead 4 (chiff)',
'Lead 5 (charang)',
'Lead 6 (voice)',
'Lead 7 (fifths)',
'Lead 8 (bass + lead)',
#Synth Pad[edit]
'Pad 1 (new age)',
'Pad 2 (warm)',
'Pad 3 (polysynth)',
'Pad 4 (choir)',
'Pad 5 (bowed)',
'Pad 6 (metallic)',
'Pad 7 (halo)',
'Pad 8 (sweep)',
#Synth Effects[edit]
'FX 1 (rain)',
'FX 2 (soundtrack)',
'FX 3 (crystal)',
'FX 4 (atmosphere)',
'FX 5 (brightness)',
'FX 6 (goblins)',
'FX 7 (echoes)',
'FX 8 (sci-fi)',
#Ethnic[edit]
'Sitar',
'Banjo',
'Shamisen',
'Koto',
'Kalimba',
'Bagpipe',
'Fiddle',
'Shanai',
#Percussive[edit]
'Tinkle Bell',
'Agogo',
'Steel Drums',
'Woodblock',
'Taiko Drum',
'Melodic Tom',
'Synth Drum',
'Reverse Cymbal',
#Sound effects[edit]
'Guitar Fret Noise',
'Breath Noise',
'Seashore',
'Bird Tweet',
'Telephone Ring',
'Helicopter',
'Applause',
'Gunshot'
]
instrument_category_names = [
'piano',
'chromatic percussion',
'organs',
'guitar',
'bass',
'strings',
'ensemble',
'brass',
'reed',
'pipe',
'synth lead',
'synth pad',
'synth effects',
'ethnic',
'percussive',
'sound effects',
]