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,StepModuleBase class for spiking neural network models to inherit from.
- __select_neuron(neuron: 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]) 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:
spikingjelly.activation_based.neuronqualia_plugin_snn.learningmodel.pytorch.quantized_SNN_layers
- Parameters:
neuron (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]) – A spiking neuron configuration dict
- Returns:
The class corresponding to the
kindspecified in the neuron configuration dict- Raises:
ValueError – When the
'kind'key cannot be found in theneurondictTypeError – When the value associated to
kindis not a stringAttributeError – When the class for
kindcannot be looked up
- Return type:
- __extract_neuron_params(neuron: 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]) 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
neuronconfiguration dict, also convertv_reset.v_resetis specified as either a float (hard-reset) orfalse(soft-reset) in the TOML configuration since there is noNoneequivalent in TOML. However SpikingJelly neurons useNoneto signify soft-reset, so convertv_reset=falsetov_reset=None.SpikingJelly expects some parameters to be float and not int, convert int to float for the following parameters:
a,b,tau,tau_w,v_reset,v_rest,v_threshold,w_rest.- Parameters:
neuron (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]) – The spiking neuron configuration dict
- Returns:
The
paramsdict for the given neuron configuration dict with convertedv_reset- Raises:
TypeError – When the value associated to
paramsis 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
neuronof :meth:__init__.- Parameters:
quant_params (QuantizationConfigDict | None) – 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__(input_shape: tuple[int, ...], output_shape: tuple[int, ...], timesteps: int, neuron: 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) None[source]
Construct
SNN.step_modeis 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.IFNodesoft-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.LearningModelwithtimestepsprependedoutput_shape (tuple[int, ...]) – Output shape passed to
qualia_core.learningmodel.pytorch.LearningModel.LearningModeltimesteps (int) – Number of timesteps
neuron (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) – Spiking neuron configuration dict
- Raises:
ValueError – When
neuronisNoneor emptyTypeError – When the value associated to
params.step_modeis not a string
- Return type:
None