【发布时间】:2018-07-18 02:52:31
【问题描述】:
如何将我的 libtensorflow_cc.so 库与我的自定义操作链接,以便我可以在 c++ 中进行培训?我的自定义操作是用 c++ 编写的,使用它的图形是在 python 中计算的。我可以加载 pb 图表,但我无法创建图表。
我在 python 中创建了一个图形并使用 write_graph 保存为一个 protobuf 文件。我的图表使用了一个自定义操作,其内核用 C++ 编写并注册为https://www.tensorflow.org/versions/master/extend/adding_an_op#compile_the_op_using_your_system_compiler_tensorflow_binary_installation。我想在 C++ 中加载我的图表进行训练,图表在没有警告的情况下加载,但是对于“session->Create(graph_def)”我得到一个错误:
Non-OK-status: session->Create(graph_def) status: Not found:
Op type not registered 'MyOp' in binary running on user-linux.
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.
我没有使用来自 tf.contrib 的任何东西。这是我的 c++ 代码的一个更简单的版本:
std::string graph_definition = "Mygraph.pb";
Session* session;
GraphDef graph_def;
SessionOptions opts;
//load graph
TF_CHECK_OK(ReadBinaryProto(Env::Default(), graph_definition, &graph_def));
// create a new session
TF_CHECK_OK(NewSession(opts, &session));
// Load graph into session
TF_CHECK_OK(session->Create(graph_def));
【问题讨论】:
标签: python c++ tensorflow