Exemplo n.º 1
0
        # Update clock (next request)
        # total_time = sum([e.value for e in map(Event.from_int, seq) if e.type == 'time_shift'])
        # self.server_state['tick_interval'] = total_time / 1000

        return seq

    def decode(self, token):
        return Event.from_int(token)


if __name__ == '__main__':
    # import utils
    print(tf.executing_eagerly())

    src = tf.constant(
        [utils.fill_with_placeholder([1, 2, 3, 4], max_len=2048)])
    trg = tf.constant(
        [utils.fill_with_placeholder([1, 2, 3, 4], max_len=2048)])
    src_mask, trg_mask, lookup_mask = utils.get_masked_with_pad_tensor(
        2048, src, trg)
    print(lookup_mask)
    print(src_mask)
    mt = MusicTransformer(debug=True,
                          embedding_dim=par.embedding_dim,
                          vocab_size=par.vocab_size)
    mt.save_weights('my_model.h5', save_format='h5')
    mt.load_weights('my_model.h5')
    result = mt.generate([27, 186, 43, 213, 115, 131], length=100)
    print(result)
    from deprecated import sequence
Exemplo n.º 2
0
        out_tar = y
        inp_tar = y[:, :-1]
        inp_tar = tf.concat([start_token, inp_tar], -1)
        return x, inp_tar, out_tar

    def reset_metrics(self):
        for metric in self.custom_metrics:
            metric.reset_states()
        return


if __name__ == '__main__':
    import utils
    print(tf.executing_eagerly())

    src = tf.constant([utils.fill_with_placeholder([1,2,3,4],max_len=2048)])
    trg = tf.constant([utils.fill_with_placeholder([1,2,3,4],max_len=2048)])
    src_mask, trg_mask, lookup_mask = utils.get_masked_with_pad_tensor(2048, src,trg)
    print(lookup_mask)
    # print(src_mask, trg_mask)
    mt = MusicTransformer(debug=True, embedding_dim=par.embedding_dim, vocab_size=par.vocab_size)
    mt.save_weights('my_model.h5', save_format='h5')
    mt.load_weights('my_model.h5')
    # print('compile...')
    # mt.compile(optimizer='adam', loss=callback.TransformerLoss(debug=True))
    # # print(mt.train_step(inp=src, tar=trg))
    #
    # print('start training...')
    # for i in range(2):
    #     mt.train_on_batch(x=src, y=trg)
    result = mt.generate([27, 186,  43, 213, 115, 131], length=100)