espressif / esp-tflite-micro

TensorFlow Lite Micro for Espressif Chipsets
Apache License 2.0
395 stars 85 forks source link

hello_world with ESP-BOX-LITE (esp32-s3) #51

Closed ozanoner closed 1 year ago

ozanoner commented 1 year ago

The _helloworld example doesn't seem working on ESP-BOX-LITE (esp32-s3) as supposed. the result of the inference is always the same for all inputs. The example is a bit modified to show the y_quantized value.

y_value: 1.0420598*2^0 y_quantized: 127

$ idf.py --version
ESP-IDF v4.4.4-1-g6727a4f775

$ git remote -v
origin  https://github.com/espressif/tflite-micro-esp-examples.git (fetch)
origin  https://github.com/espressif/tflite-micro-esp-examples.git (push)

$ git log -1
commit 5f3c9064b60f9cd1f1ee0fcd6a0a8539d9c7dc50 (HEAD -> master, origin/master, origin/HEAD)
Merge: 8b518cd c08362b
Author: Vikram <vikram.dattu@espressif.com>
Date:   Fri Jun 9 16:43:38 2023 +0800

    Merge branch 'support/update_esp_nn' into 'master'

    Update esp-nn submodule

    See merge request app-frameworks/tflite-micro-esp-examples!100

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   main/main_functions.cc

$ pwd
$HOME/tflite-micro-esp-examples/examples/hello_world

--- idf_monitor on /dev/ttyACM0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x40048df9
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x17cc
load:0x403c9700,len:0xe78
load:0x403cc700,len:0x310c
entry 0x403c9980
I (24) boot: ESP-IDF v4.4.4-1-g6727a4f775 2nd stage bootloader
I (25) boot: compile time 00:55:36
I (25) boot: chip revision: v0.1
I (28) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (35) qio_mode: Enabling default flash chip QIO
I (40) boot.esp32s3: Boot SPI Speed : 80MHz
I (45) boot.esp32s3: SPI Mode       : QIO
I (49) boot.esp32s3: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (70) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (85) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0b030h ( 45104) map
I (120) esp_image: segment 1: paddr=0001b058 vaddr=3fc905a0 size=0280ch ( 10252) load
I (123) esp_image: segment 2: paddr=0001d86c vaddr=40374000 size=027ach ( 10156) load
I (132) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=1ba5ch (113244) map
I (155) esp_image: segment 4: paddr=0003ba84 vaddr=403767ac size=09df0h ( 40432) load
I (168) boot: Loaded app from partition at offset 0x10000
I (169) boot: Disabling RNG early entropy source...
I (180) cpu_start: Pro cpu up.
I (180) cpu_start: Starting app cpu, entry point is 0x40375160
0x40375160: call_start_cpu1 at /home/esp32b2/esp/esp-idf/components/esp_system/port/cpu_start.c:148

I (0) cpu_start: App cpu up.
I (194) cpu_start: Pro cpu start user code
I (194) cpu_start: cpu freq: 160000000
I (194) cpu_start: Application information:
I (197) cpu_start: Project name:     hello_world
I (202) cpu_start: App version:      5f3c906
I (207) cpu_start: Compile time:     Jun 13 2023 01:02:05
I (213) cpu_start: ELF file SHA256:  0583855cdc69b5fe...
I (219) cpu_start: ESP-IDF:          v4.4.4-1-g6727a4f775
I (225) heap_init: Initializing. RAM available for dynamic allocation:
I (232) heap_init: At 3FC940A8 len 00055668 (341 KiB): D/IRAM
I (239) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (245) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (252) heap_init: At 600FE000 len 00002000 (8 KiB): RTCRAM
I (258) spi_flash: detected chip: gd
I (262) spi_flash: flash io: qio
W (266) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (280) sleep: Configure to isolate all GPIO pins in sleep state
I (286) sleep: Enable automatic switching of GPIO sleep configuration
I (293) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
y_quantized: 127

x_value: 1.0*2^-127, y_value: 1.0420598*2^0

y_quantized: 127

x_value: 1.2566366*2^-2, y_value: 1.0420598*2^0

y_quantized: 127

x_value: 1.2566366*2^-1, y_value: 1.0420598*2^0

y_quantized: 127

x_value: 1.8849551*2^-1, y_value: 1.0420598*2^0

y_quantized: 127

x_value: 1.2566366*2^0, y_value: 1.0420598*2^0

The same example works on ESP32-C3-DevKitM-1 v1.0 without an issue:

--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xc (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x1834
load:0x403cc710,len:0xc28
load:0x403ce710,len:0x2dfc
entry 0x403cc710
I (30) boot: ESP-IDF v4.4.4-1-g6727a4f775 2nd stage bootloader
I (30) boot: compile time 01:19:32
I (30) boot: chip revision: v0.3
I (33) qio_mode: Enabling default flash chip QIO
I (39) boot.esp32c3: SPI Speed      : 80MHz
I (43) boot.esp32c3: SPI Mode       : QIO
I (48) boot.esp32c3: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label            Usage          Type ST Offset   Length
I (69) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (77) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (84) boot:  2 factory          factory app      00 00 00010000 00100000
I (92) boot: End of partition table
I (96) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=0a140h ( 41280) map
I (110) esp_image: segment 1: paddr=0001a168 vaddr=3fc8a200 size=013a0h (  5024) load
I (113) esp_image: segment 2: paddr=0001b510 vaddr=40380000 size=04b08h ( 19208) load
I (124) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=17b20h ( 97056) map
I (143) esp_image: segment 4: paddr=00037b48 vaddr=40384b08 size=05680h ( 22144) load
I (151) boot: Loaded app from partition at offset 0x10000
I (151) boot: Disabling RNG early entropy source...
I (163) cpu_start: Pro cpu up.
I (172) cpu_start: Pro cpu start user code
I (172) cpu_start: cpu freq: 160000000
I (172) cpu_start: Application information:
I (175) cpu_start: Project name:     hello_world
I (180) cpu_start: App version:      5f3c906-dirty
I (185) cpu_start: Compile time:     Jun 13 2023 01:19:26
I (191) cpu_start: ELF file SHA256:  3f962536b2c50b47...
I (197) cpu_start: ESP-IDF:          v4.4.4-1-g6727a4f775
I (204) heap_init: Initializing. RAM available for dynamic allocation:
I (211) heap_init: At 3FC8CD10 len 0004FA00 (318 KiB): DRAM
I (217) heap_init: At 3FCDC710 len 00002950 (10 KiB): STACK/DRAM
I (224) heap_init: At 50000020 len 00001FE0 (7 KiB): RTCRAM
I (230) spi_flash: detected chip: generic
I (235) spi_flash: flash io: qio
W (239) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (252) sleep: Configure to isolate all GPIO pins in sleep state
I (258) sleep: Enable automatic switching of GPIO sleep configuration
I (265) cpu_start: Starting scheduler.
y_quantized: 4

x_value: 1.0*2^-127, y_value: 1.0*2^-127

y_quantized: 48

x_value: 1.2566366*2^-2, y_value: 1.4910772*2^-2

y_quantized: 70

x_value: 1.2566366*2^-1, y_value: 1.1183078*2^-1

y_quantized: 103

x_value: 1.8849551*2^-1, y_value: 1.677462*2^-1

y_quantized: 118

x_value: 1.2566366*2^0, y_value: 1.9316229*2^-1

y_quantized: 127
vikramdattu commented 1 year ago

Hi @ozanoner does disabling optimisations work as expected for you? If it does, please apply a patch to esp-nn mentioned here and share you observation if the issue is fixed.

ozanoner commented 1 year ago

Thank you! I confirm that the example works with NN optimisations disabled ( (Top) → ESP-NN → Optimization for nn functions ) and fix_mismatch.patch applied.