spikingjelly.activation_based.model package#

PLIF-Net#

class spikingjelly.activation_based.model.parametric_lif_net.MNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

用于 MNIST 手写数字分类的 Parametric LIF 网络。


  • English

  • English

Parametric LIF network for MNIST digit classification.

forward(x: Tensor)[源代码]#
class spikingjelly.activation_based.model.parametric_lif_net.FashionMNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:MNISTNet

API Language: 中文 | English


  • 中文

  • 中文

用于 Fashion-MNIST 分类的 Parametric LIF 网络。即 MNISTNet 的别名。 :param args: 与 MNISTNet 相同的参数 :type args: tuple :param kwargs: 与 MNISTNet 相同的关键字参数 :type kwargs: dict


  • English

  • English

Parametric LIF network for Fashion-MNIST classification. Alias of MNISTNet. :param args: Same as MNISTNet :type args: tuple :param kwargs: Same as MNISTNet :type kwargs: dict

class spikingjelly.activation_based.model.parametric_lif_net.NMNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:MNISTNet

API Language: 中文 | English


  • 中文

  • 中文

用于 N-MNIST 事件流分类的 Parametric LIF 网络。基于 MNISTNet,将首层卷积输入通道调整为 2。

参数:
  • channels (int) -- 卷积层的通道数

  • spiking_neuron (callable) -- 脉冲神经元类


  • English

  • English

Parametric LIF network for N-MNIST event stream classification. Based on MNISTNet with first conv layer adjusted to 2 input channels.

参数:
  • channels (int) -- Number of channels in conv layers

  • spiking_neuron (callable) -- Spiking neuron class

class spikingjelly.activation_based.model.parametric_lif_net.CIFAR10Net(channels=256, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

用于 CIFAR-10 分类的 Parametric LIF 网络。


  • English

  • English

Parametric LIF network for CIFAR-10 classification.

forward(x)[源代码]#
class spikingjelly.activation_based.model.parametric_lif_net.CIFAR10DVSNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

用于 CIFAR10-DVS 事件流分类的 Parametric LIF 网络。


  • English

  • English

Parametric LIF network for CIFAR10-DVS event stream classification.

forward(x: Tensor)[源代码]#
class spikingjelly.activation_based.model.parametric_lif_net.DVSGestureNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

用于 DVS128 Gesture 手势识别的 Parametric LIF 网络。


  • English

  • English

Parametric LIF network for DVS128 Gesture recognition.

forward(x: Tensor)[源代码]#

SEW ResNet#

class spikingjelly.activation_based.model.sew_resnet.SEWResNet(block, layers, num_classes=1000, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

SEW(Spike-Element-Wise)ResNet 网络。使用逐元素相加连接代替传统 shortcut 中的激活函数,以减少信息损失。


  • English

  • English

SEW (Spike-Element-Wise) ResNet network. Uses element-wise addition connections in shortcuts to reduce information loss.

forward(x)[源代码]#
spikingjelly.activation_based.model.sew_resnet.sew_resnet18(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 SEW-ResNet-18。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • cnf (str) -- spike-element-wise 连接方式

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

SEW-ResNet-18

返回类型:

torch.nn.Module


  • English

Construct SEW-ResNet-18.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • cnf (str) -- spike-element-wise connection type

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

SEW-ResNet-18

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.sew_resnet.sew_resnet34(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 SEW-ResNet-34。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • cnf (str) -- spike-element-wise 连接方式

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

SEW-ResNet-34

返回类型:

torch.nn.Module


  • English

Construct SEW-ResNet-34.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • cnf (str) -- spike-element-wise connection type

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

SEW-ResNet-34

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.sew_resnet.sew_resnet50(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 SEW-ResNet-50。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • cnf (str) -- spike-element-wise 连接方式

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

SEW-ResNet-50

返回类型:

torch.nn.Module


  • English

Construct SEW-ResNet-50.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • cnf (str) -- spike-element-wise connection type

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

SEW-ResNet-50

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.sew_resnet.sew_resnet101(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a spiking neuron layer

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking ResNet-101

返回类型:

torch.nn.Module

The spike-element-wise ResNet-101 "Deep Residual Learning in Spiking Neural Networks" modified by the ResNet-101 model from "Deep Residual Learning for Image Recognition"

spikingjelly.activation_based.model.sew_resnet.sew_resnet152(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a single step neuron

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking ResNet-152

返回类型:

torch.nn.Module

The spike-element-wise ResNet-152 "Deep Residual Learning in Spiking Neural Networks" modified by the ResNet-152 model from "Deep Residual Learning for Image Recognition"

spikingjelly.activation_based.model.sew_resnet.sew_resnext50_32x4d(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a single step neuron

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking ResNeXt-50 32x4d

返回类型:

torch.nn.Module

The spike-element-wise ResNeXt-50 32x4d "Deep Residual Learning in Spiking Neural Networks" modified by the ResNeXt-50 32x4d model from "Aggregated Residual Transformation for Deep Neural Networks"

spikingjelly.activation_based.model.sew_resnet.sew_resnext101_32x8d(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a single step neuron

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking ResNeXt-101 32x8d

返回类型:

torch.nn.Module

The spike-element-wise ResNeXt-101 32x8d "Deep Residual Learning in Spiking Neural Networks" modified by the ResNeXt-101 32x8d model from "Aggregated Residual Transformation for Deep Neural Networks"

spikingjelly.activation_based.model.sew_resnet.sew_wide_resnet50_2(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a single step neuron

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking Wide ResNet-50-2

返回类型:

torch.nn.Module

The spike-element-wise Wide ResNet-50-2 "Deep Residual Learning in Spiking Neural Networks" modified by the Wide ResNet-50-2 model from "Wide Residual Networks"

The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048.

spikingjelly.activation_based.model.sew_resnet.sew_wide_resnet101_2(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
参数:
  • pretrained (bool) -- If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) -- If True, displays a progress bar of the download to stderr

  • cnf (str) -- the name of spike-element-wise function

  • spiking_neuron (callable) -- a single step neuron

  • kwargs (dict) -- kwargs for spiking_neuron

返回:

Spiking Wide ResNet-101-2

返回类型:

torch.nn.Module

The spike-element-wise Wide ResNet-101-2 "Deep Residual Learning in Spiking Neural Networks" modified by the Wide ResNet-101-2 model from "Wide Residual Networks"

The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048.

Spiking ResNet#

class spikingjelly.activation_based.model.spiking_resnet.SpikingResNet(block, layers, num_classes=1000, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

脉冲 ResNet 网络。继承自 torchvision.models.ResNet,将原网络的激活函数替换为脉冲神经元。


  • English

  • English

Spiking ResNet network. Inherits from torchvision.models.ResNet with activations replaced by spiking neurons.

参数:
  • block (type) -- 残差块的类型(BasicBlockBottleneck

  • layers (list) -- 每个层的残差块数量

  • num_classes (int) -- 分类任务的类别数

  • zero_init_residual (bool) -- 是否将最后一个 BN 初始化为零

  • groups (int) -- 分组卷积的组数

  • width_per_group (int) -- 每组的宽度

  • replace_stride_with_dilation (Optional[List[bool]]) -- 是否用膨胀卷积替换步长

  • norm_layer (Optional[Callable]) -- 归一化层类型

  • spiking_neuron (callable) -- 脉冲神经元类

  • kwargs (dict) -- 传递给脉冲神经元的额外参数

  • block -- Type of residual block (BasicBlock or Bottleneck)

  • layers -- Number of residual blocks per layer

  • num_classes -- Number of classes for classification

  • zero_init_residual -- Whether to zero-initialize the last BN

  • groups -- Number of groups for grouped convolution

  • width_per_group -- Width per group

  • replace_stride_with_dilation -- Replace stride with dilated convolution

  • norm_layer -- Normalization layer type

  • spiking_neuron -- Spiking neuron class

  • kwargs -- Extra arguments for the spiking neuron

返回:

None

返回类型:

None

forward(x)[源代码]#
spikingjelly.activation_based.model.spiking_resnet.spiking_resnet18(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNet-18。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNet-18

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNet-18.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNet-18

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnet34(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNet-34。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNet-34

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNet-34.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNet-34

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnet50(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNet-50。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNet-50

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNet-50.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNet-50

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnet101(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNet-101。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNet-101

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNet-101.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNet-101

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnet152(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNet-152。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNet-152

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNet-152.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNet-152

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnext50_32x4d(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNeXt-50 32x4d。

参数:
  • pretrained (bool) -- 若为 True, 加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNeXt-50 32x4d

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNeXt-50 32x4d.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNeXt-50 32x4d

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_resnext101_32x8d(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking ResNeXt-101 32x8d。

参数:
  • pretrained (bool) -- 若为 True, 加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking ResNeXt-101 32x8d

返回类型:

torch.nn.Module


  • English

Construct Spiking ResNeXt-101 32x8d.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking ResNeXt-101 32x8d

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_wide_resnet50_2(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking Wide ResNet-50-2。

该模型来自 Wide Residual Networks 的脉冲版本。

参数:
  • pretrained (bool) -- 若为 True, 加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking Wide ResNet-50-2

返回类型:

torch.nn.Module


  • English

Construct Spiking Wide ResNet-50-2.

This is the spiking version of Wide Residual Networks.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking Wide ResNet-50-2

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_resnet.spiking_wide_resnet101_2(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking Wide ResNet-101-2。

该模型来自 Wide Residual Networks 的脉冲版本。

参数:
  • pretrained (bool) -- 若为 True, 加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking Wide ResNet-101-2

返回类型:

torch.nn.Module


  • English

Construct Spiking Wide ResNet-101-2.

This is the spiking version of Wide Residual Networks.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking Wide ResNet-101-2

返回类型:

torch.nn.Module

Spiking VGG#

class spikingjelly.activation_based.model.spiking_vgg.SpikingVGG(cfg, batch_norm=False, norm_layer=None, num_classes=1000, init_weights=True, spiking_neuron: callable = None, **kwargs)[源代码]#

基类:Module

API Language: 中文 | English


  • 中文

  • 中文

脉冲 VGG 网络。继承自 torchvision.models.VGG,将原网络的激活函数替换为脉冲神经元。


  • English

  • English

Spiking VGG network. Inherits from torchvision.models.VGG with activations replaced by spiking neurons.

forward(x)[源代码]#
static make_layers(cfg, batch_norm=False, norm_layer=None, neuron: callable = None, **kwargs)[源代码]#
spikingjelly.activation_based.model.spiking_vgg.spiking_vgg11(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking VGG-11 模型。

该模型来自 Very Deep Convolutional Networks for Large-Scale Image Recognition 的脉冲版本。

参数:
  • pretrained (bool) -- 若为 True,则加载在 ImageNet 上预训练的 ANN 参数

  • progress (bool) -- 是否在下载时显示进度条

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking VGG-11

返回类型:

torch.nn.Module


  • English

Construct a Spiking VGG-11 model.

This is the spiking version of the model from Very Deep Convolutional Networks for Large-Scale Image Recognition.

参数:
  • pretrained (bool) -- If True, load ANN parameters pretrained on ImageNet

  • progress (bool) -- If True, display a progress bar for the download

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-11

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg11_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造带 BatchNorm 的 Spiking VGG-11。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • norm_layer (callable) -- BatchNorm 层

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

带 BatchNorm 的 Spiking VGG-11

返回类型:

torch.nn.Module


  • English

Construct a Spiking VGG-11 with BatchNorm.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • norm_layer (callable) -- BatchNorm layer

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-11 with BatchNorm

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg13(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking VGG-13。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking VGG-13

返回类型:

torch.nn.Module


  • English

Construct Spiking VGG-13.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-13

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg13_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造带 BatchNorm 的 Spiking VGG-13。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • norm_layer (callable) -- BatchNorm 层

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

带 BatchNorm 的 Spiking VGG-13

返回类型:

torch.nn.Module


  • English

Construct a Spiking VGG-13 with BatchNorm.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • norm_layer (callable) -- BatchNorm layer

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-13 with BatchNorm

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg16(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking VGG-16。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking VGG-16

返回类型:

torch.nn.Module


  • English

Construct Spiking VGG-16.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-16

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg16_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造带 BatchNorm 的 Spiking VGG-16。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • norm_layer (callable) -- BatchNorm 层

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

带 BatchNorm 的 Spiking VGG-16

返回类型:

torch.nn.Module


  • English

Construct a Spiking VGG-16 with BatchNorm.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • norm_layer (callable) -- BatchNorm layer

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-16 with BatchNorm

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg19(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造 Spiking VGG-19。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

Spiking VGG-19

返回类型:

torch.nn.Module


  • English

Construct Spiking VGG-19.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-19

返回类型:

torch.nn.Module

spikingjelly.activation_based.model.spiking_vgg.spiking_vgg19_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#

API Language: 中文 | English


  • 中文

构造带 BatchNorm 的 Spiking VGG-19。

参数:
  • pretrained (bool) -- 若为 True,加载 ImageNet 预训练权重

  • progress (bool) -- 是否显示下载进度

  • norm_layer (callable) -- BatchNorm 层

  • spiking_neuron (callable) -- 脉冲神经元层

  • kwargs (dict) -- 传给 spiking_neuron 的关键字参数

返回:

带 BatchNorm 的 Spiking VGG-19

返回类型:

torch.nn.Module


  • English

Construct a Spiking VGG-19 with BatchNorm.

参数:
  • pretrained (bool) -- If True, load ImageNet pretrained weights

  • progress (bool) -- Whether to display download progress

  • norm_layer (callable) -- BatchNorm layer

  • spiking_neuron (callable) -- Spiking neuron layer

  • kwargs (dict) -- Keyword arguments for spiking_neuron

返回:

Spiking VGG-19 with BatchNorm

返回类型:

torch.nn.Module

Trainers#

class spikingjelly.activation_based.model.train_classify.Trainer[源代码]#

基类:object

API Language: 中文 | English


  • 中文

  • 中文

分类任务的训练器。封装了训练/验证循环、学习率调度、混合精度训练、torch.compile 支持、TensorBoard 日志等功能。


  • English

  • English

Classification task trainer. Wraps training/validation loops, LR scheduling, mixed-precision training, torch.compile support, and TensorBoard logging.

get_data_to_device_kwargs(args)[源代码]#
cal_acc1_acc5(output, target)[源代码]#
preprocess_train_sample(args, x: Tensor)[源代码]#
preprocess_test_sample(args, x: Tensor)[源代码]#
process_model_output(args, y: Tensor)[源代码]#
compile_model(args, model: Module, *, enabled: bool | None = None) Module[源代码]#
get_eval_model(args, train_model, model_without_ddp)[源代码]#
train_one_epoch(model, criterion, optimizer, data_loader, device, epoch, args, model_ema=None, scaler=None)[源代码]#
evaluate(args, model, criterion, data_loader, device, log_suffix='')[源代码]#
load_data(args)[源代码]#
load_CIFAR10(args)[源代码]#
load_ImageNet(args)[源代码]#
load_model(args, num_classes)[源代码]#
get_tb_logdir_name(args)[源代码]#
set_optimizer(args, parameters)[源代码]#
set_lr_scheduler(args, optimizer)[源代码]#
main(args)[源代码]#
before_test_one_epoch(args, model, epoch)[源代码]#
before_train_one_epoch(args, model, epoch)[源代码]#
get_args_parser(add_help=True)[源代码]#
spikingjelly.activation_based.model.train_classify.set_deterministic(_seed_: int = 2020, disable_uda=False)[源代码]#

API Language: 中文 | English


  • 中文

设置 PyTorch 为确定性模式,使得在相同输入下结果可复现。此函数会设置 Python、NumPy 和 PyTorch(CPU/CUDA)的随机种子,并启用 CuDNN 确定性算法 和 PyTorch 的确定性模式。

参数:
  • _seed_ (int) -- 随机种子,默认为 2020

  • disable_uda (bool) -- 是否禁用 UDA(不确定区域丢弃算法)

返回:

None

返回类型:

None


  • English

Set PyTorch to deterministic mode so that results are reproducible under the same input. This function seeds Python, NumPy and PyTorch (CPU/CUDA) random number generators, enables CuDNN deterministic algorithms and PyTorch deterministic mode.

参数:
  • _seed_ (int) -- random seed, default is 2020

  • disable_uda (bool) -- whether to disable UDA (unreliable data augmentation)

返回:

None

返回类型:

None

spikingjelly.activation_based.model.train_classify.seed_worker(worker_id)[源代码]#

API Language: 中文 | English


  • 中文

DataLoader 的 worker 初始化函数,用于确保每个 worker 进程使用不同的、 可复现的随机种子。

参数:

worker_id (int) -- worker 的索引

返回:

None

返回类型:

None


  • English

DataLoader worker initialization function that ensures each worker process uses a distinct and reproducible random seed.

参数:

worker_id (int) -- the index of the worker

返回:

None

返回类型:

None

class spikingjelly.activation_based.model.train_imagenet_example.SResNetTrainer[源代码]#

基类:Trainer

API Language: 中文 | English


  • 中文

  • 中文

SResNetTrainer 是一个用于在 ImageNet 数据集上训练脉冲 ResNet 模型的训练器类。 它继承自 train_classify.Trainer,并重写了数据预处理、模型输出处理、模型加载等方法。

主要功能:

  • 数据预处理:将 [N, C, H, W] 形状的输入扩展为 [T, N, C, H, W],其中 T 为总时间步数。

  • 模型输出处理:将 T 个时间步的输出沿时间维取均值,作为最终的预测结果(发放率)。

  • 模型加载:支持从 spiking_resnet 加载多种脉冲 ResNet 模型,并可选择 CuPy 后端加速。

  • 额外命令行参数:添加了 ``--T``(时间步数)和 ``--cupy``(是否使用 CuPy 后端)参数。


  • English

  • English

SResNetTrainer is a trainer for training spiking ResNet models on the ImageNet dataset. It inherits from train_classify.Trainer and overrides data preprocessing, model output processing, and model loading methods.

Key features:

  • Data preprocessing: expands input from [N, C, H, W] to [T, N, C, H, W], where T is the total number of time-steps.

  • Model output processing: averages outputs over T time-steps along the time dimension as the final prediction (firing rate).

  • Model loading: supports loading various spiking ResNet models from spiking_resnet with an optional CuPy backend for acceleration.

  • Extra CLI arguments: adds --T (number of time-steps) and --cupy (enable CuPy backend) arguments.

preprocess_train_sample(args, x: Tensor)[源代码]#
preprocess_test_sample(args, x: Tensor)[源代码]#
process_model_output(args, y: Tensor)[源代码]#
get_args_parser(add_help=True)[源代码]#
get_tb_logdir_name(args)[源代码]#
load_model(args, num_classes)[源代码]#