Example #1
0
        # traini
        batch_size=32,
        continued=False,
        overwrite_workdir=True,
        iterations=10000,
        workdir='./temp/Fillblank/')
    model = DCRNN(hparam)
    model.build()
    # coder = NoteDurationCoder(normalize_key='C5', first_voice=False)
    coder = MultiHotCoder(normalize_key='C5', with_velocity=True)

    try:
        data = np.load('temp/easy.npz')['data']
    except:
        data = np.array(
            map_dir(lambda fn: coder.encode(ms.converter.parse(fn)),
                    './datasets/easymusicnotes/'))
        np.savez('temp/easy.npz', data=data)

    print(len(data), map(lambda x: len(x), data))
    data = filter(lambda x: len(x) > 0 and x.shape[1] > hparam.timesteps, data)
    # import matplotlib.pyplot as plt
    # for d in data:
    #     print d.shape
    #     for v in d:
    #         fig, ax = plt.subplots()
    #         ax.imshow(v)
    #     plt.show()
    data = map(lambda x: x.sum(0), data)
    print(len(data), map(lambda x: len(x), data))

    def sample(batch_size, noise=0.20):
Example #2
0
    # mode = 'train'
    mode = 'generate'
    if mode == 'train':
        hparam = StackedLSTMHParam(batch_size=64,
                                   cells=[256, 256],
                                   input_dim=363,
                                   timesteps=100,
                                   output_dim=363,
                                   learning_rate=5e-3,
                                   iterations=3000,
                                   overwrite_workdir=True)
        model = StackedLSTM(hparam)

        coder = ExampleCoder()
        data = np.array(
            map_dir(lambda fn: coder.encode(get_midi(fn)),
                    './datasets/easymusicnotes'))

        def fetch_data(batch_size):
            x, y = [], []
            for _ in range(batch_size):
                ind = np.random.randint(len(data))
                start = np.random.randint(data[ind].shape[0] -
                                          hparam.timesteps - 1)
                xi = data[ind][start:start + hparam.timesteps]
                yi = data[ind][start + 1:start + hparam.timesteps + 1]
                x.append(coder.onehot(xi))
                y.append(yi)
            x, y = np.array(x), np.array(y)
            return x, y

        model.train(fetch_data)
Example #3
0
    try:
        # data = np.load('temp/easy.npz')
        data = np.load('temp/piano-midi.npz')
        voi, vel = data['voice'], data['velocity']
        # data = (voi*vel)/127.
        data = voi
    except:

        def read_song(filename):
            return coder.encode(ms.converter.parse(filename))

        data = np.array(
            map_dir(
                read_song,
                # './datasets/piano-midi.de/', cores=6))
                './datasets/easymusicnotes/',
                cores=8))
        data = filter(lambda x: x is not None, data)
        voi, vel = zip(*data)
        np.savez('temp/easy.npz', voice=voi, velocity=vel)
        # np.savez('temp/piano-midi.npz', voice=voi, velocity=vel)

    print(len(data), map(lambda x: len(x), data))
    data = filter(lambda x: len(x) > 0 and x.shape[0] > hparam.timesteps, data)
    print(len(data), map(lambda x: len(x), data))

    train_data, test_data = train_test_split(data,
                                             test_size=0.22,
                                             random_state=32)
Example #4
0
if __name__ == '__main__':
    timesteps = 128
    batch_size = 32
    mode = 'train'
    mode = 'test'

    coder = NoteDurationCoder(normalize_key='C5', resolution=1. / 16.)

    try:
        # raise Exception
        data = np.load('temp/piano-midi_duration.npz')
        notes = data['notes']
        durations = data['durations']
    except:
        data = np.array(map_dir(handle, './datasets/piano-midi.de/', cores=8))
        print map(lambda x: len(x[0]), data)
        data = filter(lambda x: len(x[0]) > 0, data)
        print map(lambda x: len(x[0]), data)
        notes, durations = zip(*data)
        np.savez('temp/piano-midi_duration.npz',
                 notes=notes,
                 durations=durations)
    notes = np.array(notes)
    durations = np.array(durations) - 1
    print 'durations'
    print np.min(map(lambda x: x.min(), durations))
    print np.max(map(lambda x: x.max(), durations))

    print 'notes'
    print np.min(map(lambda x: x.min(), notes))
Example #5
0
                          # only_major=True,
                          length_limit=np.inf)

    try:
        # data = np.load('temp/easy.npz')
        # raise Exception
        data = np.load('temp/piano-midi.npz')
        voi, vel = data['voice'], data['velocity']
        # data = (voi*vel)/127.
        data = voi
    except:
        def read_song(filename):
            return coder.encode(ms.converter.parse(filename))

        data = np.array(map_dir(
            read_song,
            './datasets/piano-midi.de/', cores=8))
            # './datasets/easymusicnotes/', cores=8))
        data = filter(lambda x: x is not None, data)
        voi, vel = zip(*data)
        np.savez('temp/easy.npz', voice=voi, velocity=vel)
        data = voi
        # np.savez('temp/piano-midi.npz', voice=voi, velocity=vel)

    print(len(data), map(lambda x: len(x), data))
    data = filter(lambda x: len(x) > 0 and x.shape[0] > hparam.timesteps, data)
    print(len(data), map(lambda x: len(x), data))

    train_data, test_data = train_test_split(data,
                                             test_size=0.22,
                                             random_state=32)
        alpha=5e-3,  # 5-->2, alpha*con_loss
        beta=1.00,
        gamma=1e-3)  # gamma*q_loss
    model = ContinuousSeqAE(hparam)
    model.build()
    # coder = ExampleCoder()
    coder = NoteDurationCoder(normalize_key='C5', )
    # single=True,
    # first_voice=True)

    try:
        data = np.load('temp/easy.npz')['data']
        # data = np.load('temp/1138.npz')['data']
    except:
        data = np.array(
            map_dir(lambda fn: coder.encode(ms.converter.parse(fn))[0],
                    './datasets/1138ChinesePopSongs/1138/'))
        np.savez('temp/1138.npz', data=data)

    print(len(data), map(lambda x: len(x), data))
    data = filter(lambda x: len(x) > hparam.timesteps, data)
    data = map(remove_con_dup, data)
    print(len(data), map(lambda x: len(x), data))

    train_data, test_data = train_test_split(data,
                                             test_size=0.22,
                                             random_state=32)

    def fetch_tri_data_g(dataset):
        def fetch_tri_data(batch_size):
            src_seqs, nei_seqs, int_seqs = [], [], []
            for _ in range(batch_size):