qualia_plugin_snn.learningmodel.pytorch.QuantizedSResNetStride module
Contains the template for a quantized residual spiking neural network.
- class qualia_plugin_snn.learningmodel.pytorch.QuantizedSResNetStride.CreateNeuron[source]
Bases:
ProtocolSignature for create_neuron from
qualia_plugin_snn.learningmodel.pytorch.SNN.create_neuron().Used to pass neuron builder to BasicBlock.
- __call__(quant_params: QuantizationConfigDict) Module[source]
Instanciate a spiking neuron.
- Parameters:
quant_params (QuantizationConfigDict) – Optional quantization configuration dict in case of quantized network, see
qualia_core.learningmodel.pytorch.layers.Quantizer.Quantizer- Returns:
A spiking neuron instance
- Return type:
- __init__(*args, **kwargs)
- class qualia_plugin_snn.learningmodel.pytorch.QuantizedSResNetStride.QuantizedBasicBlockBuilder[source]
Bases:
ProtocolSignature for basicblockbuilder.
Used to bind hyperparameters constant across all the ResNet blocks.
- __call__(in_planes: int, planes: int, kernel_size: int, pool_size: int, stride: int, padding: int) QuantizedBasicBlock[source]
Build a
QuantizedBasicBlock.- Parameters:
in_planes (int) – Number of input channels
planes (int) – Number of filters (i.e., output channels) in the main branch Conv layers
kernel_size (int) –
kernel_sizefor the main branch Conv layerspool_size (int) –
kernel_sizefor the MaxPool layers, no MaxPool layer added if 1stride (int) –
kernel_sizefor the MaxPool layers, no MaxPool layer added if 1padding (int) – Padding for the main branch Conv layers
- Returns:
- Return type:
- __init__(*args, **kwargs)
- class qualia_plugin_snn.learningmodel.pytorch.QuantizedSResNetStride.QuantizedBasicBlock[source]
Bases:
ModuleA single quantized ResNetv1 block.
Should have topology identical to
qualia_plugin_snn.learningmodel.pytorch.SResNet.BasicBlockbut with layers replaced with their quantized equivalent.Structure is:
| / \ | | QuantizedConv | | | QuantizedBatchNorm | | | QuantizedMaxPool QuantizedConv | | QuantizedIF QuantizedBatchNorm | | QuantizedConv QuantizedMaxPool | | QuantizedBatchNorm QuantizedIF | | QuantizedIF | | | \ / | QuantizedAdd
Main (left) branch QuantizedConv use
kernel_size=kernel_size, while residual (right) branch QuantizedConv usekernel_size=1.QuantizedBatchNorm layers will be absent if
batch_norm == FalseQuantizedMaxPool layer will be absent if
pool_size == 1.Residual (right) branch QuantizedConv layer will be asbent if
in_planes==planes, except ifforce_projection_with_pooling==Trueandpool_size != 1.- __init__(sjlayers_t: ModuleType, in_planes: int, planes: int, kernel_size: int, pool_size: int, stride: int, padding: int, batch_norm: bool, bn_momentum: float, force_projection_with_pooling: bool, create_neuron: CreateNeuron, step_mode: str, quant_params: QuantizationConfigDict) None[source]
Construct
QuantizedBasicBlock.- Parameters:
sjlayers_t (ModuleType) – Module containing the aliased quantized layers to use (1D or 2D)
in_planes (int) – Number of input channels
planes (int) – Number of filters (i.e., output channels) in the main branch QuantizedConv layers
kernel_size (int) –
kernel_sizefor the main branch QuantizedConv layersstride (int) –
kernel_sizefor the QuantizedMaxPool layers, no QuantizedMaxPool layer added if 1padding (int) – Padding for the main branch QuantizedConv layers
batch_norm (bool) – If
True, add BatchNorm layer after each QuantizedConv layerbn_momentum (float) – QuantizedBatchNorm layer
momentumforce_projection_with_pooling (bool) – If
True, residual QuantizedConv layer is kept whenstride != 1even ifin_planes == planescreate_neuron (CreateNeuron) –
qualia_plugin_snn.learningmodel.pytorch.SNN.SNN.create_neuron()method to instantiate a spiking neuronstep_mode (str) – SpikingJelly
step_modefromqualia_plugin_snn.learningmodel.pytorch.SNN.SNN.step_modequant_params (QuantizationConfigDict) – Quantization configuration dict, see
qualia_core.learningmodel.pytorch.layers.Quantizer.Quantizerpool_size (int)
- Return type:
None
- class qualia_plugin_snn.learningmodel.pytorch.QuantizedSResNetStride.QuantizedSResNetStride[source]
Bases:
SNNQuantized residual spiking neural network template.
Should have topology identical to
qualia_plugin_snn.learningmodel.pytorch.SResNetStride.SResNetStridebut with layers replaced with their quantized equivalent.- __init__(input_shape: tuple[int, ...], output_shape: tuple[int, ...], filters: list[int], kernel_sizes: list[int], pool_sizes: list[int], num_blocks: list[int], strides: list[int], paddings: list[int], quant_params: QuantizationConfig, prepool: int = 1, postpool: str = 'max', batch_norm: bool = False, bn_momentum: float = 0.1, force_projection_with_pooling: bool = True, neuron: RecursiveConfigDict | None = None, timesteps: int = 2, dims: int = 1, basicblockbuilder: QuantizedBasicBlockBuilder | None = None) None[source]
Construct
QuantizedSResNet.Structure is:
QuantizedInput | QuantizedAvgPool | QuantizedConv | QuantizedBatchNorm | QuantizedIF | QuantizedBasicBlock | … | QuantizedBasicBlock | QuantizedGlobalPool | Flatten | QuantizedLinear- Parameters:
filters (list[int]) – List of
out_channelsfor QuantizedConv layers inside eachQuantizedBasicBlockgroup, must be be of the same size asnum_blocks, first element is for the first QuantizedConv layer at the beginning of the networkkernel_sizes (list[int]) – List of
kernel_sizefor QuantizedConv layers inside eachQuantizedBasicBlockgroup, must be of the same size asnum_blocks, first element is for the first QuantizedConv layer at the beginning of the networkpool_size – List of
kernel_sizefor QuantizedMaxPool layers inside eachQuantizedBasicBlockgroup, must be of the same size asnum_blocks,strideis applied only to the firstQuantizedBasicBlockof the group, nextQuantizedBasicBlockin the group use astrideof1, first element is the stride of the first QuantizedConv layer at the beginning of the networknum_blocks (list[int]) – List of number of
QuantizedBasicBlockin each group, also defines the number ofQuantizedBasicBlockgroups inside the networkstrides (list[int]) – List of
stridefor first QuantizedConv layers inside eachQuantizedBasicBlockgroup, must be of the same size asnum_blocks, first element is for the first Conv layer at the beginning of the networkpaddings (list[int]) – List of
paddingfor QuantizedConv layer inside eachQuantizedBasicBlockgroup, must be of the same size asnum_blocks, first element is for the first QuantizedConv layer at the beginning of the networkprepool (int) – QuantizedAvgPool layer
kernel_sizeto add at the beginning of the network, no layer added if 0postpool (str) – Quantized global pooling layer type after all
QuantizedBasicBlock, either max for QuantizedMaxPool or avg for QuantizedAvgPoolbatch_norm (bool) – If
True, add a QuantizedBatchNorm layer after each QuantizedConv layer, otherwise no layer addedbn_momentum (float) – QuantizedBatchNorm
momentumforce_projection_with_pooling (bool) – If
True, residual QuantizedConv layer is kept whenstride != 1even ifin_planes == planesinside aQuantizedBasicBlockneuron (RecursiveConfigDict | None) – Spiking neuron configuration, see
qualia_plugin_snn.learningmodel.pytorch.SNN.SNN.__init__()timesteps (int) – Number of timesteps
dims (int) – Either 1 or 2 for 1D or 2D convolutional network.
basicblockbuilder (QuantizedBasicBlockBuilder | None) – Optional function with
QuantizedBasicBlockBuilder.__call__()signature to build a basic block after binding constants common across all basic blocksquant_params (QuantizationConfig)
- Return type:
None