TensorFlow Lite for Microcontrollers

Overview

TensorFlow Lite for Microcontrollers

The TFLM code is currently in the process of being refactored out of the Tensorflow github repository into a standalone repo. This refactoring is currently in the initial stages and is expected to be completed towards the end of June 2021.

Build Status

Official Builds

Build Type Status
CI (Linux) CI
Code Sync Sync from Upstream TF

Community Supported Builds

Build Type Status
Arduino Arduino
Cortex-M Cortex-M
Sparkfun Edge Sparkfun Edge

Additional Documentation

Comments
  • lstm: micro speech model with lstm op running on HiFi5 DSP

    lstm: micro speech model with lstm op running on HiFi5 DSP

    opened by nyadla-sys 20
  • Couldn't open elf file generated by hello world example

    Couldn't open elf file generated by hello world example

    Hey, so I was attempting to build the hello world example for RISC-V target and then use Spike to run the subsequent binary file. These are the commands I used to do this:

    1. git clone https://github.com/tensorflow/tflite-micro.git
    2. cd tflite-micro
    3. make -f tensorflow/lite/micro/tools/make/Makefile third_party_downloads
    4. Change the target from riscv32_mcu to mcu_riscv in /tensorflow/lite/micro/tools/make/mcu_riscv_makefile.inc and in /tensorflow/lite/micro/examples/hello_world/riscv32_mcu/Makefile.inc
    5. Moved the flags -fnothreadsafe-statics and -fno-use-cxa-atexit from PLATFORM FLAGS to CXX FLAGS in /tensorflow/lite/micro/tools/make/targets/mcu_riscv_makefile.inc
    6. Changed -c11 to -gnu11 under CCFLAGS in /tensorflow/lite/micro/tools/make/Makefile
    7. Changed the functions fmin and fmax to min and max respectively in /tensorflow/lite/kernels/internal/min.h and /tensorflow/lite/kernels/internal/max.h.
    8. Run the command make -f tensorflow/lite/micro/tools/make/Makefile TARGET=mcu_riscv TARGET_ARCH=riscv32_mcu hello_world_bin
    9. Run the binary using Spike: spike --isa=rv32imafdc pk tensorflow/lite/micro/tools/make/gen/mcu_riscv_riscv32_mcu_default/bin/hello_world

    I've checked that the binary generated is indeed ELF 32-bit RISC-V executable, but still on running the final command, it shows bbl loader couldn't open ELF program: tensorflow/lite/micro/tools/make/gen/mcu_riscv_riscv32_mcu_default/bin/hello_world!

    Can anyone let me know what I'm doing wrong in this case??

    opened by iams07 16
  • Trouble using Make to build examples.

    Trouble using Make to build examples.

    I'm seeing build errors with the different TFLM build attempts I've been making. I have not tried a Bazel build, if there are build instructions on how to do a Bazel build for this repo on Windows I would try that, currently I am trying to build with a Make project. I am successfully building Tensorflow Lite (from the main Tensorflow repo) with CMake, but with that build I don't have clarity on what is just needed for TFLM.

    Build attempt #1:

    Following the first Micro Speech example "Deploy to ARC EM SDP" found here: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/micro_speech

    Command line commands from an empty folder: git clone https://github.com/tensorflow/tflite-micro tflite-micro cd tflite-micro make -f tensorflow/lite/micro/tools/make/Makefile TARGET=arc_emsdp ARC_TAGS=reduce_codesize OPTIMIZED_KERNEL_DIR=arc_mli generate_micro_speech_mock_make_project

    Result: Several packages are downloaded, but the end result is "make: *** No rule to make target 'generate_micro_speech_mock_make_project'. Stop."

    Build attempt #2:

    Following the Micro Speech example "Deploy to ESP32" found here: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/micro_speech

    ESP IDF should be properly installed.

    Command line commands from an empty folder: git clone https://github.com/tensorflow/tflite-micro tflite-micro cd tflite-micro make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_micro_speech_esp_project

    Result: There are a couple "FIND: Parameter format not correct" messages and "File not found - *.cc", "File not found - *.h". It appears that pigweed is downloaded, along with some other packages. Ultimately, the build fails with "make: *** No rule to make target 'generate_micro_speech_esp_project'. Stop.".

    Build attempt #3:

    Following the Micro Speech example "Deploy to Sparkfun Edge" found here: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/micro_speech

    Command line commands from an empty folder: git clone https://github.com/tensorflow/tflite-micro tflite-micro cd tflite-micro make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge OPTIMIZED_KERNEL_DIR=cmsis_nn micro_speech_bin

    Results: Essentially the same results as build attempt #2 above.

    Build attempt #4:

    Following the Micro Speech example "Deploy to STM32F746" found here: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/micro_speech

    Command line commands from an empty folder: git clone https://github.com/tensorflow/tflite-micro tflite-micro cd tflite-micro make -f tensorflow/lite/micro/tools/make/Makefile TARGET=disco_f746ng OPTIMIZED_KERNEL_DIR=cmsis_nn generate_micro_speech_mbed_project

    Same results as above.

    Build attempt #5:

    Following the Hello World example "Deploy to SparkFun Edge" found here: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/hello_world

    Command line commands from an empty folder: git clone https://github.com/tensorflow/tflite-micro tflite-micro cd tflite-micro make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge hello_world_bin

    Same results as above.

    opened by embeddetech 14
  • Strange outputs

    Strange outputs

    Arduino 33 BLE Sense Tensorflow 2.5.0

    I have the following model, on Linux this model classifies all 20 images in an Acute Lymphoblastic Leukemia test set correctly:

    micro_op_resolver.AddAveragePool2D(); micro_op_resolver.AddConv2D(); micro_op_resolver.AddDepthwiseConv2D(); micro_op_resolver.AddReshape(); micro_op_resolver.AddFullyConnected(); micro_op_resolver.AddSoftmax();

    On Arduino 33 BLE Sense I am using JpegDecoder to decode the images from an SD and pass them to input->data.int8, I have also tested with the instructions for converting to c array in the following link: https://github.com/tensorflow/tflite-micro/blob/f583f92992c3c9dfb8e10f36d66b2fe7267cf7bc/tensorflow/lite/micro/examples/person_detection/person_image_data.h#L17-L20 with exact same results.

    It is not working well :D On Arduino I am always receiving an integer for positive and the negative of the integer for negative. IE:

    Positive image: Positive score: 111 Negative score: -111

    Negative image: Positive score: 74 Negative score: -74

    Nearly always 74, -74 for negative and nearly always 111, -111 for positive.

    At first I was simply reading the image in using SD.open ........ jpegFile.read() and looping through assigning to input->data.int8, but then I made a version that uses decodeSdFile and made a script based on the person detector project that does the grayscaling etc, but either way gets exactly the same results as above.

    Do you have any suggestions as to why this is happening, I don't have the experience with Arduino ML to work this out. Thanks in advance.

    opened by AdamMiltonBarker 12
  • make TARGET_ARCH and BUILD_TYPE variable could be overrided in target makefile

    make TARGET_ARCH and BUILD_TYPE variable could be overrided in target makefile

    In the latest source code of tflite-micro, TARGET_ARCH and BUILD_TYPE could not be override by Makefile of selected TARGET, this commit is trying to fix this issue introduced by PR #432

    Thanks Huaqi

    opened by fanghuaqi 10
  • Oreilly TinyML example build issue on Windows 10

    Oreilly TinyML example build issue on Windows 10

    Oreilly TinyML example build issue: page 84 OS Windows x64 (cygwin)

    make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

    Log: $ make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test FIND: Parameter format not correct FIND: Parameter format not correct File not found - *.cc File not found - *.h tensorflow/lite/micro/tools/make/downloads/flatbuffers already exists, skipping the download. tensorflow/lite/micro/tools/make/downloads/pigweed already exists, skipping the download. tensorflow/lite/micro/tools/make/downloads/person_model_int8 already exists, skipping the download. make: *** No rule to make target 'test_hello_world_test'. Stop.

    opened by vyosypenko 10
  • Revert

    Revert "Revert: PR #48758: TFLM: Remove uint8 support for CMSIS-NN ke…

    Some CMSIS-NN kernels are still having uint8 support.

    Remove uint8 support for remaining CMSIS-NN kernels.
    Remove uint8 support for equivalent reference kernels.
    Remove uint8 unit tests for equivalent kernels.
    Replace uint8 default model in network tester to a int8 model.
    

    This is a fix for: https://github.com/tensorflow/tflite-micro/issues/108

    This was previously merged and reverted in the old repo because of some unknown issue. There was also a revert of the reverted PR in the old repo, which this is based on. Here is that PR for more background: https://github.com/tensorflow/tensorflow/pull/49485

    cla: yes ci:run 
    opened by mansnils 10
  • Adding the TENSORFLOW_ROOT to the target tool chain path for cortex_m_generic

    Adding the TENSORFLOW_ROOT to the target tool chain path for cortex_m_generic

    • adding toolchain root so that the generated project can be set to the downloaded toolchain.

    make -f tensorflow/lite/micro/tools/make/Makefile generate_hello_world_make_project TARGET=cortex_m_generic TARGET_ARCH=cortex-m4+fp TENSORFLOW_ROOT=/path/to/tflite-micro

    the generated makefile will now have the correct path for the compiler

    in tools/make/gen/cortexm4_cortex-m4_micro/prj/xxxx/Makefile

    
      TARGET_TOOLCHAIN_ROOT := <path-to-tflite-micro>/tensorflow/lite/micro/tools/make/downloads/gcc_embedded/bin/
      TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
      
      # These are microcontroller-specific rules for converting the ELF output
      # of the linker into a binary image that can be loaded directly.
      CXX             := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)g++'
      CC              := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)gcc'
      AS              := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)as'
      AR              := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)ar'
      LD              := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)ld'
      NM              := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)nm'
      OBJDUMP         := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)objdump'
      OBJCOPY         := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)objcopy'
      SIZE            := '$(TARGET_TOOLCHAIN_ROOT)$(TARGET_TOOLCHAIN_PREFIX)size'
    
    

    BUG=fix makefile project generation.

    cla: yes 
    opened by cdknorow 9
  • fatal error: 'am_bsp.h' file not found

    fatal error: 'am_bsp.h' file not found

    While compiling the hello_world code for development machine, I keep getting the following error.

    tensorflow/lite//micro/sparkfun_edge/system_setup.cc:22:10: fatal error: 'am_bsp.h' file not found

    Wondering if it is just me or is it a known bug.

    opened by amitkac 9
  • Sigmoid,tanh: TFL int16 reference code compared to float implementation is off by 3-4 bits

    Sigmoid,tanh: TFL int16 reference code compared to float implementation is off by 3-4 bits

    @advaitjain , @njeffrie, @petewarden, @nyadla-sys

    Describe the problem

    TFL int16 reference code compared to float implementation is off by 3-4 bits (int8 is off by 1 bit). TFLM does not have int16 support yet. Sigmoid shows maxdiff of 6 (3 bit). Tanh shows maxdiff of 12 (4 bit). Cadence’s hardware implementation is 1 bit off and that’s how it was discovered that TFLM implementation was off A bug with test vectors will help the TFLM team figure out what needs to be done here

    Source code / logs

    input_file_sigmoid_Q12.txt input_file_tanh_Q12.txt Attached couple of files with input data which shows maximum difference. This input list is for Q12 (1 sign bit, 3 integer bits, 12 fractional bits). We also observed 3-4 bit difference for other Q format as well (Q11 and Q15).

    opened by lukmanr-cadence 9
  • Support for automatic MicroMutableOpResolver generation

    Support for automatic MicroMutableOpResolver generation

    Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

    System information

    • TensorFlow version (you are using): 2.5.0
    • Are you willing to contribute it (Yes/No): Yes

    Describe the feature and the current behavior/state. Currently, when using an interpreter in TFLM you need to manually add the desired operators, or use an AllOpsResolver. The first option is tedious, and the other has a significantly larger memory footprint.

    We propose an automatic way to generate a MicroMutableOpResolver with only the used operators in a given model.

    Will this change the current api? How? It can be a standalone script that takes a tflite file as input, which doesn't affect the existing API. Alternatively, it can be done at the convert stage, however, this limits the usage, as you cannot get the MicroMutableOpResolver from an existing tflite model.

    Who will benefit with this feature? Most TFLM users.

    Any Other info.

    opened by Sebastian-Larsson 8
  • [Request] Add code comments for inferencing APIs

    [Request] Add code comments for inferencing APIs

    Several essential classes and functions are missing code comments that would be helpful for new users who want to run inference with TFLM.

    I've already written several API doc comments for the coralmicro project, so I'll offer these in a pull request.

    opened by scottamain 0
  • Add API doc comments for core inferencing classes and functions

    Add API doc comments for core inferencing classes and functions

    These code comments cover the essential APIs needed to setup a MicroInterpreter and run inference with TFLM. The comments are written in a style that's intended for parsing into HTML with Doxygen. (RE: issue #1640)

    I originally created these code comments for the coralmicro API reference. (See info about building the API docs.)

    Basically all of the code comments are still the same as created for coralmicro, except I removed the ErrorReporter parameter from the MicroInterpreter constructor (no longer used in tflite-micro) and made a few new small copyedits.

    opened by scottamain 0
  • Performance considerably drops when invoking with tflite-micro compared to tflite

    Performance considerably drops when invoking with tflite-micro compared to tflite

    Given same tflite model, I have attempted to benchmark using tflite and tflite-micro. tflite benchmark https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/benchmark tflite micro benchmark https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/benchmarks However, there is a significant difference on its performance. Using same tflite model, tflite benchmark gives about 40ms for one interpreter->invoke process, while tflite micro benchmark gives about 1200ms for one interpreter->invoke process. Test log is attached. benchmark_log_from_tflite.log benchmark_log_from_tflite_micro.log

    Machine system info : x86_64 GNU/Linux Ubuntu22.04

    I question if this difference is expected. Any comments would be appreciated.

    opened by doo5643 0
  • Updated HiFi LSTM optimizations to latest refactored LSTM reference code

    Updated HiFi LSTM optimizations to latest refactored LSTM reference code

    Updated HiFi LSTM optimizations to latest refactored LSTM reference code. All kelnel_lstm_eval_test (10/10) and unidirectional_sequence_lstm_test (8/8) are passing okay.

    opened by vp-cad 0
  • Cannot open create_sine_model.ipynb

    Cannot open create_sine_model.ipynb

    I am going to the link that was posted in this discussion. However, when I open the link, it can't open the file. I also can't find create_sine_model.ipynb anywhere else. Screenshot 2022-12-21 125824

    opened by tinyBrkML 0
Owner
null
Want a faster ML processor? Do it yourself! -- A framework for playing with custom opcodes to accelerate TensorFlow Lite for Microcontrollers (TFLM).

CFU Playground Want a faster ML processor? Do it yourself! This project provides a framework that an engineer, intern, or student can use to design an

Google 331 Jan 1, 2023
TensorFlow Lite for Microcontrollers

TensorFlow Lite for Microcontrollers Build Status Official Builds Community Supported Builds Additional Documentation TensorFlow Lite for Microcontrol

null 998 Jan 3, 2023
KSAI Lite is a deep learning inference framework of kingsoft, based on tensorflow lite

KSAI Lite English | 简体中文 KSAI Lite是一个轻量级、灵活性强、高性能且易于扩展的深度学习推理框架,底层基于tensorflow lite,定位支持包括移动端、嵌入式以及服务器端在内的多硬件平台。 当前KSAI Lite已经应用在金山office内部业务中,并逐步支持金山

null 80 Dec 27, 2022
Openvino tensorflow - OpenVINO™ integration with TensorFlow

English | 简体中文 OpenVINO™ integration with TensorFlow This repository contains the source code of OpenVINO™ integration with TensorFlow, designed for T

OpenVINO Toolkit 169 Dec 23, 2022
Pose-tensorflow - Human Pose estimation with TensorFlow framework

Human Pose Estimation with TensorFlow Here you can find the implementation of the Human Body Pose Estimation algorithm, presented in the DeeperCut and

Eldar Insafutdinov 1.1k Dec 29, 2022
TensorFlow Lite, Coral Edge TPU samples (Python/C++, Raspberry Pi/Windows/Linux).

TensorFlow Lite, Coral Edge TPU samples (Python/C++, Raspberry Pi/Windows/Linux).

Nobuo Tsukamoto 87 Nov 16, 2022
Swapping face using Face Mesh with TensorFlow Lite

demo.mp4 Aiine Transform (アイン変換) Swapping face using FaceMesh. (could be used to unveil masked faces) Tested Environment Computer Windows 10 (x64) + V

iwatake 17 Apr 26, 2022
A demo to run tensorflow-lite on Penglai TEE.

Documentation TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries, a

IPADS 4 Dec 15, 2021
Helper Class for Deep Learning Inference Frameworks: TensorFlow Lite, TensorRT, OpenCV, ncnn, MNN, SNPE, Arm NN, NNAbla

InferenceHelper This is a helper class for deep learning frameworks especially for inference This class provides an interface to use various deep lear

iwatake 192 Dec 26, 2022
Lite.AI.ToolKit 🚀🚀🌟: A lite C++ toolkit of awesome AI models such as RobustVideoMatting🔥, YOLOX🔥, YOLOP🔥 etc.

Lite.AI.ToolKit ?? ?? ?? : A lite C++ toolkit of awesome AI models which contains 70+ models now. It's a collection of personal interests. Such as RVM, YOLOX, YOLOP, YOLOR, YoloV5, DeepLabV3, ArcFace, etc.

DefTruth 2.4k Jan 9, 2023
Spying on Microcontrollers using Current Sensing and embedded TinyML models

Welcome to CurrentSense-TinyML CurrentSense-TinyML is all about detecting microcontroller behaviour with current sensing and TinyML. Basically we are

Santander Security Research 71 Sep 17, 2022
Deep Learning API and Server in C++11 support for Caffe, Caffe2, PyTorch,TensorRT, Dlib, NCNN, Tensorflow, XGBoost and TSNE

Open Source Deep Learning Server & API DeepDetect (https://www.deepdetect.com/) is a machine learning API and server written in C++11. It makes state

JoliBrain 2.4k Dec 30, 2022
Training and Evaluating Facial Classification Keras Models using the Tensorflow C API Implemented into a C++ Codebase.

CFace Training and Evaluating Facial Classification Keras Models using the Tensorflow C API Implemented into a C++ Codebase. Dependancies Tensorflow 2

null 7 Oct 18, 2022
OpenEmbedding is an open source framework for Tensorflow distributed training acceleration.

OpenEmbedding English version | 中文版 About OpenEmbedding is an open-source framework for TensorFlow distributed training acceleration. Nowadays, many m

4Paradigm 19 Jul 25, 2022
TensorFlow implementation of SQN based on RandLA-Net's encoder

SQN_tensorflow This repo is a TensorFlow implementation of Semantic Query Network (SQN). For Pytorch implementation, check our SQN_pytorch repo. Our i

PointCloudYC 9 Nov 3, 2022
PSTensor provides a way to hack the memory management of tensors in TensorFlow and PyTorch by defining your own C++ Tensor Class.

PSTensor : Custimized a Tensor Data Structure Compatible with PyTorch and TensorFlow. You may need this software in the following cases. Manage memory

Jiarui Fang 8 Feb 12, 2022
Movenet cpp deploy; model transformed from tensorflow

MoveNet-PaddleLite Adapted from PaddleDetection; Movenet cpp deploy based on PaddleLite; Movenet model transformed from tensorflow; 简介 Movenet是近年的优秀开源

null 11 Dec 27, 2022
DeepRec is a recommendation engine based on TensorFlow.

DeepRec Introduction DeepRec is a recommendation engine based on TensorFlow 1.15, Intel-TensorFlow and NVIDIA-TensorFlow. Background Sparse model is a

Alibaba 673 Dec 29, 2022
Lite.AI 🚀🚀🌟 is a user-friendly C++ lib for awesome🔥🔥🔥 AI models based on onnxruntime, ncnn or mnn. YOLOX, YoloV5, YoloV4, DeepLabV3, ArcFace, CosFace, Colorization, SSD

Lite.AI ?????? is a user-friendly C++ lib for awesome?????? AI models based on onnxruntime, ncnn or mnn. YOLOX??, YoloV5??, YoloV4??, DeepLabV3??, ArcFace??, CosFace??, Colorization??, SSD??, etc.

Def++ 2.4k Jan 4, 2023