Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

python - tflite micro outputs nonsense values

I try to run a tensorflow lite on a ESP32 to classify sensordata, but the model keeps predicting wrong values. In the notebook the model performs well. Here is what I do: I read the values of 4 sensors acceleration sensors and want to classify the direction of movement. Therefore i recorded data to train a neural network in tensorflow. My model is correct on almost all test data runnning in a notebook, both the keras model and tensorflow lite model.

I tried to run in on the ESP and I get no errors, but nonsense results. Here is what i do on the ESP32:

  1. I take the values of the 4 sensors
  2. I load them into the input tensor with:
for (int i = 0; i < model_input_size; i++)
  {
    input->data.int8[i] = inputDataFinal[i];
  }
  1. I run the inference and print the output
  Serial.print("Output: ");
  Serial.print(output->data.f[0]);
  Serial.print("");
  Serial.print(output->data.f[1]);
  Serial.print("");
  Serial.print(output->data.f[2]);
  Serial.println("");

The printed output looks like this (for a couple of loops):

Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00
Output: 0.23    0.25    0.52
Output: 0.23    0.25    0.52
Output: 0.00    0.00    1.00
Output: 0.00    0.00    1.00

The real class should be the 3rd, so sometimes its is correctly predcicted, even though I suspect it to be by chance. I tried to print the raw sensor values and manually copied them into my notebook. Here the tf and tf lite model classify it correctly.

I guess it has something to do with how the values are handed to the model or even the datatypes, but I can't find the issue. The predictiob 0.23, 0.25, 0.52 seems to repeat and might be a hint for someone who is more into tflite micro?

I appreciate every hint on this! Any information missing just ask and i'll do my best to provide it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...