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:
- I take the values of the 4 sensors
- I load them into the input tensor with:
for (int i = 0; i < model_input_size; i++)
{
input->data.int8[i] = inputDataFinal[i];
}
- 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!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…