【问题标题】:How to convert a tflite model into a frozen graph (.pb) in Tensorflow?如何将 tflite 模型转换为 Tensorflow 中的冻结图 (.pb)?
【发布时间】:2020-07-20 13:24:51
【问题描述】:

我想在 Tensorflow 中将整数量化 tflite 模型转换为 冻结图 (.pb)。我在 StackOverflow 上通读并尝试了许多解决方案,但都没有奏效。具体来说,toco 不起作用(output_format 不能是 TENSORFLOW_GRAPHDEF)。

我的最终目标是通过tf2onnx得到一个量化的ONNX模型,但是tf2onnx不支持tflite作为输入(只支持save_model、checkpoint和graph_def)。但是,使用 TFLiteConverter 对训练好的模型进行量化后,它只返回一个 tflite 文件。这就是问题出现的地方。

理想的流程本质上是这样的:float32 中的 tf 模型 -> int8 中的 tflite 模型 -> graph_def -> onnx 模型。我被第二个箭头卡住了。

【问题讨论】:

    标签: tensorflow quantization onnx tensorflow-lite


    【解决方案1】:

    在 Tensorflow 版本 r1.9 之后,将 tflite 模型转换为 .pb 的功能已被删除。尝试将您的 TF 版本降级到 1.9,然后像这样

    bazel run --config=opt \
      //tensorflow/contrib/lite/toco:toco -- \
      --input_file=/tmp/foo.tflite \
      --output_file=/tmp/foo.pb \
      --input_format=TFLITE \
      --output_format=TENSORFLOW_GRAPHDEF \
      --input_shape=1,128,128,3 \
      --input_array=input \
      --output_array=MobilenetV1/Predictions/Reshape_1
    

    Here 是来源。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 2018-09-03
      • 1970-01-01
      • 2021-06-11
      • 2019-05-06
      • 2019-11-28
      • 2018-01-08
      相关资源
      最近更新 更多