【问题标题】:Error while converting tensorflow model to tensorflow lite (.h5 to .tflite) = ValueError: bad marshal data (unknown type code)将 tensorflow 模型转换为 tensorflow lite(.h5 到 .tflite)时出错 = ValueError: bad marshal data (unknown type code)
【发布时间】:2020-04-13 14:57:00
【问题描述】:

我正在使用基于 keras 和基于 tensorflow 的预训练模型和 yolov2 架构进行坑洼检测,在将 tensorflow 模型转换为 tensorflow lite 时出现错误

from tensorflow.contrib import lite

converter = lite.TFLiteConverter.from_keras_model_file( 'model.h5' )
model = converter.convert()
file = open( 'model.tflite' , 'wb' )
file.write( model )

【问题讨论】:

  • 您知道您的模型中是否有任何 custom_ops 和/或 controlflow 操作?我建议您将 TF2.x 与 converter = tf.compat.v1.lite.TFLiteConverter.from_keras_model_file( 'model.h5' ), converter.experimental_new_converter = True 一起使用。查看TF_website 获取示例。
  • 感谢您的快速回复!不幸的是,那没有用。我得到同样的错误:(
  • 如果你能分享模型文件,我可以帮忙。如果不研究模型,就很难找到根本原因。谢谢

标签: python tensorflow tensorflow-lite yolo


【解决方案1】:

我建议走更长但经过测试的路径。

1) 将您的模型直接转换为.pb 冻结图形格式或使用How to export Keras .h5 to tensorflow .pb?h5 转换为.pb

2) 将.pb 转换为tflite,正如我在此处所述:https://medium.com/@prashantdandriyal7/darknet-to-tensorflow-to-tensorflowlite-b783d55b106a

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 2020-11-21
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多