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"
_INPUT_NORM_STD = 128.0
_INPUT_NORM_MEAN = 128.0
writer = ImageClassifierWriter.create_for_inference(
writer_utils.load_file(tflite_path), [_INPUT_NORM_MEAN], [_INPUT_NORM_STD],
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.