wav.write("sound/" + experiment_name + "_random.wav", sample_rate, random) wav.write("sound/" + experiment_name + "_reconstruction.wav", sample_rate, reconstruction) wav.write("sound/" + experiment_name + "_reconstruction_original.wav", sample_rate, original) ou1 = net1.output(x_train[:50]) ou2 = net2.output(x_train[:50]) for i in range(ou2.shape[0]): if i < 100: plt.figure() plt.plot(ou1[i, 0, :, 0], color="g") plt.plot(ou2[i, 0, :, 0], color="b") plt.plot(x_train[i, 0, :, 0], color="r") plt.savefig(plot_dir + str(i) + "_compare.png", cmap=plt.cm.binary) pickle_saver(net2.params, "model_no_boost.pkl") f = open("readme", "w") f.write("SingVAE parameters for experiment: \n------ \n \n") f.write("Number of filters: " + str([net1.in_filters]) + "\n") f.write("Filter lengths: " + str([net1.filter_lengths]) + "\n") f.write("Latend variables: " + str(dim_z) + "\n") f.write("Iterations: " + str(iterations) + "\n") f.write("Sample rate: " + str(sample_rate) + "\n") f.close() #device_play(net,sample_rate,duration = 1000) #use np.squeeze to remove redundant dimentions. #out = out.reshape(out.shape[0],out.shape[1],out.shape[3]) #print out2.shape
wav.write("sound/"+experiment_name+"_reconstruction_original.wav",sample_rate,original) # Weights plot_params(net.params,weight_plot_dir) #ou1 = net1.output(x_train[:50]) # Reconstruction images ou2 = net.output(x_train[:50]) for i in range(ou2.shape[0]): if i <100: plt.figure() # plt.plot(ou1[i,0,:,0],color = "g") plt.plot(ou2[i,0,:,0],color = "b") plt.plot(x_train[i,0,:,0],color = "r") plt.savefig(plot_dir+str(i)+"_compare.png",cmap=plt.cm.binary) # The model to_save = {"architecture":net_args,"weights":net.params,"dataset":data_name,"sample_rate":sample_rate} pickle_saver(to_save,model_dir+experiment_name+"_model.pkl") # The model hyper parameters f = open(experiment_name+"readme","w") f.write("SingVAE parameters for experiment: \n------ \n \n") f.write("Number of filters: "+ str([net.in_filters]) +"\n") f.write("Filter lengths: "+str([net.filter_lengths])+"\n") f.write("Latend variables: "+str(net_args["dim_z"])+"\n") f.write("Iterations: "+str(iterations)+"\n") f.write("Sample rate: "+str(sample_rate)+"\n") f.close()
wav.write("sound/"+experiment_name+"_reconstruction.wav",sample_rate,reconstruction) wav.write("sound/"+experiment_name+"_reconstruction_original.wav",sample_rate,original) # Weights plot_params(net2.params,weight_plot_dir) #ou1 = net1.output(x_train[:50]) # Reconstruction images ou2 = net2.output(x_train[:50]) for i in range(ou2.shape[0]): if i <100: plt.figure() # plt.plot(ou1[i,0,:,0],color = "g") plt.plot(ou2[i,0,:,0],color = "b") plt.plot(x_train[i,0,:,0],color = "r") plt.savefig(plot_dir+str(i)+"_compare.png",cmap=plt.cm.binary) # The model pickle_saver(net2.params,model_dir+"model.pkl") # The model hyper parameters f = open("readme","w") f.write("SingVAE parameters for experiment: \n------ \n \n") f.write("Number of filters: "+ str([net1.in_filters]) +"\n") f.write("Filter lengths: "+str([net1.filter_lengths])+"\n") f.write("Latend variables: "+str(dim_z)+"\n") f.write("Iterations: "+str(iterations)+"\n") f.write("Sample rate: "+str(sample_rate)+"\n") f.close()
print "Creating Theano functions" encoder.createGradientFunctions() print "Initializing weights and biases" encoder.initParams() lowerbound = np.array([]) testlowerbound = np.array([]) begin = time.time() # Declare figures for interactive mode plt.ion() f1 = plt.figure(1) for j in xrange(n_steps): encoder.lowerbound = 0 print 'Iteration:', j begin = time.time() encoder.iterate(data) end = time.time() print("Iteration %d, lower bound = %.2f," " time = %.2fs" % (j, encoder.lowerbound/N, end - begin)) if j%10 == 0: mu_out3 = encoder.getTestOutput(data) data.shape plot_reconstructed(data[:10,:1000],mu_out3.T[:10,:1000],f1,interactive=True) pickle_saver(encoder,"encoder.pkl")
random,reconstruction,original = sound_write.sample_write(net1,880,duration = 10) wav.write("sound/"+experiment_name+"_random.wav",sample_rate,random) wav.write("sound/"+experiment_name+"_reconstruction.wav",sample_rate,reconstruction) wav.write("sound/"+experiment_name+"_reconstruction_original.wav",sample_rate,original) ou1 = net1.output(x_train[:50]) ou2 = net2.output(x_train[:50]) for i in range(ou2.shape[0]): if i <100: plt.figure() plt.plot(ou1[i,0,:,0],color = "g") plt.plot(ou2[i,0,:,0],color = "b") plt.plot(x_train[i,0,:,0],color = "r") plt.savefig(plot_dir+str(i)+"_compare.png",cmap=plt.cm.binary) pickle_saver(net2.params,"model_no_boost.pkl") f = open("readme","w") f.write("SingVAE parameters for experiment: \n------ \n \n") f.write("Number of filters: "+ str([net1.in_filters]) +"\n") f.write("Filter lengths: "+str([net1.filter_lengths])+"\n") f.write("Latend variables: "+str(dim_z)+"\n") f.write("Iterations: "+str(iterations)+"\n") f.write("Sample rate: "+str(sample_rate)+"\n") f.close() #device_play(net,sample_rate,duration = 1000) #use np.squeeze to remove redundant dimentions. #out = out.reshape(out.shape[0],out.shape[1],out.shape[3]) #print out2.shape