問題描述
來自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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!