dynapcnn_layer#

This module defines the DynapcnnLayer class that is used to reproduce the behavior of a layer on the dynapcnn chip.

class sinabs.backend.dynapcnn.dynapcnn_layer.DynapcnnLayer(conv: Conv2d, spk: IAFSqueeze, in_shape: Tuple[int, int, int], pool: List[int], discretize: bool = True, rescale_weights: int = 1)[source]#

Create a DynapcnnLayer object representing a layer on DynapCNN or Speck.

Requires a convolutional layer, a sinabs spiking layer and a list of pooling values. The layers are used in the order conv -> spike -> pool.

Parameters:
  • conv (Conv2d)

  • spk (IAFSqueeze)

  • in_shape (Tuple[int, int, int])

  • pool (List[int])

  • discretize (bool)

  • rescale_weights (int)

conv#

torch.nn.Conv2d or torch.nn.Linear. Convolutional or linear layer. Linear will be converted to convolutional.

spk#

Sinabs IAF layer.

Type:

sinabs.layers.IAFSqueeze

in_shape#

The input shape, needed to create dynapcnn configs if the network does not contain an input layer. Convention: (features, height, width).

Type:

tuple of int

pool#

Each integer entry represents an output (destination on chip) and whether pooling should be applied (values > 1) or not (values equal to 1). The number of entries determines the number of tensors the layer’s forward method returns.

Type:

List of integers

discretize#

Whether to discretize parameters.

Type:

bool

rescale_weights#

Layer weights will be multiplied by this value.

Type:

int

forward(x) List[Tensor][source]#

Torch forward pass.

Return type:

List[Tensor]

get_neuron_shape() Tuple[int, int, int][source]#

Return the output shape of the neuron layer.

Returns:

formatted as (features, height, width).

Return type:

conv_out_shape (tuple)

get_output_shape() List[Tuple[int, int, int]][source]#

Return the output shapes of the layer, including pooling.

Returns:

One entry per destination, each formatted as (features, height, width).

Return type:

List[Tuple[int, int, int]]

memory_summary()[source]#

Computes the amount of memory required for each of the components. Note that this is not necessarily the same as the number of parameters due to some architecture design constraints.

\[K_{MT} = c \cdot 2^{\lceil \log_2\left(k_xk_y\right) \rceil + \lceil \log_2\left(f\right) \rceil}\]
\[N_{MT} = f \cdot 2^{ \lceil \log_2\left(f_y\right) \rceil + \lceil \log_2\left(f_x\right) \rceil }\]
Returns:

A dictionary with keys kernel, neuron and bias and the corresponding memory sizes

summary() dict[source]#

Returns a summary of the convolution’s/pooling’s kernel sizes and the output shape of the spiking layer.

Return type:

dict

zero_grad(set_to_none: bool = False) None[source]#

Call zero_grad method of spiking layer

Parameters:

set_to_none (bool)

Return type:

None

sinabs.backend.dynapcnn.dynapcnn_layer.convert_linear_to_conv(lin: Linear, input_shape: Tuple[int, int, int]) Conv2d[source]#

Convert Linear layer to Conv2d.

Parameters:
  • lin (nn.Linear) – linear layer to be converted.

  • input_shape (tuple) – the tensor shape the layer expects.

Returns:

convolutional layer equivalent to lin.

Return type:

Conv2d