3

Is it possible to convert tflite model to pb model?

I have seen many articles about converting "pb->tflite", but no chance to find "tflite->pb".

If it is not possible, is there any way I can do the quantization with only tflite file?

(so far, I noticed that tf.lite.TFLiteConverter.from_saved_model() only accepts pb file, and that is why I am trying to convert tflite to pb).

Any hint or suggestions will be great!

Thanks

Jyoona
  • 33
  • 4
  • 1
    Unfortunately, this is not (easily) possible or officially supported. The TensorFlow Lite team has looked into supporting this, but it's generally better to use the original TensorFlow graph if you can. Note that TensorFlow also doesn't yet support native quantized graph execution, so if you're trying to reverse-convert a model that used TensorFlow Lite quantization tooling during conversion to Lite, that would be problematic. – jdduke Apr 23 '21 at 16:00
  • I guess I need to try the original TensorFlow graph to do the quantization. Thanks for letting me know! – Jyoona Apr 26 '21 at 03:22

1 Answers1

0

First of all, there is no official TensorFlow API to support the conversion from tflite to graphdef (pb) file as jdduke@ described in the above section.

Actually, there are two TensorFlow graph serialization formats, that are using the "pb" extension:

(1) Saved Model (recommended) - Exporting the given TF graph to the saved model is possible in both TF version one and two. The saved model format is not simple and usually is represented as a directory. In the saved model directory, it consists the following files including the "pb" file:

  • saved_model.pb (or sometimes saved_model.pbtxt)
  • variables/variables.index
  • variables.data-00000-of-00001

You can provide the directory name of the above file location into the tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) to convert the saved model format to the corresponding TFLite model file.

(2) Graph def serialized file (deprecated) - The graph def serialized file is a TF v1 stuff and deprecated. The graph def file is stored with the "pb" extension at most of times. In such case, you can use tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(...) to convert.

The meaning of the "pb" keyword is the "protobuf", which is a binary serialization format that is being used in the TensorFlow product. So, there are possibilities that the "pb" files in the TensorFlow can carry different things per context.

Jae sung Chung
  • 835
  • 1
  • 6
  • 7