This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creating the class Mobile | |
class Mobile: | |
def __init__(self, serviceProvider, mobileNumber, dataUsed, paymentMethod): | |
self.serviceProvider = serviceProvider | |
self.mobileNumber = mobileNumber | |
self.dataUsed = dataUsed | |
self.paymentMethod = paymentMethod | |
# Creating the class Bill | |
class Bill: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creating the class Apartment | |
class Apartment: | |
def __init__(self, flatNumber, ownerName, billAmount): | |
self.flatNumber = flatNumber | |
self.ownerName = ownerName | |
self.billAmount = billAmount | |
# Creating the class Apartment_Demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
offset = 0 # Time | |
output_notes = [] | |
for pattern in prediction_output: | |
# if the pattern is a chord | |
if ('+' in pattern) or pattern.isdigit(): | |
notes_in_chord = pattern.split('+') | |
temp_notes = [] | |
for current_note in notes_in_chord: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sequence_length = 100 | |
network_input = [] | |
for i in range(len(notes) - sequence_length): | |
seq_in = notes[i : i+sequence_length] # contains 100 values | |
network_input.append([ele_to_int[ch] for ch in seq_in]) | |
# Any random start index | |
start = np.random.randint(len(network_input) - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Sequential, load_model | |
from keras.layers import * | |
from keras.callbacks import ModelCheckpoint, EarlyStopping | |
model = Sequential() | |
model.add( LSTM(units=512, | |
input_shape = (normalised_network_input.shape[1], normalised_network_input.shape[2]), | |
return_sequences = True) ) | |
model.add( Dropout(0.3) ) | |
model.add( LSTM(512, return_sequences=True) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No. of examples | |
n_patterns = len(network_input) | |
print(n_patterns) | |
# Desired shape for LSTM | |
network_input = np.reshape(network_input, (n_patterns, sequence_length, 1)) | |
print(network_input.shape) | |
normalised_network_input = network_input/float(n_vocab) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hoe many elements LSTM input should consider | |
sequence_length = 100 | |
# All unique classes | |
pitchnames = sorted(set(notes)) | |
# Mapping between ele to int value | |
ele_to_int = dict( (ele, num) for num, ele in enumerate(pitchnames) ) | |
network_input = [] | |
network_output = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n_vocab = len(set(notes)) | |
print("Total notes- ", len(notes)) | |
print("Unique notes- ", n_vocab) | |
#output: Total notes- 60498 | |
# Unique notes- 359 | |
print(notes[100:200]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notes = [] | |
for file in glob.glob("midi_songs/*.mid"): | |
midi = converter.parse(file) # Convert file into stream.Score Object | |
print("parsing %s"%file) | |
elements_to_parse = midi.flat.notes | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notes_demo = [] | |
for ele in elements_to_parse: | |
# If the element is a Note, then store it's pitch | |
if isinstance(ele, note.Note): | |
notes_demo.append(str(ele.pitch)) | |
# If the element is a Chord, split each note of chord and join them with + | |
elif isinstance(ele, chord.Chord): | |
notes_demo.append("+".join(str(n) for n in ele.normalOrder)) |
NewerOlder