tflite model not fitting in OpenMV Cam H7

I have an OpenMV Cam H7 and I trained a neural network, after quantization, it is 376 KB and when I load it using tf.load an error occurs saying
MemoryError: Out of normal MicroPython Heap Memory! Please reduce the resolution of the image you are running this algorithm on to bypass this issue!
MicroPython v1.12-omv OpenMV v3.6.7 2020-07-20; OPENMV4-STM32H743

In the documentation, it says that a model of size 400KB will fit but here it is not the case.
Please help me find a solution

That 400KBs some of it is also used for the framebuffer, you should try to lower the resolution or make the model smaller. We’ll fix the docs to explain this better.

I really want to know how the 400KB is divided into the framebuffer and the model.
is there a way to put the model on the flash and run it from there?


The frame buffer is 496KB - your model has to fit in this, the sensor image, another copy of the image that is the size of the mode input, then all the activation buffers of the network. How many activation buffers the network needs is not known. This can be a lot. Typically, it’s as big as the largest two layers in the network.

Set your resolution to a very low res and you’ll free up alot of ram.

is there a way to put the model on the flash and run it from there?

Yes, this is possible. Please read how to compile our firmware on GitHub. If you can do this then removing the person detector mode and putting your own in is easy.