diff --git a/README.md b/README.md index b1716c75..f7d8e740 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,3 @@ -# Important: - -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. - -[Survey link](https://docs.google.com/forms/d/e/1FAIpQLSfOZSyoWL4J_MfHTIq5Jx0dnJSVHNFH7UP3AHG_x7ddlMvBPA/viewform?usp=sf_link) - -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. - -

A Python package used for simulating spiking neural networks (SNNs) on CPUs or GPUs using [PyTorch](http://pytorch.org/) `Tensor` functionality. diff --git a/bindsnet/analysis/plotting.py b/bindsnet/analysis/plotting.py index 7813dd7f..cb4470ac 100644 --- a/bindsnet/analysis/plotting.py +++ b/bindsnet/analysis/plotting.py @@ -228,6 +228,7 @@ def plot_weights( save = a[0] + a[1] plt.savefig(save, bbox_inches="tight") + plt.savefig(a[0] + ".png", bbox_inches="tight") plt.close(fig) plt.ion() @@ -407,6 +408,13 @@ def plot_assignments( if save is not None: plt.ioff() + a = save.split(".") + if len(a) == 2: + save = a[0] + ".1." + a[1] + else: + a[1] = "." + str(1 + int(a[1])) + ".png" + save = a[0] + a[1] + fig, ax = plt.subplots(figsize=figsize) ax.set_title("Categorical assignments") @@ -440,7 +448,7 @@ def plot_assignments( plt.close() plt.ion() - return im + return im, save else: if not im: fig, ax = plt.subplots(figsize=figsize) @@ -749,8 +757,7 @@ def plot_voltages( v[1] .cpu() .numpy()[ - time[0] : time[1], - n_neurons[v[0]][0] : n_neurons[v[0]][1], + time[0] : time[1], n_neurons[v[0]][0] : n_neurons[v[0]][1] ] ) if thresholds is not None and thresholds[v[0]].size() == torch.Size( @@ -764,8 +771,7 @@ def plot_voltages( v[1] .cpu() .numpy()[ - time[0] : time[1], - n_neurons[v[0]][0] : n_neurons[v[0]][1], + time[0] : time[1], n_neurons[v[0]][0] : n_neurons[v[0]][1] ] .T, cmap=cmap, diff --git a/bindsnet/encoding/encodings.py b/bindsnet/encoding/encodings.py index 63ae10bf..1ff231f9 100644 --- a/bindsnet/encoding/encodings.py +++ b/bindsnet/encoding/encodings.py @@ -141,7 +141,7 @@ def poisson( # Create Poisson distribution and sample inter-spike intervals # (incrementing by 1 to avoid zero intervals). - dist = torch.distributions.Poisson(rate=rate) + dist = torch.distributions.Poisson(rate=rate, validate_args=False) intervals = dist.sample(sample_shape=torch.Size([time + 1])) intervals[:, datum != 0] += (intervals[:, datum != 0] == 0).float() diff --git a/bindsnet/evaluation/evaluation.py b/bindsnet/evaluation/evaluation.py index d2cf1a08..9d47f35f 100644 --- a/bindsnet/evaluation/evaluation.py +++ b/bindsnet/evaluation/evaluation.py @@ -207,7 +207,7 @@ def ngram( predictions.append(torch.argmax(score)) - return torch.tensor(predictions).long() + return torch.tensor(predictions, device=spikes.device).long() def update_ngram_scores( @@ -246,7 +246,7 @@ def update_ngram_scores( for order in zip(*(fire_order[k:] for k in range(n))): for sequence in product(*order): if sequence not in ngram_scores: - ngram_scores[sequence] = torch.zeros(n_labels) + ngram_scores[sequence] = torch.zeros(n_labels, device=spikes.device) ngram_scores[sequence][int(labels[i])] += 1 diff --git a/bindsnet/network/nodes.py b/bindsnet/network/nodes.py index 7c721383..87c08955 100644 --- a/bindsnet/network/nodes.py +++ b/bindsnet/network/nodes.py @@ -101,7 +101,7 @@ def forward(self, x: torch.Tensor) -> None: if self.traces_additive: self.x += self.trace_scale * self.s.float() else: - self.x.masked_fill_(self.s, 1) + self.x.masked_fill_(self.s.bool(), 1) if self.sum_input: # Add current input to running sum. diff --git a/bindsnet/network/topology.py b/bindsnet/network/topology.py index e132014a..8ef3cb7c 100644 --- a/bindsnet/network/topology.py +++ b/bindsnet/network/topology.py @@ -794,12 +794,12 @@ def __init__( ) if self.wmin == -np.inf or self.wmax == np.inf: v = torch.clamp( - torch.rand(*source.shape, *target.shape)[i.byte()], + torch.rand(*source.shape, *target.shape)[i.bool()], self.wmin, self.wmax, ) else: - v = self.wmin + torch.rand(*source.shape, *target.shape)[i.byte()] * ( + v = self.wmin + torch.rand(*source.shape, *target.shape)[i.bool()] * ( self.wmax - self.wmin ) w = torch.sparse.FloatTensor(i.nonzero().t(), v) diff --git a/examples/mnist/SOM_LM-SNNs.py b/examples/mnist/SOM_LM-SNNs.py index 480aaa2e..e7726e0f 100644 --- a/examples/mnist/SOM_LM-SNNs.py +++ b/examples/mnist/SOM_LM-SNNs.py @@ -77,7 +77,7 @@ # Determines number of workers to use if n_workers == -1: - n_workers = torch.cuda.is_available() * 4 * torch.cuda.device_count() + n_workers = 0 # torch.cuda.is_available() * 4 * torch.cuda.device_count() n_sqrt = int(np.ceil(np.sqrt(n_neurons))) start_intensity = intensity diff --git a/examples/mnist/batch_eth_mnist.py b/examples/mnist/batch_eth_mnist.py index 6dbee43c..cc1dcecf 100644 --- a/examples/mnist/batch_eth_mnist.py +++ b/examples/mnist/batch_eth_mnist.py @@ -49,7 +49,7 @@ parser.add_argument("--test", dest="train", action="store_false") parser.add_argument("--plot", dest="plot", action="store_true") parser.add_argument("--gpu", dest="gpu", action="store_true") -parser.set_defaults(plot=True, gpu=False) +parser.set_defaults(plot=True, gpu=True) args = parser.parse_args() @@ -90,7 +90,7 @@ # Determines number of workers to use if n_workers == -1: - n_workers = gpu * 4 * torch.cuda.device_count() + n_workers = 0 # gpu * 1 * torch.cuda.device_count() n_sqrt = int(np.ceil(np.sqrt(n_neurons))) start_intensity = intensity @@ -116,7 +116,7 @@ dataset = MNIST( PoissonEncoder(time=time, dt=dt), None, - root=os.path.join(ROOT_DIR, "data", "MNIST"), + "../../data/MNIST", download=True, transform=transforms.Compose( [transforms.ToTensor(), transforms.Lambda(lambda x: x * intensity)] diff --git a/examples/mnist/conv_mnist.py b/examples/mnist/conv_mnist.py index 1656d6a3..88225300 100644 --- a/examples/mnist/conv_mnist.py +++ b/examples/mnist/conv_mnist.py @@ -41,7 +41,7 @@ parser.add_argument("--test", dest="train", action="store_false") parser.add_argument("--plot", dest="plot", action="store_true") parser.add_argument("--gpu", dest="gpu", action="store_true") -parser.set_defaults(plot=True, gpu=False, train=True) +parser.set_defaults(plot=True, gpu=True, train=True) args = parser.parse_args() @@ -164,7 +164,7 @@ start = t() train_dataloader = torch.utils.data.DataLoader( - train_dataset, batch_size=1, shuffle=True, num_workers=4, pin_memory=gpu + train_dataset, batch_size=1, shuffle=True, num_workers=0, pin_memory=gpu ) for step, batch in enumerate(tqdm(train_dataloader)): diff --git a/examples/mnist/eth_mnist.py b/examples/mnist/eth_mnist.py index e14eda0c..30fd3411 100644 --- a/examples/mnist/eth_mnist.py +++ b/examples/mnist/eth_mnist.py @@ -48,7 +48,7 @@ parser.add_argument("--test", dest="train", action="store_false") parser.add_argument("--plot", dest="plot", action="store_true") parser.add_argument("--gpu", dest="gpu", action="store_true") -parser.set_defaults(plot=True, gpu=False) +parser.set_defaults(plot=True, gpu=True) args = parser.parse_args() @@ -85,7 +85,7 @@ # Determines number of workers to use if n_workers == -1: - n_workers = gpu * 4 * torch.cuda.device_count() + n_workers = 0 # gpu * 4 * torch.cuda.device_count() if not train: update_interval = n_test diff --git a/examples/mnist/supervised_mnist.py b/examples/mnist/supervised_mnist.py index 657fbb28..1df86edf 100644 --- a/examples/mnist/supervised_mnist.py +++ b/examples/mnist/supervised_mnist.py @@ -46,7 +46,7 @@ parser.add_argument("--plot", dest="plot", action="store_true") parser.add_argument("--gpu", dest="gpu", action="store_true") parser.add_argument("--device_id", type=int, default=0) -parser.set_defaults(plot=True, gpu=False, train=True) +parser.set_defaults(plot=True, gpu=True, train=True) args = parser.parse_args() diff --git a/requirements.txt b/requirements.txt index 9c5463e1..ef142705 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,8 @@ foolbox scipy>=1.1.0 numpy>=1.14.2 cython>=0.28.5 -torch==1.8.1 -torchvision==0.9.1 +torch>=1.5.1 +torchvision>=0.6.1 tqdm>=4.19.9 setuptools>=39.0.1 matplotlib>=2.1.0 diff --git a/setup.py b/setup.py index 287e2ea0..044a8dfa 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="BindsNET", - version="0.2.8", + version="0.2.9", description="Spiking neural networks for ML in Python", license="AGPL-3.0", long_description=long_description, @@ -17,8 +17,8 @@ zip_safe=False, install_requires=[ "numpy>=1.14.2", - "torch==1.8.1", - "torchvision==0.9.1", + "torch>=1.5.1", + "torchvision>=0.6.1", "tensorboardX>=1.7", "tqdm>=4.19.9", "matplotlib>=2.1.0",