Difference: MicroPythonExamples (1 vs. 3)

Revision 32023-11-08 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="TinyML"

Running the TensorFlow examples in MicroPython

The MicroPython interface to TensorFlow

Line: 39 to 39
 
  • getInputTensor(tensor_number)
  • getOutputTensor(tensor_number)
  • invoke()
Added:
>
>
Here is a description of the MicroPython version of the examples:
 -- Uli Raich - 2023-09-07

Comments

Revision 22023-10-12 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="TinyML"
Changed:
<
<

Running the TensorFlow examples in MicroPython

>
>

Running the TensorFlow examples in MicroPython

The MicroPython interface to TensorFlow

 
Changed:
<
<
Article text.
>
>
The MicroPython interface to TensorFlow is implemented as a module written in C. It contains several Python classes:
  • interpreter: gives access to the tflite-micro runtime interpreter
  • tensor: allows to define and fille the input tensor and to interpret the output tensor
  • audio_frontend: needed for the wake words example.

Running inference on the ESP32

 
Changed:
<
<
-- Uli Raich - 2023-09-07
>
>
After having defined and trained the model with TensorFlow, it must be converted into a TensorFlow Lite model, which is an optimized FlatBuffer format identified by the .tflite extension. This file must be transfered to the MicroPython file system. In my examples I create a "models" folder on the ESP32 into which I save the models. You can easily find the size of the model with the ls -l command on the PC. The model is read into a bytearray:

readModel.png

Once the model is loaded we can create the runtime interpreter:

interpreter.png

invoke.png

input_callback is called when you invoke the interpreter. It gives access to the input tensor and allows to fill it using the setValue method of the tensor class. In the example below, the input tensor is filled with pixel values on an image that has previously been read from the ESP32 file system.

 
Added:
>
>
input_callback.png

Finally the output_callback is called in which you access the output tensor and interpret it.

The classes and their resources

tensor

The tensor class has the methods:

  • getValue(index)
  • setValue(index,value)
  • getType()
  • quantizeFloatToInt8()
  • quantiteInt8ToFloat()
The interpreter

The interpreter has methods to get the input and output tensors and for invocation:

  • getInputTensor(tensor_number)
  • getOutputTensor(tensor_number)
  • invoke()
-- Uli Raich - 2023-09-07
 

Comments

Deleted:
<
<
<--/commentPlugin-->
 \ No newline at end of file
Added:
>
>

<--/commentPlugin-->

META FILEATTACHMENT attachment="readModel.png" attr="" comment="" date="1697099031" name="readModel.png" path="readModel.png" size="23132" user="UliRaich" version="1"
META FILEATTACHMENT attachment="interpreter.png" attr="" comment="" date="1697099257" name="interpreter.png" path="interpreter.png" size="7416" user="UliRaich" version="1"
META FILEATTACHMENT attachment="input_callback.png" attr="" comment="" date="1697099870" name="input_callback.png" path="input_callback.png" size="30590" user="UliRaich" version="1"
META FILEATTACHMENT attachment="output_callback.png" attr="" comment="" date="1697099870" name="output_callback.png" path="output_callback.png" size="22925" user="UliRaich" version="1"
META FILEATTACHMENT attachment="invoke.png" attr="" comment="" date="1697099941" name="invoke.png" path="invoke.png" size="3044" user="UliRaich" version="1"

Revision 12023-09-07 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="TinyML"

Running the TensorFlow examples in MicroPython

Article text.

-- Uli Raich - 2023-09-07

Comments

<--/commentPlugin-->
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback