【问题标题】:Fetching TFLite Version information from TFLite model从 TFLite 模型中获取 TFLite 版本信息
【发布时间】:2021-06-08 05:17:48
【问题描述】:

我有一个 TFLite 模型。 如何获取用于创建模型的 TFLite 版本?

在自动化过程中,我试图获取 TFLite 模型并对其进行推理。目前,我正在使用 TFLite 2.4.1 库。在此版本之上创建的模型有不支持的操作,需要报错。

最好的处理方式是什么? 如何从模型中获取 TFLite 版本。

【问题讨论】:

    标签: tensorflow tensorflow2.0 tensorflow-lite


    【解决方案1】:

    TFLite 模式文件中的“min_runtime_version”模型元数据包含描述能够运行给定模型的最小运行时版本的信息。

    TFLite flatbuffer 模式中的上述值可以被现有的 C++ 和 Python 模式库读取。例如,

    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()
    

    参考资料:

    Model metadata table in TFLite flatbuffer schema

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      • 2020-07-13
      • 2023-01-31
      • 2022-01-05
      • 1970-01-01
      • 2021-07-08
      相关资源
      最近更新 更多