Global MetaONNX workflow

This example demonstrates how to deploy an ONNX model to Akida hardware using the onnx2akida toolkit. Starting from an ONNX model, we’ll show how to:

  1. Convert and analyze compatibility with Akida hardware

  2. Display compatibility reports

  3. Create hybrid models combining Akida-compatible and ONNX operators

  4. Generate inference models for deployment

We’ll use a MobileNetV4 model exported from HuggingFace as our example, though the workflow applies to any ONNX model.

Overall MetaONNX workflow

Global MetaONNX workflow

1. Export model to ONNX format

1.1. Export MobileNetV4 from HuggingFace

We’ll export a MobileNetV4 model from HuggingFace using the Optimum library. This demonstrates the typical workflow of obtaining an ONNX model for analysis.

You can also export models from other frameworks:

import os

from optimum.exporters.onnx import main_export

model_dir = "mbv4"
main_export("timm/mobilenetv4_conv_small.e2400_r224_in1k", output=model_dir)
print(f"Model exported to {model_dir}/model.onnx")
Weight deduplication check in the ONNX export requires accelerate. Please install accelerate to run it.
Model exported to mbv4/model.onnx

1.2. Load the ONNX model

Load the exported ONNX model for analysis.

import onnx

model_path = os.path.join(model_dir, "model.onnx")
model = onnx.load(model_path)
print(f"\nLoaded ONNX model from {model_path}")
print(f"Model has {len(model.graph.node)} nodes.")
Loaded ONNX model from mbv4/model.onnx
Model has 89 nodes.

2. Convert to Akida

2.1. Convert and get compatibility information

The main entry point is the convert function, which analyzes the ONNX model and returns both a HybridModel and detailed compatibility information. The input_shape parameter specifies the expected input dimensions for the model. Models can be exported with a dynamic shape, but quantization and later Akida conversion and mapping need all input dimensions to be fixed.

from onnx2akida import convert

# Convert the model and analyze compatibility
# For MobileNetV4, the input shape is (channels, height, width)
print("\nAnalyzing model compatibility with Akida hardware...")
hybrid_model, compatibility_info = convert(model, input_shape=(3, 224, 224))
Analyzing model compatibility with Akida hardware...
Applied 1 of general pattern rewrite rules.

Calibrating with 1/1.0 samples

Quantizing:   0%|          | 0/1 [00:00<?, ?it/s]
Quantizing: 100%|██████████| 1/1 [00:00<00:00,  4.44it/s]
Quantizing: 100%|██████████| 1/1 [00:00<00:00,  4.43it/s]

Converting:   0%|          | 0/1 [00:00<?, ?it/s]
Converting: 100%|██████████| 1/1 [00:00<00:00,  2.91it/s]
Converting: 100%|██████████| 1/1 [00:00<00:00,  2.91it/s]

2.2. Display compatibility report

The obtained ModelCompatibilityInfo object contains detailed information about which nodes and subgraphs are compatible with Akida hardware. Use print_report to display a comprehensive analysis.

from onnx2akida import print_report

# Print detailed compatibility report
print_report(hybrid_model, compatibility_info)
[INFO]: Percentage of nodes compatible with akida: 100.0000 %

[INFO]: Number of mappable sequences on akida: 1

List of backends exchanges:
 • CPU -> Akida at layer /conv_stem/Conv: 147.000 KB
 • Akida -> CPU at layer /classifier/Gemm: 3.906 KB

The report shows:

  • The list of incompatibles operation types,

  • The list of incompatibilities indexed by node and by stage (quantization, conversion, mapping) indicating where an incompatibility was found and why,

  • Overall compatibility percentage,

  • The memory report for Akida to CPU transfers.

2.3. Understanding the HybridModel

The returned HybridModel object represents a model that can contain both:

  • Akida-compatible submodels (will be accelerated on Akida hardware)

  • Standard ONNX operators (will run on CPU via ONNXRuntime)

This hybrid approach allows partial acceleration even when not all operations are Akida-compatible.

You can inspect the structure of the HybridModel using its summary method.

print(hybrid_model.summary())
                                                                                              HybridModel Summary: HybridModel
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
Layer (type)                                                       Output shape    Inbounds                                                                                                        Data movement

================================================================================================== --- ONNX Sub-model 0 --- =================================================================================================

02ac12d1-cf8f-4fdd-a729-f34a9c88e41c/quantizer_0 (InputQuantizer)  [3, 224, 224]   pixel_values                                                                                                    N/A

================================================================================================= --- Akida Sub-model 1 --- =================================================================================================

/conv_stem/Conv (InputConv2D)                                      [112, 112, 32]  02ac12d1-cf8f-4fdd-a729-f34a9c88e41c/quantize_0                                                                 147.00 KB (CPU -> Akida)
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.0/blocks.0.0/conv/Conv (Conv2D)                     [56, 56, 32]    /bn1/act/Relu_output_0                                                                                          N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.0/blocks.0.1/conv/Conv (Conv2D)                     [56, 56, 32]    /blocks/blocks.0/blocks.0.0/bn1/act/Relu_output_0                                                               N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.1/blocks.1.0/conv/Conv (Conv2D)                     [28, 28, 96]    /blocks/blocks.0/blocks.0.1/bn1/act/Relu_output_0                                                               N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.1/blocks.1.1/conv/Conv (Conv2D)                     [28, 28, 64]    /blocks/blocks.1/blocks.1.0/bn1/act/Relu_output_0                                                               N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.0/dw_start/conv/Conv (DepthwiseConv2D)   [28, 28, 64]    /blocks/blocks.1/blocks.1.1/bn1/act/Relu_output_0                                                               N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.0/pw_exp/conv/Conv (Conv2D)              [28, 28, 192]   /blocks/blocks.2/blocks.2.0/dw_start/conv/Conv_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
node_Conv_0 (DepthwiseConv2D)                                      [28, 28, 192]   /blocks/blocks.2/blocks.2.0/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
node_Conv_1 (DepthwiseConv2D)                                      [14, 14, 192]   val_0                                                                                                           N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.0/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.0/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.1/pw_exp/conv/Conv (Conv2D)              [14, 14, 192]   /blocks/blocks.2/blocks.2.0/pw_proj/conv/Conv_output_0                                                          N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.1/dw_mid/conv/Conv (DepthwiseConv2D)     [14, 14, 192]   /blocks/blocks.2/blocks.2.1/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.1/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.1/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.1/Add (Add)                              [14, 14, 96]    /blocks/blocks.2/blocks.2.1/pw_proj/conv/Conv_output_0, /blocks/blocks.2/blocks.2.0/pw_proj/conv/Conv_output_0  N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.2/pw_exp/conv/Conv (Conv2D)              [14, 14, 192]   /blocks/blocks.2/blocks.2.1/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.2/dw_mid/conv/Conv (DepthwiseConv2D)     [14, 14, 192]   /blocks/blocks.2/blocks.2.2/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.2/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.2/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.2/Add (Add)                              [14, 14, 96]    /blocks/blocks.2/blocks.2.2/pw_proj/conv/Conv_output_0, /blocks/blocks.2/blocks.2.1/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.3/pw_exp/conv/Conv (Conv2D)              [14, 14, 192]   /blocks/blocks.2/blocks.2.2/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.3/dw_mid/conv/Conv (DepthwiseConv2D)     [14, 14, 192]   /blocks/blocks.2/blocks.2.3/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.3/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.3/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.3/Add (Add)                              [14, 14, 96]    /blocks/blocks.2/blocks.2.3/pw_proj/conv/Conv_output_0, /blocks/blocks.2/blocks.2.2/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.4/pw_exp/conv/Conv (Conv2D)              [14, 14, 192]   /blocks/blocks.2/blocks.2.3/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.4/dw_mid/conv/Conv (DepthwiseConv2D)     [14, 14, 192]   /blocks/blocks.2/blocks.2.4/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.4/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.4/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.4/Add (Add)                              [14, 14, 96]    /blocks/blocks.2/blocks.2.4/pw_proj/conv/Conv_output_0, /blocks/blocks.2/blocks.2.3/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.5/dw_start/conv/Conv (DepthwiseConv2D)   [14, 14, 96]    /blocks/blocks.2/blocks.2.4/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.5/pw_exp/conv/Conv (Conv2D)              [14, 14, 384]   /blocks/blocks.2/blocks.2.5/dw_start/conv/Conv_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.5/pw_proj/conv/Conv (Conv2D)             [14, 14, 96]    /blocks/blocks.2/blocks.2.5/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.2/blocks.2.5/Add (Add)                              [14, 14, 96]    /blocks/blocks.2/blocks.2.5/pw_proj/conv/Conv_output_0, /blocks/blocks.2/blocks.2.4/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.0/dw_start/conv/Conv (DepthwiseConv2D)   [14, 14, 96]    /blocks/blocks.2/blocks.2.5/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.0/pw_exp/conv/Conv (Conv2D)              [14, 14, 576]   /blocks/blocks.3/blocks.3.0/dw_start/conv/Conv_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.0/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 576]     /blocks/blocks.3/blocks.3.0/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.0/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.0/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.1/dw_start/conv/Conv (DepthwiseConv2D)   [7, 7, 128]     /blocks/blocks.3/blocks.3.0/pw_proj/conv/Conv_output_0                                                          N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.1/pw_exp/conv/Conv (Conv2D)              [7, 7, 512]     /blocks/blocks.3/blocks.3.1/dw_start/conv/Conv_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.1/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 512]     /blocks/blocks.3/blocks.3.1/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.1/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.1/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.1/Add (Add)                              [7, 7, 128]     /blocks/blocks.3/blocks.3.1/pw_proj/conv/Conv_output_0, /blocks/blocks.3/blocks.3.0/pw_proj/conv/Conv_output_0  N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.2/pw_exp/conv/Conv (Conv2D)              [7, 7, 512]     /blocks/blocks.3/blocks.3.1/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.2/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 512]     /blocks/blocks.3/blocks.3.2/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.2/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.2/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.2/Add (Add)                              [7, 7, 128]     /blocks/blocks.3/blocks.3.2/pw_proj/conv/Conv_output_0, /blocks/blocks.3/blocks.3.1/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.3/pw_exp/conv/Conv (Conv2D)              [7, 7, 384]     /blocks/blocks.3/blocks.3.2/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.3/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 384]     /blocks/blocks.3/blocks.3.3/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.3/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.3/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.3/Add (Add)                              [7, 7, 128]     /blocks/blocks.3/blocks.3.3/pw_proj/conv/Conv_output_0, /blocks/blocks.3/blocks.3.2/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.4/pw_exp/conv/Conv (Conv2D)              [7, 7, 512]     /blocks/blocks.3/blocks.3.3/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.4/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 512]     /blocks/blocks.3/blocks.3.4/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.4/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.4/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.4/Add (Add)                              [7, 7, 128]     /blocks/blocks.3/blocks.3.4/pw_proj/conv/Conv_output_0, /blocks/blocks.3/blocks.3.3/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.5/pw_exp/conv/Conv (Conv2D)              [7, 7, 512]     /blocks/blocks.3/blocks.3.4/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.5/dw_mid/conv/Conv (DepthwiseConv2D)     [7, 7, 512]     /blocks/blocks.3/blocks.3.5/pw_exp/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.5/pw_proj/conv/Conv (Conv2D)             [7, 7, 128]     /blocks/blocks.3/blocks.3.5/dw_mid/bn/act/Relu_output_0                                                         N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.3/blocks.3.5/Add (Add)                              [7, 7, 128]     /blocks/blocks.3/blocks.3.5/pw_proj/conv/Conv_output_0, /blocks/blocks.3/blocks.3.4/Add_output_0                N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/blocks/blocks.4/blocks.4.0/conv/Conv (Conv2D)                     [1, 1, 960]     /blocks/blocks.3/blocks.3.5/Add_output_0                                                                        N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/conv_head/Conv (Conv2D)                                           [1, 1, 1280]    /global_pool/pool/GlobalAveragePool_output_0                                                                    N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
/classifier/Gemm (Dense1D)                                         [1, 1, 1000]    /norm_head/act/Relu_output_0                                                                                    3.91 KB (Akida -> CPU)

================================================================================================== --- ONNX Sub-model 2 --- =================================================================================================

8169490d-2690-4763-b107-ec66da21332f/dequantizer_0 (Dequantizer)   [1000]          logits/to_dequantize                                                                                            N/A
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________
None

Inference is possible on the HybridModel. This is allowed for convenience and computing quantization impact on accuracy even before generating a deployable inference model.

import numpy as np

hybrid_out = hybrid_model(np.random.randn(1, 3, 224, 224).astype(np.float32))
print(f"Example output of the hybrid model: {hybrid_out[0][0][:10]}")
Example output of the hybrid model: [-18.864746 -19.465176 -18.957663 -18.882053 -19.691698 -18.62758
 -19.674084 -18.256859 -18.6689   -19.358564]

Warning

This is a pure software simulation and does not use any Akida hardware acceleration. For deployment, an inference model needs to be generated as shown in next section.

3. Generate inference model

3.1. Generate hybrid inference model with Akida device

To create a deployable inference model, you need an Akida device.

Important

A 2.0 FPGA device like available in Akida Cloud is used here for demonstration.

import akida

# Check for available Akida devices
assert len(devices := akida.devices()) > 0, "No device found, this example needs a 2.0 device."
print(f'Available devices: {[dev.desc for dev in devices]}')
Available devices: ['fpga-1766']

Inference happens on a device, so we need to map the hybrid model onto it. This can be done using HybridModel.map like shown below.

# Map on the device
fpga_device = devices[0]
try:
    hybrid_model.map(fpga_device)
except RuntimeError as e:
    print("Mapping failed:\n", e)
Mapping failed:
 Failed to map Akida model at index 0 within 'akida_models'. Reason: Cannot map layer '/conv_head/Conv'. Not enough hardware components of type CNP1 available. 27 are needed but 21 are available..

Mapping the HybridModel onto the Akida device after conversion might fail: while some layers are supported by Akida hardware, they might not fit on device due to resource constraints. In such cases, you can try mapping on a larger virtual device - but that cannot be used for inference, it only serves for prototyping - or you can go back to model conversion and provide the device as a convert parameter.

hybrid_model, compatibility_info = convert(model, input_shape=(3, 224, 224), device=fpga_device)
Applied 1 of general pattern rewrite rules.

Calibrating with 1/1.0 samples

Quantizing:   0%|          | 0/1 [00:00<?, ?it/s]
Quantizing: 100%|██████████| 1/1 [00:00<00:00,  3.97it/s]
Quantizing: 100%|██████████| 1/1 [00:00<00:00,  3.96it/s]

Converting:   0%|          | 0/1 [00:00<?, ?it/s]
Converting: 100%|██████████| 1/1 [00:00<00:00,  4.90it/s]
Converting: 100%|██████████| 1/1 [00:00<00:00,  4.90it/s]
print_report(hybrid_model, compatibility_info)
Set of incompatible op_types: ['Conv', 'Relu']
List of incompatibilities:
 ❌ Node sequence: [/conv_head/Conv(op_type=Conv), /norm_head/act/Relu(op_type=Relu)]
     • Stage: Mapping
     • Faulty node: /conv_head/Conv
     • Reason: Cannot map layer '/conv_head/Conv'. Not enough hardware components of type CNP1 available. 27 are needed but 24 are available.

[INFO]: Percentage of nodes compatible with akida: 97.7778 %

[INFO]: Number of mappable sequences on akida: 2

List of backends exchanges:
 • CPU -> Akida at layer /conv_stem/Conv: 147.000 KB
 • Akida -> CPU at layer /blocks/blocks.4/blocks.4.0/conv/Conv: 0.938 KB
 • CPU -> Akida at layer /classifier/Gemm: 1.250 KB
 • Akida -> CPU at layer /classifier/Gemm: 3.906 KB

The conversion algorithm knows the resource limitations, so it now avoids converting parts that do not fit on the device. That is why there are more incompatibilities (the node that was too big to fit on 6-node device will run on CPU), but operations that were mapped on the device can be accelerated by it.

# Generate the inference model
infer_model = hybrid_model.generate_inference_model()

3.2. Save the inference model

Once generated, the inference model can be saved for deployment.

inference_model_path = "model_inference.onnx"
onnx.save(infer_model, inference_model_path)

The inference model is a standard ONNX model that can be executed using ONNXRuntime. It’s graph can be visualized with Netron and it will show AkidaOp nodes that are custom wrappers for all Akida-accelerated submodels. It will also contain Transpose nodes between ONNX and AkidaOp operators are automatically inserted to handle the different data layout conventions (NCHW for ONNX, NHWC for Akida).

3.3. Perform an inference

The inference model can be executed using ONNXRuntime and the provided AkidaInferenceSession.

from onnx2akida.inference import AkidaInferenceSession

# Generate random input samples with shape (batch_size, channels, height, width)
input_samples = np.random.randn(1, 3, 224, 224).astype(np.float32)

# Prepare and run inference
session = AkidaInferenceSession(inference_model_path)
input_name = session.get_inputs()[0].name
outputs = session.run(None, {input_name: input_samples})
print(f"Output shape: {outputs[0].shape}")
Output shape: (1, 1000)

4. Summary

The onnx2akida workflow enables you to:

  1. Analyze any ONNX model for Akida compatibility

  2. Identify which operations can be accelerated on Akida hardware

  3. Generate hybrid models that combine Akida acceleration with standard ONNX operators

  4. Deploy optimized inference models using ONNXRuntime

This approach maximizes hardware acceleration while maintaining full model functionality, even when only portions of the model are Akida-compatible.

Total running time of the script: (0 minutes 19.714 seconds)

Gallery generated by Sphinx-Gallery