我应该如何在 TensorFlow SavedModel 中存储元数据?

gmr*_*gmr 6 tensorflow tensorflow-serving

我们训练了模型的许多变体,这些变体具有不同的配置,并且需要不同的输入预处理(其中预处理是在 TensorFlow 之外完成的)。我想将我们的模型导出为 SavedModels,并且我认为我们将拥有一个 API 服务器,它将提供对模型的访问并处理预处理并使用配置与 TensorFlow 服务器进行通信,该配置将通过 TensorFlow 从模型元数据中检索服务器。模型元数据可能采用 JSON 结构,或者可能使用协议缓冲区。我不清楚这方面的最佳实践是什么。特别是,MetaInfoDef 协议缓冲区具有三个不同的字段,这些字段似乎旨在保存元数据(meta_graph_versionany_infotags)。但除了现场之外,我找不到任何使用任何例子的例子tags

// User specified Version string. Can be the name of the model and revision,
// steps this model has been trained to, etc.
string meta_graph_version = 1;

[...]

// A serialized protobuf. Can be the time this meta graph is created, or
// modified, or name of the model.
google.protobuf.Any any_info = 3;

// User supplied tag(s) on the meta_graph and included graph_def.
//
// MetaGraphDefs should be tagged with their capabilities or use-cases.
// Examples: "train", "serve", "gpu", "tpu", etc.
// These tags enable loaders to access the MetaGraph(s) appropriate for a
// specific use-case or runtime environment.
repeated string tags = 4;
Run Code Online (Sandbox Code Playgroud)

(尽管我不确定这三个字段是否都可以使用 TensorFlow 服务的客户端 API 以相同的方式检索?)

Rak*_*eek 0

使用客户端 API (REST) 提取元数据的命令如下所示

获取http://host:port/v1/models/ ${MODEL_NAME}[/versions/${MODEL_VERSION}]/metadata

/versions/${MODEL_VERSION} 是可选的。如果省略,最新版本的模型元数据将在响应中返回。

您可以在链接中找到更多详细信息,https://www.tensorflow.org/tfx/serving/api_rest/ => 模型元数据 API