如何使用 Google Cloud 上 Tensorflow Training 中的 model.ckpt 文件进行预测? [英] How can I use the model.ckpt Files from Tensorflow Training on Google Cloud for making predictions?
问题描述
我正在使用 Tensorflow 1.15 和 Python 3.7,我是初学者.我在谷歌云上用我自己的数据集训练了一个张量流模型,如下所述:https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_training_and_evaluation.md
I am using Tensorflow 1.15 and Python 3.7 and I am a beginner. I trained a tensorflow model with my own dataset on google cloud as described here: 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 和一个空的 variables 文件夹.到现在为止还挺好.现在我想使用这些文件来使用这个笔记本进行预测:https://colab.research.google.com/github/tensorflow/models/blob/master/research/object_detection/colab_tutorials/object_detection_tutorial.ipynb 但我坚持负载对象检测模型"部分,我总是得到这个
After training my google cloud bucket had listed the model.ckpt files. I saved the model as described here: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/exporting_models.md . Doing this generated some files: checkpoint, frozen_inference_graph.pb, model.ckpt.data-00000-of-00001, model.ckpt.index, model.ckpt.meta, pipeline.config and a folder "saved_model" which contains a file saved_model.pb and an empty variables folder. So far so good. Now I wanted to use these files to make predictions using this notebook: https://colab.research.google.com/github/tensorflow/models/blob/master/research/object_detection/colab_tutorials/object_detection_tutorial.ipynb but I stuck at the "load object detection model" section, I always get this
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/进行预测?
What am I doing wrong? I tried all the possibilities and read dozens of stackoverflow articles but I can't find any usable solution. Is there any other possibility to use the model.ckpt files which were generated by training to make a .h5 / make predictions?
在此先非常感谢您!
推荐答案
首先将saved_model
上传到Google_cloud,并使用下面的代码片段加载saved_model
.
Firstly upload saved_model
on Google_cloud, and use below code snippet to load 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
这篇关于如何使用 Google Cloud 上 Tensorflow Training 中的 model.ckpt 文件进行预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!