Flatbuffer Conversion #

The Tensorflow Lite for Microcontrollers software package takes a binary blob containing a TFLite flatbuffer as input. The flatbuffer is typically created using the TensorFlow Lite Flatbuffer Converter . The SLC tools used by the Gecko SDK Suite support automatically serializing .tflite files present in the project config/tflite directory to C arrays in the sl_ml_model.c file in the project autogen directory.

The symbol name for the array is inherited from the file name. If multiple .tflite files are present in the config/tflite directory, multiple arrays with corresponding symbols are created.

The conversion is automatically performed on every project generation if a file with the .tflite extension is found in the config/tflite directory.

Example #

The file config/tflite/micro_speech.tflite exists in the project. Upon SLC project generation, the files autogen/sl_ml_model.c and autogen/sl_ml_model.h are created, exposing the following symbols:

const uint8_t micro_speech_array[];
const uint32_t micro_speech_len;

Usage:

#include "sl_ml_model.h"

const tflite::Model* model = tflite::GetModel(micro_speech_array);

Manual Usage #

If conversion is desired outside of a full SLC project generation, the flatbuffer converter can be invoked using several methods.

As SLC Project Generator #

The flatbuffer conversion step of the project generation process can be run standalone by passing -tools tflite to the slc generate command, e.g.

slc generate -p my_project.slcp -tools tflite

As Standalone SLC Command #

The flatbuffer converter is also available as a standalone command in SLC for use outside of the context of a project. Execute the following command, using absolute paths for both input and output directories.

slc tflite generate -contentFolder [/path/to/config/tflite] -generationOutput [/path/to/autogen]