コード例 #1
0
            x = to_categorical(x.flatten(), num_classes=DIM).\
                reshape(x.shape[0], x.shape[1], DIM)
            y = y.reshape(x.shape[0], x.shape[1], 1)
            yield (x, y)

    # model
    model = StackedRNN(
        timespan=LEN,
        input_dim=DIM,
        output_dim=DIM,
        cells=[512, 512, 512],
    )
    #                  block_kwargs={'kernel_regularizer': l2(1e-5)})
    model.build()
    #   model.model.load_weights('temp/stackedrnn_kernel_l2.h5')
    #   model.model.load_weights('temp/simple_rnn.h5')
    #   model.train(data_generator(),
    #               opt=1e-5,
    #               steps_per_epoch=30,
    #               epochs=100,
    #               save_path='temp/simple_rnn.h5')

    model.build_generator('temp/e-comp_simple_rnn.h5')
    res = model.generate(seed=32, length=2000)

    mid = Song()
    track = mid.add_track()
    for msgi in AllInOneCoder().decode(res):
        track.append(msgi)
    mid.save_as('simple_rnn.mid')
コード例 #2
0
from DeepSymphony.coders import AllInOneCoder
from DeepSymphony.models import StackedRNN
from DeepSymphony.utils import Song
from DeepSymphony.utils.stat import LCS
from tqdm import tqdm
from pprint import pprint
from keras import optimizers


if __name__ == '__main__':
    LEN = 100  # length of input
    DIM = 128+128+100+7

    data, filelist = Song.load_from_dir(
        "./datasets/easymusicnotes/",
        encoder=AllInOneCoder(return_indices=True),
        return_list=True)

    def data_generator():
        batch_size = 32
        while True:
            x = []
            y = []
            for _ in range(batch_size):
                ind = np.random.randint(len(data))
                start = np.random.randint(data[ind].shape[0]-LEN-1)
                x.append(data[ind][start:start+LEN])
                y.append(data[ind][start+1:start+LEN+1])
            x = np.array(x)
            y = np.array(y)
コード例 #3
0
from __future__ import print_function

import sys
from DeepSymphony.utils import Song
import mido

if __name__ == '__main__':
    if len(sys.argv) < 2:
        sys.argv.append('simple_rnn.mid')
    song = Song(sys.argv[1])

    # run `timidity -iA` to open the daemon synthesizer
    # use port to send message to the daemon synthesizer

    port = mido.open_output(name='TiMidity port 0')
    keyboard = ['_'] * 128
    for msg in song.playback():
        if msg.type == 'note_on':
            keyboard[msg.note] = '^'
        elif msg.type == 'note_off':
            keyboard[msg.note] = '_'
        print(''.join(keyboard), end='\r')
        sys.stdout.flush()

        port.send(msg)
コード例 #4
0
from DeepSymphony.utils import Song
from DeepSymphony.utils.stat import LCS
from tqdm import tqdm
from pprint import pprint
from DeepSymphony.coders import AllInOneCoder

import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':
    coder = AllInOneCoder()
    song = Song('masterpiece/0035.mid')
    song = coder.encode(song.midi)

    data, filelist = Song.load_from_dir(
        "./datasets/easymusicnotes/",
        encoder=AllInOneCoder(return_indices=True),
        return_list=True)

    # LCS check
    song = filter(lambda x: x < 128, song.argmax(1))
    print len(song)
    matches = []
    for ind, ele in tqdm(enumerate(data)):
        ele = filter(lambda x: x < 128, ele)
        matches.append((LCS(ele, song, return_seq=True), filelist[ind]))
    matches = sorted(matches, key=lambda x: x[0][0])[::-1]
    # pprint(sorted(matches)[::-1])

    for (count, lcs, p, q), filename in matches:
        print count