square_weights = get_square_weights( input_exc_weights.view(784, n_neurons), n_sqrt, 28) square_assignments = get_square_assignments(assignments, n_sqrt) spikes_ = { layer: spikes[layer].get("s")[:, 0].contiguous() for layer in spikes } voltages = {"Ae": exc_voltages, "Ai": inh_voltages} inpt_axes, inpt_ims = plot_input(image, inpt, label=labels[step], axes=inpt_axes, ims=inpt_ims) spike_ims, spike_axes = plot_spikes(spikes_, ims=spike_ims, axes=spike_axes) weights_im = plot_weights(square_weights, im=weights_im) assigns_im = plot_assignments(square_assignments, im=assigns_im) perf_ax = plot_performance(accuracy, ax=perf_ax) voltage_ims, voltage_axes = plot_voltages(voltages, ims=voltage_ims, axes=voltage_axes, plot_type="line") plt.pause(1e-8) network.reset_state_variables() # Reset state variables. print("Progress: %d / %d (%.4f seconds)" % (epoch + 1, n_epochs, t() - start)) print("Training complete.\n")
input_exc_weights = network.connections[("X", "Ae")].w square_weights = get_square_weights( input_exc_weights.view(784, n_neurons), n_sqrt, 28) voltages = {"Ae": exc_voltages, "Ai": inh_voltages} inpt_axes, inpt_ims, inpt_fig = plot_input(image.sum(1).view(28, 28), inpt, label=label, axes=inpt_axes, ims=inpt_ims, fig=inpt_fig) save_plot(fig=inpt_fig, directory=directory, name="input", n=i) spike_ims, spike_axes, spike_fig = plot_spikes( { layer: spikes[layer].get("s").view(time, 1, -1) for layer in spikes }, ims=spike_ims, axes=spike_axes, fig=spike_fig) save_plot(fig=spike_fig, directory=directory, name="spikes", n=i) weights_im, weights_fig = plot_weights(square_weights, im=weights_im, fig=weights_fig) save_plot(fig=weights_fig, directory=directory, name="weights", n=i) voltage_ims, voltage_axes, voltage_fig = plot_voltages( voltages, ims=voltage_ims, axes=voltage_axes, fig=voltage_fig) save_plot(fig=voltage_fig, directory=directory, name="voltage", n=i) if i % update_interval == 0: square_assignments = get_square_assignments(assignments, n_sqrt) assigns_im, assigns_fig = plot_assignments(square_assignments, im=assigns_im,
if plot: image = batch["image"].view(28, 28) inpt = inputs["X"].view(time, 784).sum(0).view(28, 28) weights1 = conv_conn.w _spikes = { "X": spikes["X"].get("s").view(time, -1), "Y": spikes["Y"].get("s").view(time, -1), } _voltages = {"Y": voltages["Y"].get("v").view(time, -1)} inpt_axes, inpt_ims = plot_input(image, inpt, label=label, axes=inpt_axes, ims=inpt_ims) spike_ims, spike_axes = plot_spikes(_spikes, ims=spike_ims, axes=spike_axes) weights1_im = plot_conv2d_weights(weights1, im=weights1_im) voltage_ims, voltage_axes = plot_voltages(_voltages, ims=voltage_ims, axes=voltage_axes) plt.pause(1) network.reset_state_variables() # Reset state variables. print("Progress: %d / %d (%.4f seconds)\n" % (n_epochs, n_epochs, t() - start)) print("Training complete.\n")
network.run(inputs={"I": datum}, time=time, input_time_dim=1) training_pairs.append([spikes["O"].get("s").sum(0), label]) if plot: inpt_axes, inpt_ims = plot_input( dataPoint["image"].view(28, 28), datum.view(time, 784).sum(0).view(28, 28), label=label, axes=inpt_axes, ims=inpt_ims, ) spike_ims, spike_axes = plot_spikes( {layer: spikes[layer].get("s").view(-1, time) for layer in spikes}, axes=spike_axes, ims=spike_ims, ) voltage_ims, voltage_axes = plot_voltages( { layer: voltages[layer].get("v").view(-1, time) for layer in voltages }, ims=voltage_ims, axes=voltage_axes, ) weights_im = plot_weights(get_square_weights(C1.w, 23, 28), im=weights_im, wmin=-2, wmax=2) weights_im2 = plot_weights(C2.w, im=weights_im2, wmin=-2, wmax=2)