Micro_Speech error on Sparkfun Edge when using new model
Hi @ldbrouwer,

There is a mismatch between the expected and actual feature data sizes while inferencing on Sparkfun Edge. This might be the reason for `Didn't find op for builtin opcode 'RESHAPE' version '1'` so please make sure input and output shapes while inferencing should match that of your model. No. of features(1960) should match the dimensions as well. 

Use TFLite Micro benchmarking tool to analyze your model and identify potential compatibility issues. Also, there is a dedicated [repo](https://github.com/tensorflow/tflite-micro/issues) for TFLite micro issues. Please try to post there for quick response.

Thank You LakshmiKalaKadali, Thank you for your response. I am working through some additions to check on input and output shapes. As I am new to working with Tensorflow, I do have a couple of follow-on questions as I work this issue. Additionally, these questions may provide clarity to you on what is happening: 1)  I am using the Sparkfun Edge micro-speech code in both instances - a) the demo cdde that uses the "yes/no" model and b) for my "On/Off" model. The only data I changed (using the model I trained in Google Colab) was in the "tiny_conv_micro_features_model_data.cc" file (substituting the hex data and the size of the hex data) and the corresponding info in the "micro_model_settings.cc" (substituting ON for Yes and Off for No) and the same in the "command_responder.cc" files. My understanding is that these changes will not change the shape of the input or output. Could you please help me understand?
2) I was getting very similar errors using the Arduino Nano BLE Sense and Arduino IDE. That error was solved by adding the opcode for CONV-2D to the micro_op_resolver as recommended in this forum. Again the only data I changed was using the same ON/OFF model trained on the Colab page. Since the model works on the Arduino, I am puzzled how the ON/OFF model shape would be the cause of the error on the Sparkfun Edge.
Thanks in advance,
Lonnie LakshmiKalaKadali, 
I have discovered a great deal about my issue, but I have not solved it. Please provide guidance:
**For clarity - I am running the example code for the Sparkfun Edge provided in the tensorflow repository
"tensorflow/tensorflow/lite/experimental/micro/examples/micro_speech".** 

1) Upon compiling the test example code with the newly trained model, the first error encountered was "Segmentation fault (core dumped)"
This suggests that the first problem is incorrectly allocated memory. You can see the error messages in paragraph A below.
Although I still get the opcode RESHAPE error and the dims errors. I believe these to be related to the memory allocation error.

2) I then used the tflite quantized model (not the micro model, but the tflite model) and ran it through the TFLite model analyzer.
I believe it shows that the model has the correct shape for all tensors - this is shown in paragraph B below

3) I was not able to use the TFLite Micro benchmarking tool you recommended. I found several references on Google, but was not able to apply them.
Could you direct me to a location and an example?

4) I also played with the arena size. When I changed it to 50, I got a segmentation error and similar "dims" results. 
However, when I changed the arena size to 20, I still got the segmentation error, but the "dims" errors changed to more "normal" numbers
as shown in paragraph C below.

Again, I would appreciate guidance,

Lonnie

A) When compiling with newly trained model from the Colab page, the compile fails with the following info at the end of the compiler messages: 
 *************************  
tensorflow/lite/experimental/micro/testing/test_linux_binary.sh tensorflow/lite/experimental/micro/tools/make/gen/linux_x86_64/bin/micro_speech_test '~~~ALL TESTS PASSED~~~'
Segmentation fault (core dumped)
tensorflow/lite/experimental/micro/tools/make/gen/linux_x86_64/bin/micro_speech_test: FAIL - '~~~ALL TESTS PASSED~~~' not found in logs.
Testing TestInvoke
Didn't find op for builtin opcode 'RESHAPE' version '1'

Failed to get registration from op code  d
 
4 == input->dims->size failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:77 (4 vs 1584022240)
1 == input->dims->data[0] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:78 (1 vs 32677)
49 == input->dims->data[1] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:79 (49 vs 1583772544)
40 == input->dims->data[2] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:80 (40 vs 32677)
1 == input->dims->data[3] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:81 (1 vs 1583773840)
kTfLiteUInt8 == input->type failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:82 (3 vs 1540943972)
Segmentation fault
make: *** [tensorflow/lite/experimental/micro/examples/micro_speech/Makefile.inc:246: test_micro_speech_test] Error 1
*********************

B) I also ran the TF Lite model analyzer on the tflite model (not the micro model) and it showed the following:
=== TFLite ModelAnalyzer ===

Your TFLite model has '1' subgraph(s). In the subgraph description below,
T# represents the Tensor numbers. For example, in Subgraph#0, the RESHAPE op takes
tensor #0 and tensor #1 as input and produces tensor #7 as output.

Subgraph#0 main(T#0) -> [T#11]
  Op#0 RESHAPE(T#0, T#1[-1, 49, 40, 1]) -> [T#7]
  Op#1 CONV_2D(T#7, T#6, T#5[-19, 14, -425, 39, 0, ...]) -> [T#8]
  Op#2 RESHAPE(T#8, T#2[-1, 4000]) -> [T#9]
  Op#3 FULLY_CONNECTED(T#9, T#4, T#3[469, -685, 534, -317]) -> [T#10]
  Op#4 SOFTMAX(T#10) -> [T#11]

Tensors of Subgraph#0
  T#0(Reshape_1) shape:[1, 1960], type:INT8
  T#1(Reshape_2/shape) shape:[4], type:INT32 RO 16 bytes, buffer: 2, data:[-1, 49, 40, 1]
  T#2(Reshape_3/shape) shape:[2], type:INT32 RO 8 bytes, buffer: 3, data:[-1, 4000]
  T#3(final_fc_bias) shape:[4], type:INT32 RO 16 bytes, buffer: 4, data:[469, -685, 534, -317]
  T#4(MatMul) shape:[4, 4000], type:INT8 RO 16000 bytes, buffer: 5, data:[., ., ., ., ., ...]
  T#5(first_bias) shape:[8], type:INT32 RO 32 bytes, buffer: 6, data:[-19, 14, -425, 39, 0, ...]
  T#6(Conv2D) shape:[8, 10, 8, 1], type:INT8 RO 640 bytes, buffer: 7, data:[., ., ., ., ., ...]
  T#7(Reshape_2) shape:[1, 49, 40, 1], type:INT8
  T#8(Relu;add;Conv2D;first_bias) shape:[1, 25, 20, 8], type:INT8
  T#9(Reshape_3) shape:[1, 4000], type:INT8
  T#10(MatMul;add_1) shape:[1, 4], type:INT8
  T#11(labels_softmax) shape:[1, 4], type:INT8

---------------------------------------------------------------
              Model size:      18960 bytes
    Non-data buffer size:       2160 bytes (11.39 %)
  Total data buffer size:      16800 bytes (88.61 %)
    (Zero value buffers):          0 bytes (00.00 %)

* Buffers of TFLite model are mostly used for constant tensors.
  And zero value buffers are buffers filled with zeros.
  Non-data buffers area are used to store operators, subgraphs and etc.
  You can find more details from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/schema/schema.fbs
===================================================

C)
tensorflow/lite/experimental/micro/testing/test_linux_binary.sh tensorflow/lite/experimental/micro/tools/make/gen/linux_x86_64/bin/micro_speech_test '~~~ALL TESTS PASSED~~~'
Segmentation fault (core dumped)
tensorflow/lite/experimental/micro/tools/make/gen/linux_x86_64/bin/micro_speech_test: FAIL - '~~~ALL TESTS PASSED~~~' not found in logs.
Testing TestInvoke
Didn't find op for builtin opcode 'RESHAPE' version '1'

Failed to get registration from op code  d
 
4 == input->dims->size failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:77 (4 vs 0)
1 == input->dims->data[0] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:78 (1 vs 0)
49 == input->dims->data[1] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:79 (49 vs 0)
40 == input->dims->data[2] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:80 (40 vs 4)
1 == input->dims->data[3] failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:81 (1 vs 0)
kTfLiteUInt8 == input->type failed at tensorflow/lite/experimental/micro/examples/micro_speech/micro_speech_test.cc:82 (3 vs -905926320)
Segmentation fault
make: *** [tensorflow/lite/experimental/micro/examples/micro_speech/Makefile.inc:246: test_micro_speech_test] Error 1
 Hi @Idbrouwer, I think that part of the repo is outdated/deprecated, do you have a link to that part of the repo? Reason being here are the current examples: 

https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental
https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/experimental

Thanks for any additional information you can provide. Hello, after ALOT of Google searches and going through GitHub repos and through Tensorflow and Sparkfun forums, I have determined that all of the info on the Sparkfun Edge board is outdated. On your current Github site, you have instructions on how to compile and run Micro_Speech_Test on a development machine, and how to create new models on Colab and other platforms, but there is no instruction/guidance or means to compile the Micro_Speech code for the Sparkfun Edge - or any microcontroller. I can find no "make" file for a TARGET=SparkfunEdge. I guess neither tensorflow not sparkfun support that board any longer and there is no way to compile and use the existing code in any expansion. My understanding has changed recently, such that I now believe that Tensorflow writes the TFLM C++ code that a microcontroller producer must then use to build a library/ compiler/loader for their specific microcontroller. Therefore, if Sparkfun no longer supports/updates a library for the Edge, any buyer is out of luck.
Oh, here is a link to the repo I was using - it is old: tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/micro_model_settings.h Hi @ldbrouwer, would you happen to know the branch/commit your code is referring to? I just want to ensure I have the right context on what's happening in your situation. I think I'm in the main branch - but I'm far from a github guru Hi @ldbrouwer, can you go to your root directory/folder of where you cloned the repo and try this:

```
git branch
```
Your current branch should have an asterisk next to it

then try:
```
git log
```
Tell me the latest commit hash that is not yours, (If you haven't made a commit to your current branch, then they are all not yours), maybe give me the top 3 so that I may gather the correct context for your situation.

Thanks. I did the pull from the webpage. What I see on the page is the commit is be4f687
Let me know if that helps.
Also, the zip folder that I cloned is named "tensorflow-be4f6874533d78f662d9777b66abe3cdde98f901"

Lonnie Hi @ldbrouwer, you are using a very old version... of well pretty much everything as that commit is very old (Dec 2019). We have since migrated tflite-micro to its own repo: https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/examples/micro_speech Is the current equivalent of your example. Can you clone that repo and ensure you are on the main branch and then try to continue your project/work? Thanks for your help. Hello. In fact I did clone the repo you referenced above before I wrote my comment on Feb 28. As I said there, " you have instructions on how to compile and run Micro_Speech_Test on a development machine (in python), and how to create new models on Colab and other platforms, but there is no instruction/guidance or means to compile the Micro_Speech code (in C++) for the Sparkfun Edge - or any microcontroller. I can find no "make" file for a TARGET=SparkfunEdge. 
Am I missing something - I'd appreciate any guidance you can provide. Hi @ldbrouwer, If I'm understanding your problem correctly, You are have made and trained a model with Colab, then when attempting to infer on a SparkfunEdge you are running into issues during inference? If that is correct, can you please share your exact steps (including commands) to do everything? Starting from compiling the code and training the model on colab and the commands/actions used to run it on your SparkfunEdge. Generally the more information you share the better context we have to help you. Thanks for your help. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Sorry for the delayed response; thank you for your advice and guidance. I have taken a detour on my journey with TFLu that will hopefully yield alternative solutions - but I plan to return to this project later. Regardless, please close this thread for now - I'll get back to you with my progress as you directed above at a later date. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62999">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62999">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

Tensorflow for microcomputers - from micro_speech repository

### Custom code

Yes

### OS platform and distribution

Linux Ubuntu 22.04

### Mobile device

_No response_

### Python version

3.10.12

### Bazel version

_No response_

### GCC/compiler version

11.4.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Initial "make" and upload of micro_speech code works fine. Upon training a new model on the Google Colab (with guidance from Tiny ML book), code compiles fine, but does not run. Error reporting shows: Didn't find op for builtin opcode 'RESHAPE' version '1', Failed to get registration from op code d, AllocateTensors() failed.
And then  a stream of : Requested feature_data_size -1560243888 doesn't match 1960, Feature generation failed - messages.
I had similar issue with Arduino Nano BLE on Arduino IDE but was able to solve the issue by adding the opcode for CONV-2D to the micro_op_resolver as recommended in this forum. However when using the Sparkfun Edge on Linux, I cannot solve the problem. I have tried to add the CONV2D op to the micro_op_resolver, but this didn't work. I also tried in increase the Arena Size from 10 to 50, but this didn't work either. 

### Standalone code to reproduce the issue

```shell
Code is directly from the tensorflow/lite/experimental/micro/examples/micro_speech repo
```


### Relevant log output

```shell
log data from serial port is included above
```
