qualia_plugin_snn.learningframework.SpikingJellyTimeStepsInData module

Provide the SpikingJelly single-step with timesteps in input data learningframework module.

class qualia_plugin_snn.learningframework.SpikingJellyTimeStepsInData.SpikingJellyTimeStepsInData[source]

Bases: SpikingJelly

SpikingJelly single-step with timesteps in data LearningFramework implementation extending SpikingJelly single-step.

class TrainerModule[source]

Bases: TrainerModule

SpikingJelly single-step with timesteps in data TrainerModule extending SpikingJelly single-step TrainerModule.

apply_dataaugmentation(batch: tuple[Tensor, Tensor], dataaugmentation: DataAugmentationPyTorch) tuple[Tensor, Tensor][source]

Call a dataaugmentation module on the current batch.

If the dataaugmentation module is not a qualia_plugin_snn.dataaugmentation.pytorch.DataAugmentationPyTorchTimeStepsInData, or if qualia_plugin_snn.dataaugmentation.pytorch.DataAugmentationPyTorchTimeStepsInData.collapse_timesteps is True, then the timestep dimension is automatically merged with the batch dimension in order to support existing non-timestep-aware Qualia-Core dataaugmentation modules transparently.

Parameters:
  • batch (tuple[Tensor, Tensor]) – Current batch of data and targets

  • dataaugmentation (DataAugmentationPyTorch) – dataaugmentation module to apply

Returns:

Augmented batch

Return type:

tuple[Tensor, Tensor]

forward(x: Tensor) Tensor[source]

Forward pass for a Spiking Neural Network model with timesteps in input data in single-step mode.

First calls SpikingJelly’s reset on the model to reset neurons potentials. Call qualia_plugin_snn.learningmodel.pytorch.SNN.SNN.forward() for each timestep of the input data. Finally, average the output of the model over the timesteps.

Parameters:

x (Tensor) – Input data with timestep dimension in [N, T, C, S] or [N, T, C, H, W] order

Returns:

Output predictions

Raises:

ValueError – when the input data does not have the correct number of dimenions or the timestep dimension does not match qualia_plugin_snn.learningmodel.pytorch.SNN.SNN.timesteps

Return type:

Tensor

static channels_last_to_channels_first(x: ndarray[Any, Any]) ndarray[Any, Any][source]

Channels last to channels first conversion with consideration of timestep dimension.

For 2D data with timestep: [N, T, H, W, C] → [N, T, C, H, W]

For 1D data with timestep: [N, T, S, C] → [N, T, C, S]

Parameters:

x (ndarray[Any, Any]) – NumPy array in channels last format

Returns:

NumPy array reordered to channels first format

Return type:

ndarray[Any, Any]

static channels_first_to_channels_last(x: ndarray[Any, Any]) ndarray[Any, Any][source]

Channels first to channels last conversion with consideration of timestep dimension.

For 2D data with timestep: [N, T, C, H, W] → [N, T, H, W, C]

For 1D data with timestep: [N, T, C, S] → [N, T, S, C]

Parameters:

x (ndarray[Any, Any]) – NumPy array in channels first format

Returns:

NumPy array reordered to channels last format

Return type:

ndarray[Any, Any]

class DatasetFromArray[source]

Bases: DatasetFromArray

Override qualia_core.learningframework.PyTorch.PyTorch.DatasetFromArray to reorder data with timestep dim.

__init__(dataset: RawData) None[source]

Load a Qualia dataset partition as a PyTorch dataset.

Reorders the input data from channels_last to channels_first, with consideration of timestep dimension.

Parameters:

dataset (RawData) – Dataset partition to load

Return type:

None