Ejemplo n.º 1
0
def make_rand_songs(write_dir, rand_vecs):
    for i in range(rand_vecs.shape[0]):
        x_rand = rand_vecs[i:i + 1]
        y_song = func([x_rand, 0])[0]
        midi.samples_to_midi(
            [y_song[0, meas] for meas in range(y_song[0].ndim)],
            write_dir + 'rand' + str(i) + '.mid',
            thresh=0.25)
Ejemplo n.º 2
0
def make_rand_songs(write_dir, rand_vecs, thresh):
    for i in range(rand_vecs.shape[0]):
        x_rand = torch.from_numpy(rand_vecs[i:i + 1]).to(device).float()
        with torch.no_grad():
            y_song = model.decoder_forward(x_rand).cpu().numpy()
            midi.samples_to_midi(y_song[0],
                                 write_dir + 'rand' + str(i) + '.mid', 16,
                                 thresh)
            fs.midi_to_audio(write_dir + 'rand' + str(i) + '.mid',
                             output_dir + 'sample' + str(i) + '.wav')
Ejemplo n.º 3
0
				else:
					rand_ix = np.array([rand_ix], dtype=np.int64)
					x = enc_model.predict(rand_ix, batch_size=1)[0]
					rand_ix = (rand_ix + 1) % model.layers[0].input_dim
				
				if use_pca:
					cur_params = np.dot(x - means, evecs.T) / evals
				else:
					cur_params = (x - means) / stds

				needs_update = True
				audio_reset = True
			if event.key == pygame.K_g:
				audio_pause = True
				audio_reset = True
				midi.samples_to_midi(cur_notes, 'live.mid', 16, note_thresh)
				save_audio = ''
				while True:
					save_audio += audio_callback(None, 1024, None, None)[0]
					if audio_time == 0:
						break
				wave_output = wave.open('live.wav', 'w')
				wave_output.setparams((1, 2, sample_rate, 0, 'NONE', 'not compressed'))
				wave_output.writeframes(save_audio)
				wave_output.close()
				audio_pause = False
			if event.key == pygame.K_ESCAPE:
				running = False
				break
			if event.key == pygame.K_SPACE:
				audio_pause = not audio_pause
Ejemplo n.º 4
0
def make_rand_songs(write_dir, rand_vecs):
    for i in range(rand_vecs.shape[0]):
        x_rand = rand_vecs[i:i + 1]
        y_song = func([x_rand, 0])[0]
        midi.samples_to_midi(y_song[0], write_dir + 'rand' + str(i) + '.mid',
                             16, 0.25)
Ejemplo n.º 5
0
    epsilon = K.random_normal(shape=K.shape(z_mean), mean=0.0, stddev=VAE_B1)
    return z_mean + K.exp(z_log_sigma_sq * 0.5) * epsilon


def vae_loss(x, x_decoded_mean):
    xent_loss = binary_crossentropy(x, x_decoded_mean)
    kl_loss = VAE_B2 * K.mean(
        1 + z_log_sigma_sq - K.square(z_mean) - K.exp(z_log_sigma_sq),
        axis=None)
    return xent_loss - kl_loss


test_ix = 0
y_test_song = np.copy(y_train[test_ix:test_ix + 1])
x_test_song = np.copy(x_train[test_ix:test_ix + 1])
midi.samples_to_midi(y_test_song[0], 'gt.mid', 16)

###################################
#  Create Model
###################################
if CONTINUE_TRAIN or PLAY_ONLY:
    print("Loading Model...")
    model = load_model('model.h5', custom_objects=custom_objects)
else:
    print("Building Model...")

    if USE_EMBEDDING:
        x_in = Input(shape=x_shape[1:])
        print((None, ) + x_shape[1:])
        x = Embedding(x_train.shape[0], PARAM_SIZE, input_length=1)(x_in)
        x = Flatten(name='pre_encoder')(x)
Ejemplo n.º 6
0
def make_rand_songs(write_dir, rand_vecs):
	for i in xrange(rand_vecs.shape[0]):
		x_rand = rand_vecs[i:i+1]
		y_song = func([x_rand, 0])[0]
		midi.samples_to_midi(y_song[0], write_dir + 'rand' + str(i) + '.mid', ticks_per_sample = 0.125, thresh=0.20)
Ejemplo n.º 7
0
    epsilon = K.random_normal(shape=K.shape(z_mean), mean=0.0, stddev=VAE_B1)
    return z_mean + K.exp(z_log_sigma_sq * 0.5) * epsilon


def vae_loss(x, x_decoded_mean):
    xent_loss = binary_crossentropy(x, x_decoded_mean)
    kl_loss = VAE_B2 * K.mean(
        1 + z_log_sigma_sq - K.square(z_mean) - K.exp(z_log_sigma_sq),
        axis=None)
    return xent_loss - kl_loss


test_ix = 120
y_test_song = np.copy(y_train[test_ix:test_ix + 1])
x_test_song = np.copy(x_train[test_ix:test_ix + 1])
midi.samples_to_midi(y_test_song[0], 'gt.mid', 16)

###################################
#  Create Model
###################################
if CONTINUE_TRAIN or PLAY_ONLY:
    print("Loading Model...")
    model = load_model('model.h5', custom_objects=custom_objects)
else:
    print("Building Model...")

    if USE_EMBEDDING:  # Embedding is used when
        x_in = Input(shape=x_shape[1:])
        print((None, ) + x_shape[1:])
        x = Embedding(x_train.shape[0], PARAM_SIZE, input_length=1)(x_in)
        x = Flatten(name='pre_encoder')(x)