[英]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.