Biologically based dynamics for machine learning and deep learning tools for neuroscience.
APACHE-2.0 License
It's time to bring deep learning and neuroscience together. With this library, we offer machine learning tools to neuroscientists and we offer neuroscience tools to computer scientists. These two domains were created to be one!
NeuroTorch was developed to be easy to use and you can do simple things with few lines of code. Moreover, NeuroTorch is modular so you can adapt it to your needs relatively quickly. Thanks and stay tuned, because more is coming!
What can be done with NeuroTorch in the current version?
Method | Commands |
---|---|
PyPi | pip install neurotorch |
source | pip install git+https://github.com/NeuroTorch/NeuroTorch |
wheel | 1.Download the .whl file here; 2. Copy the path of this file on your computer; 3. pip install [path].whl
|
To install the last unstable version, you can install it by downloading the last version of the .whl file and following the instructions above.
See the readme of the tutorials folder here.
Tutorial | Project | Description |
---|---|---|
Jupyter Notebook | Repository | Image classification with spiking networks (Mnist/Fashion-Mnist). |
Jupyter Notebook | Repository | Time series classification with spiking networks (Heidelberg). |
Jupyter Notebook | Repository | Time series forecasting with spiking networks (Neuronal activity) Sorry, it's a work in progress, so it's not publish yet. |
Jupyter Notebook | Null | Time series forecasting with Wilson-Cowan (Neuronal activity). |
import neurotorch as nt
import torch
import pprint
n_hidden_neurons = 128
checkpoint_folder = "./checkpoints/checkpoint_000"
checkpoint_manager = nt.CheckpointManager(checkpoint_folder)
dataloaders = get_dataloaders(
batch_size=256,
train_val_split_ratio=0.95,
)
network = nt.SequentialRNN(
layers=[
nt.LIFLayer(
input_size=nt.Size(
[
nt.Dimension(None, nt.DimensionProperty.TIME),
nt.Dimension(dataloaders["test"].dataset.n_units, nt.DimensionProperty.NONE)
]
),
output_size=n_hidden_neurons,
use_recurrent_connection=True,
),
nt.SpyLILayer(output_size=dataloaders["test"].dataset.n_classes),
],
name=f"Network",
checkpoint_folder=checkpoint_folder,
).build()
learning_algorithm = nt.BPTT(optimizer=torch.optim.Adam(network.parameters(), lr=1e-3))
trainer = nt.ClassificationTrainer(
model=network,
callbacks=[checkpoint_manager, learning_algorithm],
verbose=True,
)
training_history = trainer.train(
dataloaders["train"],
dataloaders["val"],
n_iterations=100,
load_checkpoint_mode=nt.LoadCheckpointMode.LAST_ITR,
)
training_history.plot(show=True)
network.load_checkpoint(checkpoint_manager.checkpoints_meta_path, nt.LoadCheckpointMode.BEST_ITR, verbose=True)
predictions = {
k: nt.metrics.ClassificationMetrics.compute_y_true_y_pred(
network, dataloader, verbose=True, desc=f"{k} predictions"
)
for k, dataloader in dataloaders.items()
}
accuracies = {
k: nt.metrics.ClassificationMetrics.accuracy(network, y_true=y_true, y_pred=y_pred)
for k, (y_true, y_pred) in predictions.items()
}
pprint.pprint(accuracies)
On the one hand, neuroscientists are increasingly using machine learning (ML) without necessarily having the expertise to create training pipelines. On the other hand, most ML experts lack the neuroscience background to implement biologically inspired models. There is thus a need for a tool providing a complete ML pipeline with features originating from neuroscience while using a simple and intuitive interface.
The goal of this work is to provide a Python package, NeuroTorch, offering a flexible and intuitive training pipeline together with biologically-constrained neuronal dynamics. This tool will include several learning strategies highly used in both ML and neuroscience to ensure that both fields can benefit from the package.
This package is part of a postgraduate research project realized by Jérémie Gince and supervised by Simon V Hardy and Patrick Desrosiers. Our work was supported by: (1) UNIQUE, a FRQNT-funded research center, (2) the Sentinelle Nord program of Université Laval, funded by the Canada First Research Excellence Fund, and (3) NSERC.
@misc{Gince2022,
title={NeuroTorch: A Python library for machine learning and neuroscience.},
author={Jérémie Gince},
year={2022},
publisher={Université Laval},
url={https://github.com/NeuroTorch},
}