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')[源代码]#
-
中文
- 参数:
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.BatchNorm1dfor other parameters' API- 返回:
None
- 返回类型:
None
- 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')[源代码]#
-
中文
- 参数:
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.BatchNorm2dfor other parameters' API- 返回:
None
- 返回类型:
None
- 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')[源代码]#
-
中文
- 参数:
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.BatchNorm3dfor other parameters' API- 返回:
None
- 返回类型:
None
- 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
中文
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\) 自动算出。
- 参数:
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_channelsis the channels of input,which is \(F\) in the paper.kis 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
wis shared over channel dim. If setTrue, the consumption of memory can decrease largelystep_mode (str) -- the step mode, which can be s (single-step) or m (multi-step)
- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm1d(alpha: float, v_th: float, *args, **kwargs)[源代码]#
基类:
_ThresholdDependentBatchNormBase
中文
Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。
警告
只支持多步运行模式
step_mode = "m"。这是因为, tdBN 需要跨时间步求统计量。*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.- 参数:
Other parameters in
*args, **kwargsare same with those oftorch.nn.BatchNorm1d.- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm2d(alpha: float, v_th: float, *args, **kwargs)[源代码]#
基类:
_ThresholdDependentBatchNormBase
中文
Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。
警告
只支持多步运行模式
step_mode = "m"。这是因为, tdBN 需要跨时间步求统计量。*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.- 参数:
Other parameters in
*args, **kwargsare same with those oftorch.nn.BatchNorm2d.- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.ThresholdDependentBatchNorm3d(alpha: float, v_th: float, *args, **kwargs)[源代码]#
基类:
_ThresholdDependentBatchNormBase
中文
Going Deeper With Directly-Trained Larger Spiking Neural Networks 一文提出的 Threshold-Dependent Batch Normalization (tdBN)。
警告
只支持多步运行模式
step_mode = "m"。这是因为, tdBN 需要跨时间步求统计量。*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.- 参数:
Other parameters in
*args, **kwargsare same with those oftorch.nn.BatchNorm3d.- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm1d(T: int, *args, **kwargs)[源代码]#
基类:
_TemporalEffectiveBatchNormBase
中文
中文
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
tof the native multi-step BN asy[t], then the output of TEBN isk[t] * y[t], wherek[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, **kwargsare same with those oftorch.nn.BatchNorm1d.- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm2d(T: int, *args, **kwargs)[源代码]#
基类:
_TemporalEffectiveBatchNormBase
中文
中文
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
tof the native multi-step BN asy[t], then the output of TEBN isk[t] * y[t], wherek[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, **kwargsare same with those oftorch.nn.BatchNorm2d.- 返回:
None
- 返回类型:
None
- class spikingjelly.activation_based.layer.bn.TemporalEffectiveBatchNorm3d(T: int, *args, **kwargs)[源代码]#
基类:
_TemporalEffectiveBatchNormBase
中文
中文
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
tof the native multi-step BN asy[t], then the output of TEBN isk[t] * y[t], wherek[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, **kwargsare same with those oftorch.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
中文
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。其余参数与
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
Ttime 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
tmarks the current time step. Every time you callsingle_step_forward()(including indirect calling throughmulti_step_forward()),twill be incremented by 1.twill be used to index the BN corresponding to the current time step.Therefore, remember to call
reset()method after completingTtime steps so as to resett.- 参数:
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
中文
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。其余参数与
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
Ttime 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
tmarks the current time step. Every time you callsingle_step_forward()(including indirect calling throughmulti_step_forward()),twill be incremented by 1.twill be used to index the BN corresponding to the current time step.Therefore, remember to call
reset()method after completingTtime steps so as to resett.- 参数:
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
中文
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。其余参数与
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
Ttime 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
tmarks the current time step. Every time you callsingle_step_forward()(including indirect calling throughmulti_step_forward()),twill be incremented by 1.twill be used to index the BN corresponding to the current time step.Therefore, remember to call
reset()method after completingTtime steps so as to resett.- 参数:
Other parameters are same with those of
torch.nn.BatchNorm3d.- 返回:
None
- 返回类型:
None
- bn_type#
BatchNorm3d的别名