from Data.DataGeneratorsLeadMeta import CombinedGenerator as CGLeadMeta from Nets.CombinedNetwork import BarEmbedding, RhythmEncoder, RhythmNetwork,\ MelodyEncoder, MelodyNetwork,\ CombinedNetwork from Nets.MetaEmbedding import MetaEmbedding from Nets.MetaPredictor import MetaPredictor import os #%% META meta_embedder = MetaEmbedding.from_saved_custom("meta_saved") meta_embed_size = meta_embedder.embed_size meta_predictor = MetaPredictor.from_saved_custom("meta_saved") meta_predictor.freeze() #%% rc = 2 mc = 2 cg = CGLeadMeta("Data/lessfiles", save_conversion_params=False, to_list=False, meta_prep_f=meta_embedder.predict) cg.get_num_pieces() def without_lead(cg_inst):
top_dir = "Trainings" # save_dir = asctime().split() # save_dir = "_".join([*save_dir[0:3], *save_dir[3].split(":")[:2]]) save_dir = "meta_no_embed_wrong_loss2" if not os.path.isdir("/".join([top_dir, save_dir, "chord"])): os.makedirs("/".join([top_dir, save_dir, "chord"])) # META # meta_embedder = MetaEmbedding.from_saved_custom("/".join([top_dir, save_dir, "meta"])) # meta_embed_size = meta_embedder.embed_size meta_predictor = MetaPredictor.from_saved_custom("/".join([top_dir, save_dir, "meta"])) meta_predictor.freeze() #%% music_dir = "../../Data/music21" 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_emb, eval_results = get_meta_embedder(meta_examples, # embed_size=10, # epochs=10, # evaluate=True, verbose=1) # # print("MetaEmbedding trained!\n\tevaluation results:\n\t", # eval_results) #%% pred_meta_gen = gen_preds_and_meta(cg, forever=True) r_params = (None, cg.rhythm_V) m_params = (48, cg.melody_V) mp = MetaPredictor(r_params, m_params, 10, #meta_embed_size 12, 24) #%% mp.fit_generator(pred_meta_gen, steps_per_epoch=cg.num_pieces, epochs=6) #%% # meta_emb.save_model_custom("/".join([top_dir, save_dir, "meta"])) #%% mp.save_model_custom("/".join([top_dir, save_dir, "meta"]))
# -*- coding: utf-8 -*- from Nets.MetaPredictor import MetaPredictor from Nets.CombinedNetwork import CombinedNetwork #%% save_dir = "Trainings/meta_no_embed_wrong_loss/" meta_pred = MetaPredictor.from_saved_custom(save_dir + "meta") #%% comb_net = CombinedNetwork.from_saved_custom(save_dir + "weights", meta_pred)
meta_emb, eval_results = get_meta_embedder(meta_examples, embed_size=10, epochs=10, evaluate=True, verbose=1) print("MetaEmbedding trained!\n\tevaluation results:\n\t", eval_results) #%% pred_meta_gen = gen_preds_and_meta(cg, meta_emb, forever=True) r_params = (None, cg.rhythm_V) m_params = (48, cg.melody_V) mp = MetaPredictor(r_params, m_params, meta_emb.embed_size, 12, 24) #%% mp.fit_generator(pred_meta_gen, steps_per_epoch=cg.num_pieces, epochs=2) #%% meta_emb.save_model_custom("/".join([top_dir, save_dir, "meta"])) #%% mp.save_model_custom("/".join([top_dir, save_dir, "meta"])) #%%