Pranathi
Pranathi

Reputation: 31

Fetching TFLite Version information from TFLite model

I have a TFLite Model. How to fetch the version of TFLite used to create the model?

During automation, I was trying to fetch the TFLite Models and running inference over them. Currently , I am using TFLite 2.4.1 library. The models created above this versions which has unsupported operations, need to error out.

What is the best way of handling ? How to get TFLite version from the model.

Upvotes: 2

Views: 3953

Answers (1)

Jae sung Chung
Jae sung Chung

Reputation: 903

The "min_runtime_version" model metadata in the TFLite mode file contains the information that describes the minimal runtime version that is capable of running the given model.

The above value in the TFLite flatbuffer schema can be read by the existing C++ and Python schema libraries. For example,

from tensorflow.lite.python import schema_py_generated as schema_fb

tflite_model = schema_fb.Model.GetRootAsModel(model_buf, 0)

# Gets metadata from the model file.
for i in range(tflite_model.MetadataLength()):
  meta = tflite_model.Metadata(i)
  if meta.Name().decode("utf-8") == "min_runtime_version":
    buffer_index = meta.Buffer()
    metadata = tflite_model.Buffers(buffer_index)
    min_runtime_version_bytes = metadata.DataAsNumpy().tobytes()

References:

Model metadata table in TFLite flatbuffer schema

Upvotes: 1

Related Questions