在官网API和Tensorflow源码头文件中查看获取。
同时参考
https://medium.com/jim-fleming/loading-a-tensorflow-graph-with-the-c-api-4caaff88463f
https://vimsky.com/article/3600.html
1.整体逻辑
/// ```c++ /// tensorflow::GraphDef graph; /// // ... Create or load graph into "graph". /// /// // This example uses the default options which connects /// // to a local runtime. /// tensorflow::SessionOptions options; /// std::unique_ptr<tensorflow::Session> /// session(tensorflow::NewSession(options)); /// /// // Create the session with this graph. /// tensorflow::Status s = session->Create(graph); /// if (!s.ok()) { ... } /// /// // Run the graph and fetch the first output of the "output" /// // operation, and also run to but do not return anything /// // for the "update_state" operation. /// std::vector<tensorflow::Tensor> outputs; /// s = session->Run({}, {"output:0"}, {"update_state"}, &outputs); /// if (!s.ok()) { ... } /// /// // Map the output as a flattened float tensor, and do something /// // with it. /// auto output_tensor = outputs[0].flat<float>(); /// if (output_tensor(0) > 0.5) { ... } /// /// // Close the session to release the resources associated with /// // this session. /// session->Close();
2.代码