Load Tensorflow Graph from file then convert to pb or TFLite

I have a tensorflow model file model.dat. It was trained by others so I know nothing about the model itself (model format and tensorflow version etc.) I only have the inference code and it can work fine.

Now I need to convert this model to TFlite for usage on Android. But I can’t find a way to do it.

Here’s part of inference code.

TF_Buffer *buffer;
buffer = ReadBufferFromFile("model.dat");
TF_Graph *graph = TF_NewGraph();
TF_Status *status = TF_NewStatus();
TF_ImportGraphDefOptions *opts = TF_NewImportGraphDefOptions();
TF_GraphImportGraphDef(graph, buffer, opts, status);

So I have TF_Graph loaded. But I cannot find the export function. How can I save the graph as, for example a pb file, So that I can convert to TFLite from it ?

Hi, @huqq1234

I apologize for the delayed response, if I’m not wrong that model may be trained with TensorFlow 1.x.x version which currently we do not support officially. TensorFlow SavedModel format primary supported file format in 2.x.x if you’re looking freezing that model using the C API not the C++ API GraphDef is still a component within SavedModel format but it’s no longer independently supported for saving models.

If you want to give it try with C++ API then please refer this article and also please refer C API for TensorFlow which contains declarations for all available functions. You can inspect these headers to see the available functions and their signatures.

Thank you for your cooperation and patience.