TensorFlow Lite Micro: Embedded Machine Learning on TinyML Systems

Robert David, Jared Duke, Advait Jain, Vijay Janapa Reddi, Nat Jeffries, Jian Li, Nick Kreeger, Ian Nappier, Meghna Natraj, Shlomi Regev, Rocky Rhodes, Tiezhen Wang, Pete WardenarXiv 2020

Abstract

Deep learning inference on embedded devices is a burgeoning field with myriad applications because tiny embedded devices are omnipresent. But we must overcome major challenges before we can benefit from this opportunity. Embedded processors are severely resource constrained. Their nearest mobile counterparts exhibit at least a 100 -- 1,000x difference in compute capability, memory availability, and power consumption. As a result, the machine-learning (ML) models and associated ML inference framework must not only execute efficiently but also operate in a few kilobytes of memory. Also, the embedded devices' ecosystem is heavily fragmented. To maximize efficiency, system vendors often omit many features that commonly appear in mainstream systems, including dynamic memory allocation and virtual memory, that allow for cross-platform interoperability. The hardware comes in many flavors (e.g., instruction-set architecture and FPU support, or lack thereof). We introduce TensorFlow Lite Micro (TF Micro), an open-source ML inference framework for running deep-learning models on embedded systems. TF Micro tackles the efficiency requirements imposed by embedded-system resource constraints and the fragmentation challenges that make cross-platform interoperability nearly impossible. The framework adopts a unique interpreter-based approach that provides flexibility while overcoming these challenges. This paper explains the design decisions behind TF Micro and describes its implementation details. Also, we present an evaluation to demonstrate its low resource requirement and minimal run-time performance overhead.

Introduction

The world is full of microcontrollers—over 250 billion of them—but running machine learning on these devices is notoriously difficult. Unlike the standardized environments of mobile or desktop platforms, the embedded world is characterized by extreme hardware fragmentation and severe resource constraints. Devices often possess only a few hundred kilobytes of RAM and Flash, and they frequently lack basic software luxuries like dynamic memory allocation (malloc) or virtual memory.

TensorFlow Lite Micro (TFLM) aims to address these hurdles by providing a single, open-source framework that works across this fragmented landscape. It is designed to be the "Linux of TinyML," allowing hardware vendors to plug in their own optimizations while maintaining a portable, memory-efficient core.

System Architecture and Design

TFLM utilizes an unconventional interpreter-based approach. While many embedded tools use "code generation" to convert models directly into C code, TFLM’s interpreter makes it easier to update models in the field without re-compiling the entire firmware.

The TFLM architecture separates the interpreter from operator implementations, allowing for portability and hardware-specific optimization via a clear Operator API.

By defining clear boundaries through an Operator API, TFLM allows developers to write generic C++ code for portability while letting hardware vendors swap in highly optimized, assembly-level kernels (like Arm's CMSIS-NN) for specific chips. This modularity is key to overcoming hardware fragmentation without sacrificing performance.

Memory Management and Planning

To prevent memory fragmentation and crashes in long-running applications, TFLM avoids dynamic allocation. Instead, it requires a pre-allocated "memory arena" and uses a two-stack allocation strategy where persistent objects grow from the head and temporary scratch buffers grow from the tail.

Since memory is the scarcest resource, TFLM includes a Memory Planner that performs "bin packing" for tensors. It calculates the lifetime of every buffer and reuses the same memory space for different tensors at different times during the inference cycle.

TFLM's memory planner uses bin packing to reuse memory for tensors with non-overlapping lifetimes, significantly reducing the total RAM footprint compared to naive allocation.

Evaluation and Results

The framework was evaluated using two primary TinyML tasks: Visual Wake Words (VWW) for person detection and the Google Hotword model for low-latency audio processing. The results debunk the myth that interpreters are too slow for embedded systems; the interpreter overhead for the VWW model was less than 0.1% on a Cortex-M4 processor.

Key performance highlights include:

  • Memory Efficiency: The complex VWW model ran using only ~82KB of total RAM.
  • Significant Speedups: By using optimized vendor libraries through the TFLM API, the authors achieved a 4x speedup on VWW compared to reference C++ kernels. On specialized DSPs, optimization provided up to a 7.7x speedup.

Conclusion

TensorFlow Lite Micro provides a portable, memory-efficient way to run deep learning models across a highly fragmented hardware landscape with negligible performance overhead. While it currently requires manual memory arena sizing and modern C++ compilers, it represents a significant step toward standardizing machine learning for the hundreds of billions of microcontrollers in use today.

Summary updated

BibTeX
@misc{david2020tensorflow,
  author = {Robert David and Jared Duke and Advait Jain and Vijay Janapa Reddi and Nat Jeffries and Jian Li and Nick Kreeger and Ian Nappier and Meghna Natraj and Shlomi Regev and Rocky Rhodes and Tiezhen Wang and Pete Warden},
  title = {{TensorFlow Lite Micro: Embedded Machine Learning on TinyML Systems}},
  year = {2020},
  eprint = {2010.08678},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.08678},
}
Figure