{"id":13717534,"url":"https://github.com/BasBuller/PySNN","last_synced_at":"2025-05-07T07:31:47.192Z","repository":{"id":43932582,"uuid":"199586819","full_name":"BasBuller/PySNN","owner":"BasBuller","description":"Efficient Spiking Neural Network framework, built on top of PyTorch for GPU acceleration","archived":false,"fork":false,"pushed_at":"2024-07-31T11:31:14.000Z","size":13371,"stargazers_count":216,"open_issues_count":4,"forks_count":28,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-03T08:46:03.157Z","etag":null,"topics":["deep-learning","dynamic","gpu-acceleration","gpu-computing","machine-learning","neural-networks","python3","pytorch","spiking-neural-networks","stdp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BasBuller.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-30T06:13:17.000Z","updated_at":"2024-09-28T15:40:01.000Z","dependencies_parsed_at":"2022-09-12T19:10:20.879Z","dependency_job_id":null,"html_url":"https://github.com/BasBuller/PySNN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasBuller%2FPySNN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasBuller%2FPySNN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasBuller%2FPySNN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasBuller%2FPySNN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BasBuller","download_url":"https://codeload.github.com/BasBuller/PySNN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224573504,"owners_count":17333804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","dynamic","gpu-acceleration","gpu-computing","machine-learning","neural-networks","python3","pytorch","spiking-neural-networks","stdp"],"created_at":"2024-08-03T00:01:23.692Z","updated_at":"2024-11-14T05:32:04.801Z","avatar_url":"https://github.com/BasBuller.png","language":"Python","readme":"# __PySNN__\n\n[![Build Status](https://travis-ci.com/BasBuller/PySNN.svg?branch=master)](https://travis-ci.com/BasBuller/PySNN)\n[![codecov.io](https://codecov.io/gh/BasBuller/PySNN/coverage.svg?branch=master)](https://codecov.io/gh/BasBuller/PySNN)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nSpiking neural network (SNN) framework written on top of PyTorch for efficient simulation of SNNs both on _**CPU**_ and _**GPU**_. The framework is intended for with correlation based learning methods. The library adheres to the highly modular and dynamic design of PyTorch, and does not require its user to learn a new framework. \n\n*This framework's power lies in the ease of defining and mixing new Neuron and Connection objects that seamlessly work together, even different versions, in a single network.*\n\nPySNN is designed to mostly provide low level objects to its user that can be combined and mixed, just as in PyTorch. The biggest difference is that a network now consists of two types of modules, instead of the single nn.Module in regular PyTorch. These new modules are the pysnn.Neuron and pysnn.Connection.\n\nDocumentation can be found at: [https://basbuller.github.io/PySNN/](https://basbuller.github.io/PySNN/)\n\nDesign of the PySNN framework took inspiration from the following two libraries:\n* [BindsNET](https://github.com/Hananel-Hazan/bindsnet)\n* [cuSNN](https://github.com/tudelft/cuSNN) \n\n## __Installation__\n\nInstallation can be done with pip:\n\n```bash\n$ pip install pysnn\n```\n\nIf you want to make updates to the library without having to reinstall it, use the following install command instead:\n\n```bash\n$ git clone https://github.com/BasBuller/PySNN.git\n$ cd PySNN/\n$ pip install -e .\n```\n\nSome examples need additional libraries. To install these, run:\n\n```bash\n$ pip install pysnn[examples]\n```\n\nCode is formatted with [Black](https://github.com/psf/black) using a pre-commit hook. To configure it, run:\n\n```bash\n$ pre-commit install\n```\n\n### Requirements\nInstalling PySNN requires a Python version of 3.6 or higher, Python 2 is not supported. It also requires PyTorch to be of version 1.2 or higher.\n\n## __Network Structure__\n\nIntention is to mirror most of the structure of PyTorch framework. As an example, the followig piece of code shows how much a Spiking Neural Network definition in PySNN looks like a network definition in PyTorch. The network's graph is cyclical, due to the feedback connection from the output neurons to the hidden neurons.\n\n```python\nclass Network(SNNNetwork):\n    def __init__(self):\n        super(Network, self).__init__()\n\n        # Input\n        self.input = Input((batch_size, 1, n_in), *input_dynamics)\n\n        # Layer 1\n        self.mlp1_c = Linear(n_in, n_hidden, *connection_dynamics)\n        self.neuron1 = LIFNeuron((batch_size, 1, n_hidden), *neuron_dynamics)\n        self.add_layer(\"fc1\", self.mlp1_c, self.neuron1)\n\n        # Layer 2\n        self.mlp2_c = Linear(n_hidden, n_out, *connection_dynamics)\n        self.neuron2 = LIFNeuron((batch_size, 1, n_out), *neuron_dynamics)\n        self.add_layer(\"fc2\", self.mlp2_c, self.neuron2)\n\n        # Feedback connection from neuron 2 to neuron 1\n        self.mlp2_prev = Linear(n_out, n_hidden, *c_dynamics)\n        self.add_layer(\"fc2_back\", self.mlp2_prev, self.neuron1)\n\n    def forward(self, input):\n        spikes, trace = self.input(input)\n\n        # Layer 1\n        x_prev, _ = self.mlp2_prev(self.neuron2.spikes, self.neuron2.trace)\n        x_forw, _ = self.mlp1_c(x, t)\n        x, t = self.neuron1([x_forw, x_rec, x_prev])\n\n        # Layer out\n        spikes, trace = self.mlp2_c(spikes, trace)\n        spikes, trace = self.neuron2(spikes, trace)\n\n        return x\n```\n\n## Contributing\n\nAny help, suggestions, or additions to PySNN are greatly appreciated! Feel free to make pull request or start a chat about the library. In case of making a pull request, please do have a look at the contribution guidelines.\n\n## __Network Definition__\n\nThe overall structure of a network definition is the same as in PyTorch where possible. All newly defined object inherit from the nn.Module class. The biggest differences are as follows:\n\n- Each layer consists out of a Connection and a Neuron object because they both implement different time based dynamics.\n- Training does not use gradients.\n- Neurons have a state that persists between consecutive timesteps.\n- Networks inherit from a special pysnn.SNNNetwork class.\n\n## __Neurons__\n\nThis object is the main difference with ANNs. Neurons have highly non-linear (and also non-differentiable) behaviour. They have an internal voltage, once that surpasses a threshold value it generates a binary spike (non-differentiable operation) which is then propagated to the following layer of Neurons through a Connection object. Defining a new Neuron class is rather simple, one only has to define new neuronal dynamics functions for the Neuron's voltage and trace. The supporting functions are (almost) all defined in the Neuron base class.\n\nFor an introduction to (biological) neuronal dynamics, and spiking neural networks the reader is referred to [Neuronal Dynamics](https://neuronaldynamics.epfl.ch/online/index.html) by Wulfram Gerstner, Werner M. Kistler, Richard Naud and Liam Paninski.\n\n## __Connections__\n\nIt contains connection weights and routes signals between different layers. It only really differs with PyTorch layers in the fact that it has a state between iterations of its past activity, and the possibility of delaying signal transmission between layers.\n\n### __Connection Shapes__\n\nIn order to keep track of traces and delays in information passing tensors an extra dimension is needed compared to the PyTorch conventions. \nDue to the addition of spike traces, each spiking tensor contains an extra trace dimension as the last dimension. The resulting dimension ordering is as follows for an image tensor (trace is indicated as R to not be confused with time for video data):\n\n    [batch size, channels, height, width, traces] (B,C,H,W,R)\n\nFor fully connected layers the resulting tensor is as follows (free dimension can be used the same as in PyTorch):\n\n    [batch size, free dimension, input elements, traces] (B,F,I,R)\n\nCurrently, no explicit 3D convolution is possible like is common within video-processing. Luckily, SNNs have a built-in temporal dimension and are (currently still theoretically) well suited for processing videos event by event, and thus not needing 3D convolution.\n\n## __Traces__\n\nTraces are stored both in the Neuron and Connection objects. Currently, Connection objects takes traces from their pre-synaptic Neurons and propagate the trace over time, meaning it does not do any further processing on the traces. If it is desired, one can implement separate trace processing in a custom Connection object.\n\nTraces are stored in a tensor in each Connection, as well as the delay for each trace propagating through the Connection. Only one trace (or signal) can tracked through each synapse. In case delay times through a synapse become very long (longer than the refractory period of the pre-synaptic cell) it is possible for a new signal to enter the Connection before the previous one has travelled through it. In the current implementation the old signal will be overwritten, meaning the information is lost before it can be used!\n\n    It is up to the user to assure refractory periods are just as long or longer than the synaptic delay in the following Connection!\n\n## __Module definitions__\n\nMake sure each module has a self.reset_state() method! It is called from the SNNNetwork class and is needed for proper simulation of multiple\ninputs.\n\n\u003c!-- ## __To do__\n\n- Determine performance of the functions in pysnn.functional, they return the difference and using inplace operations in the Module that is\n  calling the functional might provide better performance.\n- Allow for having a local copy of a cell's entire trace history. Possibly also extending this to Connection objects. This will result in a large increase in memory usage.\n- Change from using .uint8 to .bool datatypes with the introduction of PyTorch 1.2.\n\n### __Learning rules__\n\n- Adjust learning rule such that it is able to select which weights are learnable and which are not. \n- Adjust layer class such that the parameter __training__ is also used within a learning rule. Just make sure gradients are always turned off since those are not needed...\n- Add support for convolutional Connections.\n\n### __Connection classes__\n\n- For connection class, make sure it can handle the transmission of multiple spike within the same synapse? --\u003e\n","funding_links":[],"categories":["Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries","Frameworks","Spiking and Neuromorphic Frameworks"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBasBuller%2FPySNN","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBasBuller%2FPySNN","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBasBuller%2FPySNN/lists"}