@@ -46,6 +46,46 @@ def f(x):
46
46
return bins
47
47
return f
48
48
49
+ def time_axis (dropout ):
50
+ def f (notes , beat , style ):
51
+ time_steps = int (notes .get_shape ()[1 ])
52
+
53
+ # TODO: Experiment with when to apply conv
54
+ note_octave = TimeDistributed (Conv1D (OCTAVE_UNITS , 2 * OCTAVE , padding = 'same' ))(notes )
55
+ note_octave = Activation ('tanh' )(note_octave )
56
+ note_octave = Dropout (dropout )(note_octave )
57
+
58
+ # Create features for every single note.
59
+ note_features = Concatenate ()([
60
+ Lambda (pitch_pos_in_f (time_steps ))(notes ),
61
+ Lambda (pitch_class_in_f (time_steps ))(notes ),
62
+ Lambda (pitch_bins_f (time_steps ))(notes ),
63
+ note_octave ,
64
+ TimeDistributed (RepeatVector (NUM_NOTES ))(beat )
65
+ ])
66
+
67
+ x = note_features
68
+
69
+ # [batch, notes, time, features]
70
+ x = Permute ((2 , 1 , 3 ))(x )
71
+
72
+ # Apply LSTMs
73
+ for l in range (TIME_AXIS_LAYERS ):
74
+ # Integrate style
75
+ style_proj = Dense (int (x .get_shape ()[3 ]))(style )
76
+ style_proj = Activation ('tanh' )(style_proj )
77
+ style_proj = Dropout (dropout )(style_proj )
78
+ style_proj = TimeDistributed (RepeatVector (NUM_NOTES ))(style_proj )
79
+ style_proj = Permute ((2 , 1 , 3 ))(style_proj )
80
+ x = Add ()([x , style_proj ])
81
+
82
+ x = TimeDistributed (LSTM (TIME_AXIS_UNITS , return_sequences = True ))(x )
83
+ x = Dropout (dropout )(x )
84
+
85
+ # [batch, time, notes, features]
86
+ return Permute ((2 , 1 , 3 ))(x )
87
+ return f
88
+
49
89
def note_axis (dropout ):
50
90
def f (x , chosen , style ):
51
91
time_steps = int (x .get_shape ()[1 ])
@@ -74,7 +114,7 @@ def f(x, chosen, style):
74
114
return f
75
115
76
116
def style_layer (input_dropout ):
77
- emb = Embedding ( NUM_STYLES , STYLE_UNITS )
117
+ emb = Dense ( STYLE_UNITS )
78
118
def f (style_in ):
79
119
style = emb (style_in )
80
120
return Dropout (input_dropout )(style )
@@ -83,7 +123,7 @@ def f(style_in):
83
123
def build_models (time_steps = SEQ_LEN , input_dropout = 0.2 , dropout = 0.5 ):
84
124
notes_in = Input ((time_steps , NUM_NOTES , NOTE_UNITS ))
85
125
beat_in = Input ((time_steps , NOTES_PER_BAR ))
86
- style_in = Input ((time_steps ,))
126
+ style_in = Input ((time_steps , NUM_STYLES ))
87
127
# Target input for conditioning
88
128
chosen_in = Input ((time_steps , NUM_NOTES , NOTE_UNITS ))
89
129
@@ -97,40 +137,7 @@ def build_models(time_steps=SEQ_LEN, input_dropout=0.2, dropout=0.5):
97
137
style = style_l (style_in )
98
138
99
139
""" Time axis """
100
- # TODO: Experiment with when to apply conv
101
- note_octave = TimeDistributed (Conv1D (OCTAVE_UNITS , 2 * OCTAVE , padding = 'same' ))(notes )
102
- note_octave = Activation ('tanh' )(note_octave )
103
- note_octave = Dropout (dropout )(note_octave )
104
-
105
- # Create features for every single note.
106
- note_features = Concatenate ()([
107
- Lambda (pitch_pos_in_f (time_steps ))(notes ),
108
- Lambda (pitch_class_in_f (time_steps ))(notes ),
109
- Lambda (pitch_bins_f (time_steps ))(notes ),
110
- note_octave ,
111
- TimeDistributed (RepeatVector (NUM_NOTES ))(beat )
112
- ])
113
-
114
- x = note_features
115
-
116
- # [batch, notes, time, features]
117
- x = Permute ((2 , 1 , 3 ))(x )
118
-
119
- # Apply LSTMs
120
- for l in range (TIME_AXIS_LAYERS ):
121
- # Integrate style
122
- style_proj = Dense (int (x .get_shape ()[3 ]))(style )
123
- style_proj = Activation ('tanh' )(style_proj )
124
- style_proj = Dropout (dropout )(style_proj )
125
- style_proj = TimeDistributed (RepeatVector (NUM_NOTES ))(style_proj )
126
- style_proj = Permute ((2 , 1 , 3 ))(style_proj )
127
- x = Add ()([x , style_proj ])
128
-
129
- x = TimeDistributed (LSTM (TIME_AXIS_UNITS , return_sequences = True ))(x )
130
- x = Dropout (dropout )(x )
131
-
132
- # [batch, time, notes, features]
133
- time_out = Permute ((2 , 1 , 3 ))(x )
140
+ time_out = time_axis (dropout )(notes , beat , style )
134
141
135
142
""" Note Axis & Prediction Layer """
136
143
naxis = note_axis (dropout )
@@ -144,7 +151,7 @@ def build_models(time_steps=SEQ_LEN, input_dropout=0.2, dropout=0.5):
144
151
145
152
note_features = Input ((1 , NUM_NOTES , TIME_AXIS_UNITS ), name = 'note_features' )
146
153
chosen_gen_in = Input ((1 , NUM_NOTES , NOTE_UNITS ), name = 'chosen_gen_in' )
147
- style_gen_in = Input ((1 ,), name = 'style_in' )
154
+ style_gen_in = Input ((1 , NUM_STYLES ), name = 'style_in' )
148
155
149
156
# Dropout inputs
150
157
chosen_gen = Dropout (input_dropout )(chosen_gen_in )
0 commit comments