OpenMV crashing while loading model

Hey guys,

I was loading an ML model using the tf.load method on to an OpenMV H7 Plus but the chip LED flash green several times then white and blue pairs 3 times.

For reference I am using a TFLite file of size 4.7 MB with load_to_fb=True

Any help is appreciated, Thanks!

Hi, can you turn load_to_fb off? The behavior you are seeing is the board crashing. May be a bug in our code.

Though pretty sure I fixed this one a long time ago.

@kwagyeman Unfortunately if I make load_to_fb as False I get memory allocation issues

image

Oh, that’s because you are trying to load it to the heap.

You can put the model name in the classify call and then it will be dynamically loaded per call. This is slow but it should not have any issues. If this crashes then there’s something off about the model that crashes the system.

Hey, Sorry for the delay.

Yes, I have tried to run it on the classify function and I am still facing the same LED sequence and then a crash. Below is the code I used for your reference.

import sensor, image, time, os, tf

sensor.reset()                        
sensor.set_pixformat(sensor.GRAYSCALE) 
sensor.set_framesize(sensor.QVGA)      
sensor.set_windowing((240, 240))       
sensor.skip_frames(time=2000)         

img = sensor.snapshot()
result = tf.classify('test_model.tflite', img)
print(result)

Yeah, that code should work… how did you generate the tflite file? From Edge Impulse?

Hey,

I am generating the TFLite file using the following script,

converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_LATENCY]
converter.allow_custom_ops = True
converter.representative_dataset = rep_data_gen
converter.experimental_new_converter = False

tflite_model_Q = converter.convert()
open(saved_model_dir+"quant.tflite", "wb").write(tflite_model_Q)

Hi, I don’t know what’s wrong then. We just support modules from Edge Impulse. I will be updating the firmware for TensorFlow soon in May though.

Okay noted. Looking forward for the new firmware.

For anyone’s reference I experimenting with the OpenMV kit by loading models from this repo : GitHub - bruceyang2012/Face-detection-with-mobilenet-ssd: Face detection with mobilenet-ssd written by tf.keras.. I will continue my research on the cause of the issue.

Hi @kwagyeman ,

May I ask if the models generated other than Edge Impulse are supported or not. I am trying to load a tflite model trained and generated outside Edge Impulse and I run into either memory issue as shown in this thread already while using tf.load or as per your suggestion if I use tf.classify then I get the disk ejected message.Please help. Thanks in advance.

Regards,
Aditi

It is, but, not advised. Until Edge Impulse came out TensorFlow Lite for Microcontrollers was not usable. Doing things without their tooling is hard.

Hi Anandha,
It’s been a year since your post. I’m wondering if you have solved this issue. If so, can you post how you solved it? Thank you!

Hey @colinzwang,

Unfortunately not, I moved on to another project shortly after I started working on OpenMV. All the best!