Burning .tflite model into firmware

Hi, I wanted to freeze the image classification model for my application into a custom firmware for Portenta Vision Shield.

Looking into where all the other models are, I placed it in /openmv/lib/models. Additionally, (although this might not be applicable to Portenta) looking at how it’s done for person_detect.tflite I edited the openmv/boards/ARDUINO_PORTENTA_H7/romfs_config.json file to add:

{
      "type": "tflite",
      "path": "{TOP}/lib/models/my_model.tflite",
      "alignment": 16,
      "optimize": "Performance"
    }, 

The model is being called in my main as:

net = ml.Model(“/rom/my_model.tflite”, load_to_fb=uos.stat(‘/rom/mymodel.tflite’)[6] > (gc.mem_free() - (64*1024)))

Am I missing a crucial step because it seems like the model is not being found at /roms.

Additionally, if I were to freeze a .txt file, where would you recommend I place it?

PC

You don’t need the load_to_fb part. Just

net = ml.Model(“/rom/my_model.tflite”)

If you want to put a txt file there too, name it the same as the model and the model will load it as it’s labels.

You have to load the romfs partition after it’s compiled. OpenMV IDE will do this for you.

Made the change and rebuilt the firmware; did not work unfortunately :frowning:

Same error:

[Errno 19] ENODEV

No worries about the .txt file anymore. I had this idea of making a table of device_id and associated LoRaWAN appkeys so all my Portentas can connect to LoRaWAN without me having to load separate appkeys, but then I realised it’s easier to make a Python dictionary and freeze that instead!

PC

Can you confim the model is on the romfs if you do:

Tools->ROMFS->edit romfs in OpenMV IDE?

Note that OpenMV IDE can update the ROMFS too.

Ah, it was missing in ROMFS. Adding manually via the IDE worked! Weird why editing the openmv/boards/ARDUINO_PORTENTA_H7/romfs_config.json file didn’t work though.

Do you have any suggestion on how I could make this process quicker since I have several boards to setup? No worries if not!

PC

Editing that file should work, saving, and then rebuilding. Not sure what is going wrong…

Note that you can save ROMFS images to disk with OpenMV IDE, and then load them from disk and flash to cameras.