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

String input support

Open fsonntag opened this issue 2 years ago • 3 comments

I have a model that I call with String inputs.

I can call it with no issues in Python:

    interpreter = tf.lite.Interpreter("thai_w2p_tf_model.tflite")
    model_signature = interpreter.get_signature_runner()
    output = model_signature(input_1=np.array(["โทรศัพท์"]))

When trying to call the model in Flutter, it tells me that the datatype is not supported:

  final interpreter = await Interpreter.fromAsset('nlp-assets/thai_w2p_tf_model.tflite');
  
  final word = "โทรศัพท์";
  var input = [word];
  var output = List.filled(1*word.length, 0).reshape([1,word.length]);
  interpreter.run(input, output);

E/flutter ( 2987): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): The input data tfliteType String is unsupported

Can support be added? That'd be great and appreciated!

fsonntag avatar Jul 01 '23 18:07 fsonntag

I never tried a model that takes strings as an input, but if I remeber correctly, sometimes i got similar error messages for int8 while doing the object detection example. Maybe try to print out interpreter.getInputTensors and try to match what the output is. Also, maybe you can provide a link to download your model, then i could test this myself.

gregorscholz avatar Jul 06 '23 17:07 gregorscholz

Hi @gregorscholz , the error coming from this method, i.e. it misses a conversion: https://github.com/tensorflow/flutter-tflite/blob/c3c36dd7695425fc325eb0345985cc5a3e68c638/lib/src/util/byte_conversion_utils.dart#L52

So I think it should be a different error than passing an int8 type input, since it's supported within this method.

fsonntag avatar Jul 07 '23 14:07 fsonntag