def generate(model, seed, mid_name, temperature=1.0, length=512): '''Generate sequence using model, seed, and temperature.''' generated = [] phrase = seed phrase_array = decode(phrase) for j in range(length): x = np.zeros((1, PHRASE_LEN, SYMBOL_DIM)) for t, config_id in enumerate(phrase): x[0, t, config_id] = 1 preds = model.predict(x, verbose=0)[0] next_id = sample(preds, temperature) generated += [next_id] phrase = phrase[1:] + [next_id] mid = array_to_midi(unfold(decode(generated), OUT_PITCHES), mid_name) mid.save(os.path.join(MIDI_OUT_DIR, mid_name)) return mid
model.load_weights(path) return model windows, X, y = prepare_data() model = train_model(X, y, path='models/accompaniment/model') #model = load_model('models/accompaniment/model') in_pattern = np.zeros(32) in_pattern[::8] = 1 in_pattern[2::8] = 1 in_pattern[::5] = 1 x = features(in_pattern)[np.newaxis, :] y = model.predict(x) print(y) y_amplitude = y[:, :32] y_phase = y[:, 32:] y_complex = y_amplitude + 1j * y_phase out_pattern = np.abs(np.fft.ifft(y_complex)) print(out_pattern) out_pattern[out_pattern < 0.05] = 0 print(out_pattern) out_pattern = (128 * out_pattern).astype(int) print(out_pattern) combined_pattern = np.vstack([in_pattern, out_pattern]) print(combined_pattern) mid = midi_util.array_to_midi(combined_pattern.transpose(), 'test', quantization=5) mid.save('beatzzz.mid')
model.load_weights(path) return model windows, X, y = prepare_data() model = train_model(X, y, path='models/accompaniment/model') #model = load_model('models/accompaniment/model') in_pattern = np.zeros(32) in_pattern[::8] = 1 in_pattern[2::8] = 1 in_pattern[::5] = 1 x = features(in_pattern)[np.newaxis, :] y = model.predict(x) print y y_amplitude = y[:,:32] y_phase = y[:,32:] y_complex = y_amplitude + 1j * y_phase out_pattern = np.abs(np.fft.ifft(y_complex)) print out_pattern out_pattern[out_pattern < 0.05] = 0 print out_pattern out_pattern = (128 * out_pattern).astype(int) print out_pattern combined_pattern = np.vstack([in_pattern, out_pattern]) print combined_pattern mid = midi_util.array_to_midi(combined_pattern.transpose(), 'test', quantization=5) mid.save('beatzzz.mid')