prev_w = w_s cond = c_mb print("Completed sampling after %i steps" % fixed_steps) completed = np.array(completed).transpose(1, 0, 2) rlookup = {v: k for k, v in vocabulary.items()} all_strings = [] for yi in y: ex_str = "".join([rlookup[c] for c in np.argmax(yi, axis=1)]) all_strings.append(ex_str) for i in range(len(completed)): ex = completed[i] ex_str = "".join( [rlookup[c] for c in np.argmax(cond[:, i], axis=1)]) s = "gen_%s_%i.wav" % (ex_str, i) ii = reconstruct(ex) wavfile.write(s, fs, soundsc(ii)) if ex_str in all_strings: inds = [ n for n, s in enumerate(all_strings) if ex_str == s ] ind = inds[0] it = reconstruct(X[ind]) s = "orig_%s_%i.wav" % (ex_str, i) wavfile.write(s, fs, soundsc(it)) valid_itr.reset() print("Sampling complete, exiting...") sys.exit() else: print("No plotting arguments, starting training mode!") X_sym = tensor.tensor3("X_sym")
prev_h2 = h2_s prev_h3 = h3_s prev_kappa = k_s prev_w = w_s cond = c_mb print("Completed sampling after %i steps" % fixed_steps) # Minibatch size first completed = np.array(completed).transpose(1, 0, 2) rlookup = {v: k for k, v in vocabulary.items()} for i in range(len(completed)): ex = completed[i] ex_str = "".join([rlookup[c] for c in np.argmax(cond[:, i], axis=1)]) s = "gen_%s_%i.wav" % (ex_str, i) ii = reconstruct(ex) wavfile.write(s, fs, soundsc(ii)) valid_itr.reset() print("Sampling complete, exiting...") sys.exit() else: print("No plotting arguments, starting training mode!") X_sym = tensor.tensor3("X_sym") X_sym.tag.test_value = X_mb[:cut_len] X_mask_sym = tensor.matrix("X_mask_sym") X_mask_sym.tag.test_value = X_mb_mask[:cut_len] c_sym = tensor.tensor3("c_sym") c_sym.tag.test_value = c_mb c_mask_sym = tensor.matrix("c_mask_sym") c_mask_sym.tag.test_value = c_mb_mask bias_sym = tensor.scalar("bias_sym")
# mb, length completed = np.array(completed)[:, 0, :] completed = completed.transpose(1, 0) # all samples would be range(len(completed)) for i in range(10): ex = completed[i].ravel() s = "gen_%i.wav" % (i) ex = ex.astype("float32") """ ex -= ex.min() ex /= ex.max() ex -= 0.5 ex *= 0.95 wavfile.write(s, fs, ex) """ wavfile.write(s, fs, soundsc(ex)) print("Sampling complete, exiting...") sys.exit() else: print("No plotting arguments, starting training mode!") X_sym = tensor.tensor3("X_sym") X_sym.tag.test_value = X_mb[:cut_len] X_mask_sym = tensor.matrix("X_mask_sym") X_mask_sym.tag.test_value = X_mb_mask[:cut_len] init_h1_i = tensor.matrix("init_h1") init_h1_i.tag.test_value = np_zeros((minibatch_size, n_hid)) init_h2_i = tensor.matrix("init_h2") init_h2_i.tag.test_value = np_zeros((minibatch_size, n_hid))
pred_srnn.load_weights(args.sample) print(pred_srnn.model().summary()) try: from keras.utils import plot_model plot_model(pred_srnn.top_tier_model_predictor, to_file='top_model.png') plot_model(pred_srnn.mid_tier_model_predictor, to_file='mid_model.png') plot_model(pred_srnn.slow_tier_model_predictor, to_file='slow_model.png') except: print('failed to plot models to png') pass w = pred_srnn.sample(4 * args.samplerate, random_state, args.debug) fs = args.samplerate wavfile.write("generated.wav", fs, soundsc(w)) exit(0) frame_size = 1 bliz_train = Blizzard_dataset( minibatch_size=minibatch_size, wav_folder_path='./blizzard/{}_parts/'.format(args.exp), prompt_path='./blizzard/{}_parts/prompts.txt'.format(args.exp), preproc_fn=wav_to_qbins_frames, frame_size=frame_size, fraction_range=[0, train_stop_index], thread_cnt=1) bliz_valid = Blizzard_dataset( minibatch_size=minibatch_size, wav_folder_path='./blizzard/{}_parts/'.format(args.exp), prompt_path='./blizzard/{}_parts/prompts.txt'.format(args.exp),