英語| 中文(中文)

Spikingjelly是基於Pytorch的Spiking神經網絡(SNN)的開源深度學習框架。
Spikingjelly的文檔用英語和中文編寫:https://spikingjelly.readthedocs.io。
請注意,Spikingjelly基於Pytorch。在安裝Spikingjelly之前,請確保您已經安裝了Pytorch。
版本註釋
奇數版號是開發版本,使用github/openi存儲庫更新。均勻版本號是穩定版本,可在PYPI上找到。
默認文檔適用於最新的開發版本。如果您使用的是穩定版本,請不要忘記在相應版本中切換到DOC。
從0.0.0.0.14版本中,包括clock_driven和event_driven在內的模塊被重命名。請參考從舊版本遷移的教程。
如果您使用舊版本的Spikingjelly,則可能會遇到一些致命的錯誤。有關更多詳細信息,請參閱帶有版本的錯誤歷史記錄。
不同版本的文檔:
從PYPI安裝最後一個穩定版本:
pip install spikingjelly從源代碼安裝最新的開發版本:
來自Github:
git clone https://github.com/fangwei123456/spikingjelly.git
cd spikingjelly
python setup.py install來自Openi:
git clone https://openi.pcl.ac.cn/OpenI/spikingjelly.git
cd spikingjelly
python setup.py installSpikingjelly對用戶友好。用Spikingjelly建造SNN就像在Pytorch中建造Ann一樣簡單:
nn . Sequential (
layer . Flatten (),
layer . Linear ( 28 * 28 , 10 , bias = False ),
neuron . LIFNode ( tau = tau , surrogate_function = surrogate . ATan ())
)這個帶有泊松編碼器的簡單網絡可以在MNIST測試數據集上實現92%的精度。閱讀有關更多詳細信息,請參閱教程。您還可以在Python終端中運行此代碼,以進行分類的MNIST培訓:
python - m spikingjelly . activation_based . examples . lif_fc_mnist - tau 2.0 - T 100 - device cuda : 0 - b 64 - epochs 100 - data - dir < PATH to MNIST > - amp - opt adam - lr 1e-3 - j 8 Spikingjelly實現了相對一般的ANN-SNN轉換接口。用戶可以通過Pytorch實現轉換。此外,用戶可以自定義轉換模式。
class ANN ( nn . Module ):
def __init__ ( self ):
super (). __init__ ()
self . network = nn . Sequential (
nn . Conv2d ( 1 , 32 , 3 , 1 ),
nn . BatchNorm2d ( 32 , eps = 1e-3 ),
nn . ReLU (),
nn . AvgPool2d ( 2 , 2 ),
nn . Conv2d ( 32 , 32 , 3 , 1 ),
nn . BatchNorm2d ( 32 , eps = 1e-3 ),
nn . ReLU (),
nn . AvgPool2d ( 2 , 2 ),
nn . Conv2d ( 32 , 32 , 3 , 1 ),
nn . BatchNorm2d ( 32 , eps = 1e-3 ),
nn . ReLU (),
nn . AvgPool2d ( 2 , 2 ),
nn . Flatten (),
nn . Linear ( 32 , 10 )
)
def forward ( self , x ):
x = self . network ( x )
return x在MNIST測試數據集上轉換後,使用模擬編碼的簡單網絡可以達到98.44%的精度。閱讀教程以獲取更多詳細信息。您還可以在Python終端中運行此代碼,以使用轉換的模型對MNIST進行分類:
> >> import spikingjelly . activation_based . ann2snn . examples . cnn_mnist as cnn_mnist
> >> cnn_mnist . main ()Spikingjelly為多步神經元提供了兩個後端。您可以使用用戶友好的torch後端來輕鬆編碼和調試,並使用cupy後端進行更快的訓練速度。
下圖比較了多步LIF神經元的兩個後端的執行時間( float32 ):

float16還由cupy後端提供,可用於自動混合精確訓練。
要使用cupy後端,請安裝Cupy。請注意, cupy後端僅支持GPU,而torch後端則支持CPU和GPU。
就像使用pytorch一樣簡單。
> >> net = nn . Sequential ( layer . Flatten (), layer . Linear ( 28 * 28 , 10 , bias = False ), neuron . LIFNode ( tau = tau ))
> >> net = net . to ( device ) # Can be CPU or CUDA devices Spikingjelly包括以下神經形態數據集:
| 數據集 | 來源 |
|---|---|
| ASL-DVS | 基於圖的神經形態視覺傳感的對象分類 |
| CIFAR10-DVS | CIFAR10-DVS:用於對象分類的事件流數據集 |
| DVS128手勢 | 低功率,完全基於事件的手勢識別系統 |
| ES-IMAGENET | ES-IMAGENET:一百萬個用於尖峰神經網絡的事件流分類數據集 |
| hardvs | HARDVS:通過動態視覺傳感器重新審視人類活動識別 |
| N-Caltech101 | 將靜態圖像數據集轉換為使用掃視的神經形態數據集 |
| N-MNIST | 將靜態圖像數據集轉換為使用掃視的神經形態數據集 |
| 導航手勢 | 基於事件的手勢識別具有智能手機計算功能的動態背景抑制 |
| 尖刺海德堡數字(SHD) | 海德堡尖峰數據集用於尖峰神經網絡的系統評估 |
| DVS-LIP | 用於基於事件的唇部閱讀的多元格式時空特徵感知到的網絡 |
用戶可以使用Spikingjelly集成的原始事件數據和框架數據:
import torch
from torch . utils . data import DataLoader
from spikingjelly . datasets import pad_sequence_collate , padded_sequence_mask
from spikingjelly . datasets . dvs128_gesture import DVS128Gesture
# Set the root directory for the dataset
root_dir = 'D:/datasets/DVS128Gesture'
# Load event dataset
event_set = DVS128Gesture ( root_dir , train = True , data_type = 'event' )
event , label = event_set [ 0 ]
# Print the keys and their corresponding values in the event data
for k in event . keys ():
print ( k , event [ k ])
# t [80048267 80048277 80048278 ... 85092406 85092538 85092700]
# x [49 55 55 ... 60 85 45]
# y [82 92 92 ... 96 86 90]
# p [1 0 0 ... 1 0 0]
# label 0
# Load a dataset with fixed frame numbers
fixed_frames_number_set = DVS128Gesture ( root_dir , train = True , data_type = 'frame' , frames_number = 20 , split_by = 'number' )
# Randomly select two frames and print their shapes
rand_index = torch . randint ( low = 0 , high = fixed_frames_number_set . __len__ (), size = [ 2 ])
for i in rand_index :
frame , label = fixed_frames_number_set [ i ]
print ( f'frame[ { i } ].shape=[T, C, H, W]= { frame . shape } ' )
# frame[308].shape=[T, C, H, W]=(20, 2, 128, 128)
# frame[453].shape=[T, C, H, W]=(20, 2, 128, 128)
# Load a dataset with a fixed duration and print the shapes of the first 5 samples
fixed_duration_frame_set = DVS128Gesture ( root_dir , data_type = 'frame' , duration = 1000000 , train = True )
for i in range ( 5 ):
x , y = fixed_duration_frame_set [ i ]
print ( f'x[ { i } ].shape=[T, C, H, W]= { x . shape } ' )
# x[0].shape=[T, C, H, W]=(6, 2, 128, 128)
# x[1].shape=[T, C, H, W]=(6, 2, 128, 128)
# x[2].shape=[T, C, H, W]=(5, 2, 128, 128)
# x[3].shape=[T, C, H, W]=(5, 2, 128, 128)
# x[4].shape=[T, C, H, W]=(7, 2, 128, 128)
# Create a data loader for the fixed duration frame dataset and print the shapes and sequence lengths
train_data_loader = DataLoader ( fixed_duration_frame_set , collate_fn = pad_sequence_collate , batch_size = 5 )
for x , y , x_len in train_data_loader :
print ( f'x.shape=[N, T, C, H, W]= { tuple ( x . shape ) } ' )
print ( f'x_len= { x_len } ' )
mask = padded_sequence_mask ( x_len ) # mask.shape = [T, N]
print ( f'mask= n { mask . t (). int () } ' )
break
# x.shape=[N, T, C, H, W]=(5, 7, 2, 128, 128)
# x_len=tensor([6, 6, 5, 5, 7])
# mask=
# tensor([[1, 1, 1, 1, 1, 1, 0],
# [1, 1, 1, 1, 1, 1, 0],
# [1, 1, 1, 1, 1, 0, 0],
# [1, 1, 1, 1, 1, 0, 0],
# [1, 1, 1, 1, 1, 1, 1]], dtype=torch.int32)將來將包含更多數據集。
如果某些數據集的下載鏈接不適用於某些用戶,則用戶可以從Openi Mirror下載:
https://openi.pcl.ac.cn/openi/spikingjelly/datasets?type=0
通過其許可證或作者的協議允許所有保存在Openi鏡中的數據集。
Spikingjelly提供精心設計的教程。以下是一些教程:
| 數字 | 教程 |
|---|---|
![]() | 基本概念 |
![]() | 神經元 |
![]() | 單個完全連接的層SNN分類MNIST |
![]() | 卷積SNN分類fmnist |
![]() | Ann2snn |
![]() | 神經形態數據集處理 |
![]() | 對DVS手勢進行分類 |
![]() | 經常連接和狀態突觸 |
![]() | STDP學習 |
![]() | 強化學習 |
此處未列出的其他教程也可以在文檔https://spikingjelly.readthedocs.io上找到。
使用Spikingjelly的出版物記錄在出版物中。如果您在紙張中使用Spikingjelly,也可以通過拉請請求將其添加到該表中。
如果您在工作中使用Spikingjelly,請如下引用:
@article{
doi:10.1126/sciadv.adi1480,
author = {Wei Fang and Yanqi Chen and Jianhao Ding and Zhaofei Yu and Timothée Masquelier and Ding Chen and Liwei Huang and Huihui Zhou and Guoqi Li and Yonghong Tian },
title = {SpikingJelly: An open-source machine learning infrastructure platform for spike-based intelligence},
journal = {Science Advances},
volume = {9},
number = {40},
pages = {eadi1480},
year = {2023},
doi = {10.1126/sciadv.adi1480},
URL = {https://www.science.org/doi/abs/10.1126/sciadv.adi1480},
eprint = {https://www.science.org/doi/pdf/10.1126/sciadv.adi1480},
abstract = {Spiking neural networks (SNNs) aim to realize brain-inspired intelligence on neuromorphic chips with high energy efficiency by introducing neural dynamics and spike properties. As the emerging spiking deep learning paradigm attracts increasing interest, traditional programming frameworks cannot meet the demands of automatic differentiation, parallel computation acceleration, and high integration of processing neuromorphic datasets and deployment. In this work, we present the SpikingJelly framework to address the aforementioned dilemma. We contribute a full-stack toolkit for preprocessing neuromorphic datasets, building deep SNNs, optimizing their parameters, and deploying SNNs on neuromorphic chips. Compared to existing methods, the training of deep SNNs can be accelerated 11×, and the superior extensibility and flexibility of SpikingJelly enable users to accelerate custom models at low costs through multilevel inheritance and semiautomatic code generation. SpikingJelly paves the way for synthesizing truly energy-efficient SNN-based machine intelligence systems, which will enrich the ecology of neuromorphic computing. Motivation and introduction of the software framework SpikingJelly for spiking deep learning.}}
您可以閱讀問題並獲取要解決的問題以及最新的開發計劃。我們歡迎所有用戶加入開發計劃,解決問題並發送拉力請求的討論。
並非所有的API文檔都用英語和中文編寫。我們歡迎用戶完成翻譯(從英語到中文或英語)。
多媒體學習小組,數字媒體研究所(NELVT),北京大學和彭本實驗室是Spikingjelly的主要開發商。


可以在此處找到開發人員列表。