Updating or Replacing the .tflite File in a Project#
This guide describes how to swap out the model in an existing project. It assumes that the project uses the Flatbuffer Converter Tool.
Replace the Model#
To replace the model in an existing project, drag-and-drop the new model file into the config/tflite/
directory of the project. If the new model has the same file name as the previous model, accept the prompt to overwrite the file. If the new model has a different name, delete or rename the old .tflite
file such that it no longer has the .tflite
extension. The Flatbuffer Converter Tool will automatically execute when the directory watcher notices that a different .tflite
file is present.
Note: If you have multiple .tflite
files in the config/tflite/
directory, the converter tool will pick the first file in alphabetical order. Hence the recommendation to rename or delete any old models to ensure that the tool uses the correct file.
Inspect the Model#
You can take steps to ensure that the automatic regeneration of the C arrays and headers from the .tflite
file executed as expected. Any of the below steps can be taken if you're ever unsure of what model is part of your application binary.
Check the Model Size#
The generated file autogen/sl_tflite_micro_model.c
defines a size variable sl_tflite_model_len
. This number can be compared to the file size of the .tflite
file in bytes, e.g., by right-clicking the .tflite
file and looking at the value of Properties > Resource > Size.
Check the Operators Used by the Model#
The generated file autogen/sl_tflite_micro_opcode_resolver.h
contains multiple calls to tflite::MicroMutableOpResolver::AddXXX
, where XXX
is the name of operators used by the model. This can be compared to the operators you know the model should use.
Check the Model Parameters#
If the .tflite
file was generated using the Silicon Labs Machine Learning Toolkit, it contains metadata that is generated into autogen/sl_tflite_micro_model_parameters.h
. These parameters can be compared to the expected parameters.
Force Generation of C files#
If anything happens that makes the generated .c
and .h
get out of sync with the .tflite
file, the project can be forcefully regenerated by pressing the "Force Generation" button on the Project Details pane of the Project Configurator.