#tfLite returns garbage data

1 messages · Page 1 of 1 (latest)

honest sluice
#
int main()
{
    // Create the model and interpreter options.
    TfLiteModel* model = TfLiteModelCreateFromFile("VNPAPA.tflite");
    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    TfLiteInterpreterOptionsSetNumThreads(options, 2);
    
    // Create the interpreter.
    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    
    // Allocate tensors and populate the input tensor data.
    TfLiteInterpreterAllocateTensors(interpreter);
    TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0);
    
    float inputs[] = {1.0f,19.0f,4.0f,1.0f,0.0f,1.0f,0.0f,1.0f,1.0f}; 
    
    TfLiteTensorCopyFromBuffer(input_tensor, inputs,sizeof(inputs) * sizeof(float));
    // Execute inference.
    TfLiteInterpreterInvoke(interpreter);
    
    // Extract the output tensor data.
const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0);
    float outputs[2];
TfLiteTensorCopyToBuffer(output_tensor, outputs, 2 * sizeof(float));
    printf("%f", outputs[0]);
    // Dispose of the model and interpreter objects.
    TfLiteInterpreterDelete(interpreter);
    TfLiteInterpreterOptionsDelete(options);
    TfLiteModelDelete(model);
}

So when I run the exact same from keras model in google colab, I get nice and concise results Around what I would expect to see.

But when I export the tflite model and run in in C program you see above, I get wast array of garbage data.

-0.000000
98539232544683341287260160.000000 
0.000000
-0.000001
-0.000000
0.000000
-23981264472346816886445254628324933632.000000
10819050381292601344.000000```

Thank you in advance for helping out!
https://colab.research.google.com/drive/1eRan90fkk_0VldlWQfQkHvb_G038B5Hg?usp=sharing <- Link to the Python Training module
honest sluice
#

Update on C program

#
int main()
{
    // Create the model and interpreter options.
    TfLiteModel* model = TfLiteModelCreateFromFile("VNPAPA.tflite");
    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    TfLiteInterpreterOptionsSetNumThreads(options, 2);
    
    // Create the interpreter.
    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    
    // Allocate tensors and populate the input tensor data.
    TfLiteInterpreterAllocateTensors(interpreter);
    TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 9);
    
    int64_t inputs[] = {0,19,3,4,0,0,1,0,1}; 
    
    TfLiteTensorCopyFromBuffer(input_tensor, inputs,9 * sizeof(int64_t));
    // Execute inference.
    TfLiteInterpreterInvoke(interpreter);
    
    // Extract the output tensor data.
const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0);
    double outputs[2];
TfLiteTensorCopyToBuffer(output_tensor, outputs, 2 * sizeof(double));
    printf("%f\n", outputs[0]);
    // Dispose of the model and interpreter objects.
    TfLiteInterpreterDelete(interpreter);
    TfLiteInterpreterOptionsDelete(options);
    TfLiteModelDelete(model);
}
#

Please any help is apreciated

#

Currently if I put in any data, output is 0.0000

honest sluice
#

Newest update

#
#include <stdio.h>
#include <tensorflow/lite/c/c_api.h>

int main()
{
    TfLiteModel* model = TfLiteModelCreateFromFile("VNPAPA.tflite");
    TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
    TfLiteInterpreterOptionsSetNumThreads(options, 0);
    
    // Create the interpreter.
    TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
    
    // Allocate tensors and populate the input tensor data.
    TfLiteInterpreterAllocateTensors(interpreter);
    TfLiteTensor* input_tensor = TfLiteInterpreterGetInputTensor(interpreter, 0);
    
    int64_t inputs[] = {0,19,3,4,0,0,1,0,1}; 
    
    TfLiteTensorCopyFromBuffer(input_tensor, inputs,9 * sizeof(int64_t));
    // Execute inference.
    TfLiteInterpreterInvoke(interpreter);
    
    // Extract the output tensor data.
    const TfLiteTensor* output_tensor = TfLiteInterpreterGetOutputTensor(interpreter, 0);
    float output[1];
    TfLiteTensorCopyToBuffer(output_tensor, output, 1 * sizeof(float));
    printf("%f\n", output[0]);
    // Dispose of the model and interpreter objects.
    TfLiteInterpreterDelete(interpreter);
    TfLiteInterpreterOptionsDelete(options);
    TfLiteModelDelete(model);

}

No matter how I change the inputs. The output will be the same:0.784447

#

:))))

#

All done