-
Notifications
You must be signed in to change notification settings - Fork 18
/
vae_definition.py
1240 lines (1010 loc) · 59.4 KB
/
vae_definition.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from keras import objectives, backend as K
from keras.layers import Bidirectional, Dense, Embedding, Input, Lambda, LSTM, RepeatVector, TimeDistributed, Add, GRU, SimpleRNN
from keras.models import Model
from keras.layers import Layer
import keras
from recurrentshop import *
from recurrentshop.cells import LSTMCell, GRUCell, SimpleRNNCell
from keras.layers.merge import Concatenate
from keras.utils import to_categorical
import data_class
from settings import *
class KLDivergenceLayer(Layer):
""" Identity transform layer that adds KL divergence
to the final model loss.
"""
def __init__(self, beta=1.0, prior_mean=0.0, prior_std=1.0, *args, **kwargs):
self.is_placeholder = True
self.beta = beta
self.prior_mean = prior_mean
self.prior_std = prior_std
super(KLDivergenceLayer, self).__init__(*args, **kwargs)
def call(self, inputs):
mu, log_var = inputs
prior_log_var = K.log(self.prior_std) * 2
prior_var = K.square(self.prior_std)
#kl_batch = self.beta *( - .5 * K.sum(1 + log_var - K.square(mu) - K.exp(log_var), axis=1))
kl_batch = self.beta * ( - 0.5 * K.sum(1 + log_var - prior_log_var - ((K.square(mu - self.prior_mean) + K.exp(log_var)) / prior_var), axis=1))
self.add_loss(K.mean(kl_batch), inputs=inputs)
return inputs
class VAE(object):
def create(self,
input_dim=64,
output_dim=64,
use_embedding=False,
embedding_dim=0,
input_length=16,
output_length=16,
latent_rep_size=256,
vae_loss = 'categorical_crossentropy',
optimizer='Adam',
activation='sigmoid',
lstm_activation='tanh',
lstm_state_activation='tanh',
epsilon_std=1.0,
epsilon_factor=0.0,
include_composer_decoder=False,
num_composers=0,
composer_weight=1.0,
lstm_size=256,
cell_type='LSTM',
num_layers_encoder=1,
num_layers_decoder=1,
bidirectional=False,
decode=True,
teacher_force=False,
learning_rate=0.001,
split_lstm_vector=True,
history=True,
beta=0.01,
prior_mean=0.0,
prior_std=1.0,
decoder_additional_input=False,
decoder_additional_input_dim=0,
extra_layer=False,
meta_instrument=False,
meta_instrument_dim=0,
meta_instrument_length=0,
meta_instrument_activation='sigmoid',
meta_instrument_weight=1.0,
signature_decoder=False,
signature_dim=0,
signature_activation='sigmoid',
signature_weight=1.0,
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',
meta_velocity=False,
meta_velocity_length=0,
meta_velocity_activation='sigmoid',
meta_velocity_weight=1.0,
meta_held_notes=False,
meta_held_notes_length=0,
meta_held_notes_activation='softmax',
meta_held_notes_weight=1.0,
meta_next_notes=False,
meta_next_notes_output_length=16,
meta_next_notes_weight=1.0,
meta_next_notes_teacher_force=False,
activation_before_splitting='tanh'
):
self.encoder = None
self.decoder = None
self.composer_decoder = None
self.autoencoder = None
self.signature_decoder = None
self.input_dim=input_dim
self.output_dim = output_dim
self.decode = decode
self.input_length = input_length
self.output_length = output_length
self.latent_rep_size = latent_rep_size
self.vae_loss = vae_loss
self.activation = activation
self.lstm_activation = lstm_activation
self.lstm_state_activation = lstm_state_activation
self.include_composer_decoder = include_composer_decoder
self.num_composers = num_composers
self.composer_weight = composer_weight
self.lstm_size = lstm_size
self.cell_type = cell_type
self.num_layers_encoder = num_layers_encoder
self.num_layers_decoder = num_layers_decoder
self.bidirectional = bidirectional
self.teacher_force = teacher_force
self.use_embedding = use_embedding
self.embedding_dim = embedding_dim
self.learning_rate = learning_rate
self.split_lstm_vector = split_lstm_vector
self.history = history
self.beta = beta
self.prior_mean=prior_mean
self.prior_std=prior_std
self.decoder_additional_input = decoder_additional_input
self.decoder_additional_input_dim = decoder_additional_input_dim
self.epsilon_std = epsilon_std
self.epsilon_factor = epsilon_factor
self.extra_layer = extra_layer
self.meta_instrument= meta_instrument
self.meta_instrument_dim= meta_instrument_dim
self.meta_instrument_length = meta_instrument_length
self.meta_instrument_activation = meta_instrument_activation
self.meta_instrument_weight = meta_instrument_weight
self.meta_velocity=meta_velocity
self.meta_velocity_length=meta_velocity_length
self.meta_velocity_activation=meta_velocity_activation
self.meta_velocity_weight=meta_velocity_weight
self.meta_held_notes=meta_held_notes
self.meta_held_notes_length=meta_held_notes_length
self.meta_held_notes_activation=meta_held_notes_activation
self.meta_held_notes_weight=meta_held_notes_weight
self.meta_next_notes=meta_next_notes
self.meta_next_notes_output_length=meta_next_notes_output_length
self.meta_next_notes_weight=meta_next_notes_weight
self.meta_next_notes_teacher_force=meta_next_notes_teacher_force
self.signature_decoder = signature_decoder
self.signature_dim = signature_dim
self.signature_activation = signature_activation
self.signature_weight = signature_weight
self.composer_decoder_at_notes_output = composer_decoder_at_notes_output
self.composer_decoder_at_notes_weight = composer_decoder_at_notes_weight
self.composer_decoder_at_notes_activation = composer_decoder_at_notes_activation
self.composer_decoder_at_instrument_output = composer_decoder_at_instrument_output
self.composer_decoder_at_instrument_weight = composer_decoder_at_instrument_weight
self.composer_decoder_at_instrument_activation = composer_decoder_at_instrument_activation
self.activation_before_splitting = activation_before_splitting
if optimizer == 'RMSprop': self.optimizer = keras.optimizers.RMSprop(lr=learning_rate)
if optimizer == 'Adam': self.optimizer = keras.optimizers.Adam(lr=learning_rate)
assert(self.num_layers_encoder > 0)
assert(self.num_layers_decoder > 0)
assert(self.input_length > 0)
assert(self.output_length > 0)
assert(self.lstm_size > 0)
assert(self.latent_rep_size > 0)
assert(self.beta > 0)
if self.use_embedding:
assert(embedding_dim > 0)
if self.meta_instrument:
assert(meta_instrument_dim > 0)
assert(meta_instrument_weight > 0)
if self.signature_decoder:
assert(self.signature_dim > 0)
assert(self.signature_weight > 0)
if self.composer_decoder_at_notes_output:
assert(composer_decoder_at_notes_weight > 0)
if self.composer_decoder_at_instrument_output:
assert(meta_instrument)
assert(composer_decoder_at_instrument_weight > 0)
if self.meta_velocity:
assert(meta_velocity_weight > 0)
assert(meta_velocity_length > 0)
if self.meta_held_notes:
assert(meta_held_notes_weight > 0)
assert(meta_held_notes_length > 0)
if self.meta_next_notes:
assert(meta_next_notes_weight > 0)
assert(meta_next_notes_output_length > 0)
if self.use_embedding:
input_x = Input(shape=(self.input_length,), name='embedding_input')
x = Embedding(self.input_dim, self.embedding_dim)(input_x)
else:
input_x = Input(shape=(self.input_length,self.input_dim), name='notes_input')
x = input_x
encoder_input_list = [input_x]
if self.meta_instrument:
if self.meta_instrument_length > 0:
meta_instrument_input = Input(shape=(self.meta_instrument_length, self.meta_instrument_dim), name='meta_instrument_input')
else:
meta_instrument_input = Input(shape=(self.meta_instrument_dim,), name='meta_instrument_input')
encoder_input_list.append(meta_instrument_input)
else:
meta_instrument_input = None
if self.meta_velocity:
meta_velocity_input = Input(shape=(self.meta_velocity_length,1), name='meta_velocity_input')
encoder_input_list.append(meta_velocity_input)
else:
meta_velocity_input = None
if self.meta_held_notes:
meta_held_notes_input = Input(shape=(self.meta_held_notes_length,2), name='meta_held_notes_input')
encoder_input_list.append(meta_held_notes_input)
else:
meta_held_notes_input = None
encoded = self._build_encoder(x, meta_instrument_input, meta_velocity_input, meta_held_notes_input)
self.encoder = Model(inputs=encoder_input_list, outputs=encoded)
encoded_input = Input(shape=(self.latent_rep_size,), name='encoded_input')
if self.use_embedding:
input_decoder_x = Input(shape=(self.output_dim,), name='embedding_input_decoder_start')
#decoder_x = Embedding(self.output_dim, self.output_dim, input_length=1)(input_decoder_x)
decoder_x = input_decoder_x
else:
input_decoder_x = Input(shape=(self.output_dim,), name='input_decoder_start')
decoder_x = input_decoder_x
autoencoder_decoder_input_list = [input_decoder_x, encoded]
decoder_input_list = [input_decoder_x, encoded_input]
autoencoder_input_list = [input_x, input_decoder_x]
autoencoder_output_list = []
if self.teacher_force:
ground_truth_input = Input(shape=(self.output_length, self.output_dim), name='ground_truth_input')
decoder_input_list.append(ground_truth_input)
autoencoder_decoder_input_list.append(ground_truth_input)
autoencoder_input_list.append(ground_truth_input)
else:
ground_truth_input = None
if self.history:
history_input = Input(shape=(self.latent_rep_size,), name='history_input')
decoder_input_list.append(history_input)
autoencoder_decoder_input_list.append(history_input)
autoencoder_input_list.append(history_input)
else:
history_input = None
if decoder_additional_input:
decoder_additional_input_layer = Input(shape=(decoder_additional_input_dim,), name='decoder_additional_input')
decoder_input_list.append(decoder_additional_input_layer )
autoencoder_decoder_input_list.append(decoder_additional_input_layer )
autoencoder_input_list.append(decoder_additional_input_layer )
else:
decoder_additional_input_layer = False
if self.meta_instrument:
input_decoder_meta_instrument_start = Input(shape=(self.meta_instrument_dim,), name='input_decoder_meta_instrument_start')
decoder_input_list.append(input_decoder_meta_instrument_start)
autoencoder_decoder_input_list.append(input_decoder_meta_instrument_start)
autoencoder_input_list.append(input_decoder_meta_instrument_start)
autoencoder_input_list.append(meta_instrument_input)
else:
input_decoder_meta_instrument_start = None
if self.meta_velocity:
input_decoder_meta_velocity_start = Input(shape=(1,), name='input_decoder_meta_velocity_start')
decoder_input_list.append(input_decoder_meta_velocity_start)
autoencoder_decoder_input_list.append(input_decoder_meta_velocity_start)
autoencoder_input_list.append(input_decoder_meta_velocity_start)
autoencoder_input_list.append(meta_velocity_input)
else:
input_decoder_meta_velocity_start = None
if self.meta_held_notes:
input_decoder_meta_held_notes_start = Input(shape=(2,), name='input_decoder_meta_held_notes_start')
decoder_input_list.append(input_decoder_meta_held_notes_start)
autoencoder_decoder_input_list.append(input_decoder_meta_held_notes_start)
autoencoder_input_list.append(input_decoder_meta_held_notes_start)
autoencoder_input_list.append(meta_held_notes_input)
else:
input_decoder_meta_held_notes_start = None
if self.meta_next_notes:
input_decoder_meta_next_notes_start = Input(shape=(self.output_dim,), name='input_decoder_meta_next_notes_start')
decoder_input_list.append(input_decoder_meta_next_notes_start)
autoencoder_input_list.append(input_decoder_meta_next_notes_start)
autoencoder_decoder_input_list.append(input_decoder_meta_next_notes_start)
if self.meta_next_notes_teacher_force:
meta_next_notes_ground_truth_input = Input(shape=(self.meta_next_notes_output_length, self.output_dim), name='meta_next_notes_ground_truth_input')
decoder_input_list.append(meta_next_notes_ground_truth_input)
autoencoder_decoder_input_list.append(meta_next_notes_ground_truth_input)
autoencoder_input_list.append(meta_next_notes_ground_truth_input)
else:
meta_next_notes_ground_truth_input = None
else:
input_decoder_meta_next_notes_start = None
meta_next_notes_ground_truth_input = None
decoded, meta_instrument_output, meta_velocity_output, meta_held_notes_output, meta_next_notes_output = self._build_decoder(decoder_x, encoded_input, ground_truth_input, history_input, decoder_additional_input_layer, input_decoder_meta_instrument_start, input_decoder_meta_velocity_start, input_decoder_meta_held_notes_start, input_decoder_meta_next_notes_start, meta_next_notes_ground_truth_input)
loss_list = []
loss_weights_list = []
sample_weight_modes = []
loss_weights_list.append(1.0)
sample_weight_modes.append('temporal')
loss_list.append(self.vae_loss)
metrics_list = ['accuracy']
if self.meta_instrument or self.meta_velocity or self.meta_held_notes or self.meta_next_notes:
decoder_output = [decoded]
if self.meta_instrument:
decoder_output.append(meta_instrument_output)
if self.meta_velocity:
decoder_output.append(meta_velocity_output)
if self.meta_held_notes:
decoder_output.append(meta_held_notes_output)
if self.meta_next_notes:
decoder_output.append(meta_next_notes_output)
else:
decoder_output = decoded
self.decoder = Model(inputs=decoder_input_list, outputs=decoder_output, name='decoder')
decoder_final_output = self.decoder(autoencoder_decoder_input_list)
if isinstance(decoder_final_output, list):
autoencoder_output_list.extend(decoder_final_output)
else:
autoencoder_output_list.append(decoder_final_output)
if self.meta_instrument:
#dont append meta_instrument since it is already appended previously to the autoencoder output
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.meta_instrument_weight)
sample_weight_modes.append('None')
if self.meta_velocity:
#dont append meta_velocity since it is already appended previously to the autoencoder output
loss_list.append('mse')
loss_weights_list.append(self.meta_velocity_weight)
sample_weight_modes.append('None')
if self.meta_held_notes:
#dont append meta_held_notes since it is already appended previously to the autoencoder output
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.meta_held_notes_weight)
sample_weight_modes.append('None')
if self.meta_next_notes:
#dont append meta_next_notes since it is already appended previously to the autoencoder output
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.meta_next_notes_weight)
sample_weight_modes.append('None')
if self.include_composer_decoder:
predicted_composer = self._build_composer_decoder(encoded_input)
self.composer_decoder = Model(encoded_input, predicted_composer, name='composer_decoder')
autoencoder_output_list.append(self.composer_decoder(encoded))
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.composer_weight)
sample_weight_modes.append('None')
if self.signature_decoder:
predicted_signature = self._build_signature_decoder(encoded_input)
self.signature_decoder = Model(encoded_input, predicted_signature, name='signature_decoder')
autoencoder_output_list.append(self.signature_decoder(encoded))
loss_list.append('mse')
loss_weights_list.append(self.signature_weight)
sample_weight_modes.append('None')
if self.composer_decoder_at_notes_output:
notes_composer_decoder_input = Input(shape=(self.output_length,self.output_dim), name='notes_composer_decoder_input')
predicted_composer_2 = self._build_composer_decoder_at_notes_output(notes_composer_decoder_input)
self.composer_decoder_2 = Model(notes_composer_decoder_input, predicted_composer_2, name='composer_decoder_at_notes')
if not meta_instrument and not meta_velocity and not meta_held_notes and not meta_next_notes:
autoencoder_output_list.append(self.composer_decoder_2(decoder_final_output))
else:
autoencoder_output_list.append(self.composer_decoder_2(decoder_final_output[0]))
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.composer_decoder_at_notes_weight)
sample_weight_modes.append('None')
if self.composer_decoder_at_instrument_output:
if self.meta_instrument_length > 0:
meta_instrument_composer_decoder_input = Input(shape=(self.meta_instrument_length, self.meta_instrument_dim), name='meta_instrument_composer_decoder_input')
else:
meta_instrument_composer_decoder_input = Input(shape=(self.meta_instrument_dim,), name='meta_instrument_composer_decoder_input')
predicted_composer_3 = self._build_composer_decoder_at_instrument_output(meta_instrument_composer_decoder_input)
self.composer_decoder_3 = Model(meta_instrument_composer_decoder_input, predicted_composer_3, name='composer_decoder_at_instruments')
autoencoder_output_list.append(self.composer_decoder_3(decoder_final_output[1]))
loss_list.append('categorical_crossentropy')
loss_weights_list.append(self.composer_decoder_at_instrument_weight)
sample_weight_modes.append('None')
self.autoencoder = Model(inputs=autoencoder_input_list, outputs=autoencoder_output_list, name='autoencoder')
self.autoencoder.compile(optimizer=self.optimizer,
loss=loss_list,
loss_weights=loss_weights_list,
sample_weight_mode=sample_weight_modes,
metrics=metrics_list)
def _build_encoder(self, x, meta_instrument_input=None, meta_velocity_input=None, meta_held_notes_input=None):
h = x
if self.bidirectional:
for layer_no in range(1,self.num_layers_encoder-1):
if self.cell_type == 'SimpleRNN': h = Bidirectional(SimpleRNN(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='rnn_' + str(layer_no)), merge_mode='concat')(h)
if self.cell_type == 'LSTM': h = Bidirectional(LSTM(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='lstm_' + str(layer_no)), merge_mode='concat')(h)
if self.cell_type == 'GRU': h = Bidirectional(GRU(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='gru_' + str(layer_no)), merge_mode='concat')(h)
if self.cell_type == 'SimpleRNN': h = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_' + str(self.num_layers_encoder))(h)
if self.cell_type == 'LSTM': h = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_' + str(self.num_layers_encoder))(h)
if self.cell_type == 'GRU': h = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_' + str(self.num_layers_encoder))(h)
else:
for layer_no in range(1, self.num_layers_encoder):
if self.cell_type == 'SimpleRNN': h = SimpleRNN(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='rnn_' + str(layer_no))(h)
if self.cell_type == 'LSTM': h = LSTM(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='lstm_' + str(layer_no))(h)
if self.cell_type == 'GRU': h = GRU(self.lstm_size, return_sequences=True, activation=self.lstm_activation, name='gru_' + str(layer_no))(h)
if self.cell_type == 'SimpleRNN': h = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_' +str(self.num_layers_encoder))(h)
if self.cell_type == 'LSTM': h = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_' +str(self.num_layers_encoder))(h)
if self.cell_type == 'GRU': h = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_' +str(self.num_layers_encoder))(h)
#h = Dense(self.lstm_size, activation='relu', name='dense_1')(h)
if self.meta_instrument:
if self.cell_type == 'SimpleRNN': m = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_meta_instrument')(meta_instrument_input)
if self.cell_type == 'LSTM': m = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_meta_instrument')(meta_instrument_input)
if self.cell_type == 'GRU': m = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_meta_instrument')(meta_instrument_input)
h = Concatenate(name='concatenated_instrument_and_notes_layer')([h, m])
if self.meta_velocity:
if self.cell_type == 'SimpleRNN': m = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_meta_velocity')(meta_velocity_input)
if self.cell_type == 'LSTM': m = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_meta_velocity')(meta_velocity_input)
if self.cell_type == 'GRU': m = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_meta_velocity')(meta_velocity_input)
h = Concatenate(name='concatenated_velocity_and_rest_layer')([h, m])
if self.meta_held_notes:
if self.cell_type == 'SimpleRNN': m = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_meta_held_notes')(meta_held_notes_input)
if self.cell_type == 'LSTM': m = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_meta_held_notes')(meta_held_notes_input)
if self.cell_type == 'GRU': m = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_meta_held_notes')(meta_held_notes_input)
h = Concatenate(name='concatenated_meta_held_notes_and_rest_layer')([h, m])
#use a dense layer to pack all the meta information + notes together
if self.meta_instrument or self.meta_velocity or self.meta_instrument:
h = Dense(self.lstm_size, name='extra_instrument_after_concat_layer', activation=self.activation_before_splitting, kernel_initializer='glorot_uniform')(h)
if self.extra_layer:
h = Dense(self.lstm_size, name='extra_layer', activation=self.activation_before_splitting, kernel_initializer='glorot_uniform')(h)
if self.split_lstm_vector:
half_size = int(self.lstm_size/2)
h_1 = Lambda(lambda x : x[:,:half_size], output_shape=(half_size,))(h)
h_2 = Lambda(lambda x : x[:,half_size:], output_shape=(self.lstm_size-half_size,))(h)
else:
h_1 = h
h_2 = h
def sampling(args):
z_mean_, z_log_var_ = args
batch_size = K.shape(z_mean_)[0]
epsilon = K.random_normal(shape=(batch_size, self.latent_rep_size), mean=0., stddev=self.epsilon_std)
return z_mean_ + K.exp(z_log_var_ / 2) * epsilon
#s_3 = (s_1^2 * s_2^2) / (s_1^2 + s_2^2)
#tf.contrib.distributions.MultivariateNormalDiag(mean=0.0, stddev=0.05, seed=None)
z_mean = Dense(self.latent_rep_size, name='z_mean', activation='linear', kernel_initializer='glorot_uniform')(h_1)
z_log_var = Dense(self.latent_rep_size, name='z_log_var', activation='linear', kernel_initializer='glorot_uniform')(h_2)
if epsilon_factor > 0:
e = Input(shape=(1,), tensor=K.constant(self.epsilon_factor))
scaled_z_log_var = Add()[z_log_var, e]
z_mean, scaled_z_log_var = KLDivergenceLayer(beta=self.beta, prior_mean=self.prior_mean, prior_std=self.prior_std, name='kl_layer')([z_mean, scaled_z_log_var])
else:
z_mean, z_log_var = KLDivergenceLayer(beta=self.beta, prior_mean=self.prior_mean, prior_std=self.prior_std, name='kl_layer')([z_mean, z_log_var])
z = Lambda(sampling, output_shape=(self.latent_rep_size,), name='lambda')([z_mean, z_log_var])
return (z)
def _build_decoder(self, input_layer, encoded, ground_truth, history_input, decoder_additional_input_layer, input_decoder_meta_instrument_start, input_decoder_meta_velocity_start, input_decoder_meta_held_notes_start, input_decoder_meta_next_notes_start, meta_next_notes_ground_truth_input):
input_states = []
for layer_no in range(0,self.num_layers_decoder):
state_c = Input((self.lstm_size,))
input_states.append(state_c)
if self.cell_type == 'LSTM':
state_h = Input((self.lstm_size,))
input_states.append(state_h)
final_states = []
lstm_input = input_layer
for layer_no in range(0,self.num_layers_decoder):
if self.cell_type == 'SimpleRNN': lstm_output, state1_t = SimpleRNNCell(self.lstm_size)([lstm_input, input_states[layer_no]])
if self.cell_type == 'LSTM': lstm_output, state1_t, state2_t = LSTMCell(self.lstm_size)([lstm_input, input_states[layer_no*2], input_states[layer_no*2+1]])
if self.cell_type == 'GRU': lstm_output, state1_t = GRUCell(self.lstm_size)([lstm_input, input_states[layer_no]])
lstm_input = lstm_output
final_states.append(state1_t)
if self.cell_type == 'LSTM':
final_states.append(state2_t)
output = Dense(self.output_dim, activation=self.activation)(lstm_output)
# use learn_mode = 'join', test_mode = 'viterbi', sparse_target = True (label indice output)
readout_input_sequence = Input((self.output_length,self.output_dim))
rnn = RecurrentModel(input_layer, output, initial_states=input_states, final_states=final_states, readout_input=readout_input_sequence, teacher_force=self.teacher_force, decode=self.decode, output_length=self.output_length, return_states=False, state_initializer=None, name='notes')
if self.history:
new_encoded = Concatenate()([encoded, history_input])
else:
new_encoded = encoded
if self.decoder_additional_input:
new_encoded = Concatenate()([new_encoded, decoder_additional_input_layer])
else:
new_encoded = new_encoded
initial_states = []
bias_initializer = 'zeros'
for layer_no in range(0,self.num_layers_decoder):
encoded_c = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_c)
if self.cell_type == 'LSTM':
encoded_h = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_h)
decoded = rnn(input_layer, initial_state=initial_states, initial_readout=input_layer, ground_truth=ground_truth)
if self.meta_instrument:
input_states = []
state_c = Input((self.lstm_size,))
input_states.append(state_c)
if self.cell_type == 'LSTM':
state_h = Input((self.lstm_size,))
input_states.append(state_h)
final_states = []
lstm_input = input_decoder_meta_instrument_start
if self.cell_type == 'SimpleRNN': lstm_output, state1_t = SimpleRNNCell(self.lstm_size)([lstm_input, input_states[0]])
if self.cell_type == 'LSTM': lstm_output, state1_t, state2_t = LSTMCell(self.lstm_size)([lstm_input, input_states[0], input_states[1]])
if self.cell_type == 'GRU': lstm_output, state1_t = GRUCell(self.lstm_size)([lstm_input, input_states[0]])
lstm_input = lstm_output
final_states.append(state1_t)
if self.cell_type == 'LSTM':
final_states.append(state2_t)
readout_input_sequence = Input((self.meta_instrument_length,self.meta_instrument_dim))
output = Dense(self.meta_instrument_dim, activation=self.meta_instrument_activation)(lstm_output)
rnn = RecurrentModel(input_decoder_meta_instrument_start, output, initial_states=input_states, final_states=final_states, readout_input=readout_input_sequence, teacher_force=False, decode=self.decode, output_length=self.meta_instrument_length, return_states=False, state_initializer=None, name='meta_instrument')
initial_states = []
bias_initializer = 'zeros'
encoded_c = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_c)
if self.cell_type == 'LSTM':
encoded_h = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_h)
meta_instrument_output = rnn(input_decoder_meta_instrument_start, initial_state=initial_states, initial_readout=input_decoder_meta_instrument_start)
else:
meta_instrument_output = None
if self.meta_velocity:
input_states = []
state_c = Input((self.lstm_size,))
input_states.append(state_c)
if self.cell_type == 'LSTM':
state_h = Input((self.lstm_size,))
input_states.append(state_h)
final_states = []
lstm_input = input_decoder_meta_velocity_start
if self.cell_type == 'SimpleRNN': lstm_output, state1_t = SimpleRNNCell(self.lstm_size)([lstm_input, input_states[0]])
if self.cell_type == 'LSTM': lstm_output, state1_t, state2_t = LSTMCell(self.lstm_size)([lstm_input, input_states[0], input_states[1]])
if self.cell_type == 'GRU': lstm_output, state1_t = GRUCell(self.lstm_size)([lstm_input, input_states[0]])
lstm_input = lstm_output
final_states.append(state1_t)
if self.cell_type == 'LSTM':
final_states.append(state2_t)
readout_input_sequence = Input((self.meta_velocity_length,1))
output = Dense(1, activation=self.meta_velocity_activation)(lstm_output)
rnn = RecurrentModel(input_decoder_meta_velocity_start, output, initial_states=input_states, final_states=final_states, readout_input=readout_input_sequence, teacher_force=False, decode=self.decode, output_length=self.meta_velocity_length, return_states=False, state_initializer=None, name='meta_velocity')
initial_states = []
bias_initializer = 'zeros'
encoded_c = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_c)
if self.cell_type == 'LSTM':
encoded_h = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_h)
meta_velocity_output = rnn(input_decoder_meta_velocity_start, initial_state=initial_states, initial_readout=input_decoder_meta_velocity_start)
else:
meta_velocity_output = None
if self.meta_held_notes:
input_states = []
state_c = Input((self.lstm_size,))
input_states.append(state_c)
if self.cell_type == 'LSTM':
state_h = Input((self.lstm_size,))
input_states.append(state_h)
final_states = []
lstm_input = input_decoder_meta_held_notes_start
if self.cell_type == 'SimpleRNN': lstm_output, state1_t = SimpleRNNCell(self.lstm_size)([lstm_input, input_states[0]])
if self.cell_type == 'LSTM': lstm_output, state1_t, state2_t = LSTMCell(self.lstm_size)([lstm_input, input_states[0], input_states[1]])
if self.cell_type == 'GRU': lstm_output, state1_t = GRUCell(self.lstm_size)([lstm_input, input_states[0]])
lstm_input = lstm_output
final_states.append(state1_t)
if self.cell_type == 'LSTM':
final_states.append(state2_t)
readout_input_sequence = Input((self.meta_held_notes_length,2))
output = Dense(2, activation=self.meta_held_notes_activation)(lstm_output)
rnn = RecurrentModel(input_decoder_meta_held_notes_start, output, initial_states=input_states, final_states=final_states, readout_input=readout_input_sequence, teacher_force=False, decode=self.decode, output_length=self.meta_held_notes_length, return_states=False, state_initializer=None, name='meta_held_notes')
initial_states = []
bias_initializer = 'zeros'
encoded_c = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_c)
if self.cell_type == 'LSTM':
encoded_h = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_h)
meta_held_notes_output = rnn(input_decoder_meta_held_notes_start, initial_state=initial_states, initial_readout=input_decoder_meta_held_notes_start)
else:
meta_held_notes_output = None
if self.meta_next_notes:
input_states = []
for layer_no in range(0,self.num_layers_decoder):
state_c = Input((self.lstm_size,))
input_states.append(state_c)
if self.cell_type == 'LSTM':
state_h = Input((self.lstm_size,))
input_states.append(state_h)
final_states = []
lstm_input = input_decoder_meta_next_notes_start
for layer_no in range(0,self.num_layers_decoder):
if self.cell_type == 'SimpleRNN': lstm_output, state1_t = SimpleRNNCell(self.lstm_size)([lstm_input, input_states[layer_no]])
if self.cell_type == 'LSTM': lstm_output, state1_t, state2_t = LSTMCell(self.lstm_size)([lstm_input, input_states[layer_no*2], input_states[layer_no*2+1]])
if self.cell_type == 'GRU': lstm_output, state1_t = GRUCell(self.lstm_size)([lstm_input, input_states[layer_no]])
lstm_input = lstm_output
final_states.append(state1_t)
if self.cell_type == 'LSTM':
final_states.append(state2_t)
output = Dense(self.output_dim, activation=self.activation)(lstm_output)
readout_input_sequence = Input((self.meta_next_notes_output_length,self.output_dim))
rnn = RecurrentModel(input_decoder_meta_next_notes_start, output, initial_states=input_states, final_states=final_states, readout_input=readout_input_sequence, teacher_force=self.meta_next_notes_teacher_force, decode=self.decode, output_length=self.meta_next_notes_output_length, return_states=False, state_initializer=None, name='next_notes')
initial_states = []
bias_initializer = 'zeros'
for layer_no in range(0,self.num_layers_decoder):
encoded_c = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_c)
if self.cell_type == 'LSTM':
encoded_h = Dense(self.lstm_size, activation=self.lstm_state_activation, bias_initializer=bias_initializer)(new_encoded)
initial_states.append(encoded_h)
meta_next_notes_output = rnn(input_decoder_meta_next_notes_start, initial_state=initial_states, initial_readout=input_decoder_meta_next_notes_start, ground_truth=meta_next_notes_ground_truth_input)
else:
meta_next_notes_output = None
return decoded, meta_instrument_output, meta_velocity_output, meta_held_notes_output, meta_next_notes_output
def _build_composer_decoder(self, encoded_rep):
composer_latent_length = self.num_composers
h = Lambda(lambda x : x[:,:composer_latent_length], output_shape=(composer_latent_length,))(encoded_rep)
composer_prediction = Activation('softmax')(h)
return composer_prediction
def _build_signature_decoder(self, encoded_rep):
decoder_latent_length = self.signature_dim
#add additional offset if the composer already is attached to the first dimensions
offset = 0
if self.composer_decoder:
offset += self.num_composers
h = Lambda(lambda x : x[:,offset:offset+decoder_latent_length], output_shape=(decoder_latent_length,))(encoded_rep)
signature_prediction = Activation(self.signature_activation)(h)
return signature_prediction
def _build_composer_decoder_at_notes_output(self, composer_notes_input):
if self.cell_type == 'SimpleRNN': composer_notes_decoder_prediction = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_composer_decoder_at_notes')(composer_notes_input)
if self.cell_type == 'LSTM': composer_notes_decoder_prediction = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_composer_decoder_at_notes')(composer_notes_input)
if self.cell_type == 'GRU': composer_notes_decoder_prediction = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_composer_decoder_at_notes')(composer_notes_input)
composer_notes_decoder_prediction = Dense(self.num_composers, activation=self.composer_decoder_at_notes_activation)(composer_notes_decoder_prediction)
return composer_notes_decoder_prediction
def _build_composer_decoder_at_instrument_output(self, composer_instrument_input):
if self.cell_type == 'SimpleRNN': composer_instrument_decoder_prediction = SimpleRNN(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='rnn_composer_decoder_at_instrument')(composer_instrument_input)
if self.cell_type == 'LSTM': composer_instrument_decoder_prediction = LSTM(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='lstm_composer_decoder_at_instrument')(composer_instrument_input)
if self.cell_type == 'GRU': composer_instrument_decoder_prediction = GRU(self.lstm_size, return_sequences=False, activation=self.lstm_activation, name='gru_composer_decoder_at_instrument')(composer_instrument_input)
composer_instrument_decoder_prediction = Dense(self.num_composers, activation=self.composer_decoder_at_instrument_activation)(composer_instrument_decoder_prediction)
return composer_instrument_decoder_prediction
# prerpares encoder input for a song that is already split
# X: input pitches of shape (num_samples, input_length, different_pitches)
# I: instruments for each voice of shape (max_voices, different_instruments)
# V: velocity information of shape (num_samples, output_length==input_length), values between 0 and 1 when there is no silent note, 1 denotes MAX_VELOCITY
# D: duration information of shape (num_samples, output_length==input_length), values are 1 if a note is held
def prepare_encoder_input_list(X,I,V,D):
num_samples = X.shape[0]
#transform duration into categorical
D_cat = np.zeros((D.shape[0], D.shape[1], 2))
for sample in range(num_samples):
for step in range(output_length):
if D[sample,step] == 0:
D_cat[sample, step, 0] = 1
else:
D_cat[sample, step, 1] = 1
D = D_cat
V = np.copy(V) #make a deep copy since it may be changed if you combine_velocity_and_held_notes
V = np.expand_dims(V, 2)
if combine_velocity_and_held_notes:
for sample in range(num_samples):
for step in range(output_length):
if D[sample,step, 1] == 1:
#assert, that it is held and therefore has no velocity since its not hit
assert(V[sample, step,0] == 0)
V[sample,step,0] = 1
#tile the meta_instrument as well for every sample
I = np.tile(np.expand_dims(I, axis=0), (num_samples,1,1))
if meta_instrument or meta_velocity or meta_held_notes:
encoder_input_list = [X]
if meta_instrument:
encoder_input_list.append(I)
if meta_velocity:
encoder_input_list.append(V)
if meta_held_notes:
encoder_input_list.append(D)
return encoder_input_list
else:
return X
# prerpares autoencoder input and output for a song that is already split
# R: latent list of shape (num_samples, latent_dim)
# C: class of epoch, integer in range(num_classes)
# S: normalized signature vector of shape (num_samples, signature_dim)
# H: history list of shape (num_samples, latent_dim), if None will form automatically from R by rolling once
def prepare_decoder_input(R,C,S,H=None):
num_samples = R.shape[0]
Y_start = np.zeros((num_samples, output_dim))
input_list = [Y_start, R]
if teacher_force:
empty_Y = np.zeros((num_samples, input_length, output_dim))
input_list.append(empty_Y)
if history:
if H is not None:
input_list.append(H)
else:
history_list = np.zeros(R.shape)
history_list[1:] = R[:-1]
input_list.append(history_list)
if decoder_additional_input:
decoder_additional_input_list = []
if decoder_input_composer:
decoder_additional_input_list.extend(C)
if append_signature_vector_to_latent:
if len(decoder_additional_input_list) > 0:
decoder_additional_input_list = np.asarray(decoder_additional_input_list)
decoder_additional_input_list = np.append(decoder_additional_input_list, S, axis=1)
else:
decoder_additional_input_list.extend(S)
decoder_additional_input_list = np.asarray(decoder_additional_input_list)
input_list.append(decoder_additional_input_list)
if meta_instrument:
meta_instrument_start = np.zeros((num_samples, meta_instrument_dim))
input_list.append(meta_instrument_start)
if meta_velocity:
meta_velocity_start = np.zeros((num_samples,))
input_list.append(meta_velocity_start)
if meta_held_notes:
meta_held_notes_start = np.zeros((num_samples,2))
input_list.append(meta_held_notes_start)
if meta_next_notes:
meta_next_notes_start = np.zeros((num_samples,output_dim))
input_list.append(meta_next_notes_start)
return input_list
# prerpares autoencoder input and output for a song that is already split
# X: input pitches of shape (num_samples, input_length, different_pitches)
# Y: ouput pitches of shape (num_samples, ouput_length, different_pitches)
# C: class of epoch, integer in range(num_classes)
# I: instruments for each voice of shape (max_voices, different_instruments)
# V: velocity information of shape (num_samples, output_length==input_length), values between 0 and 1 when there is no silent note, 1 denotes MAX_VELOCITY
# D: duration information of shape (num_samples, output_length==input_length), values are 1 if a note is held
# S: normalized signature vector of shape (num_samples, signature_dim)
# H: history list of shape (num_samples, latent_dim)
def prepare_autoencoder_input_and_output_list(X,Y,C,I,V,D,S,H, return_sample_weight=False):
num_samples = X.shape[0]
#transform duration into categorical
D_cat = np.zeros((D.shape[0], D.shape[1], 2))
for sample in range(num_samples):
for step in range(output_length):
if D[sample,step] == 0:
D_cat[sample, step, 0] = 1
else:
D_cat[sample, step, 1] = 1
D = D_cat
V = np.copy(V) #make a deep copy since it may be changed if you combine_velocity_and_held_notes
V = np.expand_dims(V, 2)
if combine_velocity_and_held_notes:
for sample in range(num_samples):
for step in range(output_length):
if D[sample,step, 1] == 1:
#assert, that it is held and therefore has no velocity since its not hit
assert(V[sample, step,0] == 0)
V[sample,step,0] = 1
#since we have to predict the last
if meta_next_notes:
N = Y[1:] #next input
X = X[:-1]
Y = Y[:-1]
V = V[:-1]
D = D[:-1]
S = S[:-1]
H = H[:-1]
num_samples = X.shape[0]
#create start symbol for every sample
Y_start = np.zeros((num_samples, Y.shape[2]))
#transform C into categorical format as well and duplicate it by num_samples
C = np.asarray([to_categorical(C, num_classes=num_classes)]*num_samples).squeeze()
#tile the meta_instrument as well for every sample
meta_instrument_input = np.tile(np.expand_dims(I, axis=0), (num_samples,1,1))
input_list = [X,Y_start]
output_list = [Y]
if return_sample_weight:
#weight matrix for every sample and steps
sample_weight = np.ones((num_samples,output_length))
if include_silent_note:
#set the weight to silent_weight for every sample where a silent note is played
sample_weight[np.where(Y[:,:,-1]==1)] = silent_weight
if include_composer_decoder:
sample_weight_composer_decoder = np.ones((num_samples,))
if isinstance(sample_weight, list):
sample_weight.append(sample_weight_composer_decoder)
else:
sample_weight = [sample_weight, sample_weight_composer_decoder]
if signature_decoder:
sample_weight_signature_decoder = np.ones((num_samples,))
if isinstance(sample_weight, list):
sample_weight.append(sample_weight_signature_decoder)
else:
sample_weight = [sample_weight, sample_weight_signature_decoder]
if composer_decoder_at_notes_output:
sample_weight_composer_notes_decoder = np.ones((num_samples,))
if isinstance(sample_weight, list):
sample_weight.append(sample_weight_composer_notes_decoder)
else:
sample_weight = [sample_weight, sample_weight_composer_notes_decoder]
if composer_decoder_at_instrument_output:
sample_weight_composer_instrument_decoder = np.ones((num_samples,))
if isinstance(sample_weight, list):
sample_weight.append(sample_weight_composer_instrument_decoder)
else:
sample_weight = [sample_weight, sample_weight_composer_instrument_decoder]
if teacher_force:
input_list.append(Y)
if history:
input_list.append(H)
if decoder_additional_input:
decoder_additional_input_list = []
if decoder_input_composer:
decoder_additional_input_list.extend(C)
if append_signature_vector_to_latent:
if len(decoder_additional_input_list) > 0:
decoder_additional_input_list = np.asarray(decoder_additional_input_list)
decoder_additional_input_list = np.append(decoder_additional_input_list, S, axis=1)
else:
decoder_additional_input_list.extend(S)
decoder_additional_input_list = np.asarray(decoder_additional_input_list)
input_list.append(decoder_additional_input_list)
if meta_instrument:
meta_instrument_start = np.zeros((num_samples, meta_instrument_dim))
input_list.append(meta_instrument_start)
input_list.append(meta_instrument_input)
output_list.append(meta_instrument_input)
if return_sample_weight:
sample_weight_meta_instrument = np.ones((num_samples,))
if isinstance(sample_weight, list):
sample_weight.append(sample_weight_meta_instrument)
else:
sample_weight = [sample_weight, sample_weight_meta_instrument]
if meta_velocity:
meta_velocity_start = np.zeros((num_samples,))
input_list.append(meta_velocity_start)
input_list.append(V)
output_list.append(V)
if return_sample_weight:
sample_weight_meta_velocity = np.ones((num_samples,))