Failed to allocate TFLite arena (error code 1) on Portenta

The FOMO model runs perfectly fine on the Portenta, but when I try to light up the LED_BUILTIN, it gives the Failed to allocate TFLite arena error.

The example code gives the following solution:

 ** NOTE: If you run into TFLite arena allocation issue.
 **
 ** This may be due to may dynamic memory fragmentation.
 ** Try defining "-DEI_CLASSIFIER_ALLOCATION_STATIC" in boards.local.txt (create
 ** if it doesn't exist) and copy this file to
 ** `<ARDUINO_CORE_INSTALL_PATH>/arduino/hardware/<mbed_core>/<core_version>/`.
 **
 ** See
 ** (https://support.arduino.cc/hc/en-us/articles/360012076960-Where-are-the-installed-cores-located-)
 ** to find where Arduino installs cores on your machine.
 **

I was successful in finding where it is located (even though the link does not work), but I am not sure how to edit the file, because the file expects a key=value format.

Hello @ElectricDragon,

The Failed to allocate TFLite arena is a memory issue, you can try to use a smaller EI model (reduce your window size or your image size is usually a good start).

For the option Try defining "-DEI_CLASSIFIER_ALLOCATION_STATIC" in boards.local.txt. I’ll check with our Embedded team if they have a deeper explanation. I’ll add it to our documentation too.

Regards,

Louis

1 Like

Okay thanks a lot! Let me know where to exactly add the flag in the boards.local.txt file

@ElectricDragon

Hi the URL looks to no longer be working. I’ve find the newer URL. You’d want to navigate to Board platforms and core and find the right path depending on your OS.

E.g. on Linux for the Portenta H7 using mbed core 2.8.0 and for the M7 you’d want to create boards.local.txt with the following path ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.8.0/boards.local.txt.

boards.local.txt:

envie_m7.build.extra_flags= -DEI_CLASSIFIER_ALLOCATION_STATIC

(Optional) For an example on how you can further expand boards.local.txt take a look at our example for our firmware repo. for our firmware repo.

1 Like

@ElectricDragon

The behavior you describe may be a memory fragmentation issue. Allocating the tensor arena may or may not solve the issue. It all depends on whether after allocating the tensor arena statically they’ll have enough memory for the rest of your application. Can you share the serial output when it fails and also the (led control) code snippet that causes the issue? And what’s the size of your model?

@rjames

This is the serial output


Starting inferencing in 2 seconds...
Taking photo...
Failed to allocate TFLite arena (error code 1)
ERR: Failed to run classifier (-6)

Following is the code for the led control:

if (bb.label == "bottle" && bb.value >= 0.90) {
   Serial.println("Bottle found!!!! with " + String(bb.value*100) + "% accuracy");
   digitalWrite(LED_BUILTIN, LOW); // further predictions failed after this line
}

I am not sure how to get the size of the model…can you tell me how to go about that?

@ElectricDragon,

you can get the size of the model from within the Deployment page of the Studio. A similar output:

.

@rjames,
Here is my model size

@ElectricDragon

Thank you. The model fits nicely in the Portenta. So I suspect your issue was due to memory fragmentation.
The combination of allocation/deallocation of the tensor arena (large area) with the alllocation/deallocation in your Serial.println("Bottle found!...") (small area) causses this. Did allocating the tensor arena statically solve your issue?

1 Like

@rjames

Yes it did…thanks a lot

1 Like

Please, could you assist with this case too?
I am using Arduino Nano 33 BLE Sense, and my model size is as shown below. I know that the RAM is 256kb for Nano BLE. Will this 254KB be the problem? Again, I have managed to locate the Boards.local.txt file, How can I redefine the “-DEI_CLASSIFIER_ALLOCATION_STATIC”

Thank you!

My Serial Monitor:

@Ipyana,

254K won’t work on the Arduino nano 33 BLE Sense with our firmware. 254K RAM is just for the model and doesn’t account for other parts of the firmware. The firmware uses more RAM more for the sensor(s), remote management and other processing, .etc…

Try reducing your model.
Another option, perhaps you don’t need all of the parts of firmware, is to write your own custom app. You can download the Arduino Library and work your way from there.

Regarding EI_CLASSIFIER_ALLOCATION_STATIC. Follow instructions here,

1 Like

Thank you very much for your assistance. I was indeed running inferences beyond what the firmware could afford. After I followed those instructions, I now run inferences smoothly on my Arduino Nano 33 BLE sense.

1 Like

Please, could you assist with this case too?

Output:
WARNING: library Arduino_OV767X claims to run on mbed architecture(s) and may be incompatible with your current board which runs on mbed_nano architecture(s).
Sketch uses 732936 bytes (74%) of program storage space. Maximum is 983040 bytes.
Global variables use 59488 bytes (22%) of dynamic memory, leaving 202656 bytes for local variables. Maximum is 262144 bytes.

I am using Arduino Nano 33 BLE Sense with a example called nano_ble33_sense_camera.ino. I obtained those images in my serial console, in my model and in my Arduino output

@soldeciara,

Your target does not have sufficient RAM to allocate the tensor arena (dynamically).
At compile time your program uses 22% RAM leaving about ~198 KB available for runtime usage. However your model is ~233 KB.
Try reducing your model under 198 KB.

(Optionally) See my previous post about defining EI_CLASSIFIER_ALLOCATION_STATIC, if you’d rather like to catch this kind of error at compile time than runtime.

1 Like

Thanks for the help, that did work.

Now I am working on another project and I am not sure how to import or join this data. I have my images on one side and I have created this csv file with the values ​​in each row for each image. Please, if you could tell me what steps to follow to import my data.