Failed to allocate memorty. Edge impulse

Hello,

I´ve trained a smalled detection dataset using impulse edge as shown in one of your youtube videos. Currently it only has two features, pedestrians and bikes. The model looks very promising but when I save the trained.tflite and lablels.txt in the cam and the execute the tf_face_recognition_1-py example I get the following error: “OSError: Failed to allocate memory. Requested 864, available 464, missing: 400”
You comment that the OpenMVH7, which is the one I am currently using, has arround 400 Kbytes for the binary size, I am guessing it has 464 kbytes. When I trained the network, in the transfer learning window I got a peak RAM usage of 270,3K and a ROM usage of 214,8K. I selected MobileNetV2 0.1 (final layer: 10 neurons, 0.1 dropout) because the page claims that the model is around 270K in size with default settings and optimizations. One pasted into the cam memory, it only takes 295K, so why am I getting the error?
Is because the program + the .tfflite file + the labels.txt file occupy 864K? If that´s the case, I´ve read that adding an SD card won´t make any difference because the constraint is the memory of the board itself, so, should I get the OpenMVH7PLUS in order to be able to use the nwtwork I trained?
I attach a screenshot of the Edge Impulse window and my tflite and labels files.

Thank you for your time and attention,

Asier
ei-heroofmonkeys-project-1-openmv-v0.zip (163 KB)

First this is in bytes not Kbytes:

Requested 864, available 464, missing: 400"

Which means you just need to make the model a few KBs smaller and it will work. Note the memory is also used for the framebuffer, TF buffers etc…

Actually I think you’re running out of heap memory in MicroPython, it’s hard to say for sure that error message looks old, which lines throws the error ? Also please update the firmware.

EDIT yes it’s the tensorflow library just running out of memory, I tested the model and it loads fine on the board with SDRAM, so like I said the model needs to be smaller.

Just a thought, what’s the point of finding faces then classifying if they are face or not, if find_features returns something it’s pedestrian… you might want to skip the haar cascade step and train and classify pedestrian vs bikes in one step.

Thank you for the answer. Regarding the firmware, I will try to upload the last version ASAP.
The line that throws the error is the 15th: net = tf.load(“trained.tflite”, load_to_fb=True)
I am completely new to neural networks so I followed the steps of the video and selected the smallest model impulse edge provides. How can I skip the haar cascade step? Is it done while training the neural network or in the code written in the IDE.
Finaly, getting the OpenMVH7PLUS would solve the insuficient memory issue?

You can try to retrain on smaller input images ex 48x48 or remove layers… About Haar, you can train a classifier on pedestrian vs bikes directly and classify every frame…And yes H7+ would also solve the issue.

I am trying to reduce the size if the images and the number of layers. However, I want to be able to find the bycicle or pedestrian in the picture and get its position so I guess I should also create a haar cascade for pedestrians and another one for bycicles. This will probably take to much space even if I reduce the size of the neural network, right?

The TF module doesn’t support localization yet, if will look at the input image as a whole will not try to find objects in it… Training cascades is harder to do but it should work. If you do train a cascade make sure to use Haar only and use the old format.

EDIT: We do have a TF sliding window example, but it runs extremely slow