Input tensor 0 is missing TensorMetadata

This article shows how to add meta_data into a tflite model before running in Android. However, it only shows example for Image classification. I am trying to add meta data for Audio classification. How can I get guide.

I am getting error in Android when running a model.tflite which has no meta data.

Error getting native address of native library: task_audio_jni
java.lang.IllegalArgumentException: Error occurred when initializing AudioClassifier: input tensor 0 is missing TensorMetadata.
at org.tensorflow.lite.task.audio.classifier.AudioClassifier.initJniWithModelFdAndOptions(Native Method)
at org.tensorflow.lite.task.audio.classifier.AudioClassifier.access$000(AudioClassifier.java:74)
at org.tensorflow.lite.task.audio.classifier.AudioClassifier$1.createHandle(AudioClassifier.java:143)
at org.tensorflow.lite.task.audio.classifier.AudioClassifier$1.createHandle(AudioClassifier.java:136)
at org.tensorflow.lite.task.core.TaskJniUtils$1.createHandle(TaskJniUtils.java:70)
at org.tensorflow.lite.task.core.TaskJniUtils.createHandleFromLibrary(TaskJniUtils.java:91)
at org.tensorflow.lite.task.core.TaskJniUtils.createHandleFromFdAndOptions(TaskJniUtils.java:66)
at org.tensorflow.lite.task.audio.classifier.AudioClassifier.createFromFileAndOptions(AudioClassifier.java:134)
at org.tensorflow.lite.task.audio.classifier.AudioClassifier.createFromFile(AudioClassifier.java:91)
at com.samsung.classification.MainActivity.startAudioClassification(MainActivity.java:86)
at com.samsung.classification.MainActivity.lambda$showActivitySelectionDialogue$0$com-samsung-classification-MainActivity(MainActivity.java:51)
at com.samsung.classification.MainActivity$ExternalSyntheticLambda0.onClick(Unknown Source:2)
at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1485)
at android.widget.AdapterView.performItemClick(AdapterView.java:376)
at android.widget.AbsListView.performItemClick(AbsListView.java:1295)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3571)
at android.widget.AbsListView$3.run(AbsListView.java:4751)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)

Hi @hissain

Is your python code working ok before trying to convert it to .tflite? What example have you used to train the model? Have you used TF Model Maker or a different approach?
The code for inserting the metadata is the same as the one you have provided. Can you share more info about the normalization and the other info for your model that must be added?

Check here some examples with the TF Lite Model Maker that adds the metadata automatically

Here is the example how TF Lite Model Maker is adding the parameters inside the model.

You can se also which are the parameters based on if it is YamnetSpec or BrowserFftSpec

It was working OK in the same Notebook as I have found evaluation score at around 90% accuracy. I was trying to install tflite_model_maker however, it is failing to install because of dependency conflicts with tflite_support. Is there any guideline on it?

Please refer to the issue I am facing. python - ERROR: Cannot install tflite-model-maker (The conflict is caused by other modules) - Stack Overflow
@George_Soloupis

It is an known issue. Please refer to Future of tflite-model-maker and mediapipe-model-maker or take a look a recent example I wrote
Use TensorFlow Lite Model Maker with a custom dataset | by George Soloupis | Nov, 2023 | Medium
Inside there you can find a python notebook with example of using a conda env inside Colad.

Regards

@George_Soloupis your blog provides examples for unix systems. I was trying to run same but tflite model maker installing for indefinite time and storage gets full. Any other suggestions?

@hissain The example is working OK inside a Colab session.
No other suggestions I can think of.

@George_Soloupis can you share any working notebook? I have same issue in colab notebook as well.

Inside the blog post there is a link to a notebook…just before the code snippets

@George_Soloupis could you please help from where can I get the /gdrive/MyDrive/JWick/gun_shot_wav.zip file? I was trying to run the colab and it failed to unzip because I have no zip file in my drive. Here is my notepad copied from your git.

All you need to use is inside the blog post!