简体   繁体   中英

How to Save and Restore a Neural Network (ClientSession) with a purly C++ API?

I would like to save a trained ClientSession (neural network) only with a C/C++ interface. (wherein I use tensorflow release 1.9 on Windows 10 with Visual Studio 2017)

I found a lot of information how to do it with python, but I have to (therefore can) use only C++. At How to save and restore a TensorFlow graph and its state in C++? I found some advice, but unfortunately I have no "overloaded function" for this example code in my release.

Basically this is my code:

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.

Thanks in advance, Martin

Finally, I can answer my own question. I found 2 "example codes" online: Here, one can see how to save a graph:

https://github.com/rockzhuang/tensorflow/commit/fb6a6f4e3dd6e663a14b672ab5c616d968d62bc5#diff-a46c94d7dc93c6f7a3b632dc14e46479

and here, how to restore the graph:

https://github.com/rockzhuang/tensorflow/commit/5b24dfcf7e235bbffd2d60ccf1689b4ecb06c63b

Awesome examples! It worked for me, so "the interested reader" may try it too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM