Running YOLOv5 Nano on ESP32-S3-EYE?

Polarbear17123
Posts: 10
Joined: Thu Sep 12, 2024 7:55 am

Running YOLOv5 Nano on ESP32-S3-EYE?

Postby Polarbear17123 » Thu Sep 12, 2024 8:42 am

Hello, and thank you for reading my question. I hope I am at the right group to ask.

I successfully compiled and loaded YOLOv5 nano using Tensor Flow lite Micro onto the ESP32-S3-EYE, using the hello_world template.
The Binary segment size is as followed:
text data bss dec hex filename
169,186 2,170,524 2,468,765 4,808,475 495f1b hello_world.elf

The Data segment size matched the size of the model parameters. And the total size (4.8M) fits within the 8M Available memory.
There is a comparable amount in the bss segment - but afaik tensor memory is dynamically allocated.

When run (see console output below) it fails on Tensor memory allocation. Tried to change the project setup in IDF but what not successful.
---------------------------------
Running now.
Failed to allocate tail memory. Requested: 4908, available 1716, missing: 3192
Failed to allocate memory for context->eval_tensors, 4908 bytes required
Failed starting model allocation.
AllocateTensors() failed

--------------------------------

I would like to ask is the following questions?
(1) Am I doing something wrong? (I am new to EPS32Se) - and if so what can I do, or read to help me solve this problem.
(2) How can I find the memory map of the system - how much is used by the RT-OS, and how much memory of the 8M is available to the program (and how can I maximize it)?
(3) How can I find how much memory was already allocated until it failed? -- Can Yolov5 Nano TF-lite Micro fit at all on the ESP32S3-EYE? I looked at github but all I could find was using the ESP32 Cam, to get the images, but the processing was done elsewhere (Raspberry-Pi), while I am trying to do the processing on the ESP32S3-EYE.
Thank you!

------------------------------ Console output ---------------------------------
ELF file SHA256: b6c2186c8
Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x2a (SPI_FAST_FLASH_BOOT)
Saved PC:0x4037598c
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x191c
load:0x403c8700,len:0x4
load:0x403c8704,len:0xe94
load:0x403cb700,len:0x3014
entry 0x403c8950
I (26) boot: ESP-IDF v5.4-dev-1523-gaf25eb447e 2nd stage bootloader
I (26) boot: compile time Jul 23 2024 21:41:29
I (27) boot: Multicore bootloader
I (31) boot: chip revision: v0.1
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 (50) boot.esp32s3: SPI Flash Size : 4MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label
Usage
Type ST Offset
Length
I (71) 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 00300000
I (93) boot: End of partition table
I (97) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=20f1e8h (2159080) map
I (433) esp_image: segment 1: paddr=0021f210 vaddr=3fc91200 size=00e08h ( 3592) load
I (434) esp_image: segment 2: paddr=00220020 vaddr=42000020 size=1b534h (111924) map
I (456) esp_image: segment 3: paddr=0023b55c vaddr=3fc92008 size=01afch ( 6908) load
I (457) esp_image: segment 4: paddr=0023d060 vaddr=40374000 size=0d13ch ( 53564) load
I (477) boot: Loaded app from partition at offset 0x10000I (477) boot: Disabling RNG early entropy source...
I (489) cpu_start: Multicore app
I (498) cpu_start: Pro cpu start user code
I (498) cpu_start: cpu freq: 160000000 Hz
I (498) app_init: Application information:
I (501) app_init: Project name:
hello_world
I (506) app_init: App version:
1
I (510) app_init: Compile time:
Jul 23 2024 21:41:22
I (516) app_init: ELF file SHA256: b6c2186c8...
I (522) app_init: ESP-IDF:
v5.4-dev-1523-gaf25eb447e
I (528) efuse_init: Min chip rev:
v0.0
I (533) efuse_init: Max chip rev:
v0.99
I (538) efuse_init: Chip rev:
v0.1
I (543) heap_init: Initializing. RAM available for dynamic allocation:
I (550) heap_init: At 3FC94D30 len 000549E0 (338 KiB): RAM
I (556) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (562) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (568) heap_init: At 600FE100 len 00001EE8 (7 KiB): RTCRAM

I (575) spi_flash: detected chip: gd
I (579) spi_flash: flash io: qio
W (582) spi_flash: Detected size(8192k) larger than the size in the binary image
header(4096k). Using the size in the binary image header.
I (596) sleep: Configure to isolate all GPIO pins in sleep state
I (603) sleep: Enable automatic switching of GPIO sleep configuration
I (610) main_task: Started on CPU0
I (620) main_task: Calling app_main()
YOLOv5 nano Test
This is esp32s3 chip with 2 CPU core(s), WiFi/BLE, silicon revision v0.1, 4MB external flash
Minimum free heap size: 391,724 bytes
call inference loop in 10 seconds...
call inference loop in 9 seconds...
call inference loop in 8 seconds...
call inference loop in 7 seconds...
call inference loop in 6 seconds...
call inference loop in 5 seconds...call inference loop in 4 seconds...
call inference loop in 3 seconds...
call inference loop in 2 seconds...
call inference loop in 1 seconds...
call inference loop in 0 seconds...
Running now.
Failed to allocate tail memory. Requested: 4908, available 1716, missing: 3192
Failed to allocate memory for context->eval_tensors, 4908 bytes required
Failed starting model allocation.
AllocateTensors() failed

Guru Meditation Error: Core0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC
: 0x42008a28 PS
A2
: 0x00000000 A3
A6
: 0x3fc94a48 A7
A10
: 0x00000000 A11
A14
: 0xffffffff A15
EXCVADDR: 0x00000008 LBEG: 0x00060430
: 0x3fc94180
: 0x00000000
: 0x41a00000
: 0x3fc94180
: 0x400556d5
A0
A4
A8
A12
SAR
LEND
: 0x82008834
: 0x00000000
: 0x3fc94a50
: 0x3fc94188
: 0x00000004
: 0x400556e5
A1
: 0x3fc978a0
A5
: 0x00000014
A9
: 0x3fc97890
A13
: 0x3fc940f8
EXCCAUSE: 0x0000001c
LCOUNT : 0xffffffff
Backtrace: 0x42008a25:0x3fc978a0 0x42008831:0x3fc978d0 0x4201afe4:0x3fc97910

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Running YOLOv5 Nano on ESP32-S3-EYE?

Postby ESP_Sprite » Fri Sep 13, 2024 12:19 am

Have you enabled PSRAM in menuconfig? If not, you can only use the internal RAM, and that's probably too little.

Polarbear17123
Posts: 10
Joined: Thu Sep 12, 2024 7:55 am

Re: Running YOLOv5 Nano on ESP32-S3-EYE?

Postby Polarbear17123 » Fri Sep 13, 2024 12:33 am

>>> Have you enabled PSRAM in menuconfig? If not, you can only use the internal RAM, and that's probably too little.

Thank you! and yes, I did, without it probably would not even load (it is a 4M image).
That said menuconfig setup is somewhat complex and I may not have the optimal setting for maximal utilization of the available memory.
If there is a document that explains the best setup specifically for the the EPS32-S3-EYE that would be very helpful!

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Running YOLOv5 Nano on ESP32-S3-EYE?

Postby ESP_Sprite » Fri Sep 13, 2024 2:05 am

You could remove your sdkconfig and drop this file in your project directory, then run menuconfig again. (Note you may need to select one of the default partition schemes there as that file uses a custom one.)

Polarbear17123
Posts: 10
Joined: Thu Sep 12, 2024 7:55 am

Re: Running YOLOv5 Nano on ESP32-S3-EYE?

Postby Polarbear17123 » Fri Sep 13, 2024 11:35 pm

Thank you!
Still fails to allocate tensor memory - the model is likely too big for the available memory :(

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 68 guests