def piano_embedding(self, piano_t, piano_past, piano_future):
        # Build input
        # Add a time axis to piano_t
        piano_t_time = tf.reshape(piano_t, [-1, 1, self.piano_dim])

        with tf.name_scope("future"):
            # Concatenate t and future
            input_seq_fut = tf.concat([piano_t_time, piano_future], 1)
            # Flip the matrix along the time axis so that the last time index is t
            input_seq_fut = tf.reverse(input_seq_fut, [1])

            with tf.name_scope("stacked_gru"):
                piano_embedding_fut = stacked_rnn(input_seq_fut, self.hs_piano, 
                    rnn_type='gru', 
                    weight_decay_coeff=self.weight_decay_coeff, 
                    dropout_probability=self.dropout_probability, 
                    activation='relu'
                    )

        with tf.name_scope("past"):
            # Concatenate t and future
            input_seq_past = tf.concat([piano_past, piano_t_time], 1)
            with tf.name_scope("stacked_gru"):
                piano_embedding_past = stacked_rnn(input_seq_past, self.hs_piano, 
                    rnn_type='gru',
                    weight_decay_coeff=self.weight_decay_coeff,
                    dropout_probability=self.dropout_probability,
                    activation='relu'
                    )
        
        return piano_embedding_past, piano_embedding_fut
    def init_weights(self):
        self.weights = {}

        ###############################
        # Past piano embedding
        self.weights["orch_past"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Past piano embedding
        self.weights["orch_future"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Piano present
        self.weights["piano_present"] = MLP(
            self.mlp_piano_present,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # orchestra present
        self.weights["orch_present"] = MLP(
            self.mlp_orch_present,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Embedding to prediction
        self.weights["final_pred"] = MLP(
            self.mlp_last_pred,
            activation='relu',
            dropout_probability=self.dropout_probability)
        # if len(self.mlp_last_pred) > 0:
        # 	W = tf.get_variable("last_W", [self.orch_dim, self.mlp_last_pred[-1]], initializer=tf.zeros_initializer())
        # else:
        # 	embedding_dim = self.recurrent_layers[-1] * 2 + self.mlp_orch_present[-1] + self.mlp_piano_present[-1]
        # 	W = tf.get_variable("last_W", [embedding_dim, self.orch_dim], initializer=tf.zeros_initializer())
        # b = tf.constant(self.static_bias, dtype=tf.float32, name='precomputed_static_biases')
        # self.weights["final_pred"].append((W,b))
        self.weights["final_pred"].append(
            Dense(self.orch_dim, activation='sigmoid'))
        ###############################
        return
示例#3
0
    def init_weights(self):
        self.weights = {}

        ###############################
        # Past piano embedding
        self.weights["orch_past"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Past piano embedding
        self.weights["orch_future"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Piano present
        self.weights["piano_present"] = MLP(
            self.mlp_piano_present,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # orchestra present
        W_shape = [self.orch_dim, self.mlp_orch_present[0]]
        first_W = tf.get_variable("first_W",
                                  W_shape,
                                  initializer=tf.zeros_initializer())
        first_b = tf.get_variable("first_b", [self.mlp_orch_present[0]],
                                  initializer=tf.zeros_initializer())
        self.weights["orch_present"] = [(first_W, first_b)]
        if len(self.mlp_orch_present) > 1:
            self.weights["orch_present"].extend(
                MLP(self.mlp_orch_present[1:],
                    activation='relu',
                    dropout_probability=self.dropout_probability))
        ###############################

        ###############################
        # Embedding to prediction
        self.weights["final_pred"] = MLP(
            self.mlp_last_pred,
            activation='relu',
            dropout_probability=self.dropout_probability)
        self.weights["final_pred"].append(Dense(1, activation='sigmoid'))
        ###############################
        return
 def init_weights(self):
     self.weights = {}
     self.weights["past_piano"] = stacked_rnn(self.recurrent_piano, "relu",
                                              self.dropout_probability)
     self.weights["future_piano"] = stacked_rnn(self.recurrent_piano,
                                                "relu",
                                                self.dropout_probability)
     self.weights["present_piano"] = MLP(self.mlp_piano, "relu",
                                         self.dropout_probability)
     self.weights["past_orchestra"] = stacked_rnn(self.recurrent_orch,
                                                  "relu",
                                                  self.dropout_probability)
     return
示例#5
0
    def piano_embedding(self, piano_t, piano_seq, reverse):
        with tf.name_scope("build_piano_input"):
            # Add a time axis to piano_t
            piano_t_time = tf.reshape(piano_t, [-1, 1, self.piano_dim])
            # Concatenate t and future
            input_seq = tf.concat([piano_t_time, piano_seq], 1)
            if reverse:
                # Flip the matrix along the time axis so that the last time index is t
                input_seq = tf.reverse(input_seq, [1])
            # Format as a 4D
            input_seq = tf.reshape(input_seq, [-1, self.temporal_order, self.piano_dim, 1])

        with tf.name_scope("conv_piano"):
            conv_layer = Conv1D(1, self.kernel_size_piano, activation='relu')
            conv_layer_timeDist = TimeDistributed(conv_layer, input_shape=(self.temporal_order, self.piano_dim, 1))
            p0 = conv_layer_timeDist(input_seq)
            keras_layer_summary(conv_layer)

        # Remove the last useless dimension
        cropped_piano_dim = self.piano_dim-self.kernel_size_piano+1
        p0 = tf.reshape(p0, [-1, self.temporal_order, cropped_piano_dim])

        with tf.name_scope("gru"):
            piano_emb = stacked_rnn(p0, self.hs_piano, 
                rnn_type='gru', 
                weight_decay_coeff=self.weight_decay_coeff,
                dropout_probability=self.dropout_probability, 
                activation='relu'
                )
        return piano_emb
    def init_weights(self):
        self.weights = {}

        self.FilM_dim_0 = 2000
        self.FilM_dim_1 = 2000

        self.weights["FiLM_generator"] = [
            Dense(self.FilM_dim_0 * 2 + self.FilM_dim_1 * 2, activation='relu')
        ]

        self.weights[""] = stacked_rnn([2000, 2000], 'relu',
                                       self.dropout_probability)

        self.weights["first_layer"] = Dense(2000, activation='relu')

        self.weights["block_0"] = [
            Dense(2000, activation='relu'),
            Dense(self.FilM_dim_0, activation='linear'),
            BatchNormalization()
        ]

        self.weights["block_1"] = [
            Dense(2000, activation='relu'),
            Dense(self.FilM_dim_1, activation='linear'),
            BatchNormalization()
        ]

        self.weights["last_layer"] = Dense(self.orch_dim, activation='softmax')

        return
    def orchestra_embedding(self, orch_past):
        conv_layer = self.weights["orch_embed_conv"]
        conv_layer_timeDist = TimeDistributed(
            conv_layer,
            input_shape=(self.temporal_order - 1, self.orch_dim, 1))
        with tf.name_scope("build_orch_input"):
            # Format as a 4D
            input_seq = tf.reshape(
                orch_past, [-1, self.temporal_order - 1, self.orch_dim, 1])

        with tf.name_scope("conv_orch"):
            o0 = conv_layer_timeDist(input_seq)
            keras_layer_summary(conv_layer)

        # Remove the last useless dimension
        cropped_orch_dim = self.orch_dim - self.kernel_size_orch + 1
        o0 = tf.reshape(o0, [-1, self.temporal_order - 1, cropped_orch_dim])

        with tf.name_scope("gru"):
            orchestra_embedding = stacked_rnn(
                o0,
                self.hs_orch,
                rnn_type='gru',
                weight_decay_coeff=self.weight_decay_coeff,
                dropout_probability=self.dropout_probability,
                activation='relu')
        return orchestra_embedding
    def init_weights(self):
        self.weights = {}

        ###############################
        # Past piano embedding
        self.weights["orch_past"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Past piano embedding
        self.weights["orch_future"] = stacked_rnn(
            self.recurrent_layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # Piano present
        self.weights["piano_present"] = MLP(
            self.layers,
            activation='relu',
            dropout_probability=self.dropout_probability)
        ###############################

        ###############################
        # orchestra present
        self.pitch_mask_shape = [self.orch_dim, self.layers[0]]
        first_W = tf.get_variable("first_W",
                                  self.pitch_mask_shape,
                                  initializer=tf.zeros_initializer())
        first_b = tf.get_variable("first_b", [self.layers[0]],
                                  initializer=tf.zeros_initializer())
        self.weights["orch_present"] = [(first_W, first_b)]
        self.weights["orch_present"].append(
            MLP(self.layers[1:],
                activation='relu',
                dropout_probability=self.dropout_probability))
        ###############################

        ###############################
        # Embedding to prediction

        ###############################
        return
 def orchestra_embedding(self, orch_past):
     with tf.name_scope("gru"):
         orchestra_embedding = stacked_rnn(orch_past, self.hs_orch, 
             rnn_type='gru', 
             weight_decay_coeff=self.weight_decay_coeff, 
             dropout_probability=self.dropout_probability, 
             activation='relu'
             )       
     return orchestra_embedding
示例#10
0
    def init_weights(self):
        self.weights = {}

        self.weights["MLP"] = Dense(self.film_dim, activation='relu')

        self.weights["FiLM_generator"] = stacked_rnn(self.rnns, 'relu',
                                                     self.dropout_probability)
        self.weights["gamma"] = Dense(self.film_dim, activation='sigmoid')
        self.weights["beta"] = Dense(self.film_dim, activation='relu')

        self.weights["last_layer"] = Dense(self.orch_dim, activation='softmax')

        return