# Edge Optimization

In the previous sections, we built models and evaluated their performance. We should have also picked the best performing one or the one we like. Now it is time to convert the model into optimized C-code that can be deployed on an Edge device.

Check here to see the supported layers for C code conversion.

Supported Layers & Functions

# Edge tab of the .h5 model

Let us open the downloaded .h5 file and go to its Edge tab. In the tab we find the following sections:

  • Architecture, we can choose to optimize our Edge model (C-code) for different target architectures. As of the time of writing this tutorial there’s only ANSI C (C99) option but more options will be added in the future.

  • Output Directory tab allows the user to determine the name of the output folder with all the generated code.

  • Timestamps API allows us to track the time of when the input data for a prediction/classification was input to the model. This is optional and it controls whether a time input argument is required in the generated code.

  • C Prefix, it defines the function names inside the generated C API for the Edge model.

  • Layers, we can select what layers to include in code generation, which depends on the need. Let’s leave both these fields as below.

# Data Compare Test (Optional)

In this section, we are going to focus on how to generate Data Compare Test together with our Edge model. The purpose of this test is to verify that the Edge model gives the same output as the HDF5 (.h5) model when feeding them both the same data as input.

Firstly, let’s enable the test by checking the box. And in order to set it up, we need to provide the input and output data to test with.

For the input, we are going to use CombinedGesture\combined1\acconeer-sparse.data. Next, click the "" button next to the Input file field. In the file browse dialog select the file as shown below. Make sure to use the same path as in the picture.

For the output, we will use Result\ModelReducedSize\Predictions_Model25\sessions\combined2\Model25.data, which is output from the Model25.h5 model. To do it by clicking the "" button next to the Expected output file field. In the file browse dialog select the file (this filename is the same the model name) as shown below. Make sure to use the same path as in the picture.

Note: it is really important that you verify that the acconeer-sparse.data and MyModel.data (in this case Model25.data) are from the same recording. Otherwise the Data Compare test will fail regardless if the Edge model is correct or not.

# Build Edge

Now we are ready to build the edge model as well as the test.

Click on Build Edge at bottom. In a matter of seconds the Edge model has been generated and a report is provided for us. Here we can see how much memory this model will use when deployed on a device. We can also see the input and out parameters, as well as the layers in the model.

After clicking OK, you can see that edge codes are generated in the edge folder.

# Edge code testing

Now it's time to verify the generated model using the generated test. Right click the Makefile in the edge folder that was generated when building edge. Select Make All. This will invoke cygwin to run the model and test.

From the output below we can now confirm that the generated Edge model is equal to the HDF5 (.h5) model to within the sixth decimal. We can safely deploy this model and be confident that it will perform just as well as the .h5 model. The only difference is that our Edge model consumes a fraction of the memory/processing power during runtime and can run on any embedded platform!

Well done! You just completed the guide with Accorneer sensor.