G.zero_grad()

        gen_input = Variable(noise())
        g_fake_data = G(gen_input)
        dg_fake_decision = D(g_fake_data)
        g_error = criterion(dg_fake_decision,
                            Variable(torch.ones(
                                dg_fake_decision.shape)))  # we want to fool,
        G_error.append(g_error.item())
        g_error.backward()
        g_optimizer.step()  # Only optimizes G's parameters
        print(epoch, " : D: ", d_fake_error.item(), " G: ", g_error.item())

fake_data = g_fake_data.detach().numpy()
thresh = 0.3  # float(input('Threshold (recommended ~ 0.1):'))
net_roll = data_utils_compose.NetOutToPianoRoll(fake_data, threshold=thresh)
# print("net_roll:", net_roll)
# print("net_roll.shape", net_roll.shape)
data_utils_compose.createMidiFromPianoRoll(net_roll,
                                           mel_lowest_note,
                                           composition_dir,
                                           2,
                                           thresh,
                                           res_factor=resolution_factor)

print("Finished composing song %d." % 2)

plt.ioff()
fig = plt.figure()
plt.xlabel('Epoch')
plt.ylabel('Error')
Exemple #2
0
model = model_from_json(open(model_path).read())
print()
print("loading weights...")
model.load_weights(weights_path)
print()
print("Compiling model...")
model.compile(loss='binary_crossentropy',
              optimizer='adam',
              class_mode=class_mode)

print()
print("Compose...")
for i, song in enumerate(test_data):
    net_output = model.predict(song)
    #print("net_output:", net_output)
    net_roll = data_utils_compose.NetOutToPianoRoll(net_output,
                                                    threshold=thresh)
    #print("net_roll:", net_roll)
    #print("net_roll.shape", net_roll.shape)
    data_utils_compose.createMidiFromPianoRoll(net_roll,
                                               mel_lowest_note,
                                               composition_dir,
                                               composition_files[i],
                                               thresh,
                                               res_factor=resolution_factor)

    print("Finished composing song %d." % (i + 1))

print()
print("Dope!")
Exemple #3
0
print("Choose a file for the weights (Model and Weights MUST correspond!):")
print("---------------------------------------")
for i, file in enumerate(weights_files):
    print(str(i) + " : " + file)
print("---------------------------------------")
file_number_weights = int(input('Type in the number in front of the file you want to choose:')) 
weights_file = weights_files[file_number_weights]
weights_path = '%s%s' %(weights_dir, weights_file)




model = model_from_json(open(model_path).read())
model.load_weights(weights_path)
model.compile(loss='binary_crossentropy', optimizer='adam')

net_output = []
net_roll = []
for i, song in enumerate(test_data):
    net_output.append(model.predict(song))
    net_roll.append(data_utils_compose.NetOutToPianoRoll(net_output[i], threshold=thresh))
    data_utils_compose.createMidiFromPianoRoll(net_roll[i], mel_lowest_note, composition_dir,
                                               composition_files[i], thresh)

orig = glob.glob('data/*.mid')
composed = glob.glob('data/split/*.mid')
for i,j in zip(orig,composed):
    data_utils_compose.merge_left_right(i,j)