sinabs.from_torch
This module provides support for importing models into the sinabs from pytorch. It currently only has limited capability.
- class SpkConverter(input_shape=None, threshold=1.0, threshold_low=- 1.0, membrane_subtract=None, bias_rescaling=1.0, batch_size=None, synops=False, add_spiking_output=False)
Converts a Torch model and returns a Sinabs network object. The modules in the model are analyzed, and a copy is returned, with all ReLUs, LeakyReLUs and NeuromorphicReLUs turned into SpikingLayers.
- Parameters
input_shape – If provided, the layer dimensions are computed. Otherwise they will computed at the first forward pass.
threshold – The membrane potential threshold for spiking in convolutional and linear layers (same for all layers).
threshold_low – The lower bound of the potential in convolutional and linear layers (same for all layers).
membrane_subtract – Value subtracted from the potential upon spiking for convolutional and linear layers (same for all layers).
bias_rescaling – Biases are divided by this value.
synops – If True (default: False), register hooks for counting synaptic operations during foward passes.
add_spiking_output – If True (default: False), add a spiking layer to the end of a sequential model if not present.
- convert(model)
Converts the Torch model and returns a Sinabs network object.
- Returns network
the Sinabs network object created by conversion.
- from_model(model, input_shape=None, threshold=1.0, threshold_low=- 1.0, membrane_subtract=None, bias_rescaling=1.0, batch_size=None, synops=False, add_spiking_output=False)
Converts a Torch model and returns a Sinabs network object. The modules in the model are analyzed, and a copy is returned, with all ReLUs, LeakyReLUs and NeuromorphicReLUs turned into SpikingLayers.
- Parameters
model – a Torch model
input_shape – If provided, the layer dimensions are computed. Otherwise they will be computed at the first forward pass.
threshold – The membrane potential threshold for spiking in convolutional and linear layers (same for all layers).
threshold_low – The lower bound of the potential in convolutional and linear layers (same for all layers).
membrane_subtract – Value subtracted from the potential upon spiking for convolutional and linear layers (same for all layers).
bias_rescaling – Biases are divided by this value.
synops – If True (default: False), register hooks for counting synaptic operations during forward passes.
add_spiking_output – If True (default: False), add a spiking layer to the end of a sequential model if not present.