Skip to content

Commit ead5521

Browse files
Merge pull request #478 from BindsNET/hananel
Update BindsNET to PyTorch 1.8.1
2 parents 9a945a3 + f8a56f2 commit ead5521

File tree

13 files changed

+31
-34
lines changed

13 files changed

+31
-34
lines changed

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
# Important:
2-
3-
If you are using BindsNET for your research, please consider answering a short survey on the value of a standardized format that could be used for the exchange of computational models in neuroscience, cognitive science, and computer science.
4-
5-
[Survey link](https://docs.google.com/forms/d/e/1FAIpQLSfOZSyoWL4J_MfHTIq5Jx0dnJSVHNFH7UP3AHG_x7ddlMvBPA/viewform?usp=sf_link)
6-
7-
Data from this survey will be used exclusively for our own internal purposes, and will not be shared beyond our small group other than summary form for any purpose. The survey is anonymous unless you chose to add an email address for follow-up correspondence.
8-
9-
101
<p align="center"><img width="25%" src="docs/logo.png"/></p>
112

123
A Python package used for simulating spiking neural networks (SNNs) on CPUs or GPUs using [PyTorch](http://pytorch.org/) `Tensor` functionality.

bindsnet/analysis/plotting.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def plot_weights(
228228
save = a[0] + a[1]
229229

230230
plt.savefig(save, bbox_inches="tight")
231+
plt.savefig(a[0] + ".png", bbox_inches="tight")
231232

232233
plt.close(fig)
233234
plt.ion()
@@ -407,6 +408,13 @@ def plot_assignments(
407408
if save is not None:
408409
plt.ioff()
409410

411+
a = save.split(".")
412+
if len(a) == 2:
413+
save = a[0] + ".1." + a[1]
414+
else:
415+
a[1] = "." + str(1 + int(a[1])) + ".png"
416+
save = a[0] + a[1]
417+
410418
fig, ax = plt.subplots(figsize=figsize)
411419
ax.set_title("Categorical assignments")
412420

@@ -440,7 +448,7 @@ def plot_assignments(
440448
plt.close()
441449

442450
plt.ion()
443-
return im
451+
return im, save
444452
else:
445453
if not im:
446454
fig, ax = plt.subplots(figsize=figsize)
@@ -749,8 +757,7 @@ def plot_voltages(
749757
v[1]
750758
.cpu()
751759
.numpy()[
752-
time[0] : time[1],
753-
n_neurons[v[0]][0] : n_neurons[v[0]][1],
760+
time[0] : time[1], n_neurons[v[0]][0] : n_neurons[v[0]][1]
754761
]
755762
)
756763
if thresholds is not None and thresholds[v[0]].size() == torch.Size(
@@ -764,8 +771,7 @@ def plot_voltages(
764771
v[1]
765772
.cpu()
766773
.numpy()[
767-
time[0] : time[1],
768-
n_neurons[v[0]][0] : n_neurons[v[0]][1],
774+
time[0] : time[1], n_neurons[v[0]][0] : n_neurons[v[0]][1]
769775
]
770776
.T,
771777
cmap=cmap,

bindsnet/encoding/encodings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def poisson(
141141

142142
# Create Poisson distribution and sample inter-spike intervals
143143
# (incrementing by 1 to avoid zero intervals).
144-
dist = torch.distributions.Poisson(rate=rate)
144+
dist = torch.distributions.Poisson(rate=rate, validate_args=False)
145145
intervals = dist.sample(sample_shape=torch.Size([time + 1]))
146146
intervals[:, datum != 0] += (intervals[:, datum != 0] == 0).float()
147147

bindsnet/evaluation/evaluation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def ngram(
207207

208208
predictions.append(torch.argmax(score))
209209

210-
return torch.tensor(predictions).long()
210+
return torch.tensor(predictions, device=spikes.device).long()
211211

212212

213213
def update_ngram_scores(
@@ -246,7 +246,7 @@ def update_ngram_scores(
246246
for order in zip(*(fire_order[k:] for k in range(n))):
247247
for sequence in product(*order):
248248
if sequence not in ngram_scores:
249-
ngram_scores[sequence] = torch.zeros(n_labels)
249+
ngram_scores[sequence] = torch.zeros(n_labels, device=spikes.device)
250250

251251
ngram_scores[sequence][int(labels[i])] += 1
252252

bindsnet/network/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def forward(self, x: torch.Tensor) -> None:
101101
if self.traces_additive:
102102
self.x += self.trace_scale * self.s.float()
103103
else:
104-
self.x.masked_fill_(self.s, 1)
104+
self.x.masked_fill_(self.s.bool(), 1)
105105

106106
if self.sum_input:
107107
# Add current input to running sum.

bindsnet/network/topology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,12 @@ def __init__(
794794
)
795795
if self.wmin == -np.inf or self.wmax == np.inf:
796796
v = torch.clamp(
797-
torch.rand(*source.shape, *target.shape)[i.byte()],
797+
torch.rand(*source.shape, *target.shape)[i.bool()],
798798
self.wmin,
799799
self.wmax,
800800
)
801801
else:
802-
v = self.wmin + torch.rand(*source.shape, *target.shape)[i.byte()] * (
802+
v = self.wmin + torch.rand(*source.shape, *target.shape)[i.bool()] * (
803803
self.wmax - self.wmin
804804
)
805805
w = torch.sparse.FloatTensor(i.nonzero().t(), v)

examples/mnist/SOM_LM-SNNs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
# Determines number of workers to use
7979
if n_workers == -1:
80-
n_workers = torch.cuda.is_available() * 4 * torch.cuda.device_count()
80+
n_workers = 0 # torch.cuda.is_available() * 4 * torch.cuda.device_count()
8181

8282
n_sqrt = int(np.ceil(np.sqrt(n_neurons)))
8383
start_intensity = intensity

examples/mnist/batch_eth_mnist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
parser.add_argument("--test", dest="train", action="store_false")
5050
parser.add_argument("--plot", dest="plot", action="store_true")
5151
parser.add_argument("--gpu", dest="gpu", action="store_true")
52-
parser.set_defaults(plot=True, gpu=False)
52+
parser.set_defaults(plot=True, gpu=True)
5353

5454
args = parser.parse_args()
5555

@@ -90,7 +90,7 @@
9090

9191
# Determines number of workers to use
9292
if n_workers == -1:
93-
n_workers = gpu * 4 * torch.cuda.device_count()
93+
n_workers = 0 # gpu * 1 * torch.cuda.device_count()
9494

9595
n_sqrt = int(np.ceil(np.sqrt(n_neurons)))
9696
start_intensity = intensity
@@ -116,7 +116,7 @@
116116
dataset = MNIST(
117117
PoissonEncoder(time=time, dt=dt),
118118
None,
119-
root=os.path.join(ROOT_DIR, "data", "MNIST"),
119+
"../../data/MNIST",
120120
download=True,
121121
transform=transforms.Compose(
122122
[transforms.ToTensor(), transforms.Lambda(lambda x: x * intensity)]

examples/mnist/conv_mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
parser.add_argument("--test", dest="train", action="store_false")
4242
parser.add_argument("--plot", dest="plot", action="store_true")
4343
parser.add_argument("--gpu", dest="gpu", action="store_true")
44-
parser.set_defaults(plot=True, gpu=False, train=True)
44+
parser.set_defaults(plot=True, gpu=True, train=True)
4545

4646
args = parser.parse_args()
4747

@@ -164,7 +164,7 @@
164164
start = t()
165165

166166
train_dataloader = torch.utils.data.DataLoader(
167-
train_dataset, batch_size=1, shuffle=True, num_workers=4, pin_memory=gpu
167+
train_dataset, batch_size=1, shuffle=True, num_workers=0, pin_memory=gpu
168168
)
169169

170170
for step, batch in enumerate(tqdm(train_dataloader)):

examples/mnist/eth_mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
parser.add_argument("--test", dest="train", action="store_false")
4949
parser.add_argument("--plot", dest="plot", action="store_true")
5050
parser.add_argument("--gpu", dest="gpu", action="store_true")
51-
parser.set_defaults(plot=True, gpu=False)
51+
parser.set_defaults(plot=True, gpu=True)
5252

5353
args = parser.parse_args()
5454

@@ -85,7 +85,7 @@
8585

8686
# Determines number of workers to use
8787
if n_workers == -1:
88-
n_workers = gpu * 4 * torch.cuda.device_count()
88+
n_workers = 0 # gpu * 4 * torch.cuda.device_count()
8989

9090
if not train:
9191
update_interval = n_test

0 commit comments

Comments
 (0)