spikingjelly.clock_driven.examples package

Subpackages

Submodules

spikingjelly.clock_driven.examples.A2C module

spikingjelly.clock_driven.examples.DQN_state module

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

基类:object

push(*args)[源代码]

Saves a transition.

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

基类:Module

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

spikingjelly.clock_driven.examples.PPO module

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

基类:Module

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

spikingjelly.clock_driven.examples.Spiking_A2C module

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

基类:LIFNode

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

基类:Module

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

spikingjelly.clock_driven.examples.Spiking_DQN_state module

class spikingjelly.clock_driven.examples.Spiking_DQN_state.Transition(state, action, next_state, reward)

基类:tuple

Create new instance of Transition(state, action, next_state, reward)

property action

Alias for field number 1

property next_state

Alias for field number 2

property reward

Alias for field number 3

property state

Alias for field number 0

class spikingjelly.clock_driven.examples.Spiking_DQN_state.ReplayMemory(capacity)[源代码]

基类:object

push(*args)[源代码]
sample(batch_size)[源代码]
class spikingjelly.clock_driven.examples.Spiking_DQN_state.NonSpikingLIFNode(*args, **kwargs)[源代码]

基类:LIFNode

forward(dv: Tensor)[源代码]
training: bool
class spikingjelly.clock_driven.examples.Spiking_DQN_state.DQSN(input_size, hidden_size, output_size, T=16)[源代码]

基类:Module

forward(x)[源代码]
training: bool
spikingjelly.clock_driven.examples.Spiking_DQN_state.train(use_cuda, model_dir, log_dir, env_name, hidden_size, num_episodes, seed)[源代码]
spikingjelly.clock_driven.examples.Spiking_DQN_state.play(use_cuda, pt_path, env_name, hidden_size, played_frames=60, save_fig_num=0, fig_dir=None, figsize=(12, 6), firing_rates_plot_type='bar', heatmap_shape=None)[源代码]

spikingjelly.clock_driven.examples.Spiking_PPO module

spikingjelly.clock_driven.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.clock_driven.examples.cifar10_r11_enabling_spikebased_backpropagation.relu[源代码]

基类:Function

static forward(ctx, x)[源代码]
static backward(ctx, grad_output)[源代码]
class spikingjelly.clock_driven.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.clock_driven.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.clock_driven.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.clock_driven.examples.cifar10_r11_enabling_spikebased_backpropagation.ResNet11[源代码]

基类:Module

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

spikingjelly.clock_driven.examples.classify_dvsg module

class spikingjelly.clock_driven.examples.classify_dvsg.VotingLayer(voter_num: int)[源代码]

基类:Module

forward(x: Tensor)[源代码]
training: bool
class spikingjelly.clock_driven.examples.classify_dvsg.PythonNet(channels: int)[源代码]

基类:Module

forward(x: Tensor)[源代码]
static conv3x3(in_channels: int, out_channels)[源代码]
training: bool
spikingjelly.clock_driven.examples.classify_dvsg.main()[源代码]

用于分类DVS128 Gesture数据集的代码样例。网络结构来自于 Incorporating Learnable Membrane Time Constant to Enhance Learning of Spiking Neural Networks

usage: classify_dvsg.py [-h] [-T T] [-device DEVICE] [-b B] [-epochs N] [-j N] [-channels CHANNELS] [-data_dir DATA_DIR] [-out_dir OUT_DIR] [-resume RESUME] [-amp] [-cupy] [-opt OPT] [-lr LR] [-momentum MOMENTUM] [-lr_scheduler LR_SCHEDULER] [-step_size STEP_SIZE] [-gamma GAMMA] [-T_max T_MAX]

Classify DVS128 Gesture

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)
  -channels CHANNELS    channels of Conv2d in SNN
  -data_dir DATA_DIR    root dir of DVS128 Gesture 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 CUDA neuron and multi-step forward mode
  -opt OPT              use which optimizer. SDG or Adam
  -lr LR                learning rate
  -momentum MOMENTUM    momentum for SGD
  -lr_scheduler LR_SCHEDULER
                        use which schedule. StepLR or CosALR
  -step_size STEP_SIZE  step_size for StepLR
  -gamma GAMMA          gamma for StepLR
  -T_max T_MAX          T_max for CosineAnnealingLR

运行示例:

python -m spikingjelly.clock_driven.examples.classify_dvsg -data_dir /userhome/datasets/DVS128Gesture -out_dir ./logs -amp -opt Adam -device cuda:0 -lr_scheduler CosALR -T_max 64 -cupy -epochs 1024

阅读教程 分类DVS128 Gesture 以获得更多信息。

The code example for classifying the DVS128 Gesture dataset. The network structure is from Incorporating Learnable Membrane Time Constant to Enhance Learning of Spiking Neural Networks.

usage: classify_dvsg.py [-h] [-T T] [-device DEVICE] [-b B] [-epochs N] [-j N] [-channels CHANNELS] [-data_dir DATA_DIR] [-out_dir OUT_DIR] [-resume RESUME] [-amp] [-cupy] [-opt OPT] [-lr LR] [-momentum MOMENTUM] [-lr_scheduler LR_SCHEDULER] [-step_size STEP_SIZE] [-gamma GAMMA] [-T_max T_MAX]

Classify DVS128 Gesture

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)
  -channels CHANNELS    channels of Conv2d in SNN
  -data_dir DATA_DIR    root dir of DVS128 Gesture 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 CUDA neuron and multi-step forward mode
  -opt OPT              use which optimizer. SDG or Adam
  -lr LR                learning rate
  -momentum MOMENTUM    momentum for SGD
  -lr_scheduler LR_SCHEDULER
                        use which schedule. StepLR or CosALR
  -step_size STEP_SIZE  step_size for StepLR
  -gamma GAMMA          gamma for StepLR
  -T_max T_MAX          T_max for CosineAnnealingLR

Running Example:

python -m spikingjelly.clock_driven.examples.classify_dvsg -data_dir /userhome/datasets/DVS128Gesture -out_dir ./logs -amp -opt Adam -device cuda:0 -lr_scheduler CosALR -T_max 64 -cupy -epochs 1024

See the tutorial Classify DVS128 Gesture for more details.

spikingjelly.clock_driven.examples.conv_fashion_mnist module

class spikingjelly.clock_driven.examples.conv_fashion_mnist.PythonNet(T)[源代码]

基类:Module

forward(x)[源代码]
training: bool
class spikingjelly.clock_driven.examples.conv_fashion_mnist.CupyNet(T)[源代码]

基类:Module

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

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 -lr LR learning rate -momentum MOMENTUM momentum for SGD -lr_scheduler LR_SCHEDULER

use which schedule. StepLR or CosALR

-step_size STEP_SIZE step_size for StepLR -gamma GAMMA gamma for StepLR -T_max T_MAX T_max for CosineAnnealingLR

使用卷积-全连接的网络结构,进行Fashion MNIST识别。这个函数会初始化网络进行训练,并显示训练过程中在测试集的正确率。会将训练过 程中测试集正确率最高的网络保存在 tensorboard 日志文件的同级目录下。这个目录的位置,是在运行 main() 函数时由用户输入的。

训练100个epoch,训练batch和测试集上的正确率如下:

_images/train1.svg _images/test1.svg

The network with Conv-FC structure for classifying Fashion MNIST. This function initials the network, starts training and shows accuracy on test dataset. The net with the max accuracy on test dataset will be saved in the root directory for saving tensorboard logs, which is inputted by user when running the main() function.

After 100 epochs, the accuracy on train batch and test dataset is as followed:

_images/train1.svg _images/test1.svg

spikingjelly.clock_driven.examples.conv_fashion_mnist_cuda_lbl module

spikingjelly.clock_driven.examples.dqn_cart_pole module

class spikingjelly.clock_driven.examples.dqn_cart_pole.Transition(state, action, next_state, reward)

基类:tuple

Create new instance of Transition(state, action, next_state, reward)

property action

Alias for field number 1

property next_state

Alias for field number 2

property reward

Alias for field number 3

property state

Alias for field number 0

class spikingjelly.clock_driven.examples.dqn_cart_pole.ReplayMemory(capacity)[源代码]

基类:object

push(*args)[源代码]
sample(batch_size)[源代码]
class spikingjelly.clock_driven.examples.dqn_cart_pole.NonSpikingLIFNode(*args, **kwargs)[源代码]

基类:LIFNode

forward(dv: Tensor)[源代码]
training: bool
class spikingjelly.clock_driven.examples.dqn_cart_pole.DQSN(hidden_num)[源代码]

基类:Module

forward(x)[源代码]
training: bool
spikingjelly.clock_driven.examples.dqn_cart_pole.train(device, root, hidden_num=128, num_episodes=256)[源代码]
spikingjelly.clock_driven.examples.dqn_cart_pole.play(device, pt_path, hidden_num, played_frames=60, save_fig_num=0, fig_dir=None, figsize=(12, 6), firing_rates_plot_type='bar', heatmap_shape=None)[源代码]

spikingjelly.clock_driven.examples.lif_fc_mnist module

spikingjelly.clock_driven.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.clock_driven.examples.spiking_lstm_sequential_mnist module

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

基类:Module

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

spikingjelly.clock_driven.examples.spiking_lstm_text module

spikingjelly.clock_driven.examples.speechcommands module

Module contents