【问题标题】:How can I use the model.ckpt Files from Tensorflow Training on Google Cloud for making predictions?如何使用来自 Google Cloud 上 TensorFlow 培训的 model.ckpt 文件进行预测?
【发布时间】:2020-09-11 13:58:52
【问题描述】:

我正在使用 Tensorflow 1.15 和 Python 3.7,我是初学者。 我在谷歌云上用我自己的数据集训练了一个张量流模型,如下所述: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_training_and_evaluation.md

训练后,我的谷歌云存储桶列出了 model.ckpt 文件。我按照此处所述保存了模型:https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/exporting_models.md。这样做会生成一些文件:checkpoint、frozen_inference_graph.pb、model.ckpt.data-00000-of-00001、model.ckpt.index、model.ckpt.meta、pipeline.config 和一个文件夹“saved_model”,其中包含一个文件 saved_model .pb 和一个空的变量文件夹。到目前为止,一切都很好。现在我想使用这些文件来使用这个笔记本进行预测:https://colab.research.google.com/github/tensorflow/models/blob/master/research/object_detection/colab_tutorials/object_detection_tutorial.ipynb 但我停留在“加载对象检测模型”部分,我总是得到这个

OSError: SavedModel file does not exist at: home/user/models/research/exported_graphs/saved_model/{saved_model.pbtxt|saved_model.pb}

我做错了什么?我尝试了所有可能性并阅读了数十篇 stackoverflow 文章,但找不到任何可用的解决方案。是否有其他可能使用通过训练生成的 model.ckpt 文件来进行 .h5 / 进行预测?

非常感谢您!

【问题讨论】:

  • 嗨 jojeko1994,欢迎来到 StackOverflow 社区。乍一看,我认为你做的事情是正确的。因此,由于您得到的行为不是预期的行为,并且此时您的错误将难以重现,我们需要更多信息来了解正在发生的事情。这是exporting a SavedModel for prediction using AI Platform 上的完整 Google Cloud 指南。请仔细查看是否有您做的不对的地方。
  • 您能否在问题描述中添加您存储桶中 SavedModel 的完整文件夹/文件结构?我们应该将其与structure of a SavedModel directory 中的进行比较,看看是否有任何差异。您能否也分享一下您遇到的错误的整个日志回溯?

标签: python tensorflow google-cloud-platform object-detection object-detection-api


【解决方案1】:

首先将saved_model上传到Google_cloud,然后使用下面的代码sn-p加载saved_model

def load_model(model_name):
  #path to model directory
  model_dir = "model_directory"

  model_dir = pathlib.Path(model_dir)/"saved_model"

  model = tf.saved_model.load(str(model_dir))

  return model

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 2019-08-09
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    相关资源
    最近更新 更多