TensorFlow用户应该使用SavedModel而不是Checkpoint或GraphDef吗? [英] Should TensorFlow users prefer SavedModel over Checkpoint or GraphDef?

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

问题描述

来自 SavedModel文档


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.

据我了解, SavedModel 。但是,我可以在没有 SavedModel 的情况下将Tensorflow Model部署到服务服务器:冻结图并将其导出为 GraphDef 并加载图使用 ReadBinaryProto 在C ++中创建或在导入

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 ,其 Variable 具有与检查点中的 Variable 相同的名称。 (如果您没有兼容的 Graph ,则仍可以将存储在检查点中的值加载到选定的 Variable 使用 init_from_checkpoint 实用工具。)

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 s( MetaGraph s,实际上是在保存集合等) ,以及应该与这些 Graph 兼容的检查点,以及运行模型所需的任何资产文件(例如,词汇表文件)。对于它包含的每个 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 命令行实用程序,将很快出现在 tools / 中),用于解释或执行其中的图形。您只需要提供数据即可。

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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆