-
Notifications
You must be signed in to change notification settings - Fork 3
/
NuMozart.py~
145 lines (110 loc) · 4.2 KB
/
NuMozart.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /usr/bin/env python
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
#
# ----------------------------------------------------------------------
# TODO:
"""
"""
# IMPORTS: ###########################
import glob
import os
import sys
import cPickle
import numpy
import utils
import model_params
try:
import pylab
except ImportError:
print (
"pylab isn't available. If you use its functionality, it will crash."
)
print "It can be installed with 'pip install -q Pillow'"
from midi.utils import midiread, midiwrite
#############################
# Data-Processing Functions: ###################
###############################################
# Generation Functions: ###############################
###########################################
# Data-Processing Functions: ###################
###############################################
# MAIN ###############################################
if __name__ == '__main__':
print " This will train on the given dataset and generate 20, hopefully enjoyable, sequences..."
# Function Calls:
############
#saving or loading?
saving = True #set true if saving is wanted
loading = False #set True if immidiatly continiung is wanted
# Plotting ?
plotting = False
#######
if saving == True:
model, files, costst = test_rnnrbm()
print "Saving current learning!"
save = model, costst
cPickle.dump(save, open( "save_learning_progress2Nott.p", "wb" ) )
print "Data saved!"
print "Proceeding with the model's Sample generation..."
elif loading == True:
print "Loading the current Model and proceeding to learn..."
saved = cPickle.load( open( "save_learning_progress.p", "rb" ) )
modelsaved, coststsaved = saved
#proceed learning:
print "Model loaded. Begin learning."
model, files, costst = test_rnnrbm(modelin = modelsaved, costsold = coststsaved)
print "Saving current learning status!"
save = model, costst
cPickle.dump(save, open( "save_learning_progress2Nott.p", "wb" ) )
print "Data saved!"
print "Proceeding with the model's Sample generation..."
else:
print "Error: Please select either loading or saving to start the model!"
########### Pianoroll Plotting:
if plotting:
import matplotlib.pyplot as plt
plt.plot(costst)
plt.title('Cost function')
plt.ylabel('Mean Energy-Cost')
plt.xlabel('Training iterations')
plt.show()
model.generate('sample1.mid')
model.generate('sample2.mid')
model.generate('sample3.mid')
model.generate('sample4.mid')
model.generate('sample5.mid')
model.generate('sample6.mid')
model.generate('sample7.mid')
model.generate('sample8.mid')
model.generate('sample9.mid')
model.generate('sample10.mid')
model.generate('sample11.mid')
model.generate('sample12.mid')
model.generate('sample13.mid')
model.generate('sample14.mid')
model.generate('sample15.mid')
model.generate('sample16.mid')
model.generate('sample17.mid')
model.generate('sample18.mid')
model.generate('sample19.mid')
model.generate('sample20.mid')
pylab.show()
#########################################