Should TensorFlow users prefer SavedModel over Checkpoint or 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 Variable
s to save, or by default saves all (non-local) Variables.
要使用检查点,您需要有一个兼容的 TensorFlow Graph
,其 Variable
与 Variable
的名称相同检查站.(如果您没有兼容的 Graph
,您仍然可以使用 init_from_checkpoint
contrib 中的实用程序.)
To use a checkpoint, you need to have a compatible TensorFlow Graph
, whose Variable
s have the same names as the Variable
s in the checkpoint. (If you don't have a compatible Graph
, you can still load the values stored in a checkpoint into selected Variable
s using the init_from_checkpoint
utilities in contrib.)
SavedModel
更加全面:它包含一组 Graph
(MetaGraph
s,实际上,保存集合等),以及应该与这些Graph
s兼容的检查点,以及运行模型所需的任何资产文件(例如词汇文件).对于它包含的每个 MetaGraph
,它还存储一组签名.签名定义(命名)输入和输出张量.
SavedModel
is much more comprehensive: It contains a set of Graph
s (MetaGraph
s, in fact, saving collections and such), as well as a checkpoint which is supposed to be compatible with these Graph
s, 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
基础教程推荐
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++,'if' 表达式中的变量声明 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01