spikingjelly.activation_based.quantize module#
- spikingjelly.activation_based.quantize.round(x)[源代码]#
-
中文
对输入张量应用
y = torch.round(x)操作,并重新定义梯度为 \(\frac{\partial y}{\partial x} = 1\)。
English
Apply
y = torch.round(x)with re-defining gradient as \(\frac{\partial y}{\partial x} = 1\).
- spikingjelly.activation_based.quantize.ceil(x)[源代码]#
-
中文
对输入张量应用
y = torch.ceil(x)操作,并重新定义梯度为 \(\frac{\partial y}{\partial x} = 1\)。
English
Apply
y = torch.ceil(x)with re-defining gradient as \(\frac{\partial y}{\partial x} = 1\).
- spikingjelly.activation_based.quantize.floor(x)[源代码]#
-
中文
对输入张量应用
y = torch.floor(x)操作,并重新定义梯度为 \(\frac{\partial y}{\partial x} = 1\)。
English
Apply
y = torch.floor(x)with re-defining gradient as \(\frac{\partial y}{\partial x} = 1\).
- spikingjelly.activation_based.quantize.clamp(x, min_value, max_value)[源代码]#
-
中文
应用
y = torch.clamp(x, min_value, max_value)操作,并重新定义梯度为:\[\begin{split}\frac{\partial y}{\partial x} = \begin{cases} 1, \mathrm{min\_value} \leq x \leq \mathrm{max\_value} \\ 0, \mathrm{otherwise} \end{cases}\end{split}\]- 参数:
- 返回:
输出张量
- 返回类型:
English
Apply
y = torch.clamp(x, min_value, max_value)with re-defining gradient as:\[\begin{split}\frac{\partial y}{\partial x} = \begin{cases} 1, \mathrm{min\_value} \leq x \leq \mathrm{max\_value} \\ 0, \mathrm{otherwise} \end{cases}\end{split}\]
- spikingjelly.activation_based.quantize.step_quantize(x, step=1.0)[源代码]#
-
中文
将
x量化到最近的i * step,其中i是整数。注意梯度定义为 \(\frac{\partial y}{\partial x} = 1\)。
English
Quantize
xto the nearesti * step, whereiis an integer.Note that the gradient is defined by \(\frac{\partial y}{\partial x} = 1\).
- spikingjelly.activation_based.quantize.k_bit_quantize(x, k)[源代码]#
-
中文
在 DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients 中定义的k位量化器。
范围为
[0, 1]的输入将被量化到最近的i / (2 ** k - 1),其中i = 0, 1, ..., (2 ** k - 1)。注意梯度定义为 \(\frac{\partial y}{\partial x} = 1\)。
要将范围为
(-inf, inf)的输入夹紧到范围(0, 1),可以使用torch.sigmoid、torch.nn.Hardtanh或spikingjelly.activation_based.quantize中的clamp_*函数(例如spikingjelly.activation_based.quantize.clamp_by_linear)。- 参数:
- 返回:
y = round((2 ** k - 1) * x) / (2 ** k - 1)- 返回类型:
English
The k-bit quantizer defined in DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients.
The input whose range is
[0, 1]will be quantized to the nearesti / (2 ** k - 1), wherei = 0, 1, ..., (2 ** k - 1).Note that the gradient is defined by \(\frac{\partial y}{\partial x} = 1\).
To clamp the input whose range is
(-inf, inf)to range(0, 1), usingtorch.sigmoid,torch.nn.Hardtanhorclamp_*functions (e.g.,spikingjelly.activation_based.quantize.clamp_by_linear) inspikingjelly.activation_based.quantize.- 参数:
- 返回:
y = round((2 ** k - 1) * x) / (2 ** k - 1)- 返回类型:
- 抛出:
ValueError -- if
k < 1
- spikingjelly.activation_based.quantize.affine_k_bit_quantize(x, k, w, b)[源代码]#
-
中文
应用仿射量化
y = w * round((2 ** k - 1) * x) / (2 ** k - 1) + b。- 参数:
- 返回:
y = w * round((2 ** k - 1) * x) / (2 ** k - 1) + b- 返回类型:
English
Apply an affine quantization with
y = w * round((2 ** k - 1) * x) / (2 ** k - 1) + b.
- spikingjelly.activation_based.quantize.clamp_by_linear(x, eps=1e-05)[源代码]#
-
中文
使用线性变换将输入范围从
(-inf, inf)夹紧到[0., 1.]:\[y = \frac{x - \mathrm{min}(x)}{\mathrm{max}(x) - \mathrm{min}(x) + eps}\]- 参数:
- 返回:
归一化后的张量,其范围为
[0., 1.]- 返回类型:
English
Using the linear transform to clamp the input range from
(-inf, inf)to[0., 1.]:\[y = \frac{x - \mathrm{min}(x)}{\mathrm{max}(x) - \mathrm{min}(x) + eps}\]