Skip to content

Commit 203c63e

Browse files
Merge pull request #412 from BindsNET/hananel
Bug fixes: GPU issues with examples, ploting and clamping
2 parents 7f89ca0 + 62bbdad commit 203c63e

17 files changed

Lines changed: 201 additions & 103 deletions

File tree

.github/workflows/black.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Black Formater
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-python@v2
11+
- uses: psf/black@stable

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ repos:
33
rev: master
44
hooks:
55
- id: black
6-
language_version: python3.8
6+
language_version: python3

bindsnet/analysis/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def plot_assignments(
450450

451451
if classes is None:
452452
cbar = plt.colorbar(im, cax=cax, ticks=list(range(-1, 11)))
453-
cbar.ax.set_yticklabels(["none"] + list(range(10)))
453+
cbar.ax.set_yticklabels(["none"] + list(range(11)))
454454
else:
455455
cbar = plt.colorbar(im, cax=cax, ticks=np.arange(-1, len(classes)))
456456
cbar.ax.set_yticklabels(["none"] + list(classes))

bindsnet/analysis/visualization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def plot_weights_movie(ws: np.ndarray, sample_every: int = 1) -> None:
1010
# language=rst
1111
"""
1212
Create and plot movie of weights.
13-
13+
1414
:param ws: Array of shape ``[n_examples, source, target, time]``.
1515
:param sample_every: Sub-sample using this parameter.
1616
"""

bindsnet/datasets/alov300.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ALOV300(Dataset):
2828
def __init__(self, root, transform, input_size, download=False):
2929
"""
3030
Class to read the ALOV dataset
31-
31+
3232
:param root: Path to the ALOV folder that contains JPEGImages, Annotations, etc. folders.
3333
:param input_size: The input size of network that is using this data, for rescaling
3434
:param download: Specify whether to download the dataset if it is not present
@@ -247,7 +247,7 @@ def _download(self):
247247
"""
248248
Downloads the correct dataset based on the given parameters
249249
250-
Relies on self.tag to determine both the name of the folder created for the dataset and for the finding the correct download url.
250+
Relies on self.tag to determine both the name of the folder created for the dataset and for the finding the correct download url.
251251
"""
252252

253253
os.makedirs(self.root)

bindsnet/encoding/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NullEncoder(Encoder):
2222
# language=rst
2323
"""
2424
Pass through of the datum that was input.
25-
25+
2626
.. note::
2727
This is not a real spike encoder. Be careful with the usage of this class.
2828
"""

bindsnet/evaluation/evaluation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def assign_labels(
3030
n_neurons = spikes.size(2)
3131

3232
if rates is None:
33-
rates = torch.zeros(n_neurons, n_labels)
33+
rates = torch.zeros((n_neurons, n_labels), device=spikes.device)
3434

3535
# Sum over time dimension (spike ordering doesn't matter).
3636
spikes = spikes.sum(1)
@@ -112,7 +112,7 @@ def all_activity(
112112
# Sum over time dimension (spike ordering doesn't matter).
113113
spikes = spikes.sum(1)
114114

115-
rates = torch.zeros(n_samples, n_labels)
115+
rates = torch.zeros((n_samples, n_labels), device=spikes.device)
116116
for i in range(n_labels):
117117
# Count the number of neurons with this label assignment.
118118
n_assigns = torch.sum(assignments == i).float()
@@ -153,7 +153,7 @@ def proportion_weighting(
153153
# Sum over time dimension (spike ordering doesn't matter).
154154
spikes = spikes.sum(1)
155155

156-
rates = torch.zeros(n_samples, n_labels)
156+
rates = torch.zeros((n_samples, n_labels), device=spikes.device)
157157
for i in range(n_labels):
158158
# Count the number of neurons with this label assignment.
159159
n_assigns = torch.sum(assignments == i).float()
@@ -191,7 +191,7 @@ def ngram(
191191
"""
192192
predictions = []
193193
for activity in spikes:
194-
score = torch.zeros(n_labels)
194+
score = torch.zeros(n_labels, device=spikes.device)
195195

196196
# Aggregate all of the firing neurons' indices
197197
fire_order = []

bindsnet/models/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ def __init__(
405405
w = w / w.max()
406406
w = (w * self.max_inhib) + self.start_inhib
407407
recurrent_output_conn = Connection(
408-
source=self.layers["Y"], target=self.layers["Y"], w=w,
408+
source=self.layers["Y"],
409+
target=self.layers["Y"],
410+
w=w,
409411
)
410412
self.add_connection(recurrent_output_conn, source="Y", target="Y")
411413

bindsnet/network/network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def clone(self) -> "Network":
197197
# language=rst
198198
"""
199199
Returns a cloned network object.
200-
200+
201201
:return: A copy of this network.
202202
"""
203203
virtual_file = tempfile.SpooledTemporaryFile()
@@ -368,9 +368,9 @@ def run(
368368
unclamp = unclamps.get(l, None)
369369
if unclamp is not None:
370370
if unclamp.ndimension() == 1:
371-
self.layers[l].s[unclamp] = 0
371+
self.layers[l].s[:, unclamp] = 0
372372
else:
373-
self.layers[l].s[unclamp[t]] = 0
373+
self.layers[l].s[:, unclamp[t]] = 0
374374

375375
# Inject voltage to neurons.
376376
inject_v = injects_v.get(l, None)

bindsnet/network/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def forward(self, x: torch.Tensor) -> None:
508508

509509
# Integrate inputs.
510510
x.masked_fill_(self.refrac_count > 0, 0.0)
511-
511+
512512
# Decrement refractory counters.
513513
self.refrac_count -= self.dt
514514

0 commit comments

Comments
 (0)