【发布时间】:2019-04-15 09:32:23
【问题描述】:
我想仅使用 C/C++ 接口保存经过训练的 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.
提前致谢, 马丁
【问题讨论】:
-
“可惜我没有“重载函数””是什么意思?在链接的问题中,没有提到这样的事情。
-
嗨 Acorn,感谢您的回复,我尝试使用上面链接中建议的“模板”代码。但是我的版本没有适合代码的重载函数,并且我通过更改函数调用中的元素进行的每个“测试”都不起作用。特别是我的释放接缝的“sess->Run(”与另一个聊天中讨论的不同。
-
我发现“freeze_saved_model.cc”中有一些可能对我有用的函数。但这只是为更高版本 r1.13 准备的,我根本无法创建高于 r1.9 的有效 Windows/C++/VisualStudio 解决方案......我完全按照tensorflow.org/install/source_windows 的说明进行操作,但我可以不要管理它让它运行。我已经看到,在 r1.9 版本中有一个名为“freeze_saved_model_test.cc”的文件,其中包含我需要的功能。有谁知道如何使用测试文件?
标签: c++ tensorflow