简体   繁体   English

在ML引擎上进行训练后,获取save_model.pb的路径

[英]Get the path of saved_model.pb after training on ML engine

I have been using the python client API of ML engine to create training jobs of some canned estimators. 我一直在使用ML引擎的python客户端API创建一些罐头估算器的培训工作。 What I'm not able to do is get the path of the saved_model.pb on GCS because the path it is stored in has a timestamp as a dir name. 我无法执行的操作是在GCS上获取save_model.pb的路径,因为它存储在的路径中有一个时间戳作为dir名称。 Is there anyway I can get this using a regular expression or something on python client, so that I'll be able to deploy the model with correct path. 无论如何,我可以使用正则表达式或python客户端上的东西来获得它,以便我能够使用正确的路径部署模型。

The path seems to be in this format right now - 该路径现在似乎采用这种格式-

gs://bucket_name/outputs/export/serv/ timestamp /saved_model.pb gs:// bucket_name / outputs / export / serv / timestamp /saved_model.pb


UPDATE UPDATE

Thanks shahin for the answer. 感谢shahin的答案。 So I wrote this, which gives me the exact path that I can pass to the deploy_uri for ml engine. 所以我写了这个,这给了我确切的路径,可以传递给ml引擎的deploy_uri。

from google.cloud import storage

def getGCSPath(prefix):
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    mlist = bucket.list_blobs(prefix=prefix)
    for line in mlist:
        if 'saved_model.pb' in line.name:
            return line.name[:-14]

# print getGCSPath('output/export/serv/')

Use gsutil and tail: 使用gsutil和tail:

MODEL_LOCATION=$(gsutil ls gs://${BUCKET}/outputs/export/serv | tail -1)
gcloud ml-engine models create ${MODEL_NAME} --regions $REGION
gcloud ml-engine versions create ${MODEL_VERSION} --model ${MODEL_NAME} --origin ${MODEL_LOCATION} --runtime-version $TFVERSION
import os
import cloudstorage as gcs
bucket = os.environ.get('BUCKET')
page_size = 1
stats = gcs.listbucket(bucket + '/outputs/export/serv', max_keys=page_size)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确创建saved_model.pb? - How to correctly create saved_model.pb? 将 tf1.x saved_model.pb 重新保存到新的 tf2.0 saved_model.pb - resave tf1.x saved_model.pb into new tf2.0 saved_model.pb 将 saved_model.pb 转换为 model.tflite - Converting saved_model.pb to model.tflite 如何从 tf.Session 保存到 saved_model.pb? - How to save to saved_model.pb from tf.Session? OSError:SavedModel 文件不存在于:/content\model\2016/{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: /content\model\2016/{saved_model.pbtxt|saved_model.pb} frozen_inference_graph.pb 和saved_model.pb 有什么区别? - What is difference frozen_inference_graph.pb and saved_model.pb? SavedModel 文件不存在于:model.h5/{saved_model.pbtxt|saved_model.pb} - SavedModel file does not exist at: model.h5/{saved_model.pbtxt|saved_model.pb} 为什么 saved_model_cli 有效而加载 saved_model.pb 无效? - Why saved_model_cli works and loading saved_model.pb does not? OSError:SavedModel 文件不存在于:cnnCat2.h5\{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: cnnCat2.h5\{saved_model.pbtxt|saved_model.pb} 无法将保存的 EfficientDet 模型 saved_model.pb 转换为 tflite 格式 - Fail to convert saved EfficientDet model saved_model.pb to tflite format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM