【发布时间】:2021-02-09 08:37:00
【问题描述】:
我正在尝试将 SavedModel 格式的 tensorflow 模型从我的谷歌云存储桶加载到我的云函数中。我正在使用本教程:https://cloud.google.com/blog/products/ai-machine-learning/how-to-serve-deep-learning-models-using-tensorflow-2-0-with-cloud-functions
云函数编译正确。但是,当我向云函数发送 http 请求时,会出现此错误:
Traceback(最近一次调用最后一次):
文件“/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py”,第 402 行,在 run_http_function 结果 = _function_handler.invoke_user_function(flask.request) 文件“/env /local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py”,第 268 行,invoke_user_function 返回 call_user_function(request_or_event) 文件“/env/local/lib/python3.7/site-packages /google/cloud/functions/worker_v2.py”,第 261 行,在 call_user_function 返回 self._user_function(request_or_event) 文件“/user_code/main.py”,第 29 行,在 predict download_blob('', 'firstModel/saved_model.pb ', '/tmp/model/saved_model.pb') 文件“/user_code/main.py”,第 17 行,在 download_blob 存储桶 = storage_client.get_bucket(bucket_name) 文件“/env/local/lib/python3.7/site -packages/google/cloud/storage/client.py”,第 356 行,在 get_bucket bucket = self._bucket_arg_to_bucket(bucket_or_name) 文件“/env/local/lib/python3.7/site-packages/google/cloud/storage/ client.py”,第 225 行,在 _bucket_arg_to_bucket 桶 = Bucket(self, name=bucket_or_name) 文件“/env/local/lib/python3.7/site-packages/google/cloud/storage/bucket.py”,第 581 行,在 init 中 name = _validate_name(name) 文件“/env/local/lib/python3.7/site-packages/google/cloud/storage/_helpers.py”,第 67 行,in _validate_name raise ValueError("bucket names must start and end带有数字或字母。”)ValueError:存储桶名称必须以数字或字母开头和结尾。
我很困惑,因为我的存储桶的标题是一串大约 20 个字符长的字母,没有任何标点符号/特殊字符。
这是我正在运行的一些代码:
if model is None:
download_blob('<terminatorbucket>', 'firstModel/saved_model.pb', '/tmp/model/saved_model.pb')
download_blob('<terminatorbucket>', 'firstModel/assets/tokens.txt', '/tmp/model/assets/tokens.txt')
download_blob('<terminatorbucket>', 'firstModel/variables/variables.index', '/tmp/model/variables/variables.index')
download_blob('<terminatorbucket>', 'firstModel/variables/variables.data-00000-of-00001', '/tmp/model/variables/variables.data-00000-of-00001')
model = tf.keras.models.load_model('/tmp/model')
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
【问题讨论】:
-
"
" 是你的存储桶的名字,带尖括号吗? -
@DougStevenson 是的,我想就是这样。我忘了去掉括号。
标签: python-3.x google-cloud-functions google-cloud-storage tensorflow2.0