spikingjelly.activation_based.model package#
PLIF-Net#
- class spikingjelly.activation_based.model.parametric_lif_net.MNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#
基类:
Module
中文
中文
用于 MNIST 手写数字分类的 Parametric LIF 网络。
English
English
Parametric LIF network for MNIST digit classification.
- class spikingjelly.activation_based.model.parametric_lif_net.FashionMNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#
基类:
MNISTNet
中文
中文
用于 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 asMNISTNet:type args: tuple :param kwargs: Same asMNISTNet:type kwargs: dict
- class spikingjelly.activation_based.model.parametric_lif_net.NMNISTNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#
基类:
MNISTNet
中文
中文
用于 N-MNIST 事件流分类的 Parametric LIF 网络。基于
MNISTNet,将首层卷积输入通道调整为 2。- 参数:
channels (int) -- 卷积层的通道数
spiking_neuron (callable) -- 脉冲神经元类
English
English
Parametric LIF network for N-MNIST event stream classification. Based on
MNISTNetwith 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
中文
中文
用于 CIFAR-10 分类的 Parametric LIF 网络。
English
English
Parametric LIF network for CIFAR-10 classification.
- class spikingjelly.activation_based.model.parametric_lif_net.CIFAR10DVSNet(channels=128, spiking_neuron: callable = None, **kwargs)[源代码]#
基类:
Module
中文
中文
用于 CIFAR10-DVS 事件流分类的 Parametric LIF 网络。
English
English
Parametric LIF network for CIFAR10-DVS event stream classification.
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
中文
中文
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.
- spikingjelly.activation_based.model.sew_resnet.sew_resnet18(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 SEW-ResNet-18。
- 参数:
- 返回:
SEW-ResNet-18
- 返回类型:
English
Construct SEW-ResNet-18.
- 参数:
- 返回:
SEW-ResNet-18
- 返回类型:
- spikingjelly.activation_based.model.sew_resnet.sew_resnet34(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 SEW-ResNet-34。
- 参数:
- 返回:
SEW-ResNet-34
- 返回类型:
English
Construct SEW-ResNet-34.
- 参数:
- 返回:
SEW-ResNet-34
- 返回类型:
- spikingjelly.activation_based.model.sew_resnet.sew_resnet50(pretrained=False, progress=True, cnf: str = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 SEW-ResNet-50。
- 参数:
- 返回:
SEW-ResNet-50
- 返回类型:
English
Construct SEW-ResNet-50.
- 参数:
- 返回:
SEW-ResNet-50
- 返回类型:
- 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
- 返回类型:
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
- 返回类型:
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
- 返回类型:
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
- 返回类型:
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
- 返回类型:
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
- 返回类型:
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
中文
中文
脉冲 ResNet 网络。继承自
torchvision.models.ResNet,将原网络的激活函数替换为脉冲神经元。
English
English
Spiking ResNet network. Inherits from
torchvision.models.ResNetwith activations replaced by spiking neurons.- 参数:
block (type) -- 残差块的类型(
BasicBlock或Bottleneck)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 (
BasicBlockorBottleneck)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
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnet18(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNet-18。
- 参数:
- 返回:
Spiking ResNet-18
- 返回类型:
English
Construct Spiking ResNet-18.
- 参数:
- 返回:
Spiking ResNet-18
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnet34(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNet-34。
- 参数:
- 返回:
Spiking ResNet-34
- 返回类型:
English
Construct Spiking ResNet-34.
- 参数:
- 返回:
Spiking ResNet-34
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnet50(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNet-50。
- 参数:
- 返回:
Spiking ResNet-50
- 返回类型:
English
Construct Spiking ResNet-50.
- 参数:
- 返回:
Spiking ResNet-50
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnet101(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNet-101。
- 参数:
- 返回:
Spiking ResNet-101
- 返回类型:
English
Construct Spiking ResNet-101.
- 参数:
- 返回:
Spiking ResNet-101
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnet152(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNet-152。
- 参数:
- 返回:
Spiking ResNet-152
- 返回类型:
English
Construct Spiking ResNet-152.
- 参数:
- 返回:
Spiking ResNet-152
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnext50_32x4d(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNeXt-50 32x4d。
- 参数:
- 返回:
Spiking ResNeXt-50 32x4d
- 返回类型:
English
Construct Spiking ResNeXt-50 32x4d.
- 参数:
- 返回:
Spiking ResNeXt-50 32x4d
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_resnext101_32x8d(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking ResNeXt-101 32x8d。
- 参数:
- 返回:
Spiking ResNeXt-101 32x8d
- 返回类型:
English
Construct Spiking ResNeXt-101 32x8d.
- 参数:
- 返回:
Spiking ResNeXt-101 32x8d
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_wide_resnet50_2(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking Wide ResNet-50-2。
该模型来自 Wide Residual Networks 的脉冲版本。
- 参数:
- 返回:
Spiking Wide ResNet-50-2
- 返回类型:
English
Construct Spiking Wide ResNet-50-2.
This is the spiking version of Wide Residual Networks.
- 参数:
- 返回:
Spiking Wide ResNet-50-2
- 返回类型:
- spikingjelly.activation_based.model.spiking_resnet.spiking_wide_resnet101_2(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking Wide ResNet-101-2。
该模型来自 Wide Residual Networks 的脉冲版本。
- 参数:
- 返回:
Spiking Wide ResNet-101-2
- 返回类型:
English
Construct Spiking Wide ResNet-101-2.
This is the spiking version of Wide Residual Networks.
- 参数:
- 返回:
Spiking Wide ResNet-101-2
- 返回类型:
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
中文
中文
脉冲 VGG 网络。继承自
torchvision.models.VGG,将原网络的激活函数替换为脉冲神经元。
English
English
Spiking VGG network. Inherits from
torchvision.models.VGGwith activations replaced by spiking neurons.
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg11(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking VGG-11 模型。
该模型来自 Very Deep Convolutional Networks for Large-Scale Image Recognition 的脉冲版本。
- 参数:
- 返回:
Spiking VGG-11
- 返回类型:
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.
- 参数:
- 返回:
Spiking VGG-11
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg11_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造带 BatchNorm 的 Spiking VGG-11。
- 参数:
- 返回:
带 BatchNorm 的 Spiking VGG-11
- 返回类型:
English
Construct a Spiking VGG-11 with BatchNorm.
- 参数:
- 返回:
Spiking VGG-11 with BatchNorm
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg13(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking VGG-13。
- 参数:
- 返回:
Spiking VGG-13
- 返回类型:
English
Construct Spiking VGG-13.
- 参数:
- 返回:
Spiking VGG-13
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg13_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造带 BatchNorm 的 Spiking VGG-13。
- 参数:
- 返回:
带 BatchNorm 的 Spiking VGG-13
- 返回类型:
English
Construct a Spiking VGG-13 with BatchNorm.
- 参数:
- 返回:
Spiking VGG-13 with BatchNorm
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg16(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking VGG-16。
- 参数:
- 返回:
Spiking VGG-16
- 返回类型:
English
Construct Spiking VGG-16.
- 参数:
- 返回:
Spiking VGG-16
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg16_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造带 BatchNorm 的 Spiking VGG-16。
- 参数:
- 返回:
带 BatchNorm 的 Spiking VGG-16
- 返回类型:
English
Construct a Spiking VGG-16 with BatchNorm.
- 参数:
- 返回:
Spiking VGG-16 with BatchNorm
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg19(pretrained=False, progress=True, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造 Spiking VGG-19。
- 参数:
- 返回:
Spiking VGG-19
- 返回类型:
English
Construct Spiking VGG-19.
- 参数:
- 返回:
Spiking VGG-19
- 返回类型:
- spikingjelly.activation_based.model.spiking_vgg.spiking_vgg19_bn(pretrained=False, progress=True, norm_layer: callable = None, spiking_neuron: callable = None, **kwargs)[源代码]#
-
中文
构造带 BatchNorm 的 Spiking VGG-19。
- 参数:
- 返回:
带 BatchNorm 的 Spiking VGG-19
- 返回类型:
English
Construct a Spiking VGG-19 with BatchNorm.
- 参数:
- 返回:
Spiking VGG-19 with BatchNorm
- 返回类型:
Trainers#
- class spikingjelly.activation_based.model.train_classify.Trainer[源代码]#
基类:
object
中文
中文
分类任务的训练器。封装了训练/验证循环、学习率调度、混合精度训练、torch.compile 支持、TensorBoard 日志等功能。
English
English
Classification task trainer. Wraps training/validation loops, LR scheduling, mixed-precision training, torch.compile support, and TensorBoard logging.
- spikingjelly.activation_based.model.train_classify.set_deterministic(_seed_: int = 2020, disable_uda=False)[源代码]#
-
中文
设置 PyTorch 为确定性模式,使得在相同输入下结果可复现。此函数会设置 Python、NumPy 和 PyTorch(CPU/CUDA)的随机种子,并启用 CuDNN 确定性算法 和 PyTorch 的确定性模式。
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.
- spikingjelly.activation_based.model.train_classify.seed_worker(worker_id)[源代码]#
-
中文
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
中文
中文
SResNetTrainer是一个用于在 ImageNet 数据集上训练脉冲 ResNet 模型的训练器类。 它继承自train_classify.Trainer,并重写了数据预处理、模型输出处理、模型加载等方法。主要功能:
数据预处理:将
[N, C, H, W]形状的输入扩展为[T, N, C, H, W],其中T为总时间步数。模型输出处理:将
T个时间步的输出沿时间维取均值,作为最终的预测结果(发放率)。模型加载:支持从
spiking_resnet加载多种脉冲 ResNet 模型,并可选择 CuPy 后端加速。
English
English
SResNetTraineris a trainer for training spiking ResNet models on the ImageNet dataset. It inherits fromtrain_classify.Trainerand 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], whereTis the total number of time-steps.Model output processing: averages outputs over
Ttime-steps along the time dimension as the final prediction (firing rate).Model loading: supports loading various spiking ResNet models from
spiking_resnetwith an optional CuPy backend for acceleration.Extra CLI arguments: adds
--T(number of time-steps) and--cupy(enable CuPy backend) arguments.