def trainTimed(self, epochs, ds): start = time.clock() self.rdm.train(ds.rhythmTimesteps) rdm = time.clock() print('RDM: {}'.format(rdm-start)) mel.trainNetwork(self.net, ds.melodyDS, epochs) net = time.clock() print('Net: {}'.format(net-rdm)) bestHMM = self.hmm bestScore = -np.inf bestI = -1 for i in range(10): nextHMM = deepcopy(self.hmm) nextHMM.fit(ds.rhythmSamps, ds.rhythmLens) nextScore = nextHMM.score(ds.rhythmSamps, ds.rhythmLens) # print('Score {}: {}'.format(i,nextScore)) if nextScore > bestScore: bestHMM = nextHMM bestScore = nextScore bestI = i self.hmm = bestHMM hmm = time.clock() print('RDM: {}'.format(rdm-start)) print('Net: {}'.format(net-rdm)) print('HMM: {}'.format(hmm-net)) print('Total: {}'.format(hmm-start))
def train(self, epochs, tracks): trackDS = TrackDataSet(tracks) mel.trainNetwork(self.net, trackDS.melodyDS, epochs) bestHMM = self.hmm bestScore = 0 for i in range(20): nextHMM = deepcopy(self.hmm) nextHMM.fit(trackDS.rhythmSamps, trackDS.rhythmLens) nextScore = nextHMM.score(trackDS.rhythmSamps, trackDS.rhythmLens) if nextScore > bestScore: bestHMM = nextHMM bestScore = nextScore self.rdm.train(trackDS.rhythmTimesteps) self.hmm = bestHMM