Exemple #1
0
def evalModelTesting(model, params):
	roll = dataUtils.createRepresentation(params["testDir"], limitSongs=50, reductionRatio=params["reductionRatio"])
	#remove songs that contain notes out of params["notesMap"]
	#only with Y, we can take the roll and remove the 1st dimension	
	Y = np.zeros((0,len(params["notesMap"])))
	count = 0
	for song in roll:
		songNotes = set()
		for i in range(song.shape[0]):
			for j in range(song.shape[1]):
				if song[i][j] == 1 and j not in songNotes:
					songNotes.add(j)
		if songNotes.issubset(set(params["notesMap"])):
			notesDel = set(range(129)).difference(params["notesMap"])
			song = np.delete(song, list(notesDel), 1)
			Y = np.concatenate((Y,song))
			count += 1

	print "%d songs" % count

	return evalModel(model, Y)
Exemple #2
0
def evalModelTesting(model, params):
    roll = dataUtils.createRepresentation(
        params["testDir"],
        limitSongs=50,
        reductionRatio=params["reductionRatio"])
    #remove songs that contain notes out of params["notesMap"]
    #only with Y, we can take the roll and remove the 1st dimension
    Y = np.zeros((0, len(params["notesMap"])))
    count = 0
    for song in roll:
        songNotes = set()
        for i in range(song.shape[0]):
            for j in range(song.shape[1]):
                if song[i][j] == 1 and j not in songNotes:
                    songNotes.add(j)
        if songNotes.issubset(set(params["notesMap"])):
            notesDel = set(range(129)).difference(params["notesMap"])
            song = np.delete(song, list(notesDel), 1)
            Y = np.concatenate((Y, song))
            count += 1

    print "%d songs" % count

    return evalModel(model, Y)
from keras.callbacks import ModelCheckpoint

#We need to ensure we're using Python 2.7.x for it to work
if sys.version_info[0] is not 2 and sys.version_info[1] is not 7:
	print("Please run this program with Python 2.7")
	sys.exit(-1)

if len(sys.argv) < 2:
	print("Please specify directory for the model")

print("Loading params...")
path = sys.argv[1] if sys.argv[1][-1] == '/' else sys.argv[1] + '/'
params = dataUtils.loadData(path + "params.nn")

print("Loading data...")
roll = dataUtils.createRepresentation("/Users/Bernat/Dropbox/UoE/Dissertation/midiFiles/", limitSongs=params["limitSongs"], reductionRatio=params["reductionRatio"]) #array of "piano roll" like representations

print("Regenerating inputs")
X, Y = dataUtils.createModelInputs(roll, padding=params["padding"], seqLength=params["seqLength"], inc=params["inc"])
X, Y, notesMap = dataUtils.compressInputs(X, Y)
Y = np.delete(Y, list([53,55]), 1)
notesMap.remove(87)
notesMap.remove(89)
input_dim = len(notesMap)

if notesMap != params["notesMap"]:
	print("Notes maps don't match!")
	print(notesMap)
	print(params["notesMap"])

print("Building model...")
Exemple #4
0
#We need to ensure we're using Python 2.7.x for it to work
if sys.version_info[0] is not 2 and sys.version_info[1] is not 7:
    print("Please run this program with Python 2.7")
    sys.exit(-1)

if len(sys.argv) < 2:
    print("Please specify directory for the model")

print("Loading params...")
path = sys.argv[1] if sys.argv[1][-1] == '/' else sys.argv[1] + '/'
params = dataUtils.loadData(path + "params.nn")

print("Loading data...")
roll = dataUtils.createRepresentation(
    "/Users/Bernat/Dropbox/UoE/Dissertation/midiFiles/",
    limitSongs=params["limitSongs"],
    reductionRatio=params["reductionRatio"]
)  #array of "piano roll" like representations

print("Regenerating inputs")
X, Y = dataUtils.createModelInputs(roll,
                                   padding=params["padding"],
                                   seqLength=params["seqLength"],
                                   inc=params["inc"])
X, Y, notesMap = dataUtils.compressInputs(X, Y)
Y = np.delete(Y, list([53, 55]), 1)
notesMap.remove(87)
notesMap.remove(89)
input_dim = len(notesMap)

if notesMap != params["notesMap"]:
Exemple #5
0
	print(key + ":  " + str(value))

while 1:
	user_input = raw_input("Continue? [y]/n: ")
	if user_input == 'n':
		print("Exiting...")
		sys.exit(-1)
	elif user_input == 'y' or user_input == '':
		break
	else:
		print("Please press ENTER or 'y' if you want to continue, or 'n' if you wish to abort.")
		continue

#Load data
print("Loading data...")
roll = dataUtils.createRepresentation(params["dataDir"], limitSongs=params["limitSongs"], reductionRatio=params["reductionRatio"]) #array of "piano roll" like representations

#Transform 
print("Creating output sequences...")
X, Y = dataUtils.createModelInputs(roll, padding=params["padding"], seqLength=params["seqLength"], inc=params["inc"])
X, Y, notesMap = dataUtils.compressInputs(X, Y)
input_dim = len(notesMap)

#Training data shape:
# X -> (nb_samples, timesteps, input_dim) => "sequences of tones"
# Y -> (nb_samples, input_dim) => "next tone for every sequence"

#Build model
print("Building model...")
model = Sequential()
model.add(LSTM(input_dim, input_dim*2, return_sequences=True))