# OpenMV crashing while loading model

**URL:** <https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754>\
**Category:** OpenMV Boards\
**Created:** [April 22, 2021, 2:11pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754 "2021-04-22T14:11:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [April 22, 2021, 2:11pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/1 "2021-04-22T14:11:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 22, 2021, 6:43pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/2 "2021-04-22T18:43:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 22, 2021, 6:43pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/3 "2021-04-22T18:43:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [April 23, 2021, 7:33am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/4 "2021-04-23T07:33:51Z")

</div>

> [@kwagyeman](#):
>
> load\_to\_fb

@kwagyeman Unfortunately if I make load\_to\_fb as False I get memory allocation issues

![image](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/5/5e18736bc379c79e60c8f6da9d5395573502b4d3.png)

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 23, 2021, 2:34pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/5 "2021-04-23T14:34:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [April 26, 2021, 7:48am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/6 "2021-04-26T07:48:08Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 26, 2021, 4:38pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/7 "2021-04-26T16:38:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [April 27, 2021, 11:24am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/8 "2021-04-27T11:24:29Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 27, 2021, 2:32pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/9 "2021-04-27T14:32:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [April 28, 2021, 1:19pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/10 "2021-04-28T13:19:08Z")

</div>

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.](https://github.com/bruceyang2012/Face-detection-with-mobilenet-ssd). I will continue my research on the cause of the issue.

---

<div class="post-metadata">

**Author:** ![aditi](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@aditi](https://forums.openmv.io/u/aditi)\
**Post date:** [April 5, 2022, 9:33am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/11 "2022-04-05T09:33:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [April 5, 2022, 8:47pm UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/12 "2022-04-05T20:47:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![colinzwang](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@colinzwang](https://forums.openmv.io/u/colinzwang)\
**Post date:** [September 23, 2022, 7:12am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/13 "2022-09-23T07:12:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![anandhakrishnan-tech](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@anandhakrishnan-tech](https://forums.openmv.io/u/anandhakrishnan-tech)\
**Post date:** [September 23, 2022, 7:30am UTC](https://forums.openmv.io/t/openmv-crashing-while-loading-model/5754/14 "2022-09-23T07:30:59Z")

</div>

Hey @colinzwang,

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