spikingjelly.activation_based.layer package#

备注

API稳定性说明

SpikingJelly 0.0.0.1.0layer 模块的内部实现进行了重构:原来的 layer.py 文件已被拆分并重组为 layer/ 包,以提升代码的模块化程度和可维护性。

该改动不会影响对外公开的 API。 我们强烈建议用户仍然通过 layer 这一顶层命名空间来访问相关功能,而不是从具体的内部子模块中进行导入。 layer 层级下的导入路径被视为稳定的公共接口;更深层的子模块仅作为内部实现细节,未来可能发生变化。

from spikingjelly.activation_based.layer import SeqToANNContainer # 推荐 ✅
from spikingjelly.activation_based.layer.container import SeqToANNContainer # 不推荐 ❌

API Stability Notice

We have refactored the internal implementation of the layer module. The original layer.py file has been reorganized into a package ( layer/ ) for better modularity and maintainability.

This change does not affect the public API. Users are strongly encouraged to continue accessing layers directly from the layer namespace, rather than importing from specific internal submodules. Import paths under layer are considered part of the stable public API, while deeper submodule paths are treated as implementation details and may change in future releases.

from spikingjelly.activation_based.layer import SeqToANNContainer # recommended ✅
from spikingjelly.activation_based.layer.container import SeqToANNContainer # not recommended ❌

Containers#

SpikingJelly 的 容器 封装了常见的网络结构,并支持单步(s)和多步(m)步进模式。


SpikingJelly's containers wrap common network architectures and support both single-step (s) and multi-step (m) step modes.

MultiStepContainer

Container for multi-step forward pass.

SeqToANNContainer

Container that merges the time and batch dimensions for forward pass.

TLastMultiStepContainer

Multi-step container whose time dimension is placed at the last.

TLastSeqToANNContainer

SeqToANNContainer whose time dimension is placed at the last.

StepModeContainer

Container that sets the step mode for all contained modules.

ElementWiseRecurrentContainer

Container for element-wise recurrent connections.

LinearRecurrentContainer

Container for linear recurrent connections.

Wrappers for Stateless Layers#

SpikingJelly 的 无状态层包装器 封装了 PyTorch 的标准层,并支持脉冲神经网络的时间步进模式。


SpikingJelly's stateless layer wrappers wrap PyTorch's standard layers and support the step mode of Spiking Neural Networks.

Convolutional Layers#

Conv1d

1D convolution layer with step mode support.

Conv2d

2D convolution layer with step mode support.

Conv3d

3D convolution layer with step mode support.

Convolutional Transpose Layers#

ConvTranspose1d

1D transposed convolution layer with step mode support.

ConvTranspose2d

2D transposed convolution layer with step mode support.

ConvTranspose3d

3D transposed convolution layer with step mode support.

Upsampling Layers#

Upsample

Upsampling layer with configurable interpolation methods.

Pooling Layers#

MaxPool1d

1D max pooling layer with step mode support.

MaxPool2d

2D max pooling layer with step mode support.

MaxPool3d

3D max pooling layer with step mode support.

AvgPool1d

1D average pooling layer with step mode support.

AvgPool2d

2D average pooling layer with step mode support.

AvgPool3d

3D average pooling layer with step mode support.

AdaptiveAvgPool1d

1D adaptive average pooling layer with step mode support.

AdaptiveAvgPool2d

2D adaptive average pooling layer with step mode support.

AdaptiveAvgPool3d

3D adaptive average pooling layer with step mode support.

Linear Layers#

Linear

Linear transformation layer with step mode support.

Flatten

Flatten layer with step mode support.

Layers with Weight Standardization#

WSConv2d

Weight Standardization 2D convolution layer with step mode support.

WSLinear

Weight Standardization linear layer with step mode support.

Group Normalization Layers#

GroupNorm

Group normalization layer with step mode support.

Attention Layers#

SpikingJelly 的 注意力层 提供了用于深度脉冲神经网络的注意力机制实现,包括用于卷积 SNN 的注意力层和用于脉冲 Transformers 的注意力层。


SpikingJelly's attention layers provide attention mechanisms for deep Spiking Neural Networks, including attention layers for convolutional SNNs and Spiking Transformers.

Attention for Convolutional SNNs#

TemporalWiseAttention

Temporal-wise attention.

MultiDimensionalAttention

Multi-dimensional attention.

Attention for Spiking Transformers#

SpikingSelfAttention

Spiking self-attention for Spikformer.

QKAttention

Query-Key attention for QKFormer.

TokenQKAttention

Token-wise Query-Key attention for QKFormer.

ChannelQKAttention

Channel-wise Query-Key attention for QKFormer.

Batch Normalization Variants#

SpikingJelly 提供了多种适用于深度 SNN 的 批归一化层变体


SpikingJelly provides multiple batch normalization variants that are optimized for deep SNNs.

Standard Batch Normalization#

BatchNorm1d

1D batch normalization layer with step mode support.

BatchNorm2d

2D batch normalization layer with step mode support.

BatchNorm3d

3D batch normalization layer with step mode support.

NeuNorm#

NeuNorm

Neural Normalization layer.

Threshold-Dependent Batch Normalization#

ThresholdDependentBatchNorm1d

1D threshold-dependent batch normalization layer.

ThresholdDependentBatchNorm2d

2D threshold-dependent batch normalization layer.

ThresholdDependentBatchNorm3d

3D threshold-dependent batch normalization layer.

Temporal Effective Batch Normalization#

TemporalEffectiveBatchNorm1d

1D temporal effective batch normalization layer.

TemporalEffectiveBatchNorm2d

2D temporal effective batch normalization layer.

TemporalEffectiveBatchNorm3d

3D temporal effective batch normalization layer.

Batch Normalization Through Time#

BatchNormThroughTime1d

1D batch normalization through time.

BatchNormThroughTime2d

2D batch normalization through time.

BatchNormThroughTime3d

3D batch normalization through time.

Dropout Variants#

SpikingJelly 提供了适用于 SNN 的 Dropout 实现,支持步进模式。


SpikingJelly provides dropout implementations suitable for SNNs with step mode support.

Dropout

Dropout layer with step mode support.

Dropout2d

2D dropout layer with step mode support.

DropConnectLinear

DropConnect linear layer with step mode support.

Online Learning Modules#

SpikingJelly 的 在线学习模块 提供了用于在线学习的辅助类和操作。


SpikingJelly's online learning modules provide auxiliary classes and operations for online learning.

ReplaceforGrad

AutoGrad function for gradient replacement.

GradwithTrace

Computing gradients using neuron traces.

SpikeTraceOp

Operation for spike and trace handling in online training.

OTTTSequential

Sequential container for online training through time.

Miscellaneous#

SpikingJelly 的 杂项模块 提供了辅助层和其他实用工具。


SpikingJelly's miscellaneous module provides auxiliary layers and other utilities.

SynapseFilter

Synapse filter layer with exponential decay.

PrintShapeModule

Module for printing input shapes during forward pass.

VotingLayer

Voting layer for multi-class classification.

Delay

Temporal delay operation.