Batch Normalization Variants#

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


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

class spikingjelly.activation_based.layer.bn.BatchNorm1d(num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode='s')[源代码]#

基类:BatchNorm1d, StepModule

API Language: 中文 | English


  • 中文

参数:

step_mode (str) -- 步进模式,可以为 's' (单步) 或 'm' (多步)

其他的参数API参见 torch.nn.BatchNorm1d


  • English

参数:

step_mode (str) -- the step mode, which can be s (single-step) or m (multi-step)

Refer to torch.nn.BatchNorm1d for other parameters' API

返回:

None

返回类型:

None

super_forward(x: Tensor)[源代码]#
forward(x: Tensor)[源代码]#
class spikingjelly.activation_based.layer.bn.BatchNorm2d(num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode='s')[源代码]#

基类:BatchNorm2d, StepModule

API Language: 中文 | English


  • 中文

参数:

step_mode (str) -- 步进模式,可以为 's' (单步) 或 'm' (多步)

其他的参数API参见 torch.nn.BatchNorm2d


  • English

参数:

step_mode (str) -- the step mode, which can be s (single-step) or m (multi-step)

Refer to torch.nn.BatchNorm2d for other parameters' API

返回:

None

返回类型:

None

super_forward(x: Tensor)[源代码]#
forward(x: Tensor)[源代码]#
class spikingjelly.activation_based.layer.bn.BatchNorm3d(num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode='s')[源代码]#

基类:BatchNorm3d, StepModule

API Language: 中文 | English


  • 中文

参数:

step_mode (str) -- 步进模式,可以为 's' (单步) 或 'm' (多步)

其他的参数API参见 torch.nn.BatchNorm3d


  • English

参数:

step_mode (str) -- the step mode, which can be s (single-step) or m (multi-step)

Refer to torch.nn.BatchNorm3d for other parameters' API

返回:

None

返回类型:

None

super_forward(x: Tensor)[源代码]#
forward(x: Tensor)[源代码]#
class spikingjelly.activation_based.layer.bn.NeuNorm(in_channels: int, height: int, width: int, k: float = 0.9, shared_across_channels: bool = False, step_mode: str = 's')[源代码]#

基类:MemoryModule

API Language: 中文 | English


  • 中文

Direct Training for Spiking Neural Networks: Faster, Larger, Better 中提出的NeuNorm层。NeuNorm层必须放在二维卷积层后的脉冲神经元后,例如: Conv2d -> LIF -> NeuNorm

要求输入的尺寸是 [batch_size, in_channels, height, width]

in_channels 是输入到NeuNorm层的通道数,也就是论文中的 \(F\)

k 是动量项系数,相当于论文中的 \(k_{\tau 2}\)

论文中的 \(\frac{v}{F}\) 会根据 \(k_{\tau 2} + vF = 1\) 自动算出。

参数:
  • in_channels (int) -- 输入数据的通道数

  • height (int) -- 输入数据的宽

  • width (int) -- 输入数据的高

  • k (float) -- 动量项系数

  • shared_across_channels (bool) -- 可学习的权重 w 是否在通道这一维度上共享。设置为 True 可以大幅度节省内存

  • step_mode (str) -- 步进模式,可以为 's' (单步) 或 'm' (多步)


  • English

The NeuNorm layer is proposed in Direct Training for Spiking Neural Networks: Faster, Larger, Better.

It should be placed after spiking neurons behind convolution layer, e.g., Conv2d -> LIF -> NeuNorm .

The input should be a 4-D tensor with shape = [batch_size, in_channels, height, width].

in_channels is the channels of input,which is \(F\) in the paper.

k is the momentum factor,which is \(k_{\tau 2}\) in the paper.

\(\frac{v}{F}\) will be calculated by \(k_{\tau 2} + vF = 1\) autonomously.

参数:
  • in_channels (int) -- channels of input

  • height (int) -- height of input

  • width (int) -- height of width

  • k (float) -- momentum factor

  • shared_across_channels (bool) -- whether the learnable parameter w is shared over channel dim. If set True, the consumption of memory can decrease largely

  • step_mode (str) -- the step mode, which can be s (single-step) or m (multi-step)

返回:

None

返回类型:

None

single_step_forward(in_spikes: Tensor)[源代码]#
class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm1d(alpha: float, v_th: float, *args, **kwargs)[源代码]#

基类:_ThresholdDependentBatchNormBase

API Language: 中文 | English


  • 中文

Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, tdBN 需要跨时间步求统计量。

参数:
  • alpha (float) -- 由网络结构决定的超参数

  • v_th (float) -- 下一个脉冲神经元层的阈值

*args, **kwargs 中的参数与 torch.nn.BatchNorm1d 的参数相同。


  • English

The Threshold-Dependent Batch Normalization (tdBN) proposed in Going Deeper With Directly-Trained Larger Spiking Neural Networks.

警告

Only supports multi-step running mode step_mode = "m" . This is because tdBN needs to calculate statistics across time steps.

参数:
  • alpha (float) -- the hyper-parameter depending on network structure

  • v_th (float) -- the threshold of next spiking neurons layer

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm1d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm2d(alpha: float, v_th: float, *args, **kwargs)[源代码]#

基类:_ThresholdDependentBatchNormBase

API Language: 中文 | English


  • 中文

Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, tdBN 需要跨时间步求统计量。

参数:
  • alpha (float) -- 由网络结构决定的超参数

  • v_th (float) -- 下一个脉冲神经元层的阈值

*args, **kwargs 中的参数与 torch.nn.BatchNorm2d 的参数相同。


  • English

The Threshold-Dependent Batch Normalization (tdBN) proposed in Going Deeper With Directly-Trained Larger Spiking Neural Networks.

警告

Only supports multi-step running mode step_mode = "m" . This is because tdBN needs to calculate statistics across time steps.

参数:
  • alpha (float) -- the hyper-parameter depending on network structure

  • v_th (float) -- the threshold of next spiking neurons layer

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm2d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm3d(alpha: float, v_th: float, *args, **kwargs)[源代码]#

基类:_ThresholdDependentBatchNormBase

API Language: 中文 | English


  • 中文

Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, tdBN 需要跨时间步求统计量。

参数:
  • alpha (float) -- 由网络结构决定的超参数

  • v_th (float) -- 下一个脉冲神经元层的阈值

*args, **kwargs 中的参数与 torch.nn.BatchNorm3d 的参数相同。


  • English

The Threshold-Dependent Batch Normalization (tdBN) proposed in Going Deeper With Directly-Trained Larger Spiking Neural Networks.

警告

Only supports multi-step running mode step_mode = "m" . This is because tdBN needs to calculate statistics across time steps.

参数:
  • alpha (float) -- the hyper-parameter depending on network structure

  • v_th (float) -- the threshold of next spiking neurons layer

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm3d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm1d(T: int, *args, **kwargs)[源代码]#

基类:_TemporalEffectiveBatchNormBase

API Language: 中文 | English


  • 中文

  • 中文

Temporal Effective Batch Normalization in Spiking Neural Networks 一文提出的 Temporal Effective Batch Normalization (TEBN)。

TEBN在多步模式的BN的基础上,给每个时刻的输出增加一个可学习的缩放。 若多步模式BN在 t 时刻的输出是 y[t],则TEBN的输出为 k[t] * y[t], 其中 k[t] 是可学习的参数。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, TEBN 需要跨时间步求统计量。

参数:

T (int) -- 总时间步数

*args, **kwargs 中的参数与 torch.nn.BatchNorm1d 的参数相同。


  • English

  • English

Temporal Effective Batch Normalization (TEBN) proposed by Temporal Effective Batch Normalization in Spiking Neural Networks.

TEBN adds a scale on outputs of each time-step from the native multi-step BN. Denote the output at time step t of the native multi-step BN as y[t], then the output of TEBN is k[t] * y[t], where k[t] is the learnable scale.

警告

Only supports multi-step running mode step_mode = "m" . This is because TEBN needs to calculate statistics across time steps.

参数:

T (int) -- the number of time-steps

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm1d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm2d(T: int, *args, **kwargs)[源代码]#

基类:_TemporalEffectiveBatchNormBase

API Language: 中文 | English


  • 中文

  • 中文

Temporal Effective Batch Normalization in Spiking Neural Networks 一文提出的 Temporal Effective Batch Normalization (TEBN)。

TEBN在多步模式的BN的基础上,给每个时刻的输出增加一个可学习的缩放。 若多步模式BN在 t 时刻的输出是 y[t],则TEBN的输出为 k[t] * y[t], 其中 k[t] 是可学习的参数。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, TEBN 需要跨时间步求统计量。

参数:

T (int) -- 总时间步数

*args, **kwargs 中的参数与 torch.nn.BatchNorm2d 的参数相同。


  • English

  • English

Temporal Effective Batch Normalization (TEBN) proposed by Temporal Effective Batch Normalization in Spiking Neural Networks.

TEBN adds a scale on outputs of each time-step from the native multi-step BN. Denote the output at time step t of the native multi-step BN as y[t], then the output of TEBN is k[t] * y[t], where k[t] is the learnable scale.

警告

Only supports multi-step running mode step_mode = "m" . This is because tdBN needs to calculate statistics across time steps.

参数:

T (int) -- the number of time-steps

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm2d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm3d(T: int, *args, **kwargs)[源代码]#

基类:_TemporalEffectiveBatchNormBase

API Language: 中文 | English


  • 中文

  • 中文

Temporal Effective Batch Normalization in Spiking Neural Networks 一文提出的 Temporal Effective Batch Normalization (TEBN)。

TEBN在多步模式的BN的基础上,给每个时刻的输出增加一个可学习的缩放。 若多步模式BN在 t 时刻的输出是 y[t],则TEBN的输出为 k[t] * y[t], 其中 k[t] 是可学习的参数。

警告

只支持多步运行模式 step_mode = "m" 。这是因为, TEBN 需要跨时间步求统计量。

参数:

T (int) -- 总时间步数

*args, **kwargs 中的参数与 torch.nn.BatchNorm3d 的参数相同。


  • English

  • English

Temporal Effective Batch Normalization (TEBN) proposed by Temporal Effective Batch Normalization in Spiking Neural Networks.

TEBN adds a scale on outputs of each time-step from the native multi-step BN. Denote the output at time step t of the native multi-step BN as y[t], then the output of TEBN is k[t] * y[t], where k[t] is the learnable scale.

警告

Only supports multi-step running mode step_mode = "m" . This is because TEBN needs to calculate statistics across time steps.

参数:

T (int) -- the number of time-steps

Other parameters in *args, **kwargs are same with those of torch.nn.BatchNorm3d.

返回:

None

返回类型:

None

class spikingjelly.activation_based.layer.bn.BatchNormThroughTime1d(T: int, num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode: str = 's')[源代码]#

基类:_BatchNormThroughTimeBase

API Language: 中文 | English


  • 中文

Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch 一文提出的 Batch Normalization Through Time (BNTT)。

BNTT为每个时间步配置一个单独的单步BN。这 T 个BN的可学习参数以及统计量都相互独立。

备注

BNTT 能以单步或多步模式运行,其状态 t 标注了当前时间步。 每次调用 single_step_forward() (包括通过 multi_step_forward() 间接调用的情况), t 将加1。 t 将被用来索引对应时间步的BN。

因此,记得在完成 T 个时间步的计算后,调用 reset() 来重制 t

参数:
  • T (int) -- 总时间步数

  • step_mode (str) -- 运行模式,'s'代表单步模式,'m'代表多步模式

其余参数与 torch.nn.BatchNorm1d 的参数相同。


  • English

Batch Normalization Through Time (BNTT) proposed by Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch .

BPTT assigns a separate single-step BN to each of the T time steps. The learnable parameters and statistics of these BNs are independent of each other.

备注

BNTT can run in single-step or multi-step mode, and its state t marks the current time step. Every time you call single_step_forward() (including indirect calling through multi_step_forward()), t will be incremented by 1. t will be used to index the BN corresponding to the current time step.

Therefore, remember to call reset() method after completing T time steps so as to reset t .

参数:
  • T (int) -- the number of time-steps

  • step_mode (str) -- running mode. 's' for single-step mode, 'm' for multi-step mode

Other parameters are same with those of torch.nn.BatchNorm1d.

返回:

None

返回类型:

None

bn_type#

BatchNorm1d 的别名

class spikingjelly.activation_based.layer.bn.BatchNormThroughTime2d(T: int, num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode: str = 's')[源代码]#

基类:_BatchNormThroughTimeBase

API Language: 中文 | English


  • 中文

Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch 一文提出的 Batch Normalization Through Time (BNTT)。

BNTT为每个时间步配置一个单独的单步BN。这 T 个BN的可学习参数以及统计量都相互独立。

备注

BNTT 能以单步或多步模式运行,其状态 t 标注了当前时间步。 每次调用 single_step_forward() (包括通过 multi_step_forward() 间接调用的情况), t 将加1。 t 将被用来索引对应时间步的BN。

因此,记得在完成 T 个时间步的计算后,调用 reset() 来重制 t

参数:
  • T (int) -- 总时间步数

  • step_mode (str) -- 运行模式,'s'代表单步模式,'m'代表多步模式

其余参数与 torch.nn.BatchNorm2d 的参数相同。


  • English

Batch Normalization Through Time (BNTT) proposed by Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch .

BPTT assigns a separate single-step BN to each of the T time steps. The learnable parameters and statistics of these BNs are independent of each other.

备注

BNTT can run in single-step or multi-step mode, and its state t marks the current time step. Every time you call single_step_forward() (including indirect calling through multi_step_forward()), t will be incremented by 1. t will be used to index the BN corresponding to the current time step.

Therefore, remember to call reset() method after completing T time steps so as to reset t .

参数:
  • T (int) -- the number of time-steps

  • step_mode (str) -- running mode. 's' for single-step mode, 'm' for multi-step mode

Other parameters are same with those of torch.nn.BatchNorm2d.

返回:

None

返回类型:

None

bn_type#

BatchNorm2d 的别名

class spikingjelly.activation_based.layer.bn.BatchNormThroughTime3d(T: int, num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True, step_mode: str = 's')[源代码]#

基类:_BatchNormThroughTimeBase

API Language: 中文 | English


  • 中文

Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch 一文提出的 Batch Normalization Through Time (BNTT)。

BNTT为每个时间步配置一个单独的单步BN。这 T 个BN的可学习参数以及统计量都相互独立。

备注

BNTT 能以单步或多步模式运行,其状态 t 标注了当前时间步。 每次调用 single_step_forward() (包括通过 multi_step_forward() 间接调用的情况), t 将加1。 t 将被用来索引对应时间步的BN。

因此,记得在完成 T 个时间步的计算后,调用 reset() 来重制 t

参数:
  • T (int) -- 总时间步数

  • step_mode (str) -- 运行模式,'s'代表单步模式,'m'代表多步模式

其余参数与 torch.nn.BatchNorm3d 的参数相同。


  • English

Batch Normalization Through Time (BNTT) proposed by Revisiting Batch Normalization for Training Low-Latency Deep Spiking Neural Networks From Scratch .

BPTT assigns a separate single-step BN to each of the T time steps. The learnable parameters and statistics of these BNs are independent of each other.

备注

BNTT can run in single-step or multi-step mode, and its state t marks the current time step. Every time you call single_step_forward() (including indirect calling through multi_step_forward()), t will be incremented by 1. t will be used to index the BN corresponding to the current time step.

Therefore, remember to call reset() method after completing T time steps so as to reset t .

参数:
  • T (int) -- the number of time-steps

  • step_mode (str) -- running mode. 's' for single-step mode, 'm' for multi-step mode

Other parameters are same with those of torch.nn.BatchNorm3d.

返回:

None

返回类型:

None

bn_type#

BatchNorm3d 的别名