Thumbnail article
No metadata found in this model on android studio
TensorFlow Lite metadata provides standard representations for metadata that are useful when training machine learning models with TensorFlow. TensorFlow Lite Model Metadata contains semantics for general model information, inputs/outputs, and associated files, which makes the model self-descriptive and exchangeable.When entering the tflite model into the android studio project, there is often an error No metadata found in this model. Then, what is the solution to solve this problem?To solve the No metadata found in this model error, that is by adding metadata to the tflite model. The following is the code used to add metadata to the tflite model.
from tflite_support.metadata_writers import image_classifier
from tflite_support.metadata_writers import writer_utils

ImageClassifierWriter = image_classifier.MetadataWriter

_SAVE_TO_PATH = "metadata.tflite"

writer = ImageClassifierWriter.create_for_inference(
    writer_utils.load_file(tflite_path), [_INPUT_NORM_MEAN], [_INPUT_NORM_STD],


writer_utils.save_file(writer.populate(), _SAVE_TO_PATH)
ImageClassifierWriter function is used to write metadata into the model. _SAVE_TO_PATH = “metadata.tflite” is used to save a file with the file name apple_metadata1.tflite. _INPUT_NORM_STD and _INPUT_NORM_MEAN are parameters used to normalize image data. writer.get_metadata_json() to verify the metadata generated by the metadata writer. writer.populate() is used to populate metadata to the model.TensorFlow Lite Model Metadata is a standard model description format. It contains rich semantics for general model information, inputs/outputs, and associated files, which makes the model self-descriptive and exchangeable. The Metadata model is currently used in the following two primary use cases:
  • Enable easy model inference using TensorFlow Lite Task Library and codegen tools. Model Metadata contains the mandatory information required during inference, such as label files in image classification, sampling rate of the audio input in audio classification, and tokenizer type to process input string in Natural Language models.
  • Enable model creators to include documentation, such as a description of model inputs/outputs or how to use the model. Model users can view these documentation via visualization tools such as Neutron.

Similar Posts


    1. Saidatul Arifah says:

      The code is placed in the line after saving the model to h5 file precisely after converting to tflite format. This is an example of the code placement.“model.h5”)

      tflite_path = “model.tflite”

      converter = tf.lite.TFLiteConverter.from_keras_model(model)
      tflite_model = converter.convert()

      with open(tflite_path, ‘wb’) as f:

      label_path = “label.txt”
      labels = [‘Label1’, ‘Label2’, ‘Label3’]

      with open(label_path, ‘w’) as f :

      #Put the code in here

Leave a Reply

Your email address will not be published. Required fields are marked *