flutter-tflite icon indicating copy to clipboard operation
flutter-tflite copied to clipboard

Missing Interpreter set_tensor method

Open ghost opened this issue 8 months ago • 3 comments

I am trying to convert a python implementation to be used in Flutter.

This is a function definition I am unable to find interpreter.set_tensor it is not part the flutter-tflite Interpreter API set_tensor is defined here https://www.tensorflow.org/api_docs/python/tf/lite/Interpreter#set_tensor

def tflite_predict(tflite_interpreter, input_index, output_index, x):
    tflite_interpreter.set_tensor(input_index, x)
    tflite_interpreter.invoke()
    return tflite_interpreter.get_tensor(output_index)[None, ]

Here is what I have

  Tensor tfliteMissPredict(
    Interpreter interpreter,
    int inputIndex,
    int outputIndex,
    dynamic data,
  ) {
    // interpreter.setTensor(data) <--- Not part of the API
    interpreter.invoke();
    return interpreter.getOutputTensor(outputIndex);
  }

Is there another approach for this case?

ghost avatar Nov 11 '23 05:11 ghost

I don't think you need to do that step. After _interpreter.allocateTensors(); interpreter.getOutputTensor should work fine.

saurabhkumar8112 avatar Nov 20 '23 11:11 saurabhkumar8112

I don't think you need to do that step. After _interpreter.allocateTensors(); interpreter.getOutputTensor should work fine.

There is data passed into tfliteMissPredict and the function is called in a stream many times very quickly with the input index being updated with each call.

I have updated the dart code to reflect the data being passed in.

ghost avatar Nov 30 '23 13:11 ghost

Any luck on solving this or finding another approach? Currently facing the same issue.

lyngbach avatar Feb 29 '24 22:02 lyngbach