• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.midiread函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中midi.utils.midiread函数的典型用法代码示例。如果您正苦于以下问题:Python midiread函数的具体用法?Python midiread怎么用?Python midiread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了midiread函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: train

	def train(self, file_name, weight_save_file, batch_size=1, num_epoch=200):
                print('load data ---------------')

                file_train=os.path.join(os.path.split(os.path.dirname(__file__))[0],
                                'data',file_name,'train','*.mid')
                dataset = [midiread(f, self.r, self.dt).piano_roll.astype(theano.config.floatX) for f in glob.glob(file_train)]

                file_test=os.path.join(os.path.split(os.path.dirname(__file__))[0],
                                'data',file_name,'test','*.mid')
                testdataset = [midiread(f, self.r, self.dt).piano_roll.astype(theano.config.floatX) for f in glob.glob(file_test)]
                print('load done --------------')
                try:
                        for epoch in range(num_epoch):
                                t0 = time.time()
                                numpy.random.shuffle(dataset)
                                costs = []
                                accuracys = []
                                for s, sequence in enumerate(dataset):
                                        y = numpy.hstack((sequence,numpy.zeros((sequence.shape[0],1)) ))
                                        x = numpy.roll(y, 1, axis=0)
                                        x[0,:]=0
                                        x[0,self.maxFeatures-1]=1
                                        cost, accuracy= self.rnnModel.train_on_batch(numpy.array([x]), numpy.array([y]), accuracy=True)
                                        costs.append(cost)
                                        accuracys.append(accuracy)

                                print('epoch: %i/%i\tcost: %.5f\taccu: %.5f\ttime: %.4f s' % (epoch+1, num_epoch, numpy.mean(costs), numpy.mean(accuracys),time.time()-t0))
                                sys.stdout.flush()
                                test_accu=self.evaluate(testdataset)
                                print('test_accu: %.5f' % ( numpy.mean(test_accu)) )
                        self.rnnModel.save_weights(weight_save_file)
                except KeyboardInterrupt:
                        print('interrupt by user !')
开发者ID:chengjunwen,项目名称:music_rnn,代码行数:33,代码来源:rnnmlp.py


示例2: modeling_n_gram

def modeling_n_gram(n, files):
    
	assert len(files) > 0, 'Training set is empty!' \
					' (did you download the data files?)'
					
	for f in files:

		print 'parsing', f

		each = midiread(f).piano_roll.astype(theano.config.floatX)
		numNote = len(each[0])

		# each [ time ] [ note ]
	
		for timeSlice in range(n-1, len(each)):
			for noteDest in range(numNote):
				valueDest = int(each[timeSlice][noteDest])
				for noteFrom in range(numNote):
					valueFrom = int(each[timeSlice-1][noteFrom])
					
					#print noteDest,valueDest,noteFrom,valueFrom
					
					probability[noteDest][valueDest][noteFrom][valueFrom] \
						= probability[noteDest][valueDest][noteFrom][valueFrom] + 1.0
						
	print 'learning_done'
	
	pkl.dump(probability, open("bi-gram-count.dat", "wb"))
	
	print 'bi-gram-count.dat saved'
开发者ID:xxjjvxb,项目名称:compose_bot,代码行数:30,代码来源:bi-gram-counter.py


示例3: load_dataset

    def load_dataset(self):
        re = ["data/JSB Chorales/train/*.mid"]
        re.append("data/JSB Chorales/test/*.mid")
        re.append("data/JSB Chorales/valid/*.mid")
        files = []
        for r in re:
            files += glob.glob(r)
        assert(len(files) > 0)
        print "generating dataset..."
        dataset = [midiread(f, self.r, self.dt).piano_roll.astype(theano.config.floatX) for f in files]
    
        memorization_dataset = [[]]  # memorize the first unit for 100 time-steps with binary noise

        n = 0

        for seq in dataset:
            for i in range(0, len(seq), self.seq_length):
                memorization_dataset[0].append(seq[i:i + self.seq_length])

        while False: #n < 100000:
            sequence = random.choice(dataset)
            if len(sequence) < self.seq_length:
                print " to short !"
            i = random.choice(range(0, len(sequence), self.seq_length))
            memorization_dataset[0].append(sequence[i:i + self.seq_length])
            n = n + 1

        print "number of sequence for training : ", len(memorization_dataset[0])

        self.train = [memorization_dataset[0][:-1000]]
        self.valid = [memorization_dataset[0][-1000:]]

        self.gradient_dataset = SequenceDataset(self.train, batch_size=None, number_batches=1000)
        self.cg_dataset = SequenceDataset(self.train, batch_size=None, number_batches=500)
        self.valid_dataset = SequenceDataset(self.valid, batch_size=None, number_batches=500)
开发者ID:clement91190,项目名称:musicbot,代码行数:35,代码来源:train_midi.py


示例4: train

    def train(self, files, batch_size=100, num_epochs=200):
        '''Train the RNN-RBM via stochastic gradient descent (SGD) using MIDI
        files converted to piano-rolls.

        files : list of strings --- List of MIDI files that will be loaded as piano-rolls for training.
        batch_size : integer    --- Training sequences will be split into subsequences of at most this size before applying the SGD updates.
        num_epochs : integer    --- Number of epochs (pass over the training set) performed. The user can safely interrupt training with Ctrl+C at any time.'''

        assert len(files) > 0, 'Training set is empty!' \
                               ' (did you download the data files?)'
        dataset = [midiread(f, self.r,
                            self.dt).piano_roll.astype(theano.config.floatX)
                   for f in files]

        try:
            for epoch in xrange(num_epochs):
                numpy.random.shuffle(dataset)
                costs = []

                for s, sequence in enumerate(dataset):
                    for i in xrange(0, len(sequence), batch_size):
                        cost = self.train_function(sequence[i:i + batch_size])
                        costs.append(cost)

                print 'Epoch %i/%i' % (epoch + 1, num_epochs),
                print numpy.mean(costs)
                sys.stdout.flush()

        except KeyboardInterrupt:
            print 'Interrupted by user.'
开发者ID:ayushmi,项目名称:Piano_Transcription,代码行数:30,代码来源:rnnrbm.py


示例5: load_jsb

def load_jsb(path):
    mkdir_p(path)
    d = os.path.join(path, 'JSB Chorales')
    if not os.path.isdir(d):
        download_jsb(path)

    train_filenames = os.path.join(path, 'JSB Chorales', 'train', '*.mid')
    valid_filenames = os.path.join(path, 'JSB Chorales', 'valid', '*.mid')
    test_filenames = os.path.join(path, 'JSB Chorales', 'test', '*.mid')
    train_files = glob.glob(train_filenames)
    valid_files = glob.glob(valid_filenames)
    test_files = glob.glob(test_filenames)

    train_datasets = [midiread(f, r=(21, 109), dt=0.3).piano_roll.astype(theano.config.floatX) for f in train_files]
    valid_datasets = [midiread(f, r=(21, 109), dt=0.3).piano_roll.astype(theano.config.floatX) for f in valid_files]
    test_datasets = [midiread(f, r=(21, 109), dt=0.3).piano_roll.astype(theano.config.floatX) for f in test_files]

    return (train_datasets, [None]), (valid_datasets, [None]), (test_datasets, [None])
开发者ID:mbeissinger,项目名称:recurrent_gsn,代码行数:18,代码来源:data_tools.py


示例6: load_midi_data

def load_midi_data(data_dir):
    import midi.utils as utils
    from midi import MidiInFile as mf
    from midi import MidiToText as mt

    f = open(data_dir, 'rb')
    midiIn = mf.MidiInFile(mt.MidiToText(), f)
    midiIn.read()
    f.close()

    midi_data = utils.midiread(data_dir, dt=0.5)
    return midi_data.piano_roll
开发者ID:ruohoruotsi,项目名称:Investigaciones,代码行数:12,代码来源:dataset.py


示例7: LoadDataForPreTraining

def LoadDataForPreTraining(r=(21, 109), dt=0.3):

    assert len(trainingSet) > 0, 'Training set is empty!' \
                           ' (did you download the data files?)'
    sampleLen=[]
    dataset=[]
    maxLen=0
    nSample=0
    for f in trainingSet:
        currentMidi=midiread(f, (21, 109),0.3).piano_roll
        dataset.append(currentMidi)
        sampleLen.append(currentMidi.shape[0])
        if maxLen< currentMidi.shape[0]:
            maxLen=currentMidi.shape[0]
        nSample=nSample+1
    return (dataset, sampleLen, nSample, maxLen)
开发者ID:jiangnanHugo,项目名称:autoencodersRNN,代码行数:16,代码来源:rnnSparsek23Print.py


示例8: train

    def train(self, files, batch_size=100, num_epochs=200):
        '''Train the RNN-RBM via stochastic gradient descent (SGD) using MIDI
        files converted to piano-rolls.

        files : list of strings
            List of MIDI files that will be loaded as piano-rolls for training.
        batch_size : integer
            Training sequences will be split into subsequences of at most this
            size before applying the SGD updates.
        num_epochs : integer
            Number of epochs (pass over the training set) performed. The user
            can safely interrupt training with Ctrl+C at any time.'''

        assert len(files) > 0, 'Training set is empty!' \
                               ' (did you download the data files?)'
        dataset = [midiread(f, self.r,
                            self.dt).piano_roll.astype(theano.config.floatX)
                   for f in files]
        print "Start training process of the recurrent network RBM machine with the given dataset..." ,
        print "Lenght of the Dataset: ", len(files)
        print "Interrupt if necessariy by pressing Ctrl+C",
        print "...Might take some time :) ..."
        costst = []
        try:
            for epoch in xrange(num_epochs):
                numpy.random.shuffle(dataset)
                costs = []

                for s, sequence in enumerate(dataset):
                    for i in xrange(0, len(sequence), batch_size):
                        cost = self.train_function(sequence[i:i + batch_size])
                        costs.append(cost)

                print 'Epoch %i/%i' % (epoch + 1, num_epochs),
                print "Current mean Energy cost:", numpy.mean(costs)
                costst.append(numpy.mean(costs))
                print "Training %i percent done; interrupt training by pressing Crtl+C." % (float((float(epoch) + 1.0)*100.0 / float(num_epochs)))
                sys.stdout.flush()

        except KeyboardInterrupt:
            print 'Training Interrupted.'
            
        return self, files, costst
开发者ID:htm-community,项目名称:nupic.audio,代码行数:43,代码来源:NuMozart_RNNRBM.py


示例9: loadDataSet

def loadDataSet(files):
    #File e il path della carterlla contente i file (*.mid)
    assert len(files) > 0, 'Training set is empty!' \
                           ' (did you download the data files?)'
    #mi calcolo quel'el 'esempio di lunghezza massima
    maxLen=0
    dataset=[]
    for f in files:
        currentMidi=midiread(f, (21, 109),0.3).piano_roll.astype(theano.config.floatX)
        dataset.append(currentMidi)
        if maxLen< currentMidi.shape[0]:
            maxLen=currentMidi.shape[0]
    #porto tutte le tracce a masima lunghezza aggiongendo silenzio
    for i, seq in enumerate(dataset):
            if seq.shape[0]<maxLen:
                dataset[i]=np.concatenate([seq, np.zeros((maxLen-seq.shape[0], 88))])
                        
    #print dataset[0].shape
    return np.array(dataset, dtype=theano.config.floatX)
开发者ID:jiangnanHugo,项目名称:autoencodersRNN,代码行数:19,代码来源:rnnSparsek23Print.py


示例10: loadDataSetMin

def loadDataSetMin(files):
    #File e il path della carterlla contente i file (*.mid)
    assert len(files) > 0, 'Training set is empty!' \
                           ' (did you download the data files?)'
    #mi calcolo quel'el 'esempio di lunghezza massima
    minLen=sys.maxint
    dataset=[]
    for f in files:
        currentMidi=midiread(f, (21, 109),0.3).piano_roll.astype(theano.config.floatX)
        dataset.append(currentMidi)
        if minLen> currentMidi.shape[0]:
            minLen=currentMidi.shape[0]
    #porto tutte le tracce a masima lunghezza aggiongendo silenzio
    for i, seq in enumerate(dataset):
            if seq.shape[0]>minLen:
                dataset[i]=seq[0:minLen,:] 
                        
    #print dataset[0].shape
    #print "MINLEN: ", minLen
    return np.array(dataset, dtype=theano.config.floatX)
开发者ID:mohammadpz,项目名称:DeepRNN,代码行数:20,代码来源:second_Layer.py


示例11: train

    def train(self, files, batch_size=500, num_epochs=300):
        assert len(files) > 0, 'Training set is empty!' \
                               ' (did you download the data files?)'
        dataset = [midiread(f, self.r,
                            self.dt).piano_roll.astype(theano.config.floatX)
                   for f in files]
        try:
            for epoch in xrange(num_epochs):
                numpy.random.shuffle(dataset)
                costs = []

                for s, sequence in enumerate(dataset):
                    for i in xrange(0, len(sequence), batch_size):
                        cost = self.train_function(sequence[i:i + batch_size])
                        costs.append(cost)

                print 'Epoch %i/%i' % (epoch + 1, num_epochs),
                print numpy.mean(costs)
                sys.stdout.flush()

        except KeyboardInterrupt:
            print 'Interrupted by user.'
开发者ID:ZheLI0319,项目名称:LSTMRBM,代码行数:22,代码来源:lstmrbm.py


示例12: LoadDataForPreTraining

def LoadDataForPreTraining(r=(21, 109), dt=0.3):

    assert len(trainingSet) > 0, 'Training set is empty!' \
                           ' (did you download the data files?)'
    sampleLen=[]
    dataset=[]
    maxLen=0
    nSample=0
    for f in trainingSet:
        
        currentMidi=midiread(f, (21, 109),0.3).piano_roll
        print f,": lenght= ",currentMidi.shape[0]
        sampleLen.append(currentMidi.shape[0])
        
        if maxLen< currentMidi.shape[0]:
            maxLen=currentMidi.shape[0]
        nSample=nSample+1
    print "#-----dataset data-----#"
    print "number of sample: ", len(trainingSet)
    print "max lenght:", maxLen
    print "# rows of matrix M:",sum(sampleLen)
    print "# columns of matrix M:", maxLen*88
    return (dataset, sampleLen, nSample, maxLen)
开发者ID:jiangnanHugo,项目名称:autoencodersRNN,代码行数:23,代码来源:dataset_Test.py


示例13: main

def main():

    #--- import data ---#
    sizeOfMiniBatch = 5 #how many tunes per miniBatch
    noOfEpoch = 100 
    noOfEpochPerMB = 2
    lengthOfMB = 100
    sparseParam = np.float32(0.01) #increases with no. of cells
    path = './Piano-midi.de/train-individual/hpps'
    #path = './Piano-midi.de/train'
    files = os.listdir(path)
    assert len(files) > 0, 'Training set is empty!' \
                               ' (did you download the data files?)'
    #pitch range is from 21 to 109
    dataset = [midiread((path + "/" + f), (21, 109),0.3).piano_roll.astype(theano.config.floatX) for f in files]
                  
    #check number of notes for each tune:       
    print(str([np.array(dataset[n]).shape[0] for n in np.arange(np.array(dataset).shape[0])]))

    # set "silent" to zero in 1-hot format
    for k in np.arange(np.array(dataset).shape[0]):
        for n in np.arange(0,np.array(dataset[k]).shape[0],1):
            if np.sum(dataset[k][n], dtype=theano.config.floatX) == 0 :
                dataset[k][n][0] = np.float32(1.0)
                

    #--- training with data ---#
    
    myRNN4Music = RNN4Music(h1_length=176, h2_length=176, h3_length=176, io_length=88, R1=np.float32(0.001), R2=np.float32(0.001), R3=np.float32(0.001), Rout=np.float32(0.001)) 
    
    #myRNN4Music.loadParameters('120_120_120_0_001_xEn_150epoch_hpps')
    #myRNN4Music.loadParameters('120_120_120_0_001_sqr_150epoch_hpps')
    myRNN4Music.loadParameters('176_176_176_0_001_xEn_L1_0_01_100epoch_hpps')
    #myRNN4Music.saveParameters('176_176_176_0_001_xEn_L1_0_1_300epoch_hpps')
    
    #myRNN4Music.train(dataset, noOfEpochPerMB, noOfEpoch, sizeOfMiniBatch, lengthOfMB, sparseParam)
    #myRNN4Music.saveParameters('176_176_176_0_001_xEn_L1_0_01_100epoch_hpps')
    #myRNN4Music.train(dataset, noOfEpochPerMB, noOfEpoch, sizeOfMiniBatch, lengthOfMB, sparseParam)
    #myRNN4Music.saveParameters('176_176_176_0_001_xEn_L1_0_01_200epoch_hpps')
    #myRNN4Music.train(dataset, noOfEpochPerMB, noOfEpoch, sizeOfMiniBatch, lengthOfMB, sparseParam)
    #myRNN4Music.saveParameters('176_176_176_0_001_xEn_L1_0_01_300epoch_hpps')
    #myRNN4Music.train(dataset, noOfEpochPerMB, noOfEpoch, sizeOfMiniBatch, lengthOfMB, sparseParam)
    #myRNN4Music.saveParameters('176_176_176_0_001_xEn_L1_0_01_400epoch_hpps')




    #--- plot some genearted tunes ---#

    for baseSample in np.array([0, 20, 15, 31]):
        exampleLength = 50
        myRNN4Music.resetStates()
        generatedTune = myRNN4Music.genMusic(np.float32(dataset[baseSample][0:exampleLength]), 300)
        midiwrite('176_176_176_0_001_sqr_hpps150_' + str(baseSample) + '.mid', generatedTune[0], (21, 109),0.3)
        #generatedTune[0] is the tune, generatedTune[1] is the probability at each iteration
        
        #plot genearted probability
        plt.figure(0 + baseSample*100)
        plt.imshow(np.array(generatedTune[1][0:50,25:65]), origin = 'lower', extent=[25,65,0,50], aspect=0.5,
                        interpolation = 'nearest', cmap='gist_stern_r')
        plt.title('probability of generated midi note piano-roll')
        plt.xlabel('midi note')
        plt.ylabel('sample number (time steps)')
        plt.colorbar()##
        #plot leading example for generation
        plt.figure(1 + baseSample*100)
        plt.imshow(np.transpose(dataset[baseSample]), origin='lower', aspect='auto',
                                 interpolation='nearest', cmap=pylab.cm.gray_r)
        plt.colorbar()
        plt.title('original piano-roll')
        plt.xlabel('sample number (time steps)')
        plt.ylabel('midi note')

        #plot generated tune
        plt.figure(2 + baseSample*100)
        plt.imshow(np.transpose(np.array(generatedTune[0][0:500])), origin='lower', aspect='auto',
                                 interpolation='nearest', cmap=pylab.cm.gray_r)
        plt.colorbar()
        plt.title('generated piano-roll')
        plt.xlabel('sample number (time steps)')
        plt.ylabel('midi note')
    plt.show()
开发者ID:freerangehen,项目名称:LSTMmusic,代码行数:82,代码来源:LSTMmusic_main.py


示例14: range

      save_dir = './'

      ### read MIDI
      #data_dir = '../Data/Cirriculum/easy/'
      #data_dir = '../biaxial-rnn-music-composition/music/'

      files = os.listdir(data_dir)
      files = [data_dir + f for f in files if '.mid' in f or '.MID' in f]

      print files 

      dataset = []

      for f in files:
          try:
              dataset.append(midiread(f, MIDI_RANGE, DT).piano_roll)
              print "{} loaded".format(f)
          except IndexError:
              print "Skipping {}".format(f)
              pass

      print np.shape(dataset)

      X = []
      y = []

      for song in dataset:
          for i in range(0, len(song) - TICKS_PER_INPUT, STEP):
              X.append(song[i: i + TICKS_PER_INPUT])
              y.append(song[i + TICKS_PER_INPUT])
开发者ID:akandykeller,项目名称:Classical_Piano_Generation,代码行数:30,代码来源:dual_lstm_generate.py


示例15: get_ipython

# In[109]:

model.train(onlyfiles)


# In[117]:

model.generate('testHaydn3.mid')


# In[23]:

get_ipython().magic(u'pylab inline')
f = 'testNotthingham6.mid'
extent = (0, 0.25 * len(piano_roll)) + (21, 109)
piano_roll = midiread(f, (21, 109), 0.25).piano_roll.astype(theano.config.floatX)
pylab.figure()
pylab.imshow(piano_roll.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')
pylab.show()


# In[ ]:



开发者ID:jasonwang999,项目名称:CS281FinalProject,代码行数:27,代码来源:RNN.py


示例16: train

    def train(self, files, batch_size=100, num_epochs=200):
        '''Train the RNN-RBM via stochastic gradient descent (SGD) using MIDI
files converted to piano-rolls.

files : list of strings
  List of MIDI files that will be loaded as piano-rolls for training.
batch_size : integer
  Training sequences will be split into subsequences of at most this size
  before applying the SGD updates.
num_epochs : integer
  Number of epochs (pass over the training set) performed. The user can
  safely interrupt training with Ctrl+C at any time.'''

        assert len(files) > 0, 'Training set is empty!' \
                               ' (did you download the data files?)'
        dataset = [midiread(f, self.r,
                            self.dt).piano_roll.astype(theano.config.floatX)
                   for f in files]
        print "DONE DOWNLOADING"
        #self.pro.start()
        try:
            count = 0
            processed = 0
            inVecs = [self.inVecQueue,self.inVecQueue2,self.inVecQueue3,self.inVecQueue4,self.inVecQueue5,self.inVecQueue6,self.inVecQueue7,self.inVecQueue8]
            for epoch in xrange(num_epochs):
                numpy.random.shuffle(dataset)
                costs = []
                ''' self.l1.acquire()
                self.l2.acquire()
                self.l3.acquire()
                self.l4.acquire()
                self.l5.acquire()
                self.l6.acquire()
                self.l7.acquire()
                self.l8.acquire()'''
                #ds = chunks(dataset, len(dataset)/4)
                count = 0
                processed = 0
                for s, sequence in enumerate(dataset):
                       inVecs[s%8].put(sequence)
                       #count = count + len(sequence)/100
                       for j in xrange(0, len(sequence), batch_size):
                       #print "GIVING DATA"
                          count = count + 1
                       #inVecs[s%8].put(sequence[j:j+batch_size])
                '''self.l1.release()
                self.l2.release()
                self.l3.release()
                self.l4.release()
                self.l5.release()
                self.l6.release()
                self.l7.release()
                self.l8.release()'''
                while processed != count:
                   if self.costQueue.qsize()>0:
                      cost = self.costQueue.get()
                      costs.append(cost)
                      processed = processed + 1
                sums = []
                items = self.weightQueue.qsize()
                #while self.weightQueue.qsize() > 0:
                #   d = self.weightQueue.get()
                #   sums.append(d)
                adder = [None,None,None,None,None,None,None,None]
                for i in xrange(0,8):
                   q = self.weights[i].get()
                   for j in xrange(0,8):
                      if adder[j] == None:
                         adder[j] = q[j]
                      else:
                         adder[j] += q[j]
                for i in range(0,8):
                   adder[i] /= float(8)
                p = adder[0],adder[1],adder[2],adder[3],adder[4],adder[5],adder[6],adder[7]
                if epoch != num_epochs:
                   self.weightQueue.put(p)
                   self.weightQueue2.put(p)
                   self.weightQueue3.put(p)
                   self.weightQueue4.put(p)
                   self.weightQueue5.put(p)
                   self.weightQueue6.put(p)
                   self.weightQueue7.put(p)
                   self.weightQueue8.put(p)   
                print 'Epoch %i/%i' % (epoch + 1, num_epochs),
                print numpy.mean(costs)
                #print profmode.print_summary()
                sys.stdout.flush()

        except KeyboardInterrupt:
            print 'Interrupted by user.'
        self.pro.terminate()
        self.pro2.terminate()
        self.pro3.terminate()
        self.pro4.terminate()
        self.pro5.terminate()
        self.pro6.terminate()
        self.pro7.terminate()
        self.pro8.terminate()
        self.weightQueue.close()
        self.weightQueue2.close()
#.........这里部分代码省略.........
开发者ID:ChaseCarthen,项目名称:Music-Neural-Nets,代码行数:101,代码来源:rnnrbm.py


示例17: range

EPOCHS = 1000
BATCH_SIZE = 128
TICKS_PER_INPUT = MEASURES*TICKS_PER_MEASURE
GEN_LENGTH = TICKS_PER_INPUT*8
DT = 0.3
    
if __name__ == '__main__':

  ### read MIDI
  #data_dir = '../Data/Cirriculum/easy/'
  data_dir = '../biaxial-rnn-music-composition/music/'

  files = os.listdir(data_dir)
  files = [data_dir + f for f in files if '.mid' in f]

  dataset = [midiread(f, MIDI_RANGE, DT).piano_roll for f in files]

  X = []
  y = []

  for song in dataset:
      for i in range(0, len(song) - TICKS_PER_INPUT, STEP):
          X.append(song[i: i + TICKS_PER_INPUT])
          y.append(song[i + TICKS_PER_INPUT])

  max_samples = (len(X) // BATCH_SIZE) * BATCH_SIZE
  X = X[:max_samples]
  y = y[:max_samples]

  X = np.array(X)
  y = np.array(y)
开发者ID:sokolov-alex,项目名称:Neural-Networks,代码行数:31,代码来源:lstm_music.py


示例18: load_midi_data

def load_midi_data(data_dir):
    import midi.utils as utils

    midi_data = utils.midiread(data_dir, dt=0.5)

    return midi_data.piano_roll
开发者ID:RyotaKatoh,项目名称:chainer-Variational-Recurrent-Autoencoder,代码行数:6,代码来源:dataset.py


示例19: dirname

from scipy.io import wavfile
import numpy as np

THIS_DATA_DIR  = dirname(realpath(__file__))
DOWNLOADED_ZIP = join(THIS_DATA_DIR, "dataset.zip")
DOWNLOADED_DIR = join(THIS_DATA_DIR, "dataset")
FILE_URL="http://c4dm.eecs.qmul.ac.uk/rdr/bitstream/handle/123456789/13/Score-informed%20Piano%20Transcription%20Dataset.zip?sequence=1"

if __name__ == '__main__':
    if not exists(DOWNLOADED_ZIP):
        execute_bash("wget -O {path} {url}".format(url=FILE_URL, path=DOWNLOADED_ZIP))
    if exists(DOWNLOADED_DIR) and isdir(DOWNLOADED_DIR):
        execute_bash("rm -rf %s" % (DOWNLOADED_DIR))
    execute_bash("rm %s " % (join(THIS_DATA_DIR, "*.npy")))
    makedirs(DOWNLOADED_DIR)
    execute_bash("unzip %s -d %s" % (DOWNLOADED_ZIP, DOWNLOADED_DIR))

    files = collect_files_with_ext(DOWNLOADED_DIR, ".wav")

    for subpath, name in files:
        if name.endswith(".wav") and "Chromatic" not in name:
            sampling_rate, music = wavfile.read(subpath)
            np.save(join(THIS_DATA_DIR, name.replace(".wav", ".npy")), music)
            piece = midiread(str(subpath).replace(".wav", "_correct.mid"))
            np.save(join(THIS_DATA_DIR, name.replace(".wav", ".mid.npy")), piece.piano_roll)

    execute_bash("rm -rf %s" % (DOWNLOADED_DIR))
    execute_bash("rm -rf %s" % (DOWNLOADED_ZIP))

开发者ID:bhack,项目名称:Dali,代码行数:28,代码来源:generate.py



注:本文中的midi.utils.midiread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base._Unit函数代码示例发布时间:2022-05-27
下一篇:
Python midi.write_midifile函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap