首页 > 解决方案 > 有没有办法在 C++ 中保存冻结的张量流图?

问题描述

我知道您可以使用 Python 将模型保存到检查点或 SavedModel 中。我想知道是否有办法使用 C++ 保存从 FreezeSavedModel C++ 函数返回的 GraphDef。谢谢!

标签: c++tensorflow

解决方案


函数 FreezeSavedModel 返回一个GraphDef -Object。您可以使用WriteBinaryProtoWriteTextProto保存此对象

//BinaryProto
const string binary_file = io::JoinPath(testing::TmpDir(), "binary_graph.pb");
TF_ASSERT_OK(WriteBinaryProto(Env::Default(), binary_file, graph_def));

//Textproto
const string text_file = io::JoinPath(testing::TmpDir(), "text_graph.pbtxt");
TF_ASSERT_OK(WriteTextProto(Env::Default(), text_file, graph_def));

您可以在file_utils_test.cc中找到一个示例


推荐阅读