Search code examples
tensorflow-litequantization

Is it possible to convert tflite to pb?


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


Solution

  • 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.