3

我想将整数量化的tflite模型转换为 Tensorflow 中的冻结图(.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 模型。我被困在第二个箭头上。

4

1 回答 1

2

在 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

是来源。

于 2020-07-21T05:27:17.217 回答