CNN2SNN Toolkit API
Akida version
- class cnn2snn.AkidaVersion(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
- v1 =Akida 1.0 SOC and IP
- v2 =Akida 2.0 IP
- cnn2snn.get_akida_version()[source]
Get the target akida version for model conversion.
- Returns:
the target akida version, by default
AkidaVersion.v2
- Return type:
- cnn2snn.set_akida_version(version)[source]
Select the target akida version for model conversion.
- Parameters:
version (AkidaVersion) – the target Akida version.
Conversion
- cnn2snn.convert(model, file_path=None, input_scaling=None)[source]
Converts a Keras or ONNX quantized model to an Akida one.
This method is compatible with model quantized with
cnn2snn.quantize()
andquantizeml.quantize()
. To check the difference between the two conversion processes check the methods _convert_cnn2snn and _convert_quantizeml below.- Parameters:
model (
tf.keras.Model
oronnx.ModelProto
) – a model to convert.file_path (str, optional) – destination for the akida model. (Default value = None)
input_scaling (2 elements tuple, optional) – value of the input scaling. (Default value = None)
- Returns:
an Akida model.
- Return type:
- cnn2snn.check_model_compatibility(model, device=None, input_dtype='uint8')[source]
Checks that a float Keras or ONNX model is Akida compatible.
The process stops on the first incompatibility encountered with an exception. The problematic step (quantization or conversion or mapping) is indicated in the exception message. Then if errors occurs, issues must be fixed iteratively in order to obtain an Akida compatible model. Note that the version context is used to determine compatibility.
- Parameters:
model (
tf.keras.Model
oronnx.ModelProto
) – the model to check.device (
akida.HwDevice
, optional) – the device to map on. If a device is provided, there will be a check that the model can fully run on such device. Defaults to None.input_dtype (np.dtype or str, optional) – expected model input format. If given as a string, should follow numpy string type requirements. Defaults to ‘uint8’.
- Raises:
ValueError – if model type is incompatbile with Akida version context.
ValueError – if device is incompatibile with Akida version context.
Exception – if an incompatibility is encountered on quantization/conversion/mapping steps.