Beispiel #1
0
else:
    config.device = torch.device('cpu')

current_time = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
gen_log_dir = 'logs/mt_decoder/generate_' + current_time + '/generate'
gen_summary_writer = SummaryWriter(gen_log_dir)

mt = MusicTransformer(embedding_dim=config.embedding_dim,
                      vocab_size=config.vocab_size,
                      num_layer=config.num_layers,
                      max_seq=config.max_seq,
                      dropout=0,
                      debug=False)
mt.load_state_dict(torch.load(args.model_dir + '/final.pth'))
mt.test()

print(config.condition_file)
if config.condition_file is not None:
    inputs = np.array([encode_midi('dataset/midi/BENABD10.mid')[:500]])
else:
    inputs = np.array([[24, 28, 31]])
inputs = torch.from_numpy(inputs)
result = mt(inputs, config.length, gen_summary_writer)

for i in result:
    print(i)

decode_midi(result, file_path=config.save_path)

gen_summary_writer.close()
Beispiel #2
0
gen_log_dir = 'logs/mt_decoder/generate_' + current_time + '/generate'
gen_summary_writer = tf.summary.create_file_writer(gen_log_dir)

if mode == 'enc-dec':
    print(">> generate with original seq2seq wise... beam size is {}".format(
        beam))
    mt = MusicTransformer(embedding_dim=256,
                          vocab_size=par.vocab_size,
                          num_layer=6,
                          max_seq=2048,
                          dropout=0.2,
                          debug=False,
                          loader_path=load_path)
else:
    print(">> generate with decoder wise... beam size is {}".format(beam))
    mt = MusicTransformerDecoder(loader_path=load_path)

inputs = encode_midi('dataset/midi/BENABD10.mid')

with gen_summary_writer.as_default():
    result = mt.generate(inputs[:10], beam=beam, length=length, tf_board=True)

for i in result:
    print(i)

if mode == 'enc-dec':
    decode_midi(list(inputs[-1 * par.max_seq:]) + list(result[1:]),
                file_path=save_path)
else:
    decode_midi(result, file_path=save_path)
Beispiel #3
0
#     param_num = 0
#     for param in model.parameters():
#         param_num += np.prod(list(param.shape))
#         print(param.shape, "num %d" % np.prod(list(param.shape)))
#     print(param_num, " in total, %.2fmb"%(param_num * 4 / 1024**2))
#
# model_size_summary(mt)
mt.cuda()
#%%
## %%time
inputs = np.array([[24, 28, 31]])
inputs = torch.from_numpy(inputs).cuda()
result = mt(inputs, 1024, gen_summary_writer)
# for i in result:
#     print(i)
mid = decode_midi(result, file_path=None)#
decode_midi(result, file_path='result/generated.mid')
#%%
# print(config.condition_file)
# if config.condition_file is not None:
#     inputs = np.array([encode_midi('dataset/midi/BENABD10.mid')[:500]])
# else:
#     inputs = np.array([[24, 28, 31]])
# inputs = torch.from_numpy(inputs)
# result = mt(inputs, config.length, gen_summary_writer)


mid = decode_midi(result, file_path=None)#
# decode_midi(result, file_path=config.save_path)

gen_summary_writer.close()
Beispiel #4
0
gen_log_dir = 'logs/mt_decoder/generate_' + current_time + '/generate'
gen_summary_writer = tf.summary.create_file_writer(gen_log_dir)

if mode == 'enc-dec':
    print(">> generate with original seq2seq wise... beam size is {}".format(
        beam))
    mt = MusicTransformer(embedding_dim=256,
                          vocab_size=par.vocab_size,
                          num_layer=6,
                          max_seq=2048,
                          dropout=0.2,
                          debug=False,
                          loader_path=load_path)
else:
    print(">> generate with decoder wise... beam size is {}".format(beam))
    mt = MusicTransformerDecoder(loader_path=load_path)

inputs = encode_midi('dataset/midi/BENABD10.mid')

with gen_summary_writer.as_default():
    result = mt.generate(inputs[:500], beam=beam, length=length, tf_board=True)

for i in result:
    print(i)

if mode == 'enc-dec':
    decode_midi(list(inputs[-1 * par.max_seq:]) + list(result[1:]),
                file_path='bin/generated.mid')
else:
    decode_midi(result, file_path='bin/generated.mid')
Beispiel #5
0
mt.cuda()
#%%
## %%time
if condition_file is not None:
    print("use condition file %s, first %d notes" %
          (condition_file, args.condition_len))
    inputs = np.array([encode_midi(condition_file)[:args.condition_len]])
    print(inputs[0])
else:
    inputs = np.array([[24, 28, 31]])
inputs = torch.from_numpy(inputs).cuda()
with torch.no_grad():
    result = mt(inputs, 2048, gen_summary_writer)
# mid = decode_midi(result.cpu(), file_path=None) #
mid = decode_midi(result,
                  file_path='result/generated_mod%s_cond%s.mid' %
                  (args.ckpt.split('.')[0], condition_fn))
gen_summary_writer.close()
ps_roll = mid.get_piano_roll()
figh = plot_piano_roll(ps_roll)
figh.savefig('result/generated_mod%s_cond%s.jpg' %
             (args.ckpt.split('.')[0], condition_fn))
#%%
# print(config.condition_file)

# inputs = torch.from_numpy(inputs)
# result = mt(inputs, config.length, gen_summary_writer)
# encode_midi('E:\Datasets\ecomp-midi\Ali03.MID')[:500]

# mid = decode_midi(result, file_path=None)#
# decode_midi(result, file_path=config.save_path)