This is a simple package to export a model trained in Tensorflow Lite to a plain C array, ready to be used for inference on microcontrollers.
pip install tinymlgenfrom tinymlgen import port
if __name__ == '__main__':
tf_model = create_tf_model()
c_code = port(tf_model)You can pass a few parameters to the port function:
optimize (=True): apply optimizers to the exported model. Can either be a list of optimizers or a boolean, in which caseOPTIMIZE_FOR_SIZEis appliedvariable_name (='model_data'): give the exported array a custom namepretty_print (=False): print the array in a nicely formatted arrangement