Exemple #1
0
class TestMuse(unittest.TestCase):

    def setUp(self):
        print("setting up!")
        # get the muse dataset
        self.muse = MuseData()
        # get the jsb dataset
        # self.jsb = JSBChorales()
        # get nottingham dataset
        self.nottingham = Nottingham()
        # get the piano-midi-de dataset
        # self.piano = PianoMidiDe()


    def testSizes(self):
        print('muse train %s' % str(self.muse.train.shape.eval()[0]))
        assert self.muse.train.shape.eval()[0] == numpy.sum([l[0] for l in self.muse.getDataShape(TRAIN)])
        assert self.muse.valid.shape.eval()[0] == numpy.sum([l[0] for l in self.muse.getDataShape(VALID)])
        assert self.muse.test.shape.eval()[0]  == numpy.sum([l[0] for l in self.muse.getDataShape(TEST)])

        print('nottingham train %s' % str(self.nottingham.train.shape.eval()[0]))
        assert self.nottingham.train.shape.eval()[0] == numpy.sum([l[0] for l in self.nottingham.getDataShape(TRAIN)])
        assert self.nottingham.valid.shape.eval()[0] == numpy.sum([l[0] for l in self.nottingham.getDataShape(VALID)])
        assert self.nottingham.test.shape.eval()[0]  == numpy.sum([l[0] for l in self.nottingham.getDataShape(TEST)])

    def tearDown(self):
        del self.muse
        # del self.jsb
        del self.nottingham
        # del self.piano
        print("done!")
Exemple #2
0
 def setUp(self):
     print("setting up!")
     # get the muse dataset
     self.muse = MuseData()
     # get the jsb dataset
     # self.jsb = JSBChorales()
     # get nottingham dataset
     self.nottingham = Nottingham()
Exemple #3
0
 def setUp(self):
     print("setting up!")
     # get the muse dataset
     self.muse = MuseData()
     # get the jsb dataset
     # self.jsb = JSBChorales()
     # get nottingham dataset
     self.nottingham = Nottingham()
Exemple #4
0
 def setUp(self):
     print("setting up!")
     config_root_logger()
     # get the muse dataset
     self.muse = MuseData(path='../../../datasets/MuseData')
     # get the jsb dataset
     self.jsb = JSBChorales(path='../../../datasets/JSB Chorales')
     # get nottingham dataset
     self.nottingham = Nottingham(path='../../../datasets/Nottingham')
     # get the piano-midi-de dataset
     self.piano = PianoMidiDe(path='../../../datasets/Piano-midi.de')
Exemple #5
0
 def setUp(self):
     print "setting up!"
     # configure the root logger
     logger.config_root_logger()
     # get a logger for this session
     self.log = logging.getLogger(__name__)
     # get the muse dataset
     self.muse = MuseData()
     # get the jsb dataset
     # self.jsb = JSBChorales()
     # get nottingham dataset
     self.nottingham = Nottingham()
Exemple #6
0
 def setUp(self):
     # configure the root logger
     logger.config_root_logger()
     # get a logger for this session
     self.log = logging.getLogger(__name__)
     # get the muse dataset
     self.muse = MuseData()
     # get the jsb dataset
     self.jsb = JSBChorales()
     # get nottingham dataset
     self.nottingham = Nottingham()
     # get the piano-midi-de dataset
     self.piano = PianoMidiDe()
Exemple #7
0
class TestMuse(unittest.TestCase):
    def setUp(self):
        print("setting up!")
        # get the muse dataset
        self.muse = MuseData()
        # get the jsb dataset
        # self.jsb = JSBChorales()
        # get nottingham dataset
        self.nottingham = Nottingham()
        # get the piano-midi-de dataset
        # self.piano = PianoMidiDe()

    def testSizes(self):
        print('muse train %s' % str(self.muse.train.shape.eval()[0]))
        assert self.muse.train.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.muse.getDataShape(TRAIN)])
        assert self.muse.valid.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.muse.getDataShape(VALID)])
        assert self.muse.test.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.muse.getDataShape(TEST)])

        print('nottingham train %s' %
              str(self.nottingham.train.shape.eval()[0]))
        assert self.nottingham.train.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.nottingham.getDataShape(TRAIN)])
        assert self.nottingham.valid.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.nottingham.getDataShape(VALID)])
        assert self.nottingham.test.shape.eval()[0] == numpy.sum(
            [l[0] for l in self.nottingham.getDataShape(TEST)])

    def tearDown(self):
        del self.muse
        # del self.jsb
        del self.nottingham
        # del self.piano
        print("done!")
Exemple #8
0
class TestMuse(unittest.TestCase):

    def setUp(self):
        print "setting up!"
        # configure the root logger
        logger.config_root_logger()
        # get a logger for this session
        self.log = logging.getLogger(__name__)
        # get the muse dataset
        self.muse = MuseData()
        # get the jsb dataset
        # self.jsb = JSBChorales()
        # get nottingham dataset
        self.nottingham = Nottingham()
        # get the piano-midi-de dataset
        # self.piano = PianoMidiDe()


    def testSizes(self):
        print 'muse train', self.muse.train.shape.eval()[0]
        assert self.muse.train.shape.eval()[0] == numpy.sum([l[0] for l in self.muse.getDataShape(TRAIN)])
        assert self.muse.valid.shape.eval()[0] == numpy.sum([l[0] for l in self.muse.getDataShape(VALID)])
        assert self.muse.test.shape.eval()[0]  == numpy.sum([l[0] for l in self.muse.getDataShape(TEST)])

        print 'nottingham train', self.nottingham.train.shape.eval()[0]
        assert self.nottingham.train.shape.eval()[0] == numpy.sum([l[0] for l in self.nottingham.getDataShape(TRAIN)])
        assert self.nottingham.valid.shape.eval()[0] == numpy.sum([l[0] for l in self.nottingham.getDataShape(VALID)])
        assert self.nottingham.test.shape.eval()[0] == numpy.sum([l[0] for l in self.nottingham.getDataShape(TEST)])


    def tearDown(self):
        del self.muse
        # del self.jsb
        del self.nottingham
        # del self.piano
        print "done!"
Exemple #9
0
def run_midi(dataset):
    log.info("Creating RNN-RBM for dataset %s!", dataset)

    outdir = "outputs/rnnrbm/%s/" % dataset

    # grab the MIDI dataset
    if dataset == 'nottingham':
        midi = Nottingham()
    elif dataset == 'jsb':
        midi = JSBChorales()
    elif dataset == 'muse':
        midi = MuseData()
    elif dataset == 'piano_de':
        midi = PianoMidiDe()
    else:
        raise AssertionError("dataset %s not recognized." % dataset)

    # create the RNN-RBM
    # rng = numpy.random
    # rng.seed(0xbeef)
    # mrg = RandomStreams(seed=rng.randint(1 << 30))
    rng = numpy.random.RandomState(1234)
    mrg = RandomStreams(rng.randint(2**30))
    # rnnrbm = RNN_RBM(input_size=88,
    #                  hidden_size=150,
    #                  rnn_hidden_size=100,
    #                  k=15,
    #                  weights_init='gaussian',
    #                  weights_std=0.01,
    #                  rnn_weights_init='gaussian',
    #                  rnn_weights_std=0.0001,
    #                  rng=rng,
    #                  outdir=outdir)
    rnnrbm = RNN_RBM(
        input_size=88,
        hidden_size=150,
        rnn_hidden_size=100,
        k=15,
        weights_init='gaussian',
        weights_std=0.01,
        rnn_weights_init='identity',
        rnn_hidden_activation='relu',
        # rnn_weights_init='gaussian',
        # rnn_hidden_activation='tanh',
        rnn_weights_std=0.0001,
        mrg=mrg,
        outdir=outdir)

    # make an optimizer to train it
    optimizer = SGD(model=rnnrbm,
                    dataset=midi,
                    epochs=200,
                    batch_size=100,
                    min_batch_size=2,
                    learning_rate=.001,
                    save_freq=10,
                    stop_patience=200,
                    momentum=False,
                    momentum_decay=False,
                    nesterov_momentum=False)

    optimizer = AdaDelta(
        model=rnnrbm,
        dataset=midi,
        epochs=200,
        batch_size=100,
        min_batch_size=2,
        # learning_rate=1e-4,
        learning_rate=1e-6,
        save_freq=10,
        stop_patience=200)

    ll = Monitor('pseudo-log', rnnrbm.get_monitors()['pseudo-log'], test=True)
    mse = Monitor('frame-error',
                  rnnrbm.get_monitors()['mse'],
                  valid=True,
                  test=True)

    plot = Plot(bokeh_doc_name='rnnrbm_midi_%s' % dataset,
                monitor_channels=[ll, mse],
                open_browser=True)

    # perform training!
    optimizer.train(plot=plot)
    # use the generate function!
    generated, _ = rnnrbm.generate(initial=None, n_steps=200)

    dt = 0.3
    r = (21, 109)
    midiwrite(outdir + 'rnnrbm_generated_midi.mid', generated, r=r, dt=dt)

    if has_pylab:
        extent = (0, dt * len(generated)) + r
        pylab.figure()
        pylab.imshow(generated.T,
                     origin='lower',
                     aspect='auto',
                     interpolation='nearest',
                     cmap=pylab.cm.gray_r,
                     extent=extent)
        pylab.xlabel('time (s)')
        pylab.ylabel('MIDI note number')
        pylab.title('generated piano-roll')

    # Construct image from the weight matrix
    image = Image.fromarray(
        tile_raster_images(
            X=rnnrbm.W.get_value(borrow=True).T,
            img_shape=closest_to_square_factors(rnnrbm.input_size),
            tile_shape=closest_to_square_factors(rnnrbm.hidden_size),
            tile_spacing=(1, 1)))
    image.save(outdir + 'rnnrbm_midi_weights.png')

    log.debug("done!")
    del midi
    del rnnrbm
    del optimizer