Melody = chords_n_notes ( Music ) Melody_midi = stream. insert ( seed, len ( seed ), index_N ) seed = seed #Now, we have music in form or a list of chords and notes and we want to be a midi file. append ( index ) Music = for char in Notes_Generated ] seed = np. argmax ( prediction ) index_N = index / float ( L_symb ) Notes_Generated. exp ( prediction ) prediction = exp_preds / np. log ( prediction ) / 1.0 #diversity exp_preds = np. predict ( seed, verbose = 0 ) prediction = np. reshape ( 1, length, 1 ) prediction = model. summary () Model : "sequential_1" _ Layer ( type ) Output Shape Param # = lstm_2 ( LSTM ) ( None, 40, 512 ) 1052672 dropout_2 ( Dropout ) ( None, 40, 512 ) 0 lstm_3 ( LSTM ) ( None, 256 ) 787456 dense_2 ( Dense ) ( None, 256 ) 65792 dropout_3 ( Dropout ) ( None, 256 ) 0 dense_3 ( Dense ) ( None, 388 ) 99716 = Total params : 2, 005, 636 Trainable params : 2, 005, 636 Non - trainable params : 0 _ĭef Malody_Generator ( Note_Count ): seed = X_seed Music = "" Notes_Generated = for i in range ( Note_Count ): seed = seed. compile ( loss = 'categorical_crossentropy', optimizer = opt ) #Initialising the Model model. shape, activation = 'softmax' )) #Compiling the model for training opt = Adamax ( learning_rate = 0.01 ) model. shape ), return_sequences = True )) model. #Initialising the Model model = Sequential () #Adding layers model. append ( mapping ) L_datapoints = len ( targets ) print ( "Total number of sequences in the Corpus:", L_datapoints ) Total number of sequences in the Corpus : 53998 symb = sorted ( list ( set ( Corpus ))) L_corpus = len ( Corpus ) #length of corpus L_symb = len ( symb ) #length of total unique characters #Building dictionary to access the vocabulary from indices and vice versa mapping = dict (( c, i ) for i, c in enumerate ( symb )) reverse_mapping = dict (( i, c ) for i, c in enumerate ( symb )) print ( "Total number of characters:", L_corpus ) print ( "Number of unique characters:", L_symb ) Total number of characters : 54038 Number of unique characters : 388 #Splitting the Corpus in equal length of strings and output target length = 40 features = targets = for i in range ( 0, L_corpus - length, 1 ): feature = Corpus target = Corpus features. # Storing all the unique characters present in my corpus to bult a mapping dic. xlabel ( "Frequency Of Chords in Corpus" ) plt. title ( "Frequency Distribution Of Notes In The Corpus" ) plt. axvline ( x = 100, color = "#DBACC1" ) plt. hist ( Recurrence, bins = bins, color = "#97BACB" ) plt. arange ( 0 ,( max ( Recurrence )), 50 ) plt. figure ( figsize = ( 18, 3 ), facecolor = "#97BACB" ) bins = np. values ()) #Average recurrenc for a note in Corpus def Average ( lst ): return sum ( lst ) / len ( lst ) print ( "Average recurrenc for a note in Corpus:", Average ( Recurrence )) print ( "Most frequent note in Corpus appeared:", max ( Recurrence ), "times" ) print ( "Least frequent note in Corpus appeared:", min ( Recurrence ), "time" ) Average recurrenc for a note in Corpus : 139.27319587628867 Most frequent note in Corpus appeared : 1586 times Least frequent note in Corpus appeared : 1 time # Plotting the distribution of Notes plt. Print ( "First fifty values in the Corpus:", Corpus ) First fifty values in the Corpus : #Creating a count dictionary count_num = Counter ( Corpus ) print ( "Total unique notes in the Corpus:", len ( count_num )) Total unique notes in the Corpus : 388 #Exploring the notes dictionary Notes = list ( count_num.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |