Suraj Chavan
Suraj Chavan

Reputation: 59

How to use TensorFlow lite in Android with custom model for audio recognition

I have example of TensorFlow lite Android and i want to implement my custom trained model for audio recognition. I have trained model using custom dataset using this tutorial. I want to implement that model to TensorFlow lite Android project but it gives following error :

Process: org.tensorflow.lite.examples.speech, PID: 22892
    java.lang.IllegalArgumentException: Invalid input Tensor index: 1
        at org.tensorflow.lite.NativeInterpreterWrapper.getInputTensor(NativeInterpreterWrapper.java:287)
        at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:136)
        at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:311)
        at org.tensorflow.lite.examples.speech.SpeechActivity.recognize(SpeechActivity.java:424)
        at org.tensorflow.lite.examples.speech.SpeechActivity.access$400(SpeechActivity.java:73)
        at org.tensorflow.lite.examples.speech.SpeechActivity$4.run(SpeechActivity.java:373)
        at java.lang.Thread.run(Thread.java:764)

I have use the TensorFlow lite android example of speech recognition and replace their tflite model to my custom dataset model

Upvotes: 0

Views: 1124

Answers (1)

Michel Meneses
Michel Meneses

Reputation: 94

I have faced the same error while adapting the TF Lite sample for Android by Google to my personal ASR project, similarly to yours. I have fixed it by deleting the statement tfLite.resizeInput(1, new int[] {1}); in the method onCreate from the SpeechActivity, since my custom model (as well as yours, I believe) has only one input tensor, differently from the original model provided by Google, which considers two input tensors.

Upvotes: 1

Related Questions