- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们训练了模型的许多变体,这些变体具有不同的配置,并且需要不同的输入预处理(其中预处理是在 TensorFlow 之外完成的)。我想将我们的模型导出为 SavedModels,并且我认为我们将拥有一个 API 服务器,它将提供对模型的访问并处理预处理并使用配置与 TensorFlow 服务器进行通信,该配置将通过 TensorFlow 从模型元数据中检索服务器。模型元数据可能采用 JSON 结构,或者可能使用 Protocol Buffer 。我不清楚这方面的最佳实践是什么。特别是,MetaInfoDef Protocol Buffer 具有三个不同的字段,这些字段似乎旨在保存元数据(meta_graph_version
、any_info
和 tags
)。但除了 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;
(尽管我不确定这三个字段是否都可以使用 TensorFlow 服务的客户端 API 以相同的方式检索?)
最佳答案
@gmr,通过 tf.add_to_collection 将原型(prototype)添加到集合中,以及 builder.add_meta_graph_and_variables 应该可以解决您的问题。
下面提到了相同的代码:
# Mention the path below where you want the model to be stored
export_dir = "/usr/local/google/home/abc/Jupyter_Notebooks/export"
tf.gfile.DeleteRecursively(export_dir)
tf.reset_default_graph()
# Check below for other ways of adding Proto to Collection
tf.add_to_collection("my_proto_collection", "my_proto_serialized")
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
with tf.Session() as session:
builder.add_meta_graph_and_variables(
session,
tags=[tf.saved_model.tag_constants.SERVING])
builder.save()
将原型(prototype)添加到集合的其他方式的代码如下所示:
tf.add_to_collection("your_collection_name", str(your_proto))
或
any_buf = any_pb2.Any()
tf.add_to_collection("your_collection_name",
any_buf.Pack(your_proto))
.pb 文件,saved_model.pb,保存在您提到的路径 (export_dir) 中,如下所示:
{ # (tensorflow.SavedModel) size=89B
saved_model_schema_version: 1
meta_graphs: { # (tensorflow.MetaGraphDef) size=85B
meta_info_def: { # (tensorflow.MetaGraphDef.MetaInfoDef) size=29B
stripped_op_list: { # (tensorflow.OpList) size=0B
} # meta_graphs[0].meta_info_def.stripped_op_list
tags : [ "serve" ] # size=5
tensorflow_version : "1.13.1" # size=9
tensorflow_git_version: "unknown" # size=7
} # meta_graphs[0].meta_info_def
graph_def: { # (tensorflow.GraphDef) size=4B
versions: { # (tensorflow.VersionDef) size=2B
producer : 23
} # meta_graphs[0].graph_def.versions
} # meta_graphs[0].graph_def
collection_def: { # (tensorflow.MetaGraphDef.CollectionDefEntry) size=46B
key : "my_proto_collection" # size=19
value: { # (tensorflow.CollectionDef) size=23B
bytes_list: { # (tensorflow.CollectionDef.BytesList) size=21B
value: [ "my_proto_serialized" ] # size=19
} # meta_graphs[0].collection_def[0].value.bytes_list
} # meta_graphs[0].collection_def[0].value
} # meta_graphs[0].collection_def[0]
} # meta_graphs[0]
}
关于tensorflow - 我应该如何在 TensorFlow SavedModel 中存储元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54271098/
我正在阅读 documentation和 TensorflowJS 转换器的源代码,它明确区分了 Keras SavedModel 和 Tensorflow SavedModel。 格式之间有什么区别
我有一个 Tensorflow R1.13 训练代码,它在长时间的训练运行期间定期保存一个 SavedModel(我正在关注关于该主题的优秀 article)。我注意到每次保存模型时,尺寸都会增加。事
我在Docker上运行了Tensorflow SavedModel。我在Docker Quickstart Terminal中使用了以下命令,它可以正常工作,为我提供了预测和概率。 curl -d'{
我写了下面的代码,它假设加载一个模型,然后对来自 MNIST 数据集的元素进行预测运行。在执行开始时,代码工作正常,我得到了我想要的预测,但突然间我确实收到了以下错误,我不确定这是否与 .predic
我刚刚完成模型的训练,却发现我导出的服务模型存在签名问题。我如何更新它们? (一个常见问题是为 CloudML Engine 设置错误的形状)。 最佳答案 别担心——您不需要重新训练您的模型。也就是说
我刚刚完成模型的训练,却发现我导出的服务模型存在签名问题。我如何更新它们? (一个常见问题是为 CloudML Engine 设置错误的形状)。 最佳答案 别担心——您不需要重新训练您的模型。也就是说
我有几个关于 SavedModel 的问题API,其documentation我发现很多细节无法解释。 前三个问题是关于传递给 add_meta_graph_and_variables() 的参数的内
我微调了来自 Tensorflow hub 的 BERT 模型,以构建一个简单的情绪分析器。该模型训练并运行良好。在导出时,我简单地使用了: tf.saved_model.save(模型, expor
如果我使用 tensorflow.saved_model.save 保存我的模型SavedModel 格式的函数,之后如何检索此模型中使用了哪些 Tensorflow Ops。由于模型可以恢复,所以这
更新:请参阅我自己对这个问题的回答。这是tensorflow Efficientnet的一个bug 我想做什么 我想微调高效网络。首先,我成功完成了训练并保存了一个模型。它由一个卡住的高效网络和全连接
我们训练了模型的许多变体,这些变体具有不同的配置,并且需要不同的输入预处理(其中预处理是在 TensorFlow 之外完成的)。我想将我们的模型导出为 SavedModels,并且我认为我们将拥有一个
我已经导出了一个 SavedModel,现在我可以将其重新加载并进行预测。它使用以下特征和标签进行训练: F1 : FLOAT32 F2 : FLOAT32 F3 : FLOAT32 L1 : FLO
我正在尝试对使用 SavedModel 加载的模型进行对抗性攻击API。我想针对给定目标的模型损失对输入进行梯度下降。代码有点长,但它是说明问题的最低限度。 from __future__ impor
我已经构建了一个系统,该系统利用 Google ML Engine 使用简单的平面 CNN 架构(从优秀的 WildML post 借用)来训练各种文本分类器。我还大量利用了现有的 ML Engine
我训练了一个用于图像分类的经典 CNN(预训练移动网络)。我现在想在 C++ 中使用这个模型。根据我的理解,我需要创建一个模型库,它可以接受输入并返回其输出。我将模型保存为 .pb (SavedMod
我在将 Keras 生成的顺序模型保存为 SavedModel 格式时遇到问题。 正如 https://www.tensorflow.org/guide/keras/save_and_serializ
我正在尝试优化用于推理的已保存图表,以便我可以在 Android 中使用它。 我第一次尝试使用 optimize_for_inference 脚本失败了 google.protobuf.message
我成功训练了 TensowFlow 增强树估计器。现在我想将其保存为 SavedModel。问题是我收到以下错误。 ValueError: All feature_columns must be _F
我正在尝试在 TensorFlow 2 中运行我以 SavedModel 格式准备的对象检测模型。 该模型采用字节编码 JPEG、PNG 或 GIF 格式作为 encoded_image_string
我想使用 MMdnn将 tensorflow ResNet 模型转换为其他框架。看来我只能使用 mmconvert 从 .pb 卡住图形文件中读取。 但是,当使用 tf.estimator.Estim
我是一名优秀的程序员,十分优秀!