chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,94 @@
# Build and convert models
Microcontrollers have limited RAM and storage, which places constraints on the
sizes of machine learning models. In addition, TensorFlow Lite for
Microcontrollers currently supports a limited subset of operations, so not all
model architectures are possible.
This document explains the process of converting a TensorFlow model to run on
microcontrollers. It also outlines the supported operations and gives some
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
[Hello World](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world#hello-world-example)
example.
## Model conversion
To convert a trained TensorFlow model to run on microcontrollers, you should use
the
[TensorFlow Lite converter Python API](https://www.tensorflow.org/lite/models/convert/).
This will convert the model into a
[`FlatBuffer`](https://google.github.io/flatbuffers/), reducing the model size,
and modify it to use TensorFlow Lite operations.
To obtain the smallest possible model size, you should consider using
[post-training quantization](https://www.tensorflow.org/lite/performance/post_training_quantization).
### Convert to a C array
Many microcontroller platforms do not have native filesystem support. The
easiest way to use a model from your program is to include it as a C array and
compile it into your program.
The following unix command will generate a C source file that contains the
TensorFlow Lite model as a `char` array:
```bash
xxd -i converted_model.tflite > model_data.cc
```
The output will look similar to the following:
```c
unsigned char converted_model_tflite[] = {
0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
// <Lines omitted>
};
unsigned int converted_model_tflite_len = 18200;
```
Once you have generated the file, you can include it in your program. It is
important to change the array declaration to `const` for better memory
efficiency on embedded platforms.
For an example of how to include and use a model in your program, see
[`hello_world_test.cc`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc)
in the *Hello World* example.
## Model architecture and training
When designing a model for use on microcontrollers, it is important to consider
the model size, workload, and the operations that are used.
### Model size
A model must be small enough to fit within your target device's memory alongside
the rest of your program, both as a binary and at runtime.
To create a smaller model, you can use fewer and smaller layers in your
architecture. However, small models are more likely to suffer from underfitting.
This means for many problems, it makes sense to try and use the largest model
that will fit in memory. However, using larger models will also lead to
increased processor workload.
Note: The core runtime for TensorFlow Lite for Microcontrollers fits in 16KB on
a Cortex M3.
### Workload
The size and complexity of the model has an impact on workload. Large, complex
models might result in a higher duty cycle, which means your device's processor
is spending more time working and less time idle. This will increase power
consumption and heat output, which might be an issue depending on your
application.
### Operation support
TensorFlow Lite for Microcontrollers currently supports a limited subset of
TensorFlow operations, which impacts the model architectures that it is possible
to run. We are working on expanding operation support, both in terms of
reference implementations and optimizations for specific architectures.
The supported operations can be seen in the file
[`micro_mutable_ops_resolver.h`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/micro_mutable_op_resolver.h)
@@ -0,0 +1,340 @@
# Get started with microcontrollers
This document explains how to train a model and run inference using a
microcontroller.
## The Hello World example
The
[Hello World](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world)
example is designed to demonstrate the absolute basics of using TensorFlow Lite
for Microcontrollers. We train and run a model that replicates a sine function,
i.e, it takes a single number as its input, and outputs the number's
[sine](https://en.wikipedia.org/wiki/Sine) value. When deployed to the
microcontroller, its predictions are used to either blink LEDs or control an
animation.
The end-to-end workflow involves the following steps:
1. [Train a model](#train_a_model) (in Python): A python file to train, convert
and optimize a model for on-device use.
2. [Run inference](#run_inference) (in C++ 17): An end-to-end unit test that
runs inference on the model using the [C++ library](library.md).
## Get a supported device
The example application we'll be using has been tested on the following devices:
* [Arduino Nano 33 BLE Sense](https://store-usa.arduino.cc/products/arduino-nano-33-ble-sense-with-headers)
(using Arduino IDE)
* [SparkFun Edge](https://www.sparkfun.com/products/15170) (building directly
from source)
* [STM32F746 Discovery kit](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
(using Mbed)
* [Adafruit EdgeBadge](https://www.adafruit.com/product/4400) (using Arduino
IDE)
* [Adafruit TensorFlow Lite for Microcontrollers Kit](https://www.adafruit.com/product/4317)
(using Arduino IDE)
* [Adafruit Circuit Playground Bluefruit](https://learn.adafruit.com/tensorflow-lite-for-circuit-playground-bluefruit-quickstart?view=all)
(using Arduino IDE)
* [Espressif ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview)
(using ESP IDF)
* [Espressif ESP-EYE](https://www.espressif.com/en/products/hardware/esp-eye/overview)
(using ESP IDF)
Learn more about supported platforms in
[TensorFlow Lite for Microcontrollers](index.md).
## Train a model
Note: You can skip this section and use the trained model included in the
example code.
Use
[train.py](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/hello_world/train.py)
for hello world model training for sinwave recognition
Run: `bazel build tensorflow/lite/micro/examples/hello_world:train`
`bazel-bin/tensorflow/lite/micro/examples/hello_world/train --save_tf_model
--save_dir=/tmp/model_created/`
## Run inference
To run the model on your device, we will walk through the instructions in the
`README.md`:
<a class="button button-primary" href="https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world/README.md">Hello
World README.md</a>
The following sections walk through the example's
[`evaluate_test.cc`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world/evaluate_test.cc),
unit test which demonstrates how to run inference using TensorFlow Lite for
Microcontrollers. It loads the model and runs inference several times.
### 1. Include the library headers
To use the TensorFlow Lite for Microcontrollers library, we must include the
following header files:
```C++
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/version.h"
```
- [`micro_mutable_op_resolver.h`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/micro_mutable_op_resolver.h)
provides the operations used by the interpreter to run the model.
- [`micro_error_reporter.h`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h)
outputs debug information.
- [`micro_interpreter.h`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/micro_interpreter.h)
contains code to load and run models.
- [`schema_generated.h`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/schema/schema_generated.h)
contains the schema for the TensorFlow Lite
[`FlatBuffer`](https://google.github.io/flatbuffers/) model file format.
- [`version.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/version.h)
provides versioning information for the TensorFlow Lite schema.
### 2. Include the model header
The TensorFlow Lite for Microcontrollers interpreter expects the model to be
provided as a C++ array. The model is defined in `model.h` and `model.cc` files.
The header is included with the following line:
```C++
#include "tensorflow/lite/micro/examples/hello_world/model.h"
```
### 3. Include the unit test framework header
In order to create a unit test, we include the TensorFlow Lite for
Microcontrollers unit test framework by including the following line:
```C++
#include "tensorflow/lite/micro/testing/micro_test.h"
```
The test is defined using the following macros:
```C++
TF_LITE_MICRO_TESTS_BEGIN
TF_LITE_MICRO_TEST(LoadModelAndPerformInference) {
. // add code here
.
}
TF_LITE_MICRO_TESTS_END
```
We now discuss the code included in the macro above.
### 4. Set up logging
To set up logging, a `tflite::ErrorReporter` pointer is created using a pointer
to a `tflite::MicroErrorReporter` instance:
```C++
tflite::MicroErrorReporter micro_error_reporter;
tflite::ErrorReporter* error_reporter = &micro_error_reporter;
```
This variable will be passed into the interpreter, which allows it to write
logs. Since microcontrollers often have a variety of mechanisms for logging, the
implementation of `tflite::MicroErrorReporter` is designed to be customized for
your particular device.
### 5. Load a model
In the following code, the model is instantiated using data from a `char` array,
`g_model`, which is declared in `model.h`. We then check the model to ensure its
schema version is compatible with the version we are using:
```C++
const tflite::Model* model = ::tflite::GetModel(g_model);
if (model->version() != TFLITE_SCHEMA_VERSION) {
TF_LITE_REPORT_ERROR(error_reporter,
"Model provided is schema version %d not equal "
"to supported version %d.\n",
model->version(), TFLITE_SCHEMA_VERSION);
}
```
### 6. Instantiate operations resolver
A
[`MicroMutableOpResolver`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/micro_mutable_op_resolver.h)
instance is declared. This will be used by the interpreter to register and
access the operations that are used by the model:
```C++
using HelloWorldOpResolver = tflite::MicroMutableOpResolver<1>;
TfLiteStatus RegisterOps(HelloWorldOpResolver& op_resolver) {
TF_LITE_ENSURE_STATUS(op_resolver.AddFullyConnected());
return kTfLiteOk;
```
The `MicroMutableOpResolver`requires a template parameter indicating the number
of ops that will be registered. The `RegisterOps` function registers the ops
with the resolver.
```C++
HelloWorldOpResolver op_resolver;
TF_LITE_ENSURE_STATUS(RegisterOps(op_resolver));
```
### 7. Allocate memory
We need to preallocate a certain amount of memory for input, output, and
intermediate arrays. This is provided as a `uint8_t` array of size
`tensor_arena_size`:
```C++
const int tensor_arena_size = 2 * 1024;
uint8_t tensor_arena[tensor_arena_size];
```
The size required will depend on the model you are using, and may need to be
determined by experimentation.
### 8. Instantiate interpreter
We create a `tflite::MicroInterpreter` instance, passing in the variables
created earlier:
```C++
tflite::MicroInterpreter interpreter(model, resolver, tensor_arena,
tensor_arena_size, error_reporter);
```
### 9. Allocate tensors
We tell the interpreter to allocate memory from the `tensor_arena` for the
model's tensors:
```C++
interpreter.AllocateTensors();
```
### 10. Validate input shape
The `MicroInterpreter` instance can provide us with a pointer to the model's
input tensor by calling `.input(0)`, where `0` represents the first (and only)
input tensor:
```C++
// Obtain a pointer to the model's input tensor
TfLiteTensor* input = interpreter.input(0);
```
We then inspect this tensor to confirm that its shape and type are what we are
expecting:
```C++
// Make sure the input has the properties we expect
TF_LITE_MICRO_EXPECT_NE(nullptr, input);
// The property "dims" tells us the tensor's shape. It has one element for
// each dimension. Our input is a 2D tensor containing 1 element, so "dims"
// should have size 2.
TF_LITE_MICRO_EXPECT_EQ(2, input->dims->size);
// The value of each element gives the length of the corresponding tensor.
// We should expect two single element tensors (one is contained within the
// other).
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]);
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[1]);
// The input is a 32 bit floating point value
TF_LITE_MICRO_EXPECT_EQ(kTfLiteFloat32, input->type);
```
The enum value `kTfLiteFloat32` is a reference to one of the TensorFlow Lite
data types, and is defined in
[`common.h`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/c/common.h).
### 11. Provide an input value
To provide an input to the model, we set the contents of the input tensor, as
follows:
```C++
input->data.f[0] = 0.;
```
In this case, we input a floating point value representing `0`.
### 12. Run the model
To run the model, we can call `Invoke()` on our `tflite::MicroInterpreter`
instance:
```C++
TfLiteStatus invoke_status = interpreter.Invoke();
if (invoke_status != kTfLiteOk) {
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed\n");
}
```
We can check the return value, a `TfLiteStatus`, to determine if the run was
successful. The possible values of `TfLiteStatus`, defined in
[`common.h`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/c/common.h),
are `kTfLiteOk` and `kTfLiteError`.
The following code asserts that the value is `kTfLiteOk`, meaning inference was
successfully run.
```C++
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status);
```
### 13. Obtain the output
The model's output tensor can be obtained by calling `output(0)` on the
`tflite::MicroInterpreter`, where `0` represents the first (and only) output
tensor.
In the example, the model's output is a single floating point value contained
within a 2D tensor:
```C++
TfLiteTensor* output = interpreter.output(0);
TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size);
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]);
TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[1]);
TF_LITE_MICRO_EXPECT_EQ(kTfLiteFloat32, output->type);
```
We can read the value directly from the output tensor and assert that it is what
we expect:
```C++
// Obtain the output value from the tensor
float value = output->data.f[0];
// Check that the output value is within 0.05 of the expected value
TF_LITE_MICRO_EXPECT_NEAR(0., value, 0.05);
```
### 14. Run inference again
The remainder of the code runs inference several more times. In each instance,
we assign a value to the input tensor, invoke the interpreter, and read the
result from the output tensor:
```C++
input->data.f[0] = 1.;
interpreter.Invoke();
value = output->data.f[0];
TF_LITE_MICRO_EXPECT_NEAR(0.841, value, 0.05);
input->data.f[0] = 3.;
interpreter.Invoke();
value = output->data.f[0];
TF_LITE_MICRO_EXPECT_NEAR(0.141, value, 0.05);
input->data.f[0] = 5.;
interpreter.Invoke();
value = output->data.f[0];
TF_LITE_MICRO_EXPECT_NEAR(-0.959, value, 0.05);
```
@@ -0,0 +1,112 @@
# TensorFlow Lite for Microcontrollers
TensorFlow Lite for Microcontrollers is designed to run machine learning models
on microcontrollers and other devices with only a few kilobytes of memory. The
core runtime just fits in 16 KB on an Arm Cortex M3 and can run many basic
models. It doesn't require operating system support, any standard C or C++
libraries, or dynamic memory allocation.
Note: The
[TensorFlow Lite for Microcontrollers Experiments](https://experiments.withgoogle.com/collection/tfliteformicrocontrollers)
features work by developers combining Arduino and TensorFlow to create awesome
experiences and tools. Check out the site for inspiration to create your own
TinyML projects.
## Why microcontrollers are important
Microcontrollers are typically small, low-powered computing devices that are
embedded within hardware that requires basic computation. By bringing machine
learning to tiny microcontrollers, we can boost the intelligence of billions of
devices that we use in our lives, including household appliances and Internet of
Things devices, without relying on expensive hardware or reliable internet
connections, which is often subject to bandwidth and power constraints and
results in high latency. This can also help preserve privacy, since no data
leaves the device. Imagine smart appliances that can adapt to your daily
routine, intelligent industrial sensors that understand the difference between
problems and normal operation, and magical toys that can help kids learn in fun
and delightful ways.
## Supported platforms
TensorFlow Lite for Microcontrollers is written in C++ 17 and requires a 32-bit
platform. It has been tested extensively with many processors based on the
[Arm Cortex-M Series](https://developer.arm.com/ip-products/processors/cortex-m)
architecture, and has been ported to other architectures including
[ESP32](https://www.espressif.com/en/products/hardware/esp32/overview). The
framework is available as an Arduino library. It can also generate projects for
development environments such as Mbed. It is open source and can be included in
any C++ 17 project.
The following development boards are supported:
* [Arduino Nano 33 BLE Sense](https://store-usa.arduino.cc/products/arduino-nano-33-ble-sense-with-headers)
* [SparkFun Edge](https://www.sparkfun.com/products/15170)
* [STM32F746 Discovery kit](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)
* [Adafruit EdgeBadge](https://www.adafruit.com/product/4400)
* [Adafruit TensorFlow Lite for Microcontrollers Kit](https://www.adafruit.com/product/4317)
* [Adafruit Circuit Playground Bluefruit](https://learn.adafruit.com/tensorflow-lite-for-circuit-playground-bluefruit-quickstart?view=all)
* [Espressif ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview)
* [Espressif ESP-EYE](https://www.espressif.com/en/products/hardware/esp-eye/overview)
* [Wio Terminal: ATSAMD51](https://www.seeedstudio.com/Wio-Terminal-p-4509.html)
* [Himax WE-I Plus EVB Endpoint AI Development Board](https://www.sparkfun.com/products/17256)
* [Synopsys DesignWare ARC EM Software Development Platform](https://www.synopsys.com/dw/ipdir.php?ds=arc-em-software-development-platform)
* [Sony Spresense](https://developer.sony.com/develop/spresense/)
## Explore the examples
Each example application is on
[Github](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples)
and has a `README.md` file that explains how it can be deployed to its supported
platforms. Some examples also have end-to-end tutorials using a specific
platform, as given below:
* [Hello World](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/hello_world) -
Demonstrates the absolute basics of using TensorFlow Lite for
Microcontrollers
* [Tutorial using any supported device](get_started_low_level.md)
* [Micro speech](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/micro_speech) -
Captures audio with a microphone to detect the words "yes" and "no"
* [Tutorial using SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow/#0)
* [Person detection](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples/person_detection) -
Captures camera data with an image sensor to detect the presence or absence
of a person
## Workflow
The following steps are required to deploy and run a TensorFlow model on a
microcontroller:
1. **Train a model**:
* *Generate a small TensorFlow model* that can fit your target device and
contains [supported operations](build_convert.md#operation-support).
* *Convert to a TensorFlow Lite model* using the
[TensorFlow Lite converter](build_convert.md#model-conversion).
* *Convert to a C byte array* using
[standard tools](build_convert.md#convert-to-a-c-array) to store it in a
read-only program memory on device.
2. **Run inference** on device using the [C++ library](library.md) and process
the results.
## Limitations
TensorFlow Lite for Microcontrollers is designed for the specific constraints of
microcontroller development. If you are working on more powerful devices (for
example, an embedded Linux device like the Raspberry Pi), the standard
TensorFlow Lite framework might be easier to integrate.
The following limitations should be considered:
* Support for a [limited subset](build_convert.md#operation-support) of
TensorFlow operations
* Support for a limited set of devices
* Low-level C++ API requiring manual memory management
* On device training is not supported
## Next steps
* [Get started with microcontrollers](get_started_low_level.md) to try the
example application and learn how to use the API.
* [Understand the C++ library](library.md) to learn how to use the library in
your own project.
* [Build and convert models](build_convert.md) to learn more about training
and converting models for deployment on microcontrollers.
@@ -0,0 +1,185 @@
# Understand the C++ library
The TensorFlow Lite for Microcontrollers C++ library is part of the
[TensorFlow repository](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro).
It is designed to be readable, easy to modify, well-tested, easy to integrate,
and compatible with regular TensorFlow Lite.
The following document outlines the basic structure of the C++ library and
provides information about creating your own project.
## File structure
The
[`micro`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro)
root directory has a relatively simple structure. However, since it is located
inside of the extensive TensorFlow repository, we have created scripts and
pre-generated project files that provide the relevant source files in isolation
within various embedded development environments.
### Key files
The most important files for using the TensorFlow Lite for Microcontrollers
interpreter are located in the root of the project, accompanied by tests:
```
[`micro_mutable_op_resolver.h`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/micro_mutable_op_resolver.h)
can be used to provide the operations used by the interpreter to run the
model.
```
- [`micro_error_reporter.h`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h)
outputs debug information.
- [`micro_interpreter.h`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/micro_interpreter.h)
contains code to handle and run models.
See [Get started with microcontrollers](get_started_low_level.md) for a
walkthrough of typical usage.
The build system provides for platform-specific implementations of certain
files. These are located in a directory with the platform name, for example
[`cortex-m`](https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/cortex_m_generic).
Several other directories exist, including:
- [`kernel`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/kernels),
which contains operation implementations and the associated code.
- [`tools`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/tools),
which contains build tools and their output.
- [`examples`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/examples),
which contains sample code.
## Start a new project
We recommend using the *Hello World* example as a template for new projects. You
can obtain a version of it for your platform of choice by following the
instructions in this section.
### Use the Arduino library
If you are using Arduino, the *Hello World* example is included in the
`Arduino_TensorFlowLite` Arduino library, which you can manually install in the
Arduino IDE and in [Arduino Create](https://create.arduino.cc/).
Once the library has been added, go to `File -> Examples`. You should see an
example near the bottom of the list named `TensorFlowLite:hello_world`. Select
it and click `hello_world` to load the example. You can then save a copy of the
example and use it as the basis of your own project.
### Generate projects for other platforms
TensorFlow Lite for Microcontrollers is able to generate standalone projects
that contain all of the necessary source files, using a `Makefile`. The current
supported environments are Keil, Make, and Mbed.
To generate these projects with Make, clone the
[TensorFlow/tflite-micro repository](https://github.com/tensorflow/tflite-micro)
and run the following command:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile generate_projects
```
This will take a few minutes, since it has to download some large toolchains for
the dependencies. Once it has finished, you should see some folders created
inside a path like `gen/linux_x86_64/prj/` (the
exact path depends on your host operating system). These folders contain the
generated project and source files.
After running the command, you'll be able to find the *Hello World* projects in
`gen/linux_x86_64/prj/hello_world`. For
example, `hello_world/keil` will contain the Keil project.
## Run the tests
To build the library and run all of its unit tests, use the following command:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile test
```
To run an individual test, use the following command, replacing `<test_name>`
with the name of the test:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile test_<test_name>
```
You can find the test names in the project's Makefiles. For example,
`examples/hello_world/Makefile.inc` specifies the test names for the *Hello
World* example.
## Build binaries
To build a runnable binary for a given project (such as an example application),
use the following command, replacing `<project_name>` with the project you wish
to build:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile <project_name>_bin
```
For example, the following command will build a binary for the *Hello World*
application:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile hello_world_bin
```
By default, the project will be compiled for the host operating system. To
specify a different target architecture, use `TARGET=` and `TARGET_ARCH=`. The
following example shows how to build the *Hello World* example for a generic
cortex-m0:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_generic TARGET_ARCH=cortex-m0 hello_world_bin
```
When a target is specified, any available target-specific source files will be
used in place of the original code. For example, the subdirectory
`examples/hello_world/cortex_m_generic` contains SparkFun Edge implementations
of the files `constants.cc` and `output_handler.cc`, which will be used when the
target `cortex_m_generic` is specified.
You can find the project names in the project's Makefiles. For example,
`examples/hello_world/Makefile.inc` specifies the binary names for the *Hello
World* example.
## Optimized kernels
The reference kernels in the root of `tensorflow/lite/micro/kernels` are
implemented in pure C/C++, and do not include platform-specific hardware
optimizations.
Optimized versions of kernels are provided in subdirectories. For example,
`kernels/cmsis-nn` contains several optimized kernels that make use of Arm's
CMSIS-NN library.
To generate projects using optimized kernels, use the following command,
replacing `<subdirectory_name>` with the name of the subdirectory containing the
optimizations:
```bash
make -f tensorflow/lite/micro/tools/make/Makefile TAGS=<subdirectory_name> generate_projects
```
You can add your own optimizations by creating a new subfolder for them. We
encourage pull requests for new optimized implementations.
## Generate the Arduino library
If you need to generate a new build of the library, you can run the following
script from the TensorFlow repository:
```bash
./tensorflow/lite/micro/tools/ci_build/test_arduino.sh
```
The resulting library can be found in
`gen/arduino_x86_64/prj/tensorflow_lite.zip`.
## Port to new devices
Guidance on porting TensorFlow Lite for Microcontrollers to new platforms and
devices can be found in
[`micro/docs/new_platform_support.md`](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/docs/new_platform_support.md).