如何序列化 protobuf 文件中的图形和值?

How to serialize both the graph and values in a protobuf file?

Tensorflow 附带的 Android 示例下载了 InceptionV3 的 protobuf 文件,其中包含图形和模型的值。在文档中,我只能找到如何序列化图表 (tf.Graph.as_graph_def) 或使用 tf.train.Saver 保存变量值。如何将所有内容保存到一个文件中,就像该示例所做的那样?

我回答过关于这个主题的类似问题:

基本思路是使用tf.import_graph_def() to replace the variables in the original (training) graph with constants, and then write out the resulting GraphDef using tf.Graph.as_graph_def()