Giter Club home page Giter Club logo

tensorflow-lite-esp32's Introduction

ko-fi

TensorFlow-Lite and Platform.io

This repo demonstrates how to use a TensorFlow model on the ESP32 using Platform.io.

There's a walkthrough video here: https://youtu.be/kZdIO82059E

Demo Video

Setup

To train the model you'll need a python environment. Make sure you have python 3 installed on your system:

python3 --version

Then run the following command to create a virtual python environment.

python3 -m venv venv

Activate the environment using:

. ./venv/bin/activate

And install the dependencies using:

pip install -r requirements.txt

Training the model

Make sure you have activated the virtual environment using:

. ./venv/bin/activate

Then run:

jupyter notebook .

Open up the train_model notebook and follow the instructions in the notebook.

Once you've trained and converted the model run:

xxd -i converted_model.tflite > firmware/src/model_data.cc

You can then open up the platform.io project in firmware folder and try it out.

tensorflow-lite-esp32's People

Contributors

cgreening avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorflow-lite-esp32's Issues

Code didn't upload

Picsart_22-04-29_18-36-44-829
I was compiled the code then the massage is successful but when i am upload the code it's said upload failed please tell me whats the reason for this please 🥺
Picsart_22-04-29_18-37-00-081

Ops Resolver

image

what is the purpose of using these ops resolvers in code? what is your intention, Mr.Chris?

DIY Alexa is not response

image

I correctly upload the codes but it's doesn't show any response when I am saying "Marvin" please help me I am waiting for your response I can't understand what is the reason for this please help me

Build failure: max.h:29:10: error: 'fmax' is not a member of 'std'

Compilation with all the newest versions of PlatformIO (5.2.0a5) and the espressif32 platform (3.1.0) gives

C:\Users\Max\temp\tensorflow-lite-esp32\firmware>pio run
Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
------------------------------------------------------------------------------------------------------------------------Tool Manager: Installing platformio/framework-arduinoespressif32 @ ~3.10005.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Tool Manager: framework-arduinoespressif32 @ 3.10005.210308 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10005.210308 (1.0.5)
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - toolchain-xtensa32 2.50200.97 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <tfmicro>
Building in release mode
[...]
Compiling .pio\build\esp32dev\lib296\tfmicro\tensorflow\lite\micro\kernels\softmax.cc.o
Compiling .pio\build\esp32dev\lib296\tfmicro\tensorflow\lite\micro\kernels\split.cc.o
In file included from lib\tfmicro/tensorflow/lite/kernels/internal/reference/reduce.h:21:0,
                 from lib\tfmicro\tensorflow\lite\micro\kernels\reduce.cc:16:
lib\tfmicro/tensorflow/lite/kernels/internal/max.h: In function 'T tflite::TfLiteMax(const T&, const T&)':
lib\tfmicro/tensorflow/lite/kernels/internal/max.h:29:10: error: 'fmax' is not a member of 'std'
   return std::fmax(x, y);
          ^
lib\tfmicro/tensorflow/lite/kernels/internal/max.h:29:10: note: suggested alternative:
In file included from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\cmath:44:0,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\random:38,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\bits\stl_algo.h:66,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\algorithm:62,
                 from lib\tfmicro\third_party\gemmlowp/fixedpoint/fixedpoint.h:21,
                 from lib\tfmicro/tensorflow/lite/kernels/internal/common.h:26,
                 from lib\tfmicro/tensorflow/lite/kernels/internal/reference/reduce.h:19,
                 from lib\tfmicro\tensorflow\lite\micro\kernels\reduce.cc:16:
C:\Users\Max\.platformio\packages\framework-arduinoespressif32\tools\sdk\include\newlib/math.h:284:15: note:   'fmax'
 extern double fmax _PARAMS((double, double));
               ^
In file included from lib\tfmicro/tensorflow/lite/kernels/internal/reference/reduce.h:22:0,
                 from lib\tfmicro\tensorflow\lite\micro\kernels\reduce.cc:16:
lib\tfmicro/tensorflow/lite/kernels/internal/min.h: In function 'T tflite::TfLiteMin(const T&, const T&)':
lib\tfmicro/tensorflow/lite/kernels/internal/min.h:29:10: error: 'fmin' is not a member of 'std'
   return std::fmin(x, y);
          ^
lib\tfmicro/tensorflow/lite/kernels/internal/min.h:29:10: note: suggested alternative:
In file included from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\cmath:44:0,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\random:38,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\bits\stl_algo.h:66,
                 from c:\users\max\.platformio\packages\[email protected]\xtensa-esp32-elf\include\c++\5.2.0\algorithm:62,
                 from lib\tfmicro\third_party\gemmlowp/fixedpoint/fixedpoint.h:21,
                 from lib\tfmicro/tensorflow/lite/kernels/internal/common.h:26,
                 from lib\tfmicro/tensorflow/lite/kernels/internal/reference/reduce.h:19,
                 from lib\tfmicro\tensorflow\lite\micro\kernels\reduce.cc:16:
C:\Users\Max\.platformio\packages\framework-arduinoespressif32\tools\sdk\include\newlib/math.h:285:15: note:   'fmin'
 extern double fmin _PARAMS((double, double));
               ^
*** [.pio\build\esp32dev\lib296\tfmicro\tensorflow\lite\micro\kernels\reduce.cc.o] Error 1
============================================= [FAILED] Took 42.69 seconds =============================================

Making PlatformIO use the master branch of Arduino-ESP32 and an 8.4.0 GCC makes the firmware build. Done so by adding

platform_packages =
  toolchain-xtensa32@~2.80400.0
  framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git

at the bottom of the platformio.ini.

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 0.0.0+sha.371f382
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - toolchain-xtensa32 2.80400.210114 (8.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 32 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <tfmicro>
Building in release mode
[..]
Indexing .pio\build\esp32dev\lib296\libtfmicro.a
Linking .pio\build\esp32dev\firmware.elf
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Building .pio\build\esp32dev\firmware.bin
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.1% (used 16608 bytes from 327680 bytes)
Flash: [==        ]  22.2% (used 291520 bytes from 1310720 bytes)
esptool.py v3.0
========== [SUCCESS] Took 27.70 seconds ==========

(To update the PlatformIO and platform packages, you can e.g. use a CLI and execute pio upgrade --dev and pio platform update espressif32)

But without these changes the firmware cannot compile.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.