I have been debugging this issue for a while now. I have developed an LSTM encoder decoder model which I plan to deploy in C++.
Having saved the model in the .pb file format, I am able to import the model and data and deploy it within python. However, when I try to import the graph using the C++ API, the function TF_GraphImportGraphDef()
returns an error code of TF_NOT_FOUND.
I suspect, this is because I am using the beam search approach and the symbols for the op GatherTree
is not contained with the tensorflow.dll/lib
that I generated using Bazel on windows.
I would like to know if anyone has come across this issue before or have any solutions for this issue.
Would linking to the _beam_search_ops.dll
be a possible solution? I tried that too using the TF_LoadLibrary()
function available in the c_api.h
. However, I was unable to load the library.
Any inputs will be appreciated. Also, I am working with tensorflow version 1.14.
So i dug deeper and managed to find a solution for the following issues which enabled me to load the LSTM encoder decoder saved model successfully with the C++ api:
TF_NOT_FOUND error: The error message read as follows: message: Op type not registered 'GatherTree' in binary running on LAPTOP-5R9P6BHL. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) tf.contrib.resampler
should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed. At this stage, i had only linked the tensorflow.dll and tensorflow.lib to my C++ project. A possible solution was to link the library which contains the definition for Gather Tree op, which was the _beam_search_ops.dll.
_beam_search_ops.dll not found error: This error was observed while trying to load the library using TF_LoadLibrary() from the c_api.h. After looking into some posts on stack overflow, it seemed as if the library is dependant on the python37.dll and _pywrap_tensorflow_internal.pyd libraries. And after linking these two libraries, i was successfully able to load the _beam_search_ops.dll.
TF_INVALID_ARGUMENT error: Even after loading the _beam_search_ops.dll library, the graph import failed with the invalid argument error. On reading the error message, i realized that this was due to the _beam_search_ops.dll and _pywrap_tensorflow_internal.pyd being generated with tensorflow V1.13 and the tensorflow.dll/lib and .pb file being generated with tensorflow V1.14. When i linked the _beam_search_ops.dll and _pywrap_tensorflow_internal.pyd from the tensorflow V1.14 version, the loading of the graph was successful and i was able to read the contents of the graph.
If anyone has got a better solution for this issue, please do post it here. Thank you.