mocleiri / tensorflow-micropython-examples

A custom micropython firmware integrating tensorflow lite for microcontrollers and ulab to implement the tensorflow micro examples.
MIT License
170 stars 79 forks source link

Improve documentation around SPIRAM_USE_MALLOC versus SPIRAM_USE_MMAP on esp32. #72

Open mocleiri opened 2 years ago

mocleiri commented 2 years ago

For implementing person detection we got a change made in upstream micropython so that building the firmware using the SPIRAM_USE_MALLOC=y sdk config enables a sharing PSRAM mode where 1/2 of PSRAM goes into the Micropython Heap and the other 1/2 is available for other idf components.

For esp32s3 accelerated ops a scratch pad is also allocated and if your model is large enough you would want it allocated from PSRAM instead of DRAM.

Lets change the ESP32 documentation for person detection but also for ESP32 at the top level should add a section about this option.

MichaelDu9226 commented 2 years ago

Hi @mocleiri This is my step

  1. Under this branch, https://github.com/mocleiri/tensorflow-micropython-examples/tree/feature/9-add-accelerated-esp-tflm-kernels
  2. Merge this bugfix into esp-nn https://github.com/espressif/tflite-micro-esp-examples/pull/11
  3. Refer to this pull, edit micropython/ports/esp32/main.chttps://github.com/micropython/micropython/pull/8219. Maybe updating micropython submodule is a better way
  4. Based on my board, config esp32 s3 SPIRAM to CONFIG_SPIRAM_MODE_OCT=y & CONFIG_SPIRAM_USE_MALLOC=y
  5. Custom sd card support in micropython, save model into sd card, run dectection.py. Remember edit bytearray of model and tensor_area_len.
  6. The attached file is my custom model and detection.py custom_model.zip .