Skip to content

Commit 0e18abf

Browse files
committed
m
1 parent 08bdb70 commit 0e18abf

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

Examples/MNIST_example.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@
77
from NeuronModels import NeuronLifAdaptiveThresh
88
import matplotlib.pyplot as plt
99

10-
n_neurons_out = 50
11-
n_neurons_in = 196
12-
n_train = 5000
13-
n_test = 800
14-
time = 350
15-
time_test = 200
16-
test = True
17-
plot = True
18-
19-
conn = Connections(n_neurons_in, n_neurons_out, "all_to_all")
20-
conn.all_to_all_conn()
21-
conn.initialize_weights("normal")
22-
23-
data_train = MNIST_train_test_14x14()[0]
24-
data_test = MNIST_train_test_14x14()[1]
10+
n_neurons_out = 50 # number of neurons in input layer
11+
n_neurons_in = 196 # number of output in input layer
12+
n_train = 5000 # number of images for training
13+
n_test = 800 # number of images for testing
14+
time = 350 # time of each image presentation during training
15+
time_test = 200 # time of each image presentation during testing
16+
test = True # do testing or not
17+
plot = True # plot graphics or not
2518

2619
out_neurons = NeuronLifAdaptiveThresh(n_neurons_in,
2720
n_neurons_out,
@@ -32,7 +25,14 @@
3225
U_rest=0,
3326
refr_time=5,
3427
traces=True,
35-
inh=True)
28+
inh=True) # activate literal inhibition
29+
30+
conn = Connections(n_neurons_in, n_neurons_out, "all_to_all")
31+
conn.all_to_all_conn()
32+
conn.initialize_weights("normal")
33+
34+
data_train = MNIST_train_test_14x14()[0]
35+
data_test = MNIST_train_test_14x14()[1]
3636

3737
assig = MnistAssignment(n_neurons_out)
3838

@@ -69,8 +69,6 @@
6969
assig.count_spikes_train(out_neurons.spikes, data_train[i][1])
7070
conn.update_w(out_neurons.spikes_trace_in, out_neurons.spikes_trace_out, out_neurons.spikes)
7171

72-
fig.savefig('foo.png')
73-
fig1.savefig('fooo.png')
7472
assig.get_assigment()
7573
evall = MnistEvaluation(n_neurons_out)
7674

46 Bytes
Binary file not shown.

tools.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
from topology import Connections
66

77

8-
def plot_mnist():
8+
def plot_mnist_test():
99
bb = MNIST_train_test_14x14()[0]
10-
print(bb[0][0])
11-
b1 = bb[0][0] * 0.80
12-
f = torch.squeeze(encoding_to_spikes(b1, 10))
13-
print(f)
10+
spike_intensity = 1
11+
b1 = bb[0][0] * spike_intensity
12+
f = torch.squeeze(encoding_to_spikes(b1, 50))
13+
1414
g = torch.zeros([14, 14], dtype=torch.float)
1515
plt.ion()
1616
fig = plt.figure(figsize=(4, 4))
@@ -23,16 +23,18 @@ def plot_mnist():
2323
plt.pause(0.0001)
2424

2525
plt.ioff()
26-
print(g)
26+
2727
fig1 = plt.figure(figsize=(6, 6))
2828
ax3 = fig1.add_subplot(121)
2929
ax2 = fig1.add_subplot(122)
30-
g = g / 10
30+
g = g / 50
31+
ax3.set_title('Image Sample')
32+
ax2.set_title('Recreated image from spike train')
3133
ax3.imshow(torch.squeeze(bb[0][0]), cmap='gray', vmin=0, vmax=1)
3234
ax2.imshow(g, cmap='gray', vmin=0, vmax=1)
3335
plt.show()
3436

35-
37+
plot_mnist_test()
3638
def if_neuron_test():
3739
""" Visualize how single IF neuron works.
3840
"""
@@ -165,4 +167,3 @@ def lif_thresh_neuron_test():
165167
plt.axhline(y=lif_test.U_tr, color='k')
166168
plt.show()
167169

168-
lif_thresh_neuron_test()

0 commit comments

Comments
 (0)