英語| 中文(中国語)

SpikingJellyは、Pytorchに基づいたNeural Network(SNN)をスパイクするためのオープンソースの深い学習フレームワークです。
Spikingjellyのドキュメントは、英語と中国語の両方で書かれています:https://spikingjelly.readthedocs.io。
SpikingjellyはPytorchに基づいていることに注意してください。 Spikingjellyをインストールする前に、Pytorchをインストールしていることを確認してください。
バージョンノート
奇妙なバージョン番号は、GitHub/Openiリポジトリで更新された開発バージョンです。均等なバージョン番号は安定したバージョンで、Pypiで入手できます。
デフォルトのドキュメントは、最新の開発バージョン用です。安定したバージョンを使用している場合は、対応するバージョンのドキュメントに切り替えることを忘れないでください。
バージョン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 installOpeniから:
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は、マルチステップニューロンに2つのバックエンドを提供します。ユーザーフレンドリーなtorchバックエンドを使用して、簡単にコーディングしてデバッグし、 cupyバックエンドを使用してトレーニング速度を高速化できます。
次の図は、マルチステップLIFニューロンの2つのバックエンドの実行時間を比較しています( 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:ニューラルネットワークをスパイクするための100万のイベント分類データセット |
| hardvs | HARDVS:動的ビジョンセンサーで人間の活動認識を再検討します |
| n-caltech101 | 静的画像データセットをサッカードを使用してスパイクニューロモーフィックデータセットに変換する |
| n-mnist | 静的画像データセットをサッカードを使用してスパイクニューロモーフィックデータセットに変換する |
| NAVジェスチャー | スマートフォンの計算機能を使用した動的な背景抑制によるイベントベースのジェスチャー認識 |
| スパイクハイデルベルクディジット(SHD) | スパイクニューラルネットワークの体系的な評価のためのハイデルバーグスパイクデータセット |
| DVS-LIP | マルチグレインの時空間は、イベントベースのリップリーディングのための知覚ネットワークを特徴としています |
ユーザーは、SpikingJellyによって統合されたOrigin Eventデータとフレームデータの両方を使用できます。
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ミラーからダウンロードできます。
https://openi.pcl.ac.cn/openi/spikingjelly/datasets?type=0
Openiミラーに保存されたすべてのデータセットは、ライセンスまたは著者の契約によって許可されます。
SpikingJellyは、精巧なチュートリアルを提供します。ここにいくつかのチュートリアルがあります:
| 形 | チュートリアル |
|---|---|
![]() | 基本的な概念 |
![]() | ニューロン |
![]() | MNISTを分類するための単一の完全に接続されたレイヤーSNN |
![]() | fmnistを分類するための畳み込みSNN |
![]() | ann2snn |
![]() | 神経形態データセット処理 |
![]() | DVSジェスチャーを分類します |
![]() | 再発接続とステートフルシナプス |
![]() | STDP学習 |
![]() | 強化学習 |
ここにリストされていない他のチュートリアルは、ドキュメントhttps://spikingjelly.readthedocs.ioでも入手できます。
Spikingjellyを使用した出版物は、出版物に記録されています。論文でSpikingjellyを使用する場合は、Pullリクエストでこのテーブルに追加することもできます。
仕事で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)、北京大学、Peng Cheng Laboratoryは、Spikingjellyの主な開発者です。


開発者のリストはここにあります。