将图形(pb)转换为SavedModel以获取gcloud ml-engine预测

问题描述 投票:4回答:2

我根据recent post by Google’s Derek Chow on the Google Cloud Big Data And Machine Learning Blog使用Cloud Machine Learning Engine训练了一个物体探测器,现在想要使用Cloud Machine Learning Engine进行预测。

这些指令包括将Tensorflow图导出为output_inference_graph.pb的代码,但不包括如何将protobuf格式(pb)转换为gcloud ml-engine预测所需的SavedModel格式。

我回顾了answer by Google’s @rhaertel80如何转换“Tensorflow For Poets”图像分类模型和answer provided by Google’s @MarkMcDonald如何转换“Tensorflow for Poets 2”图像分类模型,但似乎都不适用于描述的对象检测器图形(pb)博客文章。

如何转换该对象检测器图(pb)以便可以使用它或gcloud ml-engine预测,好吗?

tensorflow object-detection google-cloud-ml google-cloud-ml-engine
2个回答
2
投票

SavedModel在其MetaGraphDef中包含一个structure。要从python中的GraphDef创建SavedModel,您可能希望使用链接中所述的构建器。

export_dir = ...
...
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
with tf.Session(graph=tf.Graph()) as sess:
  ...
  builder.add_meta_graph_and_variables(sess,
                                       [tag_constants.TRAINING],
                                       signature_def_map=foo_signatures,
                                       assets_collection=foo_assets)
...
with tf.Session(graph=tf.Graph()) as sess:
  ...
  builder.add_meta_graph(["bar-tag", "baz-tag"])
...
builder.save()

0
投票

这篇文章救了我!希望能帮到那些来这里的人。我用的方法导出成功的qazxsw poi

https://stackoverflow.com/a/48102615/6124383

https://github.com/tensorflow/tensorflow/pull/15855/commits/81ec5d20935352d71ff56fac06c36d6ff0a7ae05
© www.soinside.com 2019 - 2024. All rights reserved.