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.75k stars 771 forks source link

Didn't find op for builtin opcode 'SPACE_TO_BATCH_ND' version '2'. An older version of this builtin might be supported. Are you using an old TFLite binary with a newer model? #496

Closed martingcavallo closed 2 years ago

martingcavallo commented 2 years ago

Hi!

I am trying to deploy a TF Lite model to an Arduino Nano 33 BLE Sense, and I get the following error:

Didn't find op for builtin opcode 'SPACE_TO_BATCH_ND' version '2'. An older version of this builtin might be supported. Are you using an old TFLite binary with a newer model?

I have trained and converted the model using python 3.8.8 and tensorflow 2.6.0. After that, I converted the model using Post Training Quantization, I also run some inferences in Juptyter Notebook using TF Lite Interpreter without any problems.

Now I want to deploy this model to my Arduino Nano 33 BLE Sense boards, but I get the error described above. I am using Arduino IDE and the library Arduino_TensorFlowLite version 2.4.0-ALPHA.

What I can see is that in all_apps_resolver.h is implemented the function AddSpaceToBatchNd();, however, if I look for this function in the file ''all_ops_resolver.cc'' included in Arduino_TensorFlowLite version 2.4.0-ALPHA., I saw that this function is missed, I mean, this function is not implemented.

So, I understand that the problem is the version of my Arduino_TensorFlowLite libreary. Is there any version that inlude AddSpaceToBatchNd(); or it is not still implemented and it does not has support for Arduino library?

Thanks in advance!!

Best regards, Martin

advaitjain commented 2 years ago

Tagging @petewarden to answer Arduino-related questions.

martingcavallo commented 2 years ago

Hi @advaitjain, thanks for tagging @petewarden .

Sorry, I did not know that was neccesary.

Let me update and tell you, that after investigating and serching a lot, I understood that efectivelly it was a problem about Arduino library version. Because I also tried to genereate my own Arduino library in .zip format as explained in O'Reilly TinyML book, but I did not find the directories mentioned in the book. Going deep, I realized that theare are new tensorflow versions and tflite-micro github repository was moved to its stand-alone github repositry.

Finally, I could solve my problem in the following way. I downloaded tensorflow 2.5.1 and this version contains both, ops that I need and tools to generate .zip Arduino libray. So I generate my Arduino library from tensorflow 2.5.1 and that is all.

If you prefer I could close this issue, but I would like to know if TFLM Arduino library will be updeated then or not. Perhaps @petewarden could tell me that.

Thanks in advance!!

Martin

antoine-lebaud commented 2 years ago

Hi @martingcavallo, I got the same issue as you mentioned. I would like to reproduce the steps you did. Would you recommend me any good resource to generate a .zip Arduino library?

Thanks in advance !! Antoine

advaitjain commented 2 years ago

Can you please try the latest TFLM Arduino library from https://github.com/tensorflow/tflite-micro-arduino-examples and reopen this issue if you continue to run into problems?

martingcavallo commented 2 years ago

@advaitjain I talk with @antoine-lebaud by DM in LinkedIn, and tried to help him with his issue. Following the same steps that I did, I found that he should download tensorflow 2.6.0 because this version has implemented AddTranspose() op and also has the Arduino directory and test_arduino.sh file as explained in Generate Arduino libreary in TensoroFlow doc.

In this way, he should solve his problem as I could do it.

Regards, Martin