def get_lead_encoder(self, encoder): m, conv_f, conv_win_size, enc_lstm_size = encoder.params lead_enc = MelodyEncoder(m=m, conv_f=conv_f, conv_win_size=1, enc_lstm_size=enc_lstm_size) return lead_enc
def init_with_Encoder(cls, encoder_params, rhythm_embed_size, dec_lstm_size, V, enc_use_meta=False, dec_use_meta=False, compile_now=False): melody_enc = MelodyEncoder(*encoder_params, compile_now=False) return cls(melody_encoder=melody_enc, rhythm_embed_size=rhythm_embed_size, dec_lstm_size=dec_lstm_size, V=V, enc_use_meta=enc_use_meta, dec_use_meta=dec_use_meta, compile_now=compile_now)
def from_saved_custom(cls, save_dir, melody_encoder=None, load_melody_encoder=False, compile_now=False): if melody_encoder and load_melody_encoder: raise ValueError( "MelodyEncoder *NOT* None and load_melody_encoder=True!") if not melody_encoder and not load_melody_encoder: raise ValueError( "MelodyEncoder *IS* None and load_melody_encoder=False!") if load_melody_encoder: with open(save_dir + "/melody_encoder_parameters.json", "r") as handle: melody_enc_params = json.load(handle) melody_encoder = MelodyEncoder(*melody_enc_params, compile_now=True) melody_encoder.load_weights(save_dir + "/melody_encoder_weights") for l in melody_encoder.layers: l.trainable = False melody_encoder.compile_default() with open(save_dir + "/chord_net_parameters.json", "r") as handle: params = json.load(handle) chord_net = cls(melody_encoder, *params, compile_now=compile_now) chord_net.load_weights(save_dir + "/chord_net_weights") return chord_net #%% #loaded_chord_net = ChordNetwork.from_saved_custom("Trainings/chord_test/chord", # load_melody_encoder=True, # compile_now=True)
ch_gen = ChordGenerator(music_dir, save_conversion_params="/".join([top_dir, save_dir]), to_list=False, meta_prep_f=None) # None # data_iter = ch_gen.generate_forever(batch_size=24) x, y = ch_gen.list_data() #%% comb_net = CombinedNetwork.from_saved_custom("/".join([top_dir, save_dir, "weights"]), meta_predictor, generation=True, compile_now=False) melody_enc = comb_net.melody_encoder size_1 = 1 fresh_melody_enc = MelodyEncoder(m=48, conv_f=4, conv_win_size=size_1, enc_lstm_size=52, compile_now=False) fresh_melody_enc.set_weights(get_smaller_weights(melody_enc, conv_win_size=size_1)) # for l in fresh_melody_enc.layers: # l.trainable = False fresh_melody_enc.compile_default() #%% chord_net = ChordNetwork(fresh_melody_enc, 28, ch_gen.V, compile_now=True) #%% log_dir = "chord_logs" tb = TensorBoard(log_dir="/".join([top_dir, save_dir, log_dir]))
bar_embedder = BarEmbedding(V=V_rhythm, beat_embed_size=beat_embed_size, embed_lstm_size=embed_lstm_size, out_size=out_size) rhythm_encoder = RhythmEncoder(bar_embedder=bar_embedder, context_size=rc_size, lstm_size=rhythm_enc_lstm_size) rhythm_net = RhythmNetwork(rhythm_encoder=rhythm_encoder, dec_lstm_size=rhythm_dec_lstm_size, V=V_rhythm, dec_use_meta=True, compile_now=True) # ATTENTION: conv_win_size must not be greater than context size! melody_encoder = MelodyEncoder(m=m, conv_f=conv_f, conv_win_size=min(mc_size, conv_win_size), enc_lstm_size=melody_enc_lstm_size) melody_net = MelodyNetwork(melody_encoder=melody_encoder, rhythm_embed_size=out_size, dec_lstm_size=melody_dec_lstm_size, V=V_melody, dec_use_meta=True, compile_now=True) print("Individual networks set up...\n") # COMBINED NETWORK comb_net = CombinedNetwork(context_size, m, meta_embed_size, bar_embedder,