TensorFlow 用户是否应该更喜欢 SavedModel 而不是 C

Should TensorFlow users prefer SavedModel over Checkpoint or GraphDef?(TensorFlow 用户是否应该更喜欢 SavedModel 而不是 Checkpoint 或 GraphDef?)

本文介绍了TensorFlow 用户是否应该更喜欢 SavedModel 而不是 Checkpoint 或 GraphDef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自SavedModel Docs,

SavedModel,TensorFlow 模型的通用序列化格式.

SavedModel, the universal serialization format for TensorFlow models.

SavedModel 包装了一个 TensorFlow Saver.Saver 主要用于生成变量检查点.

SavedModel wraps a TensorFlow Saver. The Saver is primarily used to generate the variable checkpoints.

根据我的理解,如果有人想使用 TensorFlow Serving,SavedModel 是必须的.但是,我可以在没有 SavedModel 的情况下将 Tensorflow 模型部署到服务服务器:冻结图形并将其导出为 GraphDef,并使用 ReadBinaryProto 和创建在 C++ 或 在 Go 中导入.

From my understanding, SavedModel is must if someone wants use TensorFlow Serving. However, I can deploy Tensorflow Model to service server without SavedModel: Freeze graph and export it as GraphDef, and load graph into Session using ReadBinaryProto and Create in C++ or Import in Go.

SavedModel 的目的是什么?用户是否应该更喜欢 SavedModel 而非 Checkpoint 或 GraphDef 来聚合更多与模型相关的数据?

What is the purpose of SavedModel? Should users prefer SavedModel over Checkpoint or GraphDef to aggregate more data related to the model?

推荐答案

检查点包含 TensorFlow 模型中(部分)变量的值.它由 Saver 创建,其中要么指定要保存的特定 Variable ,要么默认保存所有(非本地)变量.

A checkpoint contains the value of (some of the) variables in a TensorFlow model. It is created by a Saver, which is either given specific Variables to save, or by default saves all (non-local) Variables.

要使用检查点,您需要有一个兼容的 TensorFlow Graph,其 VariableVariable 的名称相同检查站.(如果您没有兼容的 Graph,您仍然可以使用 init_from_checkpoint contrib 中的实用程序.)

To use a checkpoint, you need to have a compatible TensorFlow Graph, whose Variables have the same names as the Variables in the checkpoint. (If you don't have a compatible Graph, you can still load the values stored in a checkpoint into selected Variables using the init_from_checkpoint utilities in contrib.)

SavedModel 更加全面:它包含一组 Graph (MetaGraphs,实际上,保存集合等),以及应该与这些Graphs兼容的检查点,以及运行模型所需的任何资产文件(例如词汇文件).对于它包含的每个 MetaGraph,它还存储一组签名.签名定义(命名)输入和输出张量.

SavedModel is much more comprehensive: It contains a set of Graphs (MetaGraphs, in fact, saving collections and such), as well as a checkpoint which is supposed to be compatible with these Graphs, and any asset files that are needed to run the model (e.g. Vocabulary files). For each MetaGraph it contains, it also stores a set of signatures. Signatures define (named) input and output tensors.

这意味着只要给定一个 SavedModel,您就可以编写工具(例如 tensorflow/serving,或将出现在 中的新 saved_model 命令行实用程序工具/ 很快)解释或执行里面的图形.您只需要提供数据即可.

This means that given only a SavedModel, you can write tools (such as tensorflow/serving, or the new saved_model command line utility that will appear in tools/ shortly) that interpret or execute the graphs inside. All you have to provide is the data.

如果有疑问,我总是会在编写 SavedModel 方面犯错,而不仅仅是一个检查点.这不仅允许您使用 tensorflow/serving(以及其他数量会增加的简洁实用程序),它还确保您拥有运行模型所需的所有信息.没有什么比检查点更令人沮丧的了,您无法再使用它,因为您修改了模型,现在它与检查点文件不兼容,您要做的就是通过它运行一些预测以进行比较.

If in doubt, I would always err on the side of writing a SavedModel, not just a checkpoint. Not only does this allow you to use tensorflow/serving (and other neat utilities that will grow in number), it makes sure that you have all the information necessary to run the model. Nothing is more frustrating than a checkpoint you cannot use any more because you modified your model and now it is incompatible with checkpoint files and all you want to do is run some predictions through it for comparison.

这篇关于TensorFlow 用户是否应该更喜欢 SavedModel 而不是 Checkpoint 或 GraphDef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:TensorFlow 用户是否应该更喜欢 SavedModel 而不是 C

基础教程推荐