qualia_plugin_snn.learningmodel.pytorch.SCNN module
Contains the template for a convolutional spiking neural network.
- class qualia_plugin_snn.learningmodel.pytorch.SCNN.SCNN[source]
Bases:
SNN
Convolutional spiking neural network template.
Similar to
qualia_core.learningmodel.pytorch.CNN.CNN
but with spiking neuron activation layers (e.g., IF) instead oftorch.nn.ReLU
.Example TOML configuration for a 2D SVGG16 over 4 timesteps with soft-reset multi-step IF based on the SCNN template:
[[model]] name = "VGG16" params.filters = [ 64, 64, 128, 128, 256, 256, 256, 512, 512, 512, 512, 512, 512] params.kernel_sizes = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] params.paddings = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] params.strides = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] params.pool_sizes = [ 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2] params.dropouts = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] params.fc_units = [4096, 4096] params.batch_norm = true params.timesteps = 4 params.dims = 2 params.neuron.kind = 'IFNode' params.neuron.params.v_reset = false # Soft reset params.neuron.params.v_threshold = 1.0 params.neuron.params.detach_reset = true params.neuron.params.step_mode = 'm' # Multi-step mode, make sure to use SpikingJellyMultiStep learningframework params.neuron.params.backend = 'cupy'
- __init__(input_shape: tuple[int, ...], output_shape: tuple[int, ...], filters: list[int], kernel_sizes: list[int], paddings: list[int], strides: list[int], dropouts: float | list[float], pool_sizes: list[int], fc_units: list[int], batch_norm: bool = False, prepool: int | list[int] = 1, postpool: int | list[int] = 1, neuron: RecursiveConfigDict | None = None, timesteps: int = 4, gsp: bool = False, dims: int = 1) None [source]
Construct
SCNN
.- Parameters:
filters (list[int]) – List of
out_channels
for each Conv layer, also defines the number of Conv layerskernel_sizes (list[int]) – List of
kernel_size
for each Conv layer, must of the same size asfilters
paddings (list[int]) – List of
padding
for each Conv layer, must of the same size asfilters
strides (list[int]) – List of
stride
for each Conv layer, must of the same size asfilters
dropouts (float | list[float]) – List of Dropout layer
p
to apply after each Conv or Linear layer, must be of the same size asfilters
+fc_units
, no layer added if element is 0pool_sizes (list[int]) – List of MaxPool layer
kernel_size
to apply after each Conv layer, must be of the same size asfilters
, no layer added if element is 0fc_units (list[int]) – List of
torch.nn.Linear
layerout_features
to add at the end of the network, no layer added if emptybatch_norm (bool) – If
True
, add a BatchNorm layer after each Conv layer, otherwise no layer addedprepool (int | list[int]) – AvgPool layer
kernel_size
to add at the beginning of the network, no layer added if 0postpool (int | list[int]) – AvgPool layer
kernel_size
to add after all Conv layers, no layer added if 0neuron (RecursiveConfigDict | None) – Spiking neuron configuration, see
qualia_plugin_snn.learningmodel.pytorch.SNN.SNN.__init__()
timesteps (int) – Number of timesteps
gsp (bool) – If
True
, a single GlobalSumPool layer is added instead of Linear layersdims (int) – Either 1 or 2 for 1D or 2D convolutional network.
- Return type:
None
- layers: nn.ModuleDict
List of sequential layers of the SCNN model