TensorFlow Lite for Microcontrollers docs update
PiperOrigin-RevId: 259163029
This commit is contained in:
parent
20562226f0
commit
b0bc0ead62
@ -32,11 +32,17 @@ Microcontrollers.
|
|||||||
|
|
||||||
### Build the code
|
### Build the code
|
||||||
|
|
||||||
To compile and test this example on a desktop Linux or MacOS machine, download
|
To compile and test this example on a desktop Linux or macOS machine, first
|
||||||
[the TensorFlow source code](https://github.com/tensorflow/tensorflow), `cd`
|
clone the TensorFlow repository from GitHub to a convenient place:
|
||||||
into the source directory from a terminal, and then run the following command:
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone --depth 1 https://github.com/tensorflow/tensorflow.git
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Next, `cd` into the source directory from a terminal, and then run the following
|
||||||
|
command:
|
||||||
|
|
||||||
|
```bash
|
||||||
make -f tensorflow/lite/experimental/micro/tools/make/Makefile test_hello_world_test
|
make -f tensorflow/lite/experimental/micro/tools/make/Makefile test_hello_world_test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ This document explains the process of converting a TensorFlow model to run on
|
|||||||
microcontrollers. It also outlines the supported operations and gives some
|
microcontrollers. It also outlines the supported operations and gives some
|
||||||
guidance on designing and training a model to fit in limited memory.
|
guidance on designing and training a model to fit in limited memory.
|
||||||
|
|
||||||
|
For an end-to-end, runnable example of building and converting a model, see the
|
||||||
|
following Jupyter notebook:
|
||||||
|
|
||||||
|
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/hello_world/create_sine_model.ipynb">create_sine_model.ipynb</a>
|
||||||
|
|
||||||
## Model conversion
|
## Model conversion
|
||||||
|
|
||||||
To convert a trained TensorFlow model to run on microcontrollers, you should use
|
To convert a trained TensorFlow model to run on microcontrollers, you should use
|
||||||
|
@ -3,12 +3,54 @@
|
|||||||
This document will help you start working with TensorFlow Lite for
|
This document will help you start working with TensorFlow Lite for
|
||||||
Microcontrollers.
|
Microcontrollers.
|
||||||
|
|
||||||
## Sample code
|
Start by reading through and running our [Examples](#examples).
|
||||||
|
|
||||||
To get started, you can explore the following example:
|
Note: If you need a device to get started, we recommend the
|
||||||
|
[SparkFun Edge Powered by TensorFlow](https://www.sparkfun.com/products/15170).
|
||||||
|
It was designed in conjunction with the TensorFlow Lite team to offer a flexible
|
||||||
|
platform for experimenting with deep learning on microcontrollers.
|
||||||
|
|
||||||
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_speech">Micro
|
For a walkthrough of the code required to run inference, see the *Run inference*
|
||||||
speech example</a>
|
section below.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
There are several examples that demonstrate how to build embedded machine
|
||||||
|
learning applications with TensorFlow Lite:
|
||||||
|
|
||||||
|
### Hello World example
|
||||||
|
|
||||||
|
This example is designed to demonstrate the absolute basics of using TensorFlow
|
||||||
|
Lite for Microcontrollers. It includes the full end-to-end workflow of training
|
||||||
|
a model, converting it for use with TensorFlow Lite, and running inference on a
|
||||||
|
microcontroller.
|
||||||
|
|
||||||
|
In the example, a model is trained to replicate a sine function. When deployed
|
||||||
|
to a microcontroller, its predictions are used to either blink LEDs or control
|
||||||
|
an animation.
|
||||||
|
|
||||||
|
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/hello_world">Hello
|
||||||
|
World example</a>
|
||||||
|
|
||||||
|
The example code includes a Jupyter notebook that demonstrates how the model is
|
||||||
|
trained and converted:
|
||||||
|
|
||||||
|
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/hello_world/create_sine_model.ipynb">create_sine_model.ipynb</a>
|
||||||
|
|
||||||
|
The process of building and converting a model is also covered in the guide
|
||||||
|
[Build and convert models](build_convert.md).
|
||||||
|
|
||||||
|
To see how inference is performed, take a look at
|
||||||
|
[hello_world_test.cc](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/hello_world/hello_world_test.cc).
|
||||||
|
|
||||||
|
The example is tested on the following platforms:
|
||||||
|
|
||||||
|
- [SparkFun Edge Powered by TensorFlow (Apollo3 Blue)](https://www.sparkfun.com/products/15170)
|
||||||
|
- [Arduino MKRZERO](https://store.arduino.cc/usa/arduino-mkrzero)
|
||||||
|
- [STM32F746G Discovery Board](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
|
||||||
|
- Mac OS X
|
||||||
|
|
||||||
|
### Micro Speech example
|
||||||
|
|
||||||
This example uses a simple
|
This example uses a simple
|
||||||
[audio recognition model](https://www.tensorflow.org/tutorials/sequences/audio_recognition)
|
[audio recognition model](https://www.tensorflow.org/tutorials/sequences/audio_recognition)
|
||||||
@ -16,48 +58,43 @@ to identify keywords in speech. The sample code captures audio from a device's
|
|||||||
microphones. The model classifies this audio in real time, determining whether
|
microphones. The model classifies this audio in real time, determining whether
|
||||||
the word "yes" or "no" has been spoken.
|
the word "yes" or "no" has been spoken.
|
||||||
|
|
||||||
The sample works end-to-end (including audio capture and inference) on the
|
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_speech">Micro
|
||||||
following platforms:
|
Speech example</a>
|
||||||
|
|
||||||
|
The [Run inference](#run_inference) section walks through the code of the Micro
|
||||||
|
Speech sample and explains how it works.
|
||||||
|
|
||||||
|
The example is tested on the following platforms:
|
||||||
|
|
||||||
- [SparkFun Edge Powered by TensorFlow (Apollo3 Blue)](https://www.sparkfun.com/products/15170)
|
- [SparkFun Edge Powered by TensorFlow (Apollo3 Blue)](https://www.sparkfun.com/products/15170)
|
||||||
- [STM32F746G Discovery Board](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
|
- [STM32F746G Discovery Board](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
|
||||||
- Mac OS X
|
- Mac OS X
|
||||||
|
|
||||||
### SparkFun Edge
|
Note: To get started using the SparkFun Edge board, we recommend following
|
||||||
|
|
||||||
If you need a device to get started, we recommend the
|
|
||||||
[SparkFun Edge Powered by TensorFlow](https://www.sparkfun.com/products/15170).
|
|
||||||
It was designed in conjunction with the TensorFlow Lite team to offer a flexible
|
|
||||||
platform for experimenting with deep learning on microcontrollers.
|
|
||||||
|
|
||||||
To get started using the Edge board, we recommend following
|
|
||||||
[Machine learning on a microcontroller with SparkFun TensorFlow](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow),
|
[Machine learning on a microcontroller with SparkFun TensorFlow](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow),
|
||||||
a codelab that introduces you to the development workflow.
|
a codelab that introduces you to the development workflow using the Micro Speech
|
||||||
|
example.
|
||||||
|
|
||||||
## Workflow
|
### Micro Vision example
|
||||||
|
|
||||||
Using TensorFlow Lite for Microcontrollers involves four major steps:
|
This example shows how you can use TensorFlow Lite to run a 250 kilobyte neural
|
||||||
|
network to recognize people in images captured by a camera. It is designed to
|
||||||
|
run on systems with small amounts of memory such as microcontrollers and DSPs.
|
||||||
|
|
||||||
1. Create or find a model architecture.
|
<a class="button button-primary" href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_vision">Micro
|
||||||
2. Train a model.
|
Vision example</a>
|
||||||
3. Convert the model.
|
|
||||||
4. Write code to run inference.
|
|
||||||
|
|
||||||
The first three steps are covered in the guide
|
The example is tested on the following platforms:
|
||||||
[Build and convert models](build_convert.md). The sample code comes with a
|
|
||||||
pretrained model, and includes scripts to train a model that recognizes
|
|
||||||
different spoken words. Instructions on training are in
|
|
||||||
[README.md](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/README.md#creating-your-own-model).
|
|
||||||
|
|
||||||
In this document, we will focus on the code that will feed processed audio data
|
- [SparkFun Edge Powered by TensorFlow (Apollo3 Blue)](https://www.sparkfun.com/products/15170)
|
||||||
into the model and execute it, resulting in a prediction of which word was
|
- [STM32F746G Discovery Board](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
|
||||||
spoken. This process is called *inference*.
|
- Mac OS X
|
||||||
|
|
||||||
## Run inference
|
## Run inference
|
||||||
|
|
||||||
The sample's
|
The following section walks through the [Micro Speech](#micro_speech) sample's
|
||||||
[main.cc](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/main.cc)
|
[main.cc](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/experimental/micro/examples/micro_speech/main.cc)
|
||||||
contains the code that runs inference. We'll now walk through the key parts.
|
and explains how it used TensorFlow Lite for Microcontrollers to run inference.
|
||||||
|
|
||||||
### Includes
|
### Includes
|
||||||
|
|
||||||
@ -277,48 +314,9 @@ recognition results across a number of frames. This is defined in
|
|||||||
The same technique can be used to improve reliability when processing any
|
The same technique can be used to improve reliability when processing any
|
||||||
continuous stream of data.
|
continuous stream of data.
|
||||||
|
|
||||||
## Build the sample
|
|
||||||
|
|
||||||
The sample contains build scripts that will download all required dependencies
|
|
||||||
and compile a binary that can be run on a device.
|
|
||||||
|
|
||||||
Note: The build process has been tested on MacOS and Linux, but not on Windows.
|
|
||||||
|
|
||||||
To build the sample, take the following steps:
|
|
||||||
|
|
||||||
1. Clone the TensorFlow repository from GitHub to a convenient place.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone --depth 1 https://github.com/tensorflow/tensorflow.git
|
|
||||||
```
|
|
||||||
|
|
||||||
1. Enter the directory that was created in the previous step.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd tensorflow
|
|
||||||
```
|
|
||||||
|
|
||||||
1. If you are using MacOS, run the following command. If you are using Linux,
|
|
||||||
you do not need to do this.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
PATH=tensorflow/lite/experimental/micro/tools/make/downloads/gcc_embedded/bin/:$PATH
|
|
||||||
```
|
|
||||||
|
|
||||||
1. To download all of the required dependencies and initiate the build process,
|
|
||||||
issue the following command. You can set `TARGET` depending on which
|
|
||||||
platform you want to build for. Explore
|
|
||||||
[`targets/`](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/tools/make/targets)
|
|
||||||
for the current options.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
make -f tensorflow/lite/experimental/micro/tools/make/Makefile
|
|
||||||
TARGET=sparkfun_edge micro_speech_bin
|
|
||||||
```
|
|
||||||
|
|
||||||
## Next steps
|
## Next steps
|
||||||
|
|
||||||
Once you have built and run the sample, read the following documents:
|
Once you have built and run the samples, read the following documents:
|
||||||
|
|
||||||
* Learn how to work with models in
|
* Learn how to work with models in
|
||||||
[Build and convert models](build_convert.md).
|
[Build and convert models](build_convert.md).
|
||||||
|
Loading…
Reference in New Issue
Block a user