tensorflow / tflite-micro

Infrastructure to enable deployment of ML models to low-power resource-constrained embedded targets (including microcontrollers and digital signal processors).
Apache License 2.0
1.83k stars 802 forks source link

LSTM Model & TFLite Select Ops #1953

Closed trylaarsdam closed 1 year ago

trylaarsdam commented 1 year ago

Hi there,

I'm trying to run a 5 LSTM layer keras model on a Portenta H7, which when I translate it to TFLite requires the SELECT_TF_OPS option to be enabled. When I allocate tensors on the M7 core of the Portenta using a freshly generated TFLM library from this repo, I get the following error: image From what I can tell, the CUSTOM operation is actually referring to the Stateless_While operator in TFLite, as when I compile with the non-experimental converter it gives me errors about no support for Stateless_While when I do not have SELECT_TF_OPS enabled.

Here is my model structure for reference: (linking since it's a very tall image) https://user-images.githubusercontent.com/50586094/236851325-cf519093-5fe1-4c6f-9663-545cb5a9ff88.png

So here are my questions:

  1. I've seen some release notes that seem to imply that LSTM models are now supported in TFLM. What could be special about my model that requires this stateless while operator vs other LSTM-based models that are compatible?
  2. Is it possible/feasible for me to implement a custom operation on my side to support the stateless while op? If not why is it impractical?

Thanks

trylaarsdam commented 1 year ago

It looks like the solution was providing signatures to TF before the conversion to TFLite which sets a fixed input size. I used this notebook as a template: https://colab.research.google.com/gist/tiruk007/f05a6e2a47943ae1e04495f306ef5c71/58668.ipynb

trylaarsdam commented 1 year ago

Cancel that, the input and output dimension sizes are reporting as large negative numbers (about -160,000,000), so something is still up. I can convert and see in Netron that all the operations listed there are in all_ops_resolver, but it still crashes my Portenta H7 image

github-actions[bot] commented 1 year ago

"This issue is being marked as stale due to inactivity. Remove label or comment to prevent closure in 5 days."

github-actions[bot] commented 1 year ago

"This issue is being closed because it has been marked as stale for 5 days with no further activity."