I’m upgrading an application on an OpenMV Cam H7 from Firmware Version 4.3.3 using tf to 4.5.9 using ml. My .tflite model is 91kB and loads and runs with tf on V4.3.3. I changed tf.load(modelFile, load_to_fb=True) to ml.Model(modelFile, load_to_fb=True) for ml on V4.5.9, and am getting the error “Failed to allocate tensors” at this line and File “ml/model.py”, line 14, in init
Hi @ajacobs - Since you have the build environment working on your machine you can debug this by turning logs on in TensorFlow. We disable these by default as they use a ton of flash and would prevent us from enabling all the operators:
Just change this here: openmv/src/omv/ports/stm32/omv_portconfig.mk at master · openmv/openmv
From: -release.a
to -release_with_logs.a
. Then recompile your firmware for the H7, flash it with the IDE, and you’ll see more detailed errors from libtflm.
Firmware does not build with -release_with_logs.a, even with other models removed except my 93kb model.
/home/ajacobs/cache/gcc/bin/…/lib/gcc/arm-none-eabi/13.2.1/…/…/…/…/arm-none-eabi/bin/ld: /home/ajacobs/openmv/src/build/bin/firmware.elf section .text' will not fit in region
FLASH_TEXT’
/home/ajacobs/cache/gcc/bin/…/lib/gcc/arm-none-eabi/13.2.1/…/…/…/…/arm-none-eabi/bin/ld: region `FLASH_TEXT’ overflowed by 6036 bytes
Memory region Used Size Region Size %age Used
DTCM: 0 GB 128 KB 0.00%
ITCM: 64 KB 64 KB 100.00%
SRAM0: 512 KB 512 KB 100.00%
SRAM1: 284732 B 280 KB 99.31%
SRAM2: 8 KB 8 KB 100.00%
SRAM4: 64 KB 64 KB 100.00%
FLASH_FFS: 0 GB 128 KB 0.00%
FLASH_TEXT: 1841044 B 1792 KB 100.33%
collect2: error: ld returned 1 exit status
make: *** [/home/ajacobs/openmv/src/omv/ports/stm32/omv_portconfig.mk:725: firmware] Error 1
Comment out things in here: openmv/src/omv/boards/OPENMV4/imlib_config.h at master · openmv/openmv
Like find_barcodes and find_datamatrixes.
Build was successful with -release_with_logs.a, and with find_barcodes and find_datamatrixes commented out.
Immediately before ml.Model(modelFile, load_to_fb=True), Mem free: 128320 allocated: 164736.
error tflm_backend: Failed to resize buffer. Requested: 84640, available 74388, missing: 10252.
Yeah, you need more heap.
So, the reason the model is not working anymore is that we moved the tensor arena to the heap. It used to be on the frame buffer which is larger. However, this prevented the model from having state. So, while you can load the model to the frame buffer, the tensor arena for the model is on the heap always now so that the model can remember things.
Can you shrink the model slightly so it uses less RAM? Also, the H7 heap is like 267KB. Seems like something else is in the heap using up the space given 164736 bytes are already allocated.
The application is complex with touch screen, graphics, wifi, database, image analysis, motor controller, etc. The complete set of python files are 353K. The TF classification speed is a critical factor. I can continue to run it on the H7 R2 with the V4.3.3 firmware, or would it be better to port this over to the RT1062 or the H7 Plus with the latest firmware?
Yes, if you could move to the H7 Plus or RT1062 then the RAM issue is resolved. The H7 Plus is more or less 100% compatible with the H7 R2. You can put the R2 camera sensor on the H7 Plus to ensure the image sensor is the same. The RT1062 will be harder to port to as the pyb module is not available.