我想仅使用 C/C++ 接口(interface)保存经过训练的 ClientSession(神经网络)。 (其中我在带有 Visual Studio 2017 的 Windows 10 上使用 tensorflow 1.9 版)
我找到了很多关于如何用 python 来做的信息,但我必须(因此可以)只使用 C++。 在 How to save and restore a TensorFlow graph and its state in C++? 我找到了一些建议,但不幸的是,我的版本中没有针对此示例代码的“重载函数”。
基本上这是我的代码:
Scope scope = Scope::NewRootScope();
...
ClientSession session(scope);
...
TF_CHECK_OK(session.Run({ w1, w2, w3, b1, b2, b3 }, nullptr));
for (int i = 0; i < 100; ++i) {
TF_CHECK_OK(session.Run({ {x, x_data}, {y, y_data} }, { loss }, &outputs));
TF_CHECK_OK(session.Run({ {x, x_data}, {y, y_data} }, { w1, w2, w3, b1, b2, b3, layer_3 }, nullptr));
}
...
// And now I would like to save the session, scope or graph such that I can use it in/on another program/function/system.
提前致谢, 马丁
最佳答案
终于可以回答我自己的问题了。我在网上找到了 2 个“示例代码”: 在这里,可以看到如何保存图表:
在这里,如何恢复图形:
https://github.com/rockzhuang/tensorflow/commit/5b24dfcf7e235bbffd2d60ccf1689b4ecb06c63b
很棒的例子!它对我有用,所以“有兴趣的读者”也可以尝试一下。
关于c++ - 如何使用纯 C++ API 保存和恢复神经网络 (ClientSession)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55686265/