Write and read Metadata from a .tflite exported model. For details, see Adding metadata to TensorFlow Lite models

class MetaInfo[source]

MetaInfo(name=None, desc=None, prop=None, prop_type=None, range_min=None, range_max=None, stats_min=None, stats_max=None, associated_files=None)

Metadata information. name: The metadata name. desc: The metadata description. prop: The metadata property. prop_type: The metadata property type. range_min: The metadata min range. range_max: The metadata max range. stats_min: A list of min statistics per channel. stats_max: A list of max statistics per channel. associated_files: A list of associated files.

create_metadata[source]

create_metadata(saved_model_dir, categories_file_path, model_type, model_name, model_version=1)

Write metadata to the Tensowflow Lite model on disk. saved_model_dir: the path to the folder containing the SavedModel categories_file_path: the path to the categories.txt file model_type: the type of the model model_name: the name of the model model_version: the version of the model returns: the model metadata

write_metadata[source]

write_metadata(model_meta, model_path, categories_file_path)

Write metadata to the Tensowflow Lite model on disk. model_meta: the model metadata model_path: the path to the Tensorflow Lite model categories_file_path: the path to the categories.txt file

read_metadata[source]

read_metadata(model_path)

Read meta-data from the Tensowflow Lite model on disk. model_path: the path to the Tensorflow Lite model returns: the metadata in JSON format

Helper Methods

configure_logging[source]

configure_logging(logging_level=20)

Configures logging for the system.

logging_level: The logging level to use.

Run from command line

To run from command line, use the following command: python -m mlcore.tensorflow.tflite_metadata [parameters]

The following parameters are supported:

  • model: The path to the Tensorflow Lite exported model file. (e.g.: datasets/image_object_detection/car_damage/model.tflite)
  • --source: The path to the folder containing the SavedModel. (e.g.: datasets/image_object_detection/car_damage/saved_model)
  • --categories: The categories file to add to the Tensorflow Lite model. (e.g.: datasets/image_object_detection/car_damage/categories.txt)
  • --name: The name of the model. (e.g.: "SSD MobileNetV2")
  • --version: The version of the model, default to 1 (=v1)
  • --type: The type of the model, if not explicitly set try to infer from categories file path.

For reading metadata from a Tensorflow Lite model, set the model parameter. For writing metadata to a Tensorflow Lite model, add corresponding additional parameters (e.g. --source, --categories).