Usage#
AIfES-Converter is designed to allow an easy conversion of your model from Keras and PyTorch to AIfES. Different types of Feed Forward Neural Networks (FFNNs) are supported with different data types. In the following section we show how to export the model to AIfES using this tool.
Export of model#
Only Keras and PyTorch are supported directly by the AIfES-Converter converter. But you can use any other framework where the FFNNs can be imported by Keras or PyTorch. We first show how to use this tool. Then a brief overview is given, how to use this tool with other frameworks.
Keras and PyTorch#
In the following section we provide a detailed description of the necessary steps.
1. Create the model#
Create a model in Python by using Keras. Keep an eye on the supported features of AIfES in the documentation as only those functions can be converted. You can also load a stored model and convert it to AIfES.
Create a model in Python by using PyTorch. Keep an eye on the supported features of AIfES in the documentation as only those functions can be converted. You can also load a stored model and convert it to AIfES.
2. Export the model using AIfES-Converter#
Choose the desired AIfES FFNN implementation from the available ones here. Call the converter tool with the chosen implementation. The converter tool will create the necessary header files for usage in your IDE in the destination file path path/to/location.
Note
If the output file path doesn’t exist, the corresponding folder will be created.
The converter tool allows you also to only export the structure of your model without any weights and biases. For this you need to set the option with_weights=False
during conversion, if supported by the corresponding
function (currently only supported for float32 based implementation, see available functions, as Q7 needs a representative dataset and
quantization parameters per layer). This creates a header file, which is prepared to include your own weights and biases.
Attention
The created header file of the conversion without weights is not executable. Please see the comments in the header file regarding the weights and biases in the function
aifes_f32_fnn_create_model()
/aifes_e_f32_fnn_inference()
.
3. Import the model into your project#
Import the files in your IDE and use the prepared function calls on top of the header file to call the FFNN in AIfES.
For this, copy the header files from the OUTPUT_PATH
and add them to your project in your desired IDE, as you would add
any other header file. Make sure, that you have installed the AIfES Library, either via the Library Manager in the
Arduino IDE or by following the instructions in our GitHub Repository for other IDEs. Then import the header files into your
project.
4. Call the prepared functions#
Finally, the prepared functions need to be called by your application. The necessary function calls are in the comments at the top
of the header file for the fnn aifes_e_{dtype}_fnn.h
respectively aifes_{dtype}_fnn.h
.
Other Frameworks#
You can convert models from other frameworks to AIfES as well, as long as a conversion of those models to Keras or PyTorch and then to AIfES is possible. Otherwise, you can recreate the model using Keras and set the weights and biases manually and then export the model to AIfES. For ONNX you can use PyTorch, as it supports ONNX out of the box. For more details about that see PyTorchs ONNX Documentation.