Akida runtime API

akida.__version__

Returns the current version of the akida module.

Model

class akida.Model

An Akida neural Model, represented as a hierarchy of layers.

The Model class is the main interface to Akida and allows:

  • to create an empty Model to which you can add layers programmatically using the sequential API,

  • to reload a full Model from a serialized file or a memory buffer,

  • to create a new Model from a list of layers taken from an existing Model.

It provides methods to instantiate, train, test and save models.

The Model input and output shapes have 4 dimensions, the first one being the number of samples.

The Model accepts only uint8 tensors as inputs, whose values are encoded using either 1, 2, 4 or 8-bit precision (i.e. whose max value is 1, 3, 15 or 255 respectively).

If the inputs are 8-bit, then the first layer of the Model must be a convolutional layer with either 1 or 3 input channels.

The Model output is an int8 our uint8 numpy array if activations are enabled for the last layer, otherwise it is an int32 numpy array.

Parameters
  • filename (str, optional) – path to the serialized Model. If None, an empty sequential model will be created, or filled with the layers in the layers parameter.

  • layers (list, optional) – list of layers that will be copied to the new model. If the list does not start with an input layer, it will be added automatically.

Methods:

add(self, layer, inbound_layers)

Add a layer to the current model.

add_classes(self, num_add_classes)

Adds classes to the last layer of the model.

compile(self, optimizer)

Select and prepare the optimizer for learning of the last layer.

evaluate(self, inputs, labels[, ...])

Returns the model class accuracy.

fit(*args, **kwargs)

Overloaded function.

forward(self, inputs[, batch_size])

Forwards a set of inputs through the model.

from_dict(model_dict)

Instantiate a Model from a dict representation

from_json(model_str)

Instantiate a Model from a JSON representation

get_layer(*args, **kwargs)

Overloaded function.

get_layer_count(self)

The number of layers.

map(self, device, hw_only)

Map the model to a Device using a target backend.

pop_layer(self)

Remove the last layer of the current model.

predict(self, inputs[, batch_size])

Predicts a set of inputs through the model.

predict_classes(inputs[, num_classes, ...])

Predicts the class labels for the specified inputs.

save(self, arg0)

Saves all the model configuration (all layers and weights) to a file on disk.

summary()

Prints a string summary of the model.

to_buffer(self)

Serializes all the model configuration (all layers and weights) to a bytes buffer.

to_dict()

Provide a dict representation of the Model

to_json()

Provide a JSON representation of the Model

Attributes:

input_shape

The model input dimensions.

layers

Get a list of layers in current model.

learning

The learning parameters set.

metrics

The model metrics.

output_shape

The model output dimensions.

power_events

Copy of power events logged after inference

sequences

The list of layer sequences in the Model

statistics

Get statistics by sequence for this model.

add(self: akida.core.Model, layer: akida::Layer, inbound_layers: List[akida::Layer] = []) None

Add a layer to the current model.

A list of inbound layers can optionally be specified. These layers must already be included in the model. if no inbound layer is specified, and the layer is not the first layer in the model, the last included layer will be used as inbound layer.

Parameters
  • layer (one of the available layers) – layer instance to be added to the model

  • inbound_layers (a list of Layer) – an optional list of inbound layers

add_classes(self: akida.core.Model, num_add_classes: int) None

Adds classes to the last layer of the model.

A model with a compiled last layer is ready to learn using the Akida built-in learning algorithm. This function allows to add new classes (i.e. new neurons) to the last layer, keeping the previously learned neurons.

Parameters

num_add_classes (int) – number of classes to add to the last layer

Raises

RuntimeError – if the last layer is not compiled

compile(self: akida.core.Model, optimizer: akida::LearningParams) None

Select and prepare the optimizer for learning of the last layer.

Parameters

optimizer (akida.LearningParams) – the optimizer used for learning

evaluate(self: akida.core.Model, inputs: numpy.ndarray[numpy.uint8], labels: numpy.ndarray[numpy.int32], num_classes: int = 0, batch_size: int = 0) float

Returns the model class accuracy.

Forwards an input tensor through the model and compute accuracy based on labels. If the number of output neurons is greater than the number of classes, the neurons are automatically assigned to a class by dividing their id by the number of classes.

Note that the evaluation is based on the activation values of the last layer: for most use cases, you may want to disable activations for that layer (ie setting activation=False) to get a better accuracy.

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • labels (numpy.ndarray) – a (n) tensor of labels for the inputs

  • num_classes (int, optional) – optional parameter (defaults to the number of neurons in the last layer).

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time

Returns

the accuracy of the model to predict the labels based on the inputs.

Return type

float

fit(*args, **kwargs)

Overloaded function.

  1. fit(self: akida.core.Model, inputs: numpy.ndarray, input_labels: float, batch_size: int = 0) -> numpy.ndarray

Trains a set of images or events through the model.

Trains the model with the specified input tensor (numpy array).

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • input_labels (float, optional) – input label

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time.

Returns

a (n, out_x, out_y, out_c) int8 or uint8 or int32 tensor.

Return type

numpy.ndarray

Raises
  • TypeError – if the input is not a numpy.ndarray.

  • ValueError – if the input doesn’t match the required shape, format, etc.

  1. fit(self: akida.core.Model, inputs: numpy.ndarray, input_labels: numpy.ndarray, batch_size: int = 0) -> numpy.ndarray

Trains a set of images or events through the model.

Trains the model with the specified input tensor (numpy array).

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • input_labels (numpy.ndarray, optional) – input labels. Must have one label per input, or a single label for all inputs. If a label exceeds the defined number of classes, the input will be discarded. (Default value = None).

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time.

Returns

a (n, out_x, out_y, out_c) int8 or int8 or int32 tensor.

Return type

numpy.ndarray

Raises
  • TypeError – if the input is not a numpy.ndarray.

  • ValueError – if the input doesn’t match the required shape, format, etc.

  1. fit(self: akida.core.Model, inputs: numpy.ndarray, input_labels: list = [], batch_size: int = 0) -> numpy.ndarray

Trains a set of images or events through the model.

Trains the model with the specified input tensor (numpy array).

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • input_labels (list(int), optional) – input labels. Must have one label per input, or a single label for all inputs. If a label exceeds the defined number of classes, the input will be discarded. (Default value = None).

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time.

Returns

a (n, out_x, out_y, out_c) int8 or int8 or int32 tensor.

Return type

numpy.ndarray

Raises
  • TypeError – if the input is not a numpy.ndarray.

  • ValueError – if the input doesn’t match the required shape, format, etc.

forward(self: akida.core.Model, inputs: numpy.ndarray, batch_size: int = 0) numpy.ndarray

Forwards a set of inputs through the model.

Forwards an input tensor through the model and returns an output tensor.

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time

Returns

a (n, out_x, out_y, out_c) uint8, int8 or int32 tensor.

Return type

numpy.ndarray

Raises
  • TypeError – if the input is not a numpy.ndarray.

  • ValueError – if the inputs doesn’t match the required shape, format, etc.

static from_dict(model_dict)

Instantiate a Model from a dict representation

Parameters

model_dict (dict) – a Model dictionary.

Returns

a Model.

Return type

Model

static from_json(model_str)

Instantiate a Model from a JSON representation

Parameters

model_str (str) – a JSON-formatted string corresponding to a Model.

Returns

a Model.

Return type

Model

get_layer(*args, **kwargs)

Overloaded function.

  1. get_layer(self: akida.core.Model, layer_name: str) -> akida::Layer

    Get a reference to a specific layer.

    This method allows a deeper introspection of the model by providing access to the underlying layers.

    param layer_name

    name of the layer to retrieve

    type layer_name

    str

    return

    a Layer

  2. get_layer(self: akida.core.Model, layer_index: int) -> akida::Layer

    Get a reference to a specific layer.

    This method allows a deeper introspection of the model by providing access to the underlying layers.

    param layer_index

    index of the layer to retrieve

    type layer_index

    int

    return

    a Layer

get_layer_count(self: akida.core.Model) int

The number of layers.

property input_shape

The model input dimensions.

property layers

Get a list of layers in current model.

property learning

The learning parameters set.

map(self: akida.core.Model, device: akida::Device, hw_only: bool = False) None

Map the model to a Device using a target backend.

This method tries to map a Model to the specified Device, implicitly identifying one or more layer sequences that are mapped individually on the Device Mesh.

An optional hw_only parameter can be specified to force the mapping strategy to use only one hardware sequence, thus reducing software intervention on the inference.

Parameters
  • device (Device) – the target Device or None

  • hw_only (bool) – when true, the model should be mapped in one sequence

property metrics

The model metrics.

property output_shape

The model output dimensions.

pop_layer(self: akida.core.Model) None

Remove the last layer of the current model.

property power_events

Copy of power events logged after inference

predict(self: akida.core.Model, inputs: numpy.ndarray, batch_size: int = 0) numpy.ndarray

Predicts a set of inputs through the model.

Forwards an input tensor through the model and returns a float array.

It applies ONLY to models without an activation on the last layer. The output values are obtained from the model discrete potentials by applying a shift and a scale.

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time

Returns

a (n, w, h, c) float tensor.

Return type

numpy.ndarray

Raises
  • TypeError – if the input is not a numpy.ndarray.

  • RuntimeError – if the model last layer has an activation.

  • ValueError – if the input doesn’t match the required shape, format, or if the model only has an InputData layer.

predict_classes(inputs, num_classes=0, batch_size=0)

Predicts the class labels for the specified inputs.

Parameters
  • inputs (numpy.ndarray) – a (n, x, y, c) uint8 tensor

  • num_classes (int, optional) – the number of output classes

  • batch_size (int, optional) – maximum number of inputs that should be processed at a time

Returns

an array of class labels

Return type

numpy.ndarray

save(self: akida.core.Model, arg0: str) None

Saves all the model configuration (all layers and weights) to a file on disk.

Parameters

model_file (str) – full path of the serialized model (.fbz file).

property sequences

The list of layer sequences in the Model

property statistics

Get statistics by sequence for this model.

Returns

a dictionary of SequenceStatistics indexed by name.

summary()

Prints a string summary of the model.

This method prints a summary of the model with details for every layer, grouped by sequences:

  • name and type in the first column

  • output shape

  • kernel shape

If there is any layer with unsupervised learning enabled, it will list them, with these details:

  • name of layer

  • number of incoming connections

  • number of weights per neuron

to_buffer(self: akida.core.Model) bytes

Serializes all the model configuration (all layers and weights) to a bytes buffer.

to_dict()

Provide a dict representation of the Model

Returns

a Model dictionary.

Return type

dict

to_json()

Provide a JSON representation of the Model

Returns

a JSON-formatted string corresponding to a Model.

Return type

str

Layer

Layer

class akida.Layer

Methods:

get_learning_histogram()

Returns an histogram of learning percentages.

get_variable(name)

Get the value of a layer variable.

get_variable_names()

Get the list of variable names for this layer.

set_variable(name, values)

Set the value of a layer variable.

to_dict()

Provide a dict representation of the Layer

Attributes:

inbounds

The layer inbound layers.

input_bits

The layer input bits.

input_dims

The layer input dimensions.

input_signed

Whether input is signed or not.

mapping

The layer hardware mapping.

name

The layer name.

output_dims

The layer output dimensions.

output_signed

Whether output is signed or not.

parameters

The layer parameters set.

variables

The layer trainable variables.

get_learning_histogram()

Returns an histogram of learning percentages.

Returns a list of learning percentages and the associated number of neurons.

Returns

a (n,2) numpy.ndarray containing the learning percentages and the number of neurons.

Return type

numpy.ndarray

get_variable(name)

Get the value of a layer variable.

Layer variables are named entities representing the weights or thresholds used during inference:

  • Weights variables are typically integer arrays of shape: (x, y, features/channels, num_neurons) row-major (‘C’).

  • Threshold variables are typically integer or float arrays of shape: (num_neurons).

Parameters

name (str) – the variable name.

Returns

an array containing the variable.

Return type

numpy.ndarray

get_variable_names()

Get the list of variable names for this layer.

Returns

a list of variable names.

property inbounds

The layer inbound layers.

property input_bits

The layer input bits.

property input_dims

The layer input dimensions.

property input_signed

Whether input is signed or not.

property mapping

The layer hardware mapping.

property name

The layer name.

property output_dims

The layer output dimensions.

property output_signed

Whether output is signed or not.

property parameters

The layer parameters set.

set_variable(name, values)

Set the value of a layer variable.

Layer variables are named entities representing the weights or thresholds used during inference:

  • Weights variables are typically integer arrays of shape:

    (num_neurons, features/channels, y, x) col-major ordered (‘F’)

or equivalently:

(x, y, features/channels, num_neurons) row-major (‘C’).

  • Threshold variables are typically integer or float arrays of shape: (num_neurons).

Parameters
  • name (str) – the variable name.

  • values (numpy.ndarray) – a numpy.ndarray containing the variable values.

to_dict()

Provide a dict representation of the Layer

Returns

a Layer dictionary.

Return type

dict

property variables

The layer trainable variables.

Mapping

class akida.Layer.Mapping

Attributes:

nps

a list of NP.Mapping objects.

property nps

a list of NP.Mapping objects.

InputData

class akida.InputData(input_shape, input_bits=4, input_signed=False, name='')[source]

This layer is used to specify the input dimensions of a low bitwidth Model.

Models accepting 8-bit images must start with an InputConvolutional layer, but layers accepting integer inputs with a lower bitwidth (i.e. not images) and layers accepting signed inputs must start instead with an InputData layer. This layer does not modify its inputs: it just allows to define the Model input dimensions and bitwidth.

Parameters
  • input_shape (tuple) – the 3D input shape.

  • input_bits (int, optional) – input bitwidth. Defaults to 4.

  • input_signed (bool, optional) – whether the input is signed or not. Defaults to False.

  • name (str, optional) – name of the layer. Defaults to empty string.

InputConvolutional

class akida.InputConvolutional(input_shape, kernel_size, filters, name='', padding=<Padding.Same: 1>, kernel_stride=(1, 1), weights_bits=1, pool_size=(-1, -1), pool_type=<PoolType.NoPooling: 0>, pool_stride=(-1, -1), activation=True, act_bits=1, padding_value=0)[source]

The InputConvolutional layer is an image-specific input layer.

The InputConvolutional layer accepts images in 8-bit pixels, either grayscale or RGB. It is the only akida layer with 8-bit weights. It applies a ‘convolution’ (actually a cross-correlation) optionally followed by a pooling operation to the input images. It can optionally apply a step-wise ReLU activation to its outputs. The layer expects a 4D tensor whose first dimension is the sample index representing the 8-bit images as input. It returns a 4D tensor whose first dimension is the sample index and the last dimension is the number of convolution filters. The order of the input spatial dimensions is preserved, but their value may change according to the convolution and pooling parameters.

Parameters
  • input_shape (tuple) – the 3D input shape.

  • kernel_size (list) – list of 2 integer representing the spatial dimensions of the convolutional kernel.

  • filters (int) – number of filters.

  • name (str, optional) – name of the layer. Defaults to empty string.

  • padding (Padding, optional) – type of convolution. Defaults to Padding.Same.

  • kernel_stride (tuple, optional) – tuple of integer representing the convolution stride (X, Y). Defaults to (1, 1).

  • weights_bits (int, optional) – number of bits used to quantize weights. Defaults to 1.

  • pool_size (list, optional) – list of 2 integers, representing the window size over which to take the maximum or the average (depending on pool_type parameter). Defaults to (-1, -1).

  • pool_type (PoolType, optional) – pooling type (NoPooling, Max or Average). Defaults to PoolType.NoPooling.

  • pool_stride (list, optional) – list of 2 integers representing the stride dimensions. Defaults to (-1, -1)

  • activation (bool, optional) – enable or disable activation function. Defaults to True.

  • act_bits (int, optional) – number of bits used to quantize the neuron response. Defaults to 1.

  • padding_value (int, optional) – value used when padding. Defaults to 0.

FullyConnected

class akida.FullyConnected(units, name='', weights_bits=1, activation=True, act_bits=1)[source]

This represents a Dense or Linear neural layer.

The FullyConnected layer accepts 1-bit, 2-bit or 4-bit input tensors. The FullyConnected can be configured with 1-bit, 2-bit or 4-bit weights. It multiplies the inputs by its internal unit weights, returning a 4D tensor of values whose first dimension is the number of samples and the last dimension represents the number of units. It can optionally apply a step-wise ReLU activation to its outputs.

Parameters
  • units (int) – number of units.

  • name (str, optional) – name of the layer. Defaults to empty string.

  • weights_bits (int, optional) – number of bits used to quantize weights. Defaults to 1.

  • activation (bool, optional) – enable or disable activation function. Defaults to True.

  • act_bits (int, optional) – number of bits used to quantize the neuron response. Defaults to 1.

Convolutional

class akida.Convolutional(kernel_size, filters, name='', padding=<Padding.Same: 1>, kernel_stride=(1, 1), weights_bits=1, pool_size=(-1, -1), pool_type=<PoolType.NoPooling: 0>, pool_stride=(-1, -1), activation=True, act_bits=1)[source]

This represents a standard Convolutional layer.

The Convolutional layer accepts 1-bit, 2-bit or 4-bit 3D input tensors with an arbitrary number of channels. The Convolutional layer can be configured with 1-bit, 2-bit or 4-bit weights. It applies a convolution (not a cross-correlation) optionally followed by a pooling operation to the input tensors. It can optionally apply a step-wise ReLU activation to its outputs. The layer expects a 4D tensor whose first dimension is the sample index as input. It returns a 4D tensor whose first dimension is the sample index and the last dimension is the number of convolution filters. The order of the input spatial dimensions is preserved, but their value may change according to the convolution and pooling parameters.

Parameters
  • kernel_size (list) – list of 2 integer representing the spatial dimensions of the convolutional kernel.

  • filters (int) – number of filters.

  • name (str, optional) – name of the layer. Defaults to empty string

  • padding (Padding, optional) – type of convolution. Defaults to Padding.Same.

  • kernel_stride (list, optional) – list of 2 integer representing the convolution stride (X, Y). Defaults to (1, 1).

  • weights_bits (int, optional) – number of bits used to quantize weights. Defaults to 1.

  • pool_size (list, optional) – list of 2 integers, representing the window size over which to take the maximum or the average (depending on pool_type parameter). Defaults to (-1, -1).

  • pool_type (PoolType, optional) – pooling type (NoPooling, Max or Average). Defaults to Pooling.NoPooling.

  • pool_stride (list, optional) – list of 2 integers representing the stride dimensions. Defaults to (-1, -1).

  • activation (bool, optional) – enable or disable activation function. Defaults to True.

  • act_bits (int, optional) – number of bits used to quantize the neuron response. Defaults to 1.

SeparableConvolutional

class akida.SeparableConvolutional(kernel_size, filters, name='', padding=<Padding.Same: 1>, kernel_stride=(1, 1), weights_bits=2, pool_size=(-1, -1), pool_type=<PoolType.NoPooling: 0>, pool_stride=(-1, -1), activation=True, act_bits=1)[source]

This represents a separable convolution layer.

This layer accepts 1-bit, 2-bit or 4-bit 3D input tensors with an arbitrary number of channels. It can be configured with 1-bit, 2-bit or 4-bit weights. Separable convolutions consist in first performing a depthwise spatial convolution (which acts on each input channel separately) followed by a pointwise convolution which mixes together the resulting output channels. Note: this layer applies a real convolution, and not a cross-correlation. It can optionally apply a step-wise ReLU activation to its outputs. The layer expects a 4D tensor whose first dimension is the sample index as input. It returns a 4D tensor whose first dimension is the sample index and the last dimension is the number of convolution filters. The order of the input spatial dimensions is preserved, but their value may change according to the convolution and pooling parameters.

Parameters
  • kernel_size (list) – list of 2 integer representing the spatial dimensions of the convolutional kernel.

  • filters (int) – number of pointwise filters.

  • name (str, optional) – name of the layer. Defaults to empty string.

  • padding (Padding, optional) – type of convolution. Defaults to Padding.Same.

  • kernel_stride (list, optional) – list of 2 integer representing the convolution stride (X, Y). Defaults to (1, 1).

  • weights_bits (int, optional) – number of bits used to quantize weights. Defaults to 2.

  • pool_size (list, optional) – list of 2 integers, representing the window size over which to take the maximum or the average (depending on pool_type parameter). Defaults to (-1, -1).

  • pool_type (PoolType, optional) – pooling type (NoPooling, Max or Average). Defaults to PoolType.NoPooling.

  • pool_stride (list, optional) – list of 2 integers representing the stride dimensions. Defaults to (-1, -1).

  • activation (bool, optional) – enable or disable activation function. Defaults to True.

  • act_bits (int, optional) – number of bits used to quantize the neuron response. Defaults to 1.

Layer parameters

LayerType

class akida.LayerType

The layer type

Members:

Unknown

InputData

InputConvolutional

FullyConnected

Convolutional

SeparableConvolutional

Add

Dense2D

Shiftmax

Attention

Stem

MadNorm

Concatenate

Padding

class akida.Padding

Sets the effective padding of the input for convolution, thereby determining the output dimensions. Naming conventions are the same as Keras/Tensorflow.

Members:

Valid : No padding

Same : Padded so that output size is input size divided by the stride

PoolType

class akida.PoolType

The pooling type

Members:

NoPooling : No pooling applied

Max : Maximum pixel value is selected

Average : Average pixel value is selected

Optimizers

class akida.core.Optimizer

Optimizer generic parameters

Methods:

get(self, key)

Retrieve a value from the LearningParams object.

get(self: akida.core.Optimizer, key: str) float

Retrieve a value from the LearningParams object.

Parameters

key (str) – key of the value.

Returns

value associated to the key.

Return type

int

Raises

ValueError – if the value is not present in the LearningParams object.

class akida.AkidaUnsupervised(num_weights: int, num_classes: int = 1, initial_plasticity: float = 1.0, learning_competition: float = 0.0, min_plasticity: float = 0.10000000149011612, plasticity_decay: float = 0.25) akida.core.Optimizer

Prepare the Akida Unsupervised optimizer for learning of the last layer.

Parameters
  • num_weights (int) – number of connections for each neuron.

  • num_classes (int, optional) – number of classes when running in a ‘labeled mode’.

  • initial_plasticity (float, optional) – defines how easily the weights will change when learning occurs.

  • learning_competition (float, optional) – controls competition between neurons.

  • min_plasticity (float, optional) – defines the minimum level to which plasticity will decay.

  • plasticity_decay (float, optional) – defines the decay of plasticity with each learning step.

  • optimizer (akida.LearningParams) – the optimizer used for learning

Sequence

Sequence

class akida.Sequence

Represents a sequence of layers.

Sequences can be mapped in Software or on a Device.

Attributes:

backend

The backend type for this Sequence.

name

The name of the sequence

passes

Get the list of passes in this sequence.

program

Get the hardware program for this sequence.

property backend

The backend type for this Sequence.

property name

The name of the sequence

property passes

Get the list of passes in this sequence.

property program

Get the hardware program for this sequence.

Returns None if the Sequence is not compatible with the selected Device.

Returns

a bytes buffer or None

BackendType

class akida.BackendType

Members:

Software

Hardware

Hybrid

Pass

class akida.Pass

Represents a subset of the Sequence.

Hardware Sequences can typically be split into multiple passes on devices that support hardware partial reconfiguration feature, reducing the intervention of the software during inference.

Attributes:

layers

Get the list of layers in this pass.

property layers

Get the list of layers in this pass.

Device

Device

class akida.Device

Attributes:

desc

Returns the Device description

mesh

The device Mesh layout

version

The device hardware version.

property desc

Returns the Device description

Returns

a string describing the Device

property mesh

The device Mesh layout

property version

The device hardware version.

akida.devices() List[akida.core.HardwareDevice]

Returns the full list of available hardware devices

Returns

list of Device

akida.AKD1000()[source]

Returns a virtual device for an AKD1000 NSoC.

This function returns a virtual device for the Brainchip’s AKD1000 NSoC.

Returns

a virtual device.

Return type

Device

akida.TwoNodesIP()[source]

Returns a virtual device for a two nodes Akida IP.

Returns

a virtual device.

Return type

Device

HwVersion

class akida.HwVersion

Attributes:

major_rev

The hardware major revision

minor_rev

The hardware minor revision

product_id

The hardware product identifier

vendor_id

The hardware vendor identifier

property major_rev

The hardware major revision

property minor_rev

The hardware minor revision

property product_id

The hardware product identifier

property vendor_id

The hardware vendor identifier

HWDevice

HWDevice

class akida.HardwareDevice

Methods:

fit(*args, **kwargs)

Overloaded function.

forward(self, arg0)

Processes inputs on a programmed device.

predict(self, arg0)

Processes inputs on a programmed device, returns a float array.

reset_top_memory(self)

Reset the device memory informations

unprogram(self)

Clear current program from hardware device, restoring its initial state

Attributes:

inference_power_events

Copy of power events logged after inference

learn_enabled

Property that enables/disables learning on current program (if possible).

learn_mem

Property that retrieves learning layer's memory or updates a device using a serialized learning layer memory buffer.

memory

The device memory usage and top usage (in bytes)

metrics

The metrics from this device

program

Property that retrieves current program or programs a device using a serialized program bytes object.

soc

The SocDriver interface used by the device, or None if the device is not a SoC

fit(*args, **kwargs)

Overloaded function.

  1. fit(self: akida.core.HardwareDevice, inputs: numpy.ndarray[numpy.uint8], input_labels: float) -> numpy.ndarray

Learn from inputs on a programmed device.

  1. fit(self: akida.core.HardwareDevice, inputs: numpy.ndarray[numpy.uint8], input_labels: numpy.ndarray) -> numpy.ndarray

Learn from inputs on a programmed device.

  1. fit(self: akida.core.HardwareDevice, inputs: numpy.ndarray[numpy.uint8], input_labels: list = []) -> numpy.ndarray

Learn from inputs on a programmed device.

forward(self: akida.core.HardwareDevice, arg0: numpy.ndarray[numpy.uint8]) numpy.ndarray

Processes inputs on a programmed device.

Parameters

inputsnumpy.ndarray with shape matching current program

:return numpy.ndarray with outputs from the device

property inference_power_events

Copy of power events logged after inference

property learn_enabled

Property that enables/disables learning on current program (if possible).

property learn_mem

Property that retrieves learning layer’s memory or updates a device using a serialized learning layer memory buffer.

property memory

The device memory usage and top usage (in bytes)

property metrics

The metrics from this device

predict(self: akida.core.HardwareDevice, arg0: numpy.ndarray[numpy.uint8]) numpy.ndarray

Processes inputs on a programmed device, returns a float array.

Parameters

inputsnumpy.ndarray with shape matching current program

:return numpy.ndarray with float outputs from the device

property program

Property that retrieves current program or programs a device using a serialized program bytes object.

reset_top_memory(self: akida.core.HardwareDevice) None

Reset the device memory informations

property soc

The SocDriver interface used by the device, or None if the device is not a SoC

unprogram(self: akida.core.HardwareDevice) None

Clear current program from hardware device, restoring its initial state

SocDriver

class akida.core.SocDriver

Attributes:

clock_mode

Clock mode of the NSoC.

power_measurement_enabled

Power measurement is off by default.

power_meter

Power meter associated to the SoC.

property clock_mode

Clock mode of the NSoC.

property power_measurement_enabled

Power measurement is off by default. Toggle it on to get power information in the statistics or when calling PowerMeter.events().

property power_meter

Power meter associated to the SoC.

ClockMode

class akida.core.soc.ClockMode

Clock mode configuration

Members:

Performance

Economy

LowPower

PowerMeter

class akida.PowerMeter

Gives access to power measurements.

When power measurements are enabled for a specific device, this object stores them as a list of PowerEvent objects. The events list cannot exceed a predefined size: when it is full, older events are replaced by newer events.

Methods:

events(self)

Retrieve all pending events

Attributes:

floor

Get the floor power

events(self: akida.core.PowerMeter) List[akida.core.PowerEvent]

Retrieve all pending events

property floor

Get the floor power

class akida.PowerEvent

A timestamped power measurement.

Each PowerEvent contains: - a voltage value in µV (microvolt), - a current value in mA (milliampere), - the corresponding power value in mW (milliwatt).

Attributes:

current

Current value in mA

power

Power value in mW

ts

Timestamp of the event

voltage

Voltage value in µV

property current

Current value in mA

property power

Power value in mW

property ts

Timestamp of the event

property voltage

Voltage value in µV

NP

class akida.NP.Mesh

Attributes:

dma_conf

DMA configuration endpoint

dma_event

DMA event endpoint

nps

Neural processors

property dma_conf

DMA configuration endpoint

property dma_event

DMA event endpoint

property nps

Neural processors

class akida.NP.Info

Attributes:

ident

NP identifier

types

NP supported types

property ident

NP identifier

property types

NP supported types

class akida.NP.Ident

Attributes:

col

NP column number

id

NP id

row

NP row number

property col

NP column number

property id

NP id

property row

NP row number

class akida.NP.Type

Members:

HRC : High Resolution Convolution

CNP1 : Convolutional Neural Processor Type 1

CNP2 : Convolutional Neural Processor Type 2

FNP2 : FullyConnected Neural Processor (external memory)

FNP3 : FullyConnected Neural Processor (internal memory)

class akida.NP.Mapping

The mapping of a subset of a Layer on a Neural Processor”

Attributes:

filters

Number of filters processed by the Neural Processor

ident

Neural Processor identifier

single_buffer

Neural Processor uses a single or dual input buffer

type

Neural Processor type

property filters

Number of filters processed by the Neural Processor

property ident

Neural Processor identifier

property single_buffer

Neural Processor uses a single or dual input buffer

property type

Neural Processor type

Tools

Sparsity

akida.evaluate_sparsity(model, inputs)[source]

Evaluate the sparsity of a Model on a set of inputs

Parameters
  • model (Model) – the model to evaluate

  • inputs (numpy.ndarray) – a numpy.ndarray

Returns

a dictionary of float sparsity values indexed by layers

Compatibility

akida.compatibility.create_from_model(model)[source]

Tries to create a HW compatible model from an incompatible one

Tries to create a HW compatible model from an incompatible one, using SW workarounds for known limitations. It returns a converted model that is not guaranteed to be HW compatible, depending if workaround have been found.

Parameters

model (Model) – a Model object to convert

Returns

a new Model with no guarantee that it is HW compatible.

Return type

Model

akida.compatibility.transpose(model)[source]

Transpose the weights of a legacy (pre-2.1.4) model

This only applies to:

  • models converted using cnn2snn,

  • models instantiated using the Sequential API starting with an InputConvolutional.

Models instantiated using the Sequential API starting with an InputData don’t need to have their weights transposed.

Parameters

model (Model) – a Model object whose weights need transposing

Returns

a new Model with transposed weights

Return type

Model

Miscellaneous:

statistics

Get statistics by sequence for this model.

akida.statistics

Get statistics by sequence for this model.

Returns

a dictionary of SequenceStatistics indexed by name.