Exemple #1
0
        clip_norm=1.,
        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']
    except:
        data = np.array(
            map_dir(lambda fn: coder.encode(ms.converter.parse(fn))[0],
                    './datasets/easymusicnotes/'))
        np.savez('temp/easy.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 = [], [], []
Exemple #2
0
        # model.compile('Adam', 'MSE')
        model.compile(Adam(5e-5), 'categorical_crossentropy',
                      ['categorical_accuracy'])
        model.load_weights('temp/duration.h5')
        model.fit_generator(fetch_data(),
                            steps_per_epoch=20,
                            epochs=10,
                            verbose=1)
        model.save('temp/duration.h5')

    if mode == 'test':
        model = load_model('temp/duration.h5')
        model.summary()

        coder = NoteDurationCoder(resolution=1. / 16.)
        notes, duras = coder.encode(ms.converter.parse('example.mid'),
                                    force=True)
        # notes, duras = coder.encode(
        #     ms.converter.parse('datasets/piano-midi.de/schumann/schum_abegg.mid'),
        #     force=True)

        print notes
        print notes.shape
        duration = model.predict([np.array([notes]),
                                  np.array([duras])])[0].argmax(-1) + 1
        print duration - duras
        print 'old', duras
        print 'new', duration
        print duration[-1]
        print 'sqr diff', ((duras - duration)**2).sum()
        coder.decode(notes, duration).write('midi', 'example.d.mid')
        # print zip(notes, duras)