spikingjelly.activation_based.examples package

Subpackages

Submodules

spikingjelly.activation_based.examples.A2C module

spikingjelly.activation_based.examples.DQN_state module

class spikingjelly.activation_based.examples.DQN_state.ReplayMemory(capacity)[源代码]

基类:object

push(*args)[源代码]

Saves a transition.

sample(batch_size)[源代码]
class spikingjelly.activation_based.examples.DQN_state.DQN(input_size, hidden_size, output_size)[源代码]

基类:Module

forward(x)[源代码]
training: bool

spikingjelly.activation_based.examples.PPO module

spikingjelly.activation_based.examples.PPO.make_env()[源代码]
class spikingjelly.activation_based.examples.PPO.ActorCritic(num_inputs, num_outputs, hidden_size, std=0.0)[源代码]

基类:Module

forward(x)[源代码]
training: bool

spikingjelly.activation_based.examples.Spiking_A2C module

class spikingjelly.activation_based.examples.Spiking_A2C.NonSpikingLIFNode(*args, **kwargs)[源代码]

基类:LIFNode

single_step_forward(x: Tensor)[源代码]
training: bool
class spikingjelly.activation_based.examples.Spiking_A2C.ActorCritic(num_inputs, num_outputs, hidden_size, T=16)[源代码]

基类:Module

forward(x)[源代码]
training: bool

spikingjelly.activation_based.examples.Spiking_DQN_state module

spikingjelly.activation_based.examples.Spiking_PPO module

spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation module

代码作者: Yanqi Chen <chyq@pku.edu.cn>

A reproduction of the paper Enabling Spike-Based Backpropagation for Training Deep Neural Network Architectures.

This code reproduces a novel gradient-based training method of SNN. We to some extent refer to the network structure and some other detailed implementation in the authors’ implementation. Since the training method and neuron models are slightly different from which in this framework, we rewrite them in a compatible style.

Assuming you have at least 1 Nvidia GPU.

class spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.relu(*args, **kwargs)[源代码]

基类:Function

static forward(ctx, x)[源代码]
static backward(ctx, grad_output)[源代码]
class spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.BaseNode(v_threshold=1.0, v_reset=0.0, surrogate_function=<built-in method apply of FunctionMeta object>, monitor=False)[源代码]

基类:Module

spiking()[源代码]
forward(dv: Tensor)[源代码]
reset()[源代码]
training: bool
class spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.LIFNode(tau=100.0, v_threshold=1.0, v_reset=0.0, surrogate_function=<built-in method apply of FunctionMeta object>, fire=True)[源代码]

基类:BaseNode

forward(dv: Tensor)[源代码]
training: bool
class spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.IFNode(v_threshold=0.75, v_reset=0.0, surrogate_function=<built-in method apply of FunctionMeta object>)[源代码]

基类:BaseNode

forward(dv: Tensor)[源代码]
training: bool
class spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.ResNet11[源代码]

基类:Module

forward(x)[源代码]
reset_()[源代码]
training: bool
spikingjelly.activation_based.examples.cifar10_r11_enabling_spikebased_backpropagation.main()[源代码]

spikingjelly.activation_based.examples.classify_dvsg module

spikingjelly.activation_based.examples.classify_dvsg.main()[源代码]

spikingjelly.activation_based.examples.conv_fashion_mnist module

class spikingjelly.activation_based.examples.conv_fashion_mnist.CSNN(T: int, channels: int, use_cupy=False)[源代码]

基类:Module

forward(x: Tensor)[源代码]
spiking_encoder()[源代码]
training: bool
spikingjelly.activation_based.examples.conv_fashion_mnist.main()[源代码]

(sj-dev) wfang@Precision-5820-Tower-X-Series:~/spikingjelly_dev$ python -m spikingjelly.activation_based.examples.conv_fashion_mnist -h

usage: conv_fashion_mnist.py [-h] [-T T] [-device DEVICE] [-b B] [-epochs N] [-j N] [-data-dir DATA_DIR] [-out-dir OUT_DIR]

[-resume RESUME] [-amp] [-cupy] [-opt OPT] [-momentum MOMENTUM] [-lr LR]

Classify Fashion-MNIST

optional arguments:
-h, --help

show this help message and exit

-T T

simulating time-steps

-device DEVICE device -b B batch size -epochs N number of total epochs to run -j N number of data loading workers (default: 4) -data-dir DATA_DIR root dir of Fashion-MNIST dataset -out-dir OUT_DIR root dir for saving logs and checkpoint -resume RESUME resume from the checkpoint path -amp automatic mixed precision training -cupy use cupy neuron and multi-step forward mode -opt OPT use which optimizer. SDG or Adam -momentum MOMENTUM momentum for SGD -save-es dir for saving a batch spikes encoded by the first {Conv2d-BatchNorm2d-IFNode}

spikingjelly.activation_based.examples.dqn_cart_pole module

spikingjelly.activation_based.examples.lif_fc_mnist module

class spikingjelly.activation_based.examples.lif_fc_mnist.SNN(tau)[源代码]

基类:Module

forward(x: Tensor)[源代码]
training: bool
spikingjelly.activation_based.examples.lif_fc_mnist.main()[源代码]
返回:

None

使用全连接-LIF的网络结构,进行MNIST识别。

这个函数会初始化网络进行训练,并显示训练过程中在测试集的正确率。

The network with FC-LIF structure for classifying MNIST.

This function initials the network, starts trainingand shows accuracy on test dataset.

spikingjelly.activation_based.examples.rsnn_sequential_fmnist module

class spikingjelly.activation_based.examples.rsnn_sequential_fmnist.PlainNet[源代码]

基类:Module

forward(x: Tensor)[源代码]
training: bool
class spikingjelly.activation_based.examples.rsnn_sequential_fmnist.StatefulSynapseNet[源代码]

基类:Module

forward(x: Tensor)[源代码]
training: bool
class spikingjelly.activation_based.examples.rsnn_sequential_fmnist.FeedBackNet[源代码]

基类:Module

forward(x: Tensor)[源代码]
training: bool
spikingjelly.activation_based.examples.rsnn_sequential_fmnist.main()[源代码]

spikingjelly.activation_based.examples.speechcommands module

代码作者: Yanqi Chen <chyq@pku.edu.cn>, Ismail Khalfaoui Hassani <ismail.khalfaoui-hassani@univ-tlse3.fr>

A reproduction of the paper Technical report: supervised training of convolutional spiking neural networks with PyTorch.

This code reproduces an audio recognition task using convolutional SNN. It provides comparable performance to ANN.

备注

To prevent too much dependency like librosa, we implement MelScale ourselves. We provide two kinds of DCT types: Slaney & HTK. Slaney style is used in the original paper and will be applied by default.

Confusion matrix of TEST set after training (50 epochs):

Count

Prediction

“Yes”

“Stop”

“No”

“Right”

“Up”

“Left”

“On”

“Down”

“Off”

“Go”

Other

Silence

Ground Truth

“Yes”

234

0

2

0

0

3

0

0

0

1

16

0

“Stop”

0

233

0

1

5

0

0

0

0

1

9

0

“No”

0

1

223

1

0

1

0

5

0

9

12

0

“Right”

0

0

0

234

0

0

0

0

0

0

24

1

“Up”

0

4

0

0

249

0

0

0

8

0

11

0

“Left”

3

1

2

3

1

250

0

0

1

0

6

0

“On”

0

3

0

0

0

0

231

0

2

1

9

0

“Down”

0

0

7

0

0

1

2

230

0

4

8

1

“Off”

0

0

2

1

4

2

6

0

237

1

9

0

“Go”

0

2

5

0

0

2

0

1

5

220

16

0

Other

6

21

12

25

22

19

25

14

11

40

4072

1

Silence

0

0

0

0

0

0

0

0

0

0

0

260

spikingjelly.activation_based.examples.speechcommands.mel_to_hz(mels, dct_type)[源代码]
spikingjelly.activation_based.examples.speechcommands.hz_to_mel(frequencies, dct_type)[源代码]
spikingjelly.activation_based.examples.speechcommands.create_fb_matrix(n_freqs: int, f_min: float, f_max: float, n_mels: int, sample_rate: int, dct_type: Optional[str] = 'slaney') Tensor[源代码]
class spikingjelly.activation_based.examples.speechcommands.MelScaleDelta(order, n_mels: int = 128, sample_rate: int = 16000, f_min: float = 0.0, f_max: Optional[float] = None, n_stft: Optional[int] = None, dct_type: Optional[str] = 'slaney')[源代码]

基类:Module

forward(specgram: Tensor) Tensor[源代码]
training: bool
class spikingjelly.activation_based.examples.speechcommands.Pad(size)[源代码]

基类:object

class spikingjelly.activation_based.examples.speechcommands.Rescale[源代码]

基类:object

spikingjelly.activation_based.examples.speechcommands.collate_fn(data)[源代码]
class spikingjelly.activation_based.examples.speechcommands.LIFWrapper(module, flatten=False)[源代码]

基类:Module

forward(x_seq: Tensor)[源代码]
参数:

x_seq (torch.Tensor) – shape=[batch size, channel, T, n_mel]

返回:

y_seq, shape=[batch size, channel, T, n_mel]

返回类型:

torch.Tensor

training: bool
class spikingjelly.activation_based.examples.speechcommands.Net[源代码]

基类:Module

forward(x)[源代码]
training: bool

spikingjelly.activation_based.examples.spiking_lstm_sequential_mnist module

class spikingjelly.activation_based.examples.spiking_lstm_sequential_mnist.Net[源代码]

基类:Module

forward(x)[源代码]
training: bool
spikingjelly.activation_based.examples.spiking_lstm_sequential_mnist.main()[源代码]

spikingjelly.activation_based.examples.spiking_lstm_text module

Module contents