Tflite Model giving rubbish output during inference

Can you please ensure your code on Android is good ? You obviously don’t exercize the same way. We have tests checking that in CI.

Didnt get you. Sorry please elaborate

I am not using any other code from my side. I am using your sample code for android and aar file which you have shared.

And you are using your own file. How are you testing on desktop ? Please ?

@sanjay.pandey We publish examples files for a reason, does it works with those files ?

@sanjay.pandey Just re-verified from scratch on my Google Pixel 2 device, both our app and https://github.com/mozilla/androidspeech/ works 100%.

After installing deepspeech-tflite on v0.6.1 I ran following command

deepspeech --model /home/sanjjayyp/export_model_0.6.1/output_graph.tflite --lm data/lm/lm.binary --trie data/lm/trie --audio /home/sanjjayyp/sapna_apna/cheese_mysore_masala_dosa_idli_vada_sambhar.wav

and it is giving inference as
cheese mysore masala dosa idli vada sambhar
which is correct.

Also i am trying with evaluate_tflite.py as well. Currently it is running for 16k audio yet to get the result.

As I already told you several times, this Android code is not really intendend for real use: https://github.com/mozilla/DeepSpeech/blob/master/native_client/java/app/src/main/java/org/mozilla/deepspeech/DeepSpeechActivity.java#L68-L102

We read the WAVE content very simply. Any malformed file will fail. Badly.

It works with those 3 file but not with any of my wav file .

One thing i observed that

Length of Byte array for our audio file is always : 26

Length of Byte array for your audio file is always : 87520

See ? Just what I told you. When did you observed that ? Your file is just bogus.

But why the same file working on desktop with tflite if it is malformed what is the reason for that and how i can overcome? i have around 7 lacs audio file i have randomly tried inference with different file of mine on android but result is always same i.e blank

It means your WAVE file has a different header format, the Android code only supports the “SoX format”. Are you using ffmpeg anywhere to generate/process this file? If so, you’ll need to use this option: https://stackoverflow.com/a/39671913/346048

Or you can make a PR to our Android code to add support for other formats, for example by using a SoX or ffmpeg library.

As @reuben said, they likely are all broken the same way.

As linked, because we read directly the file on Android for simplicity (less deps, not supposed to be any user-facing app) while on desktop we use more generic tools.

Understood what was going wrong. I used sox to convert audio into 16 bit mono 16 khz and now it is working fine and i am getting output on android. So actually python file was already using SoX for all the audio i trained on and hence i was not receiving any error on desktop or in python.

Thanks a lot @reuben @lissyx for the help. but the inference is too slow . For 5 seconds audio it took 10 seconds. Shouldnt tflite be fast?

And we should know that without knowing your hardware?

Redmi 7A

Qualcomm Snapdragon 439 Octa core Processor . 2 GB RAM .

While if i use Realme 5 pro which have 8 gb RAM.

5 seconds file gives inference in 2.5 seconds itself.

Wont 2GB will be sufficient for realtime inference on android device?

Might just be too slow. Amount of RAM is not a big big deal.

What’s the SoC inside?

But again, we do document performances on some devices we have verified, namely Snapdragon 820 and 835, and we document that the tflite runtime will run on one core to perform inference.