-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (45 loc) · 2.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from wbn import Spiking
if __name__ == '__main__':
# Build SNNs and decide the number of input neurons and the simulation time.
snn = Spiking(input_l=784, obs_time=300, dt=0.5)
snn.IMAGE_DIR += 'diehl/'
# Add a layer and give the num of neurons and the neuron model.
snn.add_layer(n=100,
node=snn.DIEHL_COOK, # or snn.DIEHL_COOK
w=snn.W_SIMPLE_RAND, # initialize weights
scale=0.4, # scale of random intensity
rule=snn.SIMPLE_STDP, # learning rule
nu=(1e-4, 1e-2), # learning rate
# norm=150, # L1 weight normalization term
)
# Add an inhibitory layer
snn.add_inhibit_layer(inh_w=-128)
# Load dataset
snn.load_MNIST()
# Check your network architecture
snn.print_model()
# If you use a small network, your network computation by GPU may be more slowly than CPU.
# So you can change directly whether using GPU or not as below.
# snn.gpu = False
# Gpu is available?? If available, make it use.
snn.to_gpu()
# Plot weight maps before training
snn.plot(plt_type='wmps', prefix='0', f_shape=(10, 10))
# Make my network run
for i in range(3):
snn.run(
# tr_size=10000, # training data size
# unsupervised=False, # do not unsupervised learning?
# alpha=0.8, # assignment decay
# debug=True, # Do you wanna watch neuron's assignments?
# interval=500, # interval of assignment
# ts_size=5000, # If you have little time for experiments, be able to reduce test size
)
snn.plot(plt_type='wmps', prefix='{}'.format(i+1), f_shape=(10, 10)) # plot maps
# Plot test accuracy transition
snn.plot(plt_type='history', prefix='result')
# Plot weight maps after training
snn.plot(plt_type='wmps', prefix='result', f_shape=(10, 10))
# Plot output spike trains after training
snn.plot(plt_type='sp', range=10)
print(snn.history)