Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation/example when using large model that overflows flash memory (TFMIC-39) #96

Closed
3 tasks done
kirianguiller opened this issue Sep 9, 2024 · 3 comments
Closed
3 tasks done

Comments

@kirianguiller
Copy link

kirianguiller commented Sep 9, 2024

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Provided a clear description of your suggestion.
  • Included any relevant context or examples.

Issue or Suggestion Description

Hello,

I'm trying to use an esp32-S3 to do sound classifiaction.
My issue is that the tflite model is 4MB big and it overflows the flash memory of my microcontroller.

I have the .tflite model that I converted to .cc file using xdd.

I have checked all issues (the issuer of this issue achieve such behavior) and searched through the documentation (here the official espressif doc for external ram) to try to understand how I should store and load the model (storing it in spiffs ? And loading it in PSRAM ?), but I don't succeed to make the changes to one of the three esp-tflite-micro examples to make a working solution.

Does someone has such a working example that I could take inspiration from? Or is there somewhere a more expressive documentation that would help me?

Thanks in advance!

@github-actions github-actions bot changed the title Documentation/example when using large model that overflows flash memory Documentation/example when using large model that overflows flash memory (TFMIC-39) Sep 9, 2024
@vikramdattu
Copy link
Collaborator

vikramdattu commented Sep 9, 2024

Hi @kirianguiller the model data pointer can be passed to getModel function and the rest of the code stays as is. Do refer main_functions.cc file for this.

model = tflite::GetModel(g_model);

  • This will need large SPIRAM to be available for the lifetime of the program and is not viable in my opinion.
  • If you have an option, you should explore:
    • Either increase the partition size, which will automatically put the static array model in flash as rodata. With this approach, you do not change the code.
    • Create a new data partition for model of desirable size, map the model and pass the mapped buffer pointer to above function. With this approach, you are flexible with the model and can update the model partition as you need on the fly. Do explore the memory mapping functions here

@kirianguiller
Copy link
Author

Thank you, I will try the options 2a and 2b and will report back my research

@kirianguiller
Copy link
Author

I did as you said in 2b :

* If you have an option, you should explore:
  
  * Either increase the partition size, which will automatically put the static array model in flash as rodata. With this approach, you do not change the code.

Here is how I proceeded:

I changed the partitions.csv to the following (0x500000 is equal to 5MB):

# Name,   Type, SubType, Offset,  Size,      Flags
nvs,      data, nvs,     0x9000,  0x5000,
phy_init, data, phy,     0xe000,  0x1000,
factory,  app,  factory, 0x10000, 0x500000,

And I got sure that the model data was assigned as a constant. Otherwise the model will not go to PSRAM (when I converted the .tflite to .cc with xdd, the const was missing and thus was making the compilation fails.

Thanks! I can close the issue as everything works (other than the fact that the model I use itself, Yamnet, has some layers that are not supported by TFLM)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants