I have a big model defined using Tensorflow 2 with Keras. The model works well in Python. Now, I want to import it into C++ project.
Inside my C++ project, I use TF_GraphImportGraphDef function.
It works well if I prepare *.pb file using the following code:
with open('load_model.pb', 'wb') as f:
f.write(tf.compat.v1.get_default_graph().as_graph_def().SerializeToString())
I've tried this code on a simple network written using Tensorflow 1 (using tf.compat.v1.* functions). It works well.
Now I want to export my big model (mentioned at the beginning, written using Tensorflow 2) to the C++ project. To do this, I need to get a Graph or GraphDef object from my model. The question is: how to do this? I didn't find any property or function to get it.
I've also tried to use tf.saved_model.save(model, 'model') to save the whole model. It generates a directory with different files including saved_model.pb file. Unfortunately, when I try to load this file in C++ using TF_GraphImportGraphDef function, the program throws an exception.