qualia_plugin_snn.learningmodel.pytorch.SNN module
Contains the base class for spiking neural network models.
- class qualia_plugin_snn.learningmodel.pytorch.SNN.SNN[source]
Bases:
LearningModelPyTorch
,StepModule
Base class for spiking neural network models to inherit from.
- __select_neuron(neuron: dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool]) type[Module]
Select a spiking neuron class from a kind specified in configuration file.
The class will be looked up by its name in the following modules successively, first match is used:
qualia_plugin_snn.learningmodel.pytorch.quantized_SNN_layers
- Parameters:
neuron (dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool]) – A spiking neuron configuration dict
- Returns:
The class corresponding to the
kind
specified in the neuron configuration dict- Raises:
ValueError – When the
'kind'
key cannot be found in theneuron
dictTypeError – When the value associated to
kind
is not a stringAttributeError – When the class for
kind
cannot be looked up
- Return type:
- __extract_neuron_params(neuron: dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool]) dict[str, dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | list[dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | str | int | float | bool | None]
Extract params from the given
neuron
configuration dict, also convertv_reset
.v_reset
is specified as either a float (hard-reset) orfalse
(soft-reset) in the TOML configuration since there is noNone
equivalent in TOML. However SpikingJelly neurons useNone
to signify soft-reset, so convertv_reset=false
tov_reset=None
.- Parameters:
neuron (dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool]) – The spiking neuron configuration dict
- Returns:
The
params
dict for the given neuron configuration dict with convertedv_reset
- Raises:
TypeError – When the value associated to
params
is not a dict- Return type:
dict[str, dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | list[dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | str | int | float | bool | None]
- create_neuron(quant_params: QuantizationConfigDict | None = None) Module [source]
Instanciate a spiking neuron from the kind and params found in
neuron
of :meth:__init__
.- Parameters:
quant_params (QuantizationConfigDict | None) – Optional quantization configuration dict in case of quantized network, see
qualia_core.learningmodel.pytorch.Quantizer.Quantizer
- Returns:
A spiking neuron instance
- Return type:
- __init__(input_shape: tuple[int, ...], output_shape: tuple[int, ...], timesteps: int, neuron: dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | None) None [source]
Construct
SNN
.step_mode
is extracted from the neuron configuration dictneuron
.__select_neuron()
and__extract_neuron_params()
are called to prepare the neuron for instanciation withcreate_neuron()
which should be used in derived classes to instanciate the spiking neurons.Below is an example of a neuron configuration dict for SpikingJelly’s multi-step
spikingjelly.activation_based.neuron.IFNode
soft-reset with threshold at 1.0.Python
neuron = { 'kind': 'IFNode', 'params': { 'v_threshold': 1.0, 'v_reset': False, 'step_mode': 'm', } }
TOML
[[model]] params.neuron.kind = 'IFNode' params.neuron.params.v_threshold = 1.0 params.neuron.params.v_reset = false params.neuron.params.step_mode = 'm'
- Parameters:
input_shape (tuple[int, ...]) – Input shape passed to
qualia_core.learningmodel.pytorch.LearningModel.LearningModel
withtimesteps
prependedoutput_shape (tuple[int, ...]) – Output shape passed to
qualia_core.learningmodel.pytorch.LearningModel.LearningModel
timesteps (int) – Number of timesteps
neuron (dict[str, dict[str, RecursiveConfigUnion] | list[RecursiveConfigUnion] | str | int | float | bool] | None) – Spiking neuron configuration dict
- Raises:
ValueError – When
neuron
isNone
or emptyTypeError – When the value associated to
params.step_mode
is not a string
- Return type:
None